]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Implement SET_FILE
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 30 Jan 2024 16:29:59 +0000 (18:29 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:11 +0000 (12:34 +0200)
src/config/config-parser.c
src/config/config-request.c
src/config/doveconf.c

index 6b3ceacea8ea2f496ac1bab8f215279b6ad0d166..b17449af792816c888ff9d4b178371139762d19e 100644 (file)
@@ -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. */
index e6e5549e81a1ffff46cc9004d7a7fddf7035fb14..0dd7b723189451816eca3dcb811e96a28e4611db 100644 (file)
@@ -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),
index 477e8b8b52839631b664d6bf68724a82cae2cd9b..db538570e444bf93f23fa9030236dfd5d361af6f 100644 (file)
@@ -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