From ce5c1382d03788189ee4476ffd08af5aeecdbc75 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 25 Sep 2009 14:49:45 -0700 Subject: [PATCH] auth: don't run over g_conf options when setting them --- src/common/ConfUtils.cc | 3 --- src/config.cc | 36 +++++++++++++++++++++++++++++++++--- src/config.h | 2 +- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/common/ConfUtils.cc b/src/common/ConfUtils.cc index ceead011a4b7e..22f41f4fde37a 100644 --- a/src/common/ConfUtils.cc +++ b/src/common/ConfUtils.cc @@ -531,7 +531,6 @@ ConfSection *ConfFile::_add_section(const char *section, ConfLine *cl) return sec; } - bool ConfFile::_parse(char *filename, ConfSection **psection) { char *buf; @@ -544,8 +543,6 @@ bool ConfFile::_parse(char *filename, ConfSection **psection) line = (char *)malloc(max_line); - - fd = open(filename, O_RDONLY); if (fd < 0) return 0; diff --git a/src/config.cc b/src/config.cc index 71362b33ec10d..ccd26a0f55438 100644 --- a/src/config.cc +++ b/src/config.cc @@ -580,10 +580,11 @@ bool conf_set_conf_val(void *field, opt_type_t type, const char *val, long long *(long long *)field = intval; break; case OPT_STR: - if (val) + if (val) { *(char **)field = strdup(val); - else + } else { *(char **)field = NULL; + } break; case OPT_FLOAT: *(float *)field = doubleval; @@ -598,6 +599,35 @@ bool conf_set_conf_val(void *field, opt_type_t type, const char *val, long long return true; } +static bool conf_reset_val(void *field, opt_type_t type) +{ + switch (type) { + case OPT_BOOL: + *(bool *)field = 0; + break; + case OPT_INT: + *(int *)field = 0; + break; + case OPT_LONGLONG: + *(long long *)field = 0; + break; + case OPT_STR: + *(char **)field = NULL; + break; + case OPT_FLOAT: + *(float *)field = 0; + break; + case OPT_DOUBLE: + *(double *)field = 0; + break; + default: + return false; + } + + return true; +} + + static void set_conf_name(config_option *opt) { char *newsection = (char *)opt->section; @@ -642,7 +672,7 @@ static bool init_g_conf() for (i = 0; ival_ptr) { - *(char **)opt->val_ptr = NULL; + conf_reset_val(opt->val_ptr, opt->type); } if (!conf_set_conf_val(opt->val_ptr, opt->type, diff --git a/src/config.h b/src/config.h index 393bd465d4d27..abfc8285eb05d 100644 --- a/src/config.h +++ b/src/config.h @@ -108,7 +108,7 @@ struct md_config_t { bool clock_tare; // auth - const char *keys_file; + char *keys_file; // messenger -- 2.39.5