diff --git a/src/security.c b/src/security.c index 78268906..6ae9fb9c 100644 --- a/src/security.c +++ b/src/security.c @@ -33,6 +33,19 @@ typedef int (*FUNC_auth_plugin_acl_check)(void *, const char *, const char *, co typedef int (*FUNC_auth_plugin_unpwd_check)(void *, const char *, const char *); typedef int (*FUNC_auth_plugin_psk_key_get)(void *, const char *, const char *, char *, int); +void LIB_ERROR(void) +{ +#ifdef WIN32 + char *buf; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING, + NULL, GetLastError(), LANG_NEUTRAL, &buf, 0, NULL); + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Load error: %s", buf); + LocalFree(buf); +#else + _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Load error: %s", dlerror()); +#endif +} + int mosquitto_security_module_init(struct mosquitto_db *db) { void *lib; @@ -44,6 +57,7 @@ int mosquitto_security_module_init(struct mosquitto_db *db) if(!lib){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load auth plugin \"%s\".", db->config->auth_plugin); + LIB_ERROR(); return 1; } @@ -51,6 +65,7 @@ int mosquitto_security_module_init(struct mosquitto_db *db) if(!(plugin_version = (FUNC_auth_plugin_version)LIB_SYM(lib, "mosquitto_auth_plugin_version"))){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load auth plugin function mosquitto_auth_plugin_version()."); + LIB_ERROR(); LIB_CLOSE(lib); return 1; } @@ -59,6 +74,7 @@ int mosquitto_security_module_init(struct mosquitto_db *db) _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Incorrect auth plugin version (got %d, expected %d).", version, MOSQ_AUTH_PLUGIN_VERSION); + LIB_ERROR(); LIB_CLOSE(lib); return 1; @@ -66,12 +82,14 @@ int mosquitto_security_module_init(struct mosquitto_db *db) if(!(db->auth_plugin.plugin_init = (FUNC_auth_plugin_init)LIB_SYM(lib, "mosquitto_auth_plugin_init"))){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load auth plugin function mosquitto_auth_plugin_init()."); + LIB_ERROR(); LIB_CLOSE(lib); return 1; } if(!(db->auth_plugin.plugin_cleanup = (FUNC_auth_plugin_cleanup)LIB_SYM(lib, "mosquitto_auth_plugin_cleanup"))){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load auth plugin function mosquitto_auth_plugin_cleanup()."); + LIB_ERROR(); LIB_CLOSE(lib); return 1; } @@ -79,6 +97,7 @@ int mosquitto_security_module_init(struct mosquitto_db *db) if(!(db->auth_plugin.security_init = (FUNC_auth_plugin_security_init)LIB_SYM(lib, "mosquitto_auth_security_init"))){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load auth plugin function mosquitto_auth_security_init()."); + LIB_ERROR(); LIB_CLOSE(lib); return 1; } @@ -86,6 +105,7 @@ int mosquitto_security_module_init(struct mosquitto_db *db) if(!(db->auth_plugin.security_cleanup = (FUNC_auth_plugin_security_cleanup)LIB_SYM(lib, "mosquitto_auth_security_cleanup"))){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load auth plugin function mosquitto_auth_security_cleanup()."); + LIB_ERROR(); LIB_CLOSE(lib); return 1; } @@ -93,6 +113,7 @@ int mosquitto_security_module_init(struct mosquitto_db *db) if(!(db->auth_plugin.acl_check = (FUNC_auth_plugin_acl_check)LIB_SYM(lib, "mosquitto_auth_acl_check"))){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load auth plugin function mosquitto_auth_acl_check()."); + LIB_ERROR(); LIB_CLOSE(lib); return 1; } @@ -100,6 +121,7 @@ int mosquitto_security_module_init(struct mosquitto_db *db) if(!(db->auth_plugin.unpwd_check = (FUNC_auth_plugin_unpwd_check)LIB_SYM(lib, "mosquitto_auth_unpwd_check"))){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load auth plugin function mosquitto_auth_unpwd_check()."); + LIB_ERROR(); LIB_CLOSE(lib); return 1; } @@ -107,6 +129,7 @@ int mosquitto_security_module_init(struct mosquitto_db *db) if(!(db->auth_plugin.psk_key_get = (FUNC_auth_plugin_psk_key_get)LIB_SYM(lib, "mosquitto_auth_psk_key_get"))){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Unable to load auth plugin function mosquitto_auth_psk_key_get()."); + LIB_ERROR(); LIB_CLOSE(lib); return 1; }