mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-25 11:15:54 +08:00
Move plugin to examples dir, plus some tweaks.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
add_subdirectory(auth-by-env)
|
||||
add_subdirectory(dynamic-security)
|
||||
add_subdirectory(persist-sqlite)
|
||||
add_subdirectory(examples)
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include
|
||||
${OPENSSL_INCLUDE_DIR} ${STDBOOL_H_PATH} ${STDINT_H_PATH})
|
||||
|
||||
add_library(mosquitto_auth_by_env MODULE mosquitto_auth_by_env.c)
|
||||
set_target_properties(mosquitto_auth_by_env PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE 1
|
||||
)
|
||||
set_target_properties(mosquitto_auth_by_env PROPERTIES PREFIX "")
|
||||
|
||||
# Don't install, these are example plugins only. XXX
|
||||
#install(TARGETS mosquitto_auth_by_env RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||
@@ -3,6 +3,7 @@ if(NOT WIN32)
|
||||
add_subdirectory(client-lifetime-stats)
|
||||
add_subdirectory(message-timestamp)
|
||||
endif()
|
||||
add_subdirectory(auth-by-env)
|
||||
add_subdirectory(auth-by-ip)
|
||||
add_subdirectory(client-properties)
|
||||
add_subdirectory(connection-state)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
DIRS= \
|
||||
add-properties \
|
||||
auth-by-env \
|
||||
auth-by-ip \
|
||||
client-lifetime-stats \
|
||||
client-properties \
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
set (PLUGIN_NAME mosquitto_auth_by_env)
|
||||
|
||||
add_library(${PLUGIN_NAME} MODULE
|
||||
${PLUGIN_NAME}.c
|
||||
)
|
||||
|
||||
target_include_directories(${PLUGIN_NAME} PRIVATE
|
||||
"${mosquitto_SOURCE_DIR}"
|
||||
"${mosquitto_SOURCE_DIR}/include"
|
||||
)
|
||||
|
||||
set_target_properties(${PLUGIN_NAME} PROPERTIES
|
||||
PREFIX ""
|
||||
POSITION_INDEPENDENT_CODE 1
|
||||
)
|
||||
|
||||
target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto)
|
||||
|
||||
# Don't install, these are example plugins only.
|
||||
#install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||
+12
-20
@@ -36,8 +36,10 @@ Contributors:
|
||||
|
||||
#define ENV_MOSQUITTO_PASSWORD "MOSQUITTO_PASSWORD"
|
||||
|
||||
MOSQUITTO_PLUGIN_DECLARE_VERSION(5);
|
||||
|
||||
static mosquitto_plugin_id_t *mosq_pid = NULL;
|
||||
static char *environment_password;
|
||||
static char *environment_password = NULL;
|
||||
|
||||
static int basic_auth_callback(int event, void *event_data, void *userdata)
|
||||
{
|
||||
@@ -58,18 +60,6 @@ static int basic_auth_callback(int event, void *event_data, void *userdata)
|
||||
}
|
||||
}
|
||||
|
||||
int mosquitto_plugin_version(int supported_version_count, const int *supported_versions)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0; i<supported_version_count; i++){
|
||||
if(supported_versions[i] == 5){
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, struct mosquitto_opt *opts, int opt_count)
|
||||
{
|
||||
UNUSED(user_data);
|
||||
@@ -81,15 +71,17 @@ int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, s
|
||||
mosq_pid = identifier;
|
||||
|
||||
env_var_content = getenv(ENV_MOSQUITTO_PASSWORD);
|
||||
if(env_var_content){
|
||||
if(strlen(env_var_content) > 0){
|
||||
environment_password = strdup(env_var_content);
|
||||
return mosquitto_callback_register(mosq_pid, MOSQ_EVT_BASIC_AUTH, basic_auth_callback, NULL, NULL);
|
||||
if(env_var_content && strlen(env_var_content) > 0){
|
||||
environment_password = mosquitto_strdup(env_var_content);
|
||||
if(!environment_password){
|
||||
mosquitto_log_printf(MOSQ_LOG_ERR, "Out of memory.");
|
||||
return MOSQ_ERR_NOMEM;
|
||||
}
|
||||
return mosquitto_callback_register(mosq_pid, MOSQ_EVT_BASIC_AUTH, basic_auth_callback, NULL, NULL);
|
||||
}
|
||||
|
||||
log__printf(NULL, MOSQ_LOG_INFO, "Auth-by-env plugin called, but "ENV_MOSQUITTO_PASSWORD" env var is empty\n");
|
||||
return 0;
|
||||
mosquitto_log_printf(MOSQ_LOG_ERR, "auth-by-env plugin called, but " ENV_MOSQUITTO_PASSWORD " environment variable is empty");
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
|
||||
int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count)
|
||||
@@ -98,7 +90,7 @@ int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int op
|
||||
UNUSED(opts);
|
||||
UNUSED(opt_count);
|
||||
|
||||
free(environment_password);
|
||||
mosquitto_free(environment_password);
|
||||
|
||||
return mosquitto_callback_unregister(mosq_pid, MOSQ_EVT_BASIC_AUTH, basic_auth_callback, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user