Fix confusing error message when dynamic security config file was a directory.

Closes #2520. Thanks to sezanzeb
This commit is contained in:
Roger A. Light 2022-08-12 08:34:56 +01:00
parent 775bd2effd
commit 80c7726d5c
2 changed files with 14 additions and 6 deletions

View File

@ -20,6 +20,8 @@ Broker:
taken over. Closes #2607. taken over. Closes #2607.
- Fix confusing "out of memory" error when a client is kicked in the dynamic - Fix confusing "out of memory" error when a client is kicked in the dynamic
security plugin. Closes #2525. security plugin. Closes #2525.
- Fix confusing error message when dynamic security config file was a
directory. Closes #2520.
Client library: Client library:
- Fix threads library detection on Windows under cmake. Bumps the minimum - Fix threads library detection on Windows under cmake. Bumps the minimum

View File

@ -361,15 +361,21 @@ static int dynsec__config_load(void)
fptr = fopen(config_file, "rb"); fptr = fopen(config_file, "rb");
if(fptr == NULL){ if(fptr == NULL){
mosquitto_log_printf(MOSQ_LOG_ERR, "Error loading Dynamic security plugin config: File is not readable - check permissions.\n"); mosquitto_log_printf(MOSQ_LOG_ERR, "Error loading Dynamic security plugin config: File is not readable - check permissions.\n");
return 1; return MOSQ_ERR_ERRNO;
} }
#ifndef WIN32
if(errno == ENOTDIR || errno == EISDIR){
mosquitto_log_printf(MOSQ_LOG_ERR, "Error loading Dynamic security plugin config: Config is not a file.\n");
return MOSQ_ERR_ERRNO;
}
#endif
fseek(fptr, 0, SEEK_END); fseek(fptr, 0, SEEK_END);
flen_l = ftell(fptr); flen_l = ftell(fptr);
if(flen_l < 0){ if(flen_l < 0){
mosquitto_log_printf(MOSQ_LOG_ERR, "Error loading Dynamic security plugin config: %s\n", strerror(errno)); mosquitto_log_printf(MOSQ_LOG_ERR, "Error loading Dynamic security plugin config: %s\n", strerror(errno));
fclose(fptr); fclose(fptr);
return 1; return MOSQ_ERR_ERRNO;
}else if(flen_l == 0){ }else if(flen_l == 0){
fclose(fptr); fclose(fptr);
return 0; return 0;
@ -380,13 +386,13 @@ static int dynsec__config_load(void)
if(json_str == NULL){ if(json_str == NULL){
mosquitto_log_printf(MOSQ_LOG_ERR, "Error: Out of memory."); mosquitto_log_printf(MOSQ_LOG_ERR, "Error: Out of memory.");
fclose(fptr); fclose(fptr);
return 1; return MOSQ_ERR_NOMEM;
} }
if(fread(json_str, 1, flen, fptr) != flen){ if(fread(json_str, 1, flen, fptr) != flen){
mosquitto_log_printf(MOSQ_LOG_WARNING, "Error loading Dynamic security plugin config: Unable to read file contents.\n"); mosquitto_log_printf(MOSQ_LOG_WARNING, "Error loading Dynamic security plugin config: Unable to read file contents.\n");
mosquitto_free(json_str); mosquitto_free(json_str);
fclose(fptr); fclose(fptr);
return 1; return MOSQ_ERR_ERRNO;
} }
fclose(fptr); fclose(fptr);
@ -394,7 +400,7 @@ static int dynsec__config_load(void)
mosquitto_free(json_str); mosquitto_free(json_str);
if(tree == NULL){ if(tree == NULL){
mosquitto_log_printf(MOSQ_LOG_ERR, "Error loading Dynamic security plugin config: File is not valid JSON.\n"); mosquitto_log_printf(MOSQ_LOG_ERR, "Error loading Dynamic security plugin config: File is not valid JSON.\n");
return 1; return MOSQ_ERR_INVAL;
} }
if(dynsec__general_config_load(tree) if(dynsec__general_config_load(tree)
@ -404,7 +410,7 @@ static int dynsec__config_load(void)
){ ){
cJSON_Delete(tree); cJSON_Delete(tree);
return 1; return MOSQ_ERR_NOMEM;
} }
cJSON_Delete(tree); cJSON_Delete(tree);