From 715da2860252a83207db0f99a425b7f491836381 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 8 Feb 2019 23:52:11 +0000 Subject: [PATCH] Fix include_dir not sorting config files before loading. Thanks to momoskitto. --- ChangeLog.txt | 2 ++ src/conf.c | 78 +++++++++---------------------------------- src/conf_includedir.c | 13 ++++++-- 3 files changed, 27 insertions(+), 66 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c5516f1a..e64cf37c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,8 @@ Broker: - Fix build failure when using WITH_ADNS=yes - Ensure that an error occurs if `per_listener_settings true` is given after other security options. Closes #1149. +- Fix include_dir not sorting config files before loading. This was partially + fixed in 1.5 previously. 1.5.6 - 20190206 diff --git a/src/conf.c b/src/conf.c index 0e822c95..aea01f0d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -732,15 +732,6 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct time_t expiration_mult; char *key; - char *conf_file; -#ifdef WIN32 - HANDLE fh; - char dirpath[MAX_PATH]; - WIN32_FIND_DATA find_data; -#else - DIR *dh; - struct dirent *de; -#endif int len; struct mosquitto__listener *cur_listener = &config->default_listener; int i; @@ -1219,66 +1210,27 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct log__printf(NULL, MOSQ_LOG_ERR, "Error: Empty include_dir value in configuration."); return 1; } -#ifdef WIN32 - snprintf(dirpath, MAX_PATH, "%s\\*.conf", token); - fh = FindFirstFile(dirpath, &find_data); - if(fh == INVALID_HANDLE_VALUE){ - /* No files found */ - continue; - } - do{ - len = strlen(token)+1+strlen(find_data.cFileName)+1; - conf_file = mosquitto__malloc(len+1); - if(!conf_file){ - FindClose(fh); - return MOSQ_ERR_NOMEM; - } - snprintf(conf_file, len, "%s\\%s", token, find_data.cFileName); - conf_file[len] = '\0'; + char **files; + int file_count; + rc = config__get_dir_files(token, &files, &file_count); + if(rc) return rc; - rc = config__read_file(config, reload, conf_file, cr, level+1, &lineno_ext); + for(i=0; id_name) > 5){ - if(!strcmp(&de->d_name[strlen(de->d_name)-5], ".conf")){ - len = strlen(token)+1+strlen(de->d_name)+1; - conf_file = mosquitto__malloc(len+1); - if(!conf_file){ - closedir(dh); - return MOSQ_ERR_NOMEM; - } - snprintf(conf_file, len, "%s/%s", token, de->d_name); - conf_file[len] = '\0'; - - rc = config__read_file(config, reload, conf_file, cr, level+1, &lineno_ext); - if(rc){ - closedir(dh); - log__printf(NULL, MOSQ_LOG_ERR, "Error found at %s:%d.", conf_file, lineno_ext); - mosquitto__free(conf_file); - return rc; - } - mosquitto__free(conf_file); - } - } + for(i=0; i