X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd%2Fconfig.c;h=7ea485c379636301d9c25aaacf20849e3a7145d9;hb=2520de08ed80b941f28c9ccb97a3785a507a831d;hp=d964aaa5b7b094679b1a0bf027090b759b75d79b;hpb=3d18b18de2e63eadc6a8dd2c375e16f7c7abadc8;p=apps%2Fpfixtools.git diff --git a/postlicyd/config.c b/postlicyd/config.c index d964aaa..7ea485c 100644 --- a/postlicyd/config.c +++ b/postlicyd/config.c @@ -75,17 +75,22 @@ config_param_register("verify_filter"); static inline config_t *config_new(void) { config_t *config = p_new(config_t, 1); + return config; +} + +static void config_close(config_t *config) +{ for (int i = 0 ; i < SMTP_count ; ++i) { config->entry_points[i] = -1; } - return config; + array_deep_wipe(config->filters, filter_wipe); + array_deep_wipe(config->params, filter_params_wipe); } void config_delete(config_t **config) { if (*config) { - array_deep_wipe((*config)->filters, filter_wipe); - array_deep_wipe((*config)->params, filter_params_wipe); + config_close(*config); p_delete(config); } } @@ -111,6 +116,9 @@ static bool config_second_pass(config_t *config) if (!ok) { return false; } + if (!filter_check_safety(&config->filters)) { + return false; + } ok = false; foreach (filter_param_t *param, config->params) { @@ -143,9 +151,8 @@ static bool config_second_pass(config_t *config) return ok; } -config_t *config_read(const char *file) +static bool config_load(config_t *config) { - config_t *config; filter_t filter; file_map_t map; const char *p; @@ -156,18 +163,18 @@ config_t *config_read(const char *file) char value[BUFSIZ]; ssize_t key_len, value_len; - if (!file_map_open(&map, file, false)) { + if (!file_map_open(&map, config->filename, false)) { return false; } - config = config_new(); + config_close(config); filter_init(&filter); linep = p = map.map; #define READ_ERROR(Fmt, ...) \ do { \ - syslog(LOG_ERR, "config file %s:%d:%d: " Fmt, file, line + 1, \ - p - linep + 1, ##__VA_ARGS__); \ + syslog(LOG_ERR, "config file %s:%d:%d: " Fmt, config->filename, \ + line + 1, p - linep + 1, ##__VA_ARGS__); \ goto error; \ } while (0) #define ADD_IN_BUFFER(Buffer, Len, Char) \ @@ -301,7 +308,8 @@ read_param_value: filter_param_t param; param.type = param_tokenize(key, key_len); if (param.type != ATK_UNKNOWN) { - param.value = m_strdup(value); + param.value = p_dupstr(value, value_len); + param.value_len = value_len; array_add(config->params, param); } } @@ -351,7 +359,7 @@ ok: goto error; } file_map_close(&map); - return config; + return true; badeof: syslog(LOG_ERR, "Unexpected end of file"); @@ -360,7 +368,22 @@ error: if (filter.name) { filter_wipe(&filter); } - config_delete(&config); file_map_close(&map); - return NULL; + return false; +} + +bool config_reload(config_t *config) +{ + return config_load(config); +} + +config_t *config_read(const char *file) +{ + config_t *config = config_new(); + config->filename = file; + if (!config_reload(config)) { + p_delete(&config); + return NULL; + } + return config; }