Fix include_dir not sorting config files before loading.

Thanks to momoskitto.
pull/1151/head
Roger A. Light 7 years ago
parent 2e1c2c430f
commit 715da28602

@ -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

@ -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; i<file_count; i++){
log__printf(NULL, MOSQ_LOG_INFO, "Loading config file %s", files[i]);
rc = config__read_file(config, reload, files[i], cr, level+1, &lineno_ext);
if(rc){
FindClose(fh);
log__printf(NULL, MOSQ_LOG_ERR, "Error found at %s:%d.", conf_file, lineno_ext);
mosquitto__free(conf_file);
return rc;
log__printf(NULL, MOSQ_LOG_ERR, "Error found at %s:%d.", files[i], lineno_ext);
/* Free happens below */
break;
}
mosquitto__free(conf_file);
}while(FindNextFile(fh, &find_data));
FindClose(fh);
#else
dh = opendir(token);
if(!dh){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open include_dir '%s'.", token);
return 1;
}
while((de = readdir(dh)) != NULL){
if(strlen(de->d_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<file_count; i++){
mosquitto__free(files[i]);
}
closedir(dh);
#endif
mosquitto__free(files);
if(rc) return rc; /* This returns if config__read_file() fails above */
}
}else if(!strcmp(token, "keepalive_interval")){
#ifdef WITH_BRIDGE

@ -46,13 +46,13 @@ Contributors:
#include "util_mosq.h"
#include "mqtt3_protocol.h"
int strcasecmp_p(const void *p1, const void *p2)
#ifdef WIN32
int scmp_p(const void *p1, const void *p2)
{
return strcasecmp(*(const char **)p1, *(const char **)p2);
}
#ifdef WIN32
int config__get_dir_files(const char *include_dir, char ***files, int *file_count)
{
int len;
@ -102,6 +102,7 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
FindClose(fh);
qsort(l_files, l_file_count, sizeof(char *), scmp_p);
*files = l_files;
*file_count = l_file_count;
@ -111,6 +112,11 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
#ifndef WIN32
int scmp_p(const void *p1, const void *p2)
{
return strcmp(*(const char **)p1, *(const char **)p2);
}
int config__get_dir_files(const char *include_dir, char ***files, int *file_count)
{
char **l_files = NULL;
@ -160,6 +166,7 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
}
closedir(dh);
qsort(l_files, l_file_count, sizeof(char *), scmp_p);
*files = l_files;
*file_count = l_file_count;

Loading…
Cancel
Save