diff --git a/mosquitto-auth-plugin/Makefile b/mosquitto-auth-plugin/Makefile index 97a554c84..fb637ccc4 100644 --- a/mosquitto-auth-plugin/Makefile +++ b/mosquitto-auth-plugin/Makefile @@ -14,7 +14,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mosquitto-auth-plugin -PKG_VERSION:=1.2.0 +PKG_VERSION:=1.2.1 PKG_MAINTAINER:=Erik Karlsson PKG_LICENSE:=EPL-2.0 diff --git a/mosquitto-auth-plugin/src/mosquitto_auth_plugin.c b/mosquitto-auth-plugin/src/mosquitto_auth_plugin.c index 50dced33b..fcb183e37 100644 --- a/mosquitto-auth-plugin/src/mosquitto_auth_plugin.c +++ b/mosquitto-auth-plugin/src/mosquitto_auth_plugin.c @@ -53,6 +53,7 @@ typedef struct { user_acl_t users[MAX_USERS]; int user_count; mosquitto_plugin_id_t *identifier; + char *config_file; } plugin_data_t; /* Parse CIDR notation for IPv4 or IPv6 (e.g., "192.168.1.0/24" or "2001:db8::/32") */ @@ -548,6 +549,30 @@ static int basic_auth_callback(int event, void *event_data, void *userdata) return check_subnet_on_auth(pdata, ed); } +static int reload_callback(int event, void *event_data, void *userdata) +{ + plugin_data_t *pdata = userdata; + + if (pdata == NULL) + return MOSQ_ERR_SUCCESS; + + mosquitto_log_printf(MOSQ_LOG_NOTICE, + "subnet_acl: Reloading subnet ACL configuration from '%s'", + pdata->config_file ? pdata->config_file : "(none)"); + + /* Reload subnet ACL configuration */ + if (load_subnet_acl_config(pdata, pdata->config_file) != 0) { + mosquitto_log_printf(MOSQ_LOG_ERR, + "subnet_acl: Failed to reload subnet ACL configuration, keeping old config"); + return MOSQ_ERR_UNKNOWN; + } + + mosquitto_log_printf(MOSQ_LOG_NOTICE, + "subnet_acl: Reload complete, now tracking %d user(s)", pdata->user_count); + + return MOSQ_ERR_SUCCESS; +} + int mosquitto_plugin_version(int supported_version_count, const int *supported_versions) { @@ -576,8 +601,20 @@ int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, pdata->identifier = identifier; + /* Store config file path for reload */ + if (config_file != NULL) { + pdata->config_file = strdup(config_file); + if (pdata->config_file == NULL) { + free(pdata); + return MOSQ_ERR_NOMEM; + } + } else { + pdata->config_file = NULL; + } + /* Load subnet ACL configuration */ if (load_subnet_acl_config(pdata, config_file) != 0) { + free(pdata->config_file); free(pdata); return MOSQ_ERR_UNKNOWN; } @@ -588,6 +625,20 @@ int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, if (rc != MOSQ_ERR_SUCCESS) { mosquitto_log_printf(MOSQ_LOG_ERR, "subnet_acl: Failed to register authentication callback"); + free(pdata->config_file); + free(pdata); + return rc; + } + + /* Register reload callback to handle SIGHUP */ + rc = mosquitto_callback_register(identifier, MOSQ_EVT_RELOAD, + reload_callback, NULL, pdata); + if (rc != MOSQ_ERR_SUCCESS) { + mosquitto_log_printf(MOSQ_LOG_ERR, + "subnet_acl: Failed to register reload callback"); + mosquitto_callback_unregister(identifier, MOSQ_EVT_BASIC_AUTH, + basic_auth_callback, NULL); + free(pdata->config_file); free(pdata); return rc; } @@ -609,6 +660,9 @@ int mosquitto_plugin_cleanup(void *user_data, if (pdata) { mosquitto_callback_unregister(pdata->identifier, MOSQ_EVT_BASIC_AUTH, basic_auth_callback, NULL); + mosquitto_callback_unregister(pdata->identifier, MOSQ_EVT_RELOAD, + reload_callback, NULL); + free(pdata->config_file); free(pdata); }