diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml index 031d1fcb..2837569c 100644 --- a/man/mosquitto.conf.5.xml +++ b/man/mosquitto.conf.5.xml @@ -488,6 +488,8 @@ options are affected: , , , + , + , , , . diff --git a/mosquitto.conf b/mosquitto.conf index 29f84fe1..14c718b0 100644 --- a/mosquitto.conf +++ b/mosquitto.conf @@ -142,7 +142,7 @@ # affected: # # password_file acl_file psk_file auth_plugin auth_opt_* allow_anonymous -# auto_id_prefix +# auto_id_prefix allow_zero_length_clientid # # The default behaviour is for this to be set to false, which maintains the # setting behaviour from previous versions of mosquitto. diff --git a/src/conf.c b/src/conf.c index c7b8469d..461a7ce7 100644 --- a/src/conf.c +++ b/src/conf.c @@ -152,7 +152,7 @@ static void config__init_reload(struct mosquitto__config *config) config->acl_file = NULL; config->security_options.allow_anonymous = -1; config->allow_duplicate_messages = false; - config->allow_zero_length_clientid = true; + config->security_options.allow_zero_length_clientid = true; config->security_options.auto_id_prefix = NULL; config->security_options.auto_id_prefix_len = 0; config->autosave_interval = 1800; @@ -714,7 +714,8 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, const }else if(!strcmp(token, "allow_duplicate_messages")){ if(conf__parse_bool(&token, "allow_duplicate_messages", &config->allow_duplicate_messages, saveptr)) return MOSQ_ERR_INVAL; }else if(!strcmp(token, "allow_zero_length_clientid")){ - if(conf__parse_bool(&token, "allow_zero_length_clientid", &config->allow_zero_length_clientid, saveptr)) return MOSQ_ERR_INVAL; + conf__set_cur_security_options(config, cur_listener, &cur_security_options); + if(conf__parse_bool(&token, "allow_zero_length_clientid", &cur_security_options->allow_zero_length_clientid, saveptr)) return MOSQ_ERR_INVAL; }else if(!strncmp(token, "auth_opt_", 9)){ if(!cur_auth_plugin){ log__printf(NULL, MOSQ_LOG_ERR, "Error: An auth_opt_ option exists in the config file without an auth_plugin."); diff --git a/src/handle_connect.c b/src/handle_connect.c index d6d5871d..3756a60a 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -240,7 +240,13 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) mosquitto__free(client_id); client_id = NULL; - if(clean_session == 0 || db->config->allow_zero_length_clientid == false){ + bool allow_zero_length_clientid; + if(db->config->per_listener_settings){ + allow_zero_length_clientid = context->listener->security_options.allow_zero_length_clientid; + }else{ + allow_zero_length_clientid = db->config->security_options.allow_zero_length_clientid; + } + if(clean_session == 0 || allow_zero_length_clientid == false){ send__connack(context, 0, CONNACK_REFUSED_IDENTIFIER_REJECTED); rc = MOSQ_ERR_PROTOCOL; goto handle_connect_error; diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 267694a6..6656aabd 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -156,6 +156,7 @@ struct mosquitto__security_options { struct mosquitto__auth_plugin_config *auth_plugins; int auth_plugin_count; char allow_anonymous; + bool allow_zero_length_clientid; char *auto_id_prefix; int auto_id_prefix_len; }; @@ -199,7 +200,6 @@ struct mosquitto__config { char *config_file; char *acl_file; bool allow_duplicate_messages; - bool allow_zero_length_clientid; int autosave_interval; bool autosave_on_changes; char *clientid_prefixes;