From: Timo Sirainen Date: Tue, 30 Jan 2024 16:29:59 +0000 (+0200) Subject: config: Implement SET_FILE X-Git-Tag: 2.4.1~1076 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7983d2ba651710bb00c6d5084c1c64393e7ea29;p=thirdparty%2Fdovecot%2Fcore.git config: Implement SET_FILE --- diff --git a/src/config/config-parser.c b/src/config/config-parser.c index 6b3ceacea8..b17449af79 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -440,6 +440,8 @@ settings_value_check(struct config_parser_context *ctx, return -1; } break; + case SET_FILE: + break; case SET_STRLIST: case SET_BOOLLIST: case SET_FILTER_ARRAY: @@ -577,6 +579,34 @@ static int config_apply_filter_array(struct config_parser_context *ctx, return 0; } +static int config_apply_file(struct config_parser_context *ctx, + const struct config_line *line, + const char *path, const char **output_r) +{ + const char *full_path, *error; + + if (path[0] == '\0') { + *output_r = ""; + return 0; + } + if (!ctx->expand_values) { + *output_r = p_strdup(ctx->pool, path); + return 0; + } + full_path = fix_relative_path(path, ctx->cur_input); + /* preserve original relative path in doveconf output */ + if (full_path != path && ctx->expand_values) + path = full_path; + if (settings_parse_read_file(full_path, path, ctx->pool, output_r, &error) < 0) { + ctx->error = p_strdup(ctx->pool, error); + if (config_apply_error(ctx, line->key) < 0) + return -1; + /* delayed error */ + *output_r = ""; + } + return 0; +} + static int config_apply_exact_line(struct config_parser_context *ctx, const struct config_line *line, @@ -623,6 +653,11 @@ config_apply_exact_line(struct config_parser_context *ctx, &l->settings[config_key->define_idx].array) < 0) return -1; break; + case SET_FILE: + if (config_apply_file(ctx, line, value, + &l->settings[config_key->define_idx].str) < 0) + return -1; + break; default: l->settings[config_key->define_idx].str = p_strdup(ctx->pool, value); @@ -1142,6 +1177,7 @@ void config_fill_set_parser(struct setting_parser_context *parser, default: { const char *value = p->settings[i].str; if (p->info->defines[i].type != SET_STR_NOVARS && + p->info->defines[i].type != SET_FILE && strchr(p->settings[i].str, '%') != NULL) { /* We don't know what the variables would expand to. */ diff --git a/src/config/config-request.c b/src/config/config-request.c index e6e5549e81..0dd7b72318 100644 --- a/src/config/config-request.c +++ b/src/config/config-request.c @@ -137,6 +137,7 @@ bool config_export_type(string_t *str, const void *value, } case SET_STR: case SET_STR_NOVARS: + case SET_FILE: case SET_ENUM: { const char *const *val = value; @@ -203,6 +204,7 @@ settings_export(struct config_export_context *ctx, dump = FALSE; str_truncate(ctx->value, 0); switch (def->type) { + case SET_FILE: case SET_BOOL: case SET_SIZE: case SET_UINT: @@ -326,6 +328,7 @@ settings_export(struct config_export_context *ctx, type = CONFIG_KEY_NORMAL; struct config_export_setting export_set = { .type = type, + .def_type = def->type, .key = def->key, .key_define_idx = define_idx, .value = str_c(ctx->value), diff --git a/src/config/doveconf.c b/src/config/doveconf.c index 477e8b8b52..db538570e4 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -66,7 +66,11 @@ config_request_get_strings(const struct config_export_setting *set, switch (set->type) { case CONFIG_KEY_NORMAL: - value = p_strdup_printf(ctx->pool, "%s=%s", set->key, set->value); + if (set->def_type != SET_FILE) + value = set->value; + else + value = t_strcut(set->value, '\n'); + value = p_strdup_printf(ctx->pool, "%s=%s", set->key, value); break; case CONFIG_KEY_BOOLLIST_ELEM: /* add list index as the prefix to preserve the configured