Add warnings if string or boolean parameters were present but not strings.

This commit is contained in:
Mike Brady
2026-04-08 13:04:38 +01:00
parent a45bf3db01
commit 0291d3656e
2 changed files with 36 additions and 19 deletions
+35 -18
View File
@@ -1041,32 +1041,49 @@ uint8_t *rsa_apply(uint8_t *input, int inlen, int *outlen, int mode) {
#endif
int config_lookup_non_empty_string(const config_t *cfg, const char *path, const char **value) {
int response = config_lookup_string(cfg, path, value);
if (response == CONFIG_TRUE) {
if ((value != NULL) && ((*value == NULL) || (*value[0] == 0))) {
warn("The \"%s\" parameter is an empty string and has been ignored.", path);
response = CONFIG_FALSE;
int response = CONFIG_FALSE;
config_setting_t *s = config_lookup(cfg, path);
if (s != NULL) {
// the setting exists, but might not be a string
if (config_setting_type(s) == CONFIG_TYPE_STRING) {
if (value != NULL) {
*value = config_setting_get_string(s);
response = CONFIG_TRUE;
// the string might be empty...
if ((*value == NULL) || (*value[0] == 0)) {
warn("The \"%s\" parameter is an empty string and has been ignored.", path);
response = CONFIG_FALSE;
}
}
} else {
warn("the \"%s\" parameter is not a string, as required, and has been ignored.", path);
}
}
return response;
}
int config_set_lookup_bool(config_t *cfg, char *where, int *dst) {
const char *str = 0;
if (config_lookup_string(cfg, where, &str)) {
if (strcasecmp(str, "no") == 0) {
(*dst) = 0;
return 1;
} else if (strcasecmp(str, "yes") == 0) {
(*dst) = 1;
return 1;
int config_set_lookup_bool(config_t *cfg, const char *where, int *dst) {
const char *str = NULL;
int response = CONFIG_FALSE;
config_setting_t *s = config_lookup(cfg, where);
if (s != NULL) {
if (config_setting_type(s) == CONFIG_TYPE_STRING) {
str = config_setting_get_string(s);
if (strcasecmp(str, "no") == 0) {
(*dst) = 0;
response = CONFIG_TRUE;
} else if (strcasecmp(str, "yes") == 0) {
(*dst) = 1;
response = CONFIG_TRUE;
} else {
die("invalid boolean parameter \"%s\" option choice \"%s\". It should be \"yes\" or \"no\"", where, str);
return 0;
}
} else {
die("Invalid %s option choice \"%s\". It should be \"yes\" or \"no\"", where, str);
return 0;
warn("the \"%s\" parameter is not a string with a value of \"yes\" or \"no\", as required, and has been ignored.", where);
}
} else {
return 0;
}
return response;
}
// remember to free the returned array of strings.
+1 -1
View File
@@ -561,7 +561,7 @@ extern int type_of_exit_cleanup; // normal, emergency, dbus requested...
extern uint64_t minimum_dac_queue_size;
int config_lookup_non_empty_string(const config_t *cfg, const char *path, const char **value);
int config_set_lookup_bool(config_t *cfg, char *where, int *dst);
int config_set_lookup_bool(config_t *cfg, const char *where, int *dst);
int check_string_or_list_setting(config_setting_t *setting, const char *item);
int check_int_or_list_setting(config_setting_t *setting, const int item);