mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-02-06 02:52:07 +08:00
Move psk-key to own file.
This commit is contained in:
@@ -44,7 +44,8 @@ set (MOSQ_SRCS
|
||||
persist_write_v5.c persist_write.c
|
||||
persist.h
|
||||
plugin.c plugin_v4.c plugin_v3.c plugin_v2.c
|
||||
plugin_connect.c plugin_disconnect.c plugin_extended_auth.c plugin_message.c plugin_public.c plugin_tick.c
|
||||
plugin_connect.c plugin_disconnect.c plugin_extended_auth.c plugin_message.c
|
||||
plugin_psk_key.c plugin_public.c plugin_tick.c
|
||||
property_broker.c
|
||||
../lib/property_mosq.c ../lib/property_mosq.h
|
||||
read_handle.c
|
||||
|
||||
@@ -63,6 +63,7 @@ OBJS= mosquitto.o \
|
||||
plugin_disconnect.o \
|
||||
plugin_extended_auth.o \
|
||||
plugin_message.o \
|
||||
plugin_psk_key.o \
|
||||
plugin_public.o \
|
||||
plugin_tick.o \
|
||||
read_handle.o \
|
||||
@@ -283,6 +284,9 @@ plugin_extended_auth.o : plugin_extended_auth.c ../include/mosquitto_plugin.h mo
|
||||
plugin_message.o : plugin_message.c ../include/mosquitto_plugin.h mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
plugin_psk_key.o : plugin_psk_key.c ../include/mosquitto_plugin.h mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
plugin_public.o : plugin_public.c ../include/mosquitto_plugin.h mosquitto_broker_internal.h
|
||||
${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
115
src/plugin_psk_key.c
Normal file
115
src/plugin_psk_key.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
Copyright (c) 2011-2021 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License 2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mosquitto_broker.h"
|
||||
#include "mosquitto_broker_internal.h"
|
||||
#include "mosquitto_plugin.h"
|
||||
#include "memory_mosq.h"
|
||||
#include "lib_load.h"
|
||||
#include "utlist.h"
|
||||
|
||||
static int plugin__psk_key_get(struct mosquitto__security_options *opts, struct mosquitto *context, const char *hint, const char *identity, char *key, int max_key_len)
|
||||
{
|
||||
struct mosquitto_evt_psk_key event_data;
|
||||
struct mosquitto__callback *cb_base;
|
||||
int rc;
|
||||
int rc_final = MOSQ_ERR_SUCCESS;
|
||||
|
||||
DL_FOREACH(opts->plugin_callbacks.psk_key, cb_base){
|
||||
memset(&event_data, 0, sizeof(event_data));
|
||||
event_data.client = context;
|
||||
event_data.hint = hint;
|
||||
event_data.identity = identity;
|
||||
event_data.key = key;
|
||||
event_data.max_key_len = max_key_len;
|
||||
rc = cb_base->cb(MOSQ_EVT_PSK_KEY, &event_data, cb_base->userdata);
|
||||
if(rc == MOSQ_ERR_PLUGIN_IGNORE){
|
||||
/* Do nothing */
|
||||
}else if(rc == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_PLUGIN_DEFER;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
return rc_final;
|
||||
}
|
||||
|
||||
|
||||
int mosquitto_psk_key_get(struct mosquitto *context, const char *hint, const char *identity, char *key, int max_key_len)
|
||||
{
|
||||
int rc;
|
||||
int rc_final = MOSQ_ERR_SUCCESS;
|
||||
|
||||
/* Global plugins */
|
||||
if(db.config->security_options.plugin_callbacks.psk_key){
|
||||
rc = plugin__psk_key_get(&db.config->security_options, context,
|
||||
hint, identity, key, max_key_len);
|
||||
|
||||
if(rc == MOSQ_ERR_PLUGIN_IGNORE){
|
||||
/* Do nothing */
|
||||
}else if(rc == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_PLUGIN_DEFER;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/* Per listener plugins */
|
||||
if(db.config->per_listener_settings){
|
||||
if(context->listener == NULL){
|
||||
return MOSQ_ERR_AUTH;
|
||||
}
|
||||
if(context->listener->security_options.plugin_callbacks.psk_key){
|
||||
rc = plugin__psk_key_get(&context->listener->security_options, context,
|
||||
hint, identity, key, max_key_len);
|
||||
|
||||
if(rc == MOSQ_ERR_PLUGIN_IGNORE){
|
||||
/* Do nothing */
|
||||
}else if(rc == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_PLUGIN_DEFER;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rc = mosquitto_psk_key_get_default(context, hint, identity, key, max_key_len);
|
||||
if(rc != MOSQ_ERR_PLUGIN_DEFER){
|
||||
return rc;
|
||||
}
|
||||
if(rc == MOSQ_ERR_PLUGIN_IGNORE){
|
||||
/* Do nothing */
|
||||
}else if(rc == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_PLUGIN_DEFER;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/* If all plugins deferred, this is a denial. If rc == MOSQ_ERR_SUCCESS
|
||||
* here, then no plugins were configured. */
|
||||
if(rc_final == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_AUTH;
|
||||
}
|
||||
return rc_final;
|
||||
}
|
||||
@@ -608,90 +608,3 @@ int mosquitto_unpwd_check(struct mosquitto *context)
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
static int plugin__psk_key_get(struct mosquitto__security_options *opts, struct mosquitto *context, const char *hint, const char *identity, char *key, int max_key_len)
|
||||
{
|
||||
struct mosquitto_evt_psk_key event_data;
|
||||
struct mosquitto__callback *cb_base;
|
||||
int rc;
|
||||
int rc_final = MOSQ_ERR_SUCCESS;
|
||||
|
||||
DL_FOREACH(opts->plugin_callbacks.psk_key, cb_base){
|
||||
memset(&event_data, 0, sizeof(event_data));
|
||||
event_data.client = context;
|
||||
event_data.hint = hint;
|
||||
event_data.identity = identity;
|
||||
event_data.key = key;
|
||||
event_data.max_key_len = max_key_len;
|
||||
rc = cb_base->cb(MOSQ_EVT_PSK_KEY, &event_data, cb_base->userdata);
|
||||
if(rc == MOSQ_ERR_PLUGIN_IGNORE){
|
||||
/* Do nothing */
|
||||
}else if(rc == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_PLUGIN_DEFER;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
return rc_final;
|
||||
}
|
||||
|
||||
|
||||
int mosquitto_psk_key_get(struct mosquitto *context, const char *hint, const char *identity, char *key, int max_key_len)
|
||||
{
|
||||
int rc;
|
||||
int rc_final = MOSQ_ERR_SUCCESS;
|
||||
|
||||
/* Global plugins */
|
||||
if(db.config->security_options.plugin_callbacks.psk_key){
|
||||
rc = plugin__psk_key_get(&db.config->security_options, context,
|
||||
hint, identity, key, max_key_len);
|
||||
|
||||
if(rc == MOSQ_ERR_PLUGIN_IGNORE){
|
||||
/* Do nothing */
|
||||
}else if(rc == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_PLUGIN_DEFER;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/* Per listener plugins */
|
||||
if(db.config->per_listener_settings){
|
||||
if(context->listener == NULL){
|
||||
return MOSQ_ERR_AUTH;
|
||||
}
|
||||
if(context->listener->security_options.plugin_callbacks.psk_key){
|
||||
rc = plugin__psk_key_get(&context->listener->security_options, context,
|
||||
hint, identity, key, max_key_len);
|
||||
|
||||
if(rc == MOSQ_ERR_PLUGIN_IGNORE){
|
||||
/* Do nothing */
|
||||
}else if(rc == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_PLUGIN_DEFER;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rc = mosquitto_psk_key_get_default(context, hint, identity, key, max_key_len);
|
||||
if(rc != MOSQ_ERR_PLUGIN_DEFER){
|
||||
return rc;
|
||||
}
|
||||
if(rc == MOSQ_ERR_PLUGIN_IGNORE){
|
||||
/* Do nothing */
|
||||
}else if(rc == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_PLUGIN_DEFER;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/* If all plugins deferred, this is a denial. If rc == MOSQ_ERR_SUCCESS
|
||||
* here, then no plugins were configured. */
|
||||
if(rc_final == MOSQ_ERR_PLUGIN_DEFER){
|
||||
rc_final = MOSQ_ERR_AUTH;
|
||||
}
|
||||
return rc_final;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user