]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-settings, config: Support inline settings for SET_FILE
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 2 Feb 2024 11:29:38 +0000 (13:29 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:11 +0000 (12:34 +0200)
All SET_FILE setting names must end with "_file". If the setting is
given without the "_file" suffix, the value is the inline content
instead of the file path.

src/config/config-parser.c
src/config/doveconf.c
src/lib-settings/settings-parser.h
src/lib-settings/settings.c

index b17449af792816c888ff9d4b178371139762d19e..40df5edd8c9e17f830e1c4bd29bb996c7c44548f 100644 (file)
@@ -621,7 +621,8 @@ config_apply_exact_line(struct config_parser_context *ctx,
                ctx->cur_section->filter_parser->filter_required_setting_seen = TRUE;
 
        /* if key is list/key, lookup only "list" */
-       config_key = hash_table_lookup(ctx->all_keys, t_strcut(key, '/'));
+       const char *lookup_key = t_strcut(key, '/');
+       config_key = hash_table_lookup(ctx->all_keys, lookup_key);
        if (config_key == NULL)
                return 0;
 
@@ -653,11 +654,20 @@ config_apply_exact_line(struct config_parser_context *ctx,
                                        &l->settings[config_key->define_idx].array) < 0)
                                return -1;
                        break;
-               case SET_FILE:
+               case SET_FILE: {
+                       const char *inline_value;
+                       if (str_begins(value, SET_FILE_INLINE_PREFIX,
+                                      &inline_value)) {
+                               l->settings[config_key->define_idx].str =
+                                       value[0] == '\0' ? "" :
+                                       p_strconcat(ctx->pool, "\n", inline_value, NULL);
+                               break;
+                       }
                        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);
index db538570e444bf93f23fa9030236dfd5d361af6f..079e92056a69cdc14a8b680205a55ddc7bc8d34d 100644 (file)
@@ -62,15 +62,19 @@ static void
 config_request_get_strings(const struct config_export_setting *set,
                           struct config_dump_human_context *ctx)
 {
-       const char *p, *value;
+       const char *p, *key, *value;
 
        switch (set->type) {
        case CONFIG_KEY_NORMAL:
+               key = set->key;
                if (set->def_type != SET_FILE)
                        value = set->value;
-               else
+               else if (set->value[0] != '\n')
                        value = t_strcut(set->value, '\n');
-               value = p_strdup_printf(ctx->pool, "%s=%s", set->key, value);
+               else
+                       value = t_strconcat(SET_FILE_INLINE_PREFIX,
+                                           set->value + 1, NULL);
+               value = p_strdup_printf(ctx->pool, "%s=%s", key, value);
                break;
        case CONFIG_KEY_BOOLLIST_ELEM:
                /* add list index as the prefix to preserve the configured
index 71f62f47346aaaed5a88f18103923b8de792932f..bef89fc0de63cbcaabbb29164eb7524e6786441c 100644 (file)
@@ -19,6 +19,8 @@ struct var_expand_func_table;
 #define SET_TIME_INFINITE UINT_MAX
 #define SET_TIME_MSECS_INFINITE UINT_MAX
 
+#define SET_FILE_INLINE_PREFIX "inline:"
+
 enum setting_type {
        SET_BOOL,
        SET_UINT,
index 7826eacbc4c498cf2784d5e8598784fdc4cf9af1..a540283f4e5a3cacce97dfc07ac2f939c2995ed5 100644 (file)
@@ -1289,7 +1289,13 @@ settings_override_get_value(struct settings_apply_ctx *ctx,
            ctx->info->defines[key_idx].type == SET_FILTER_ARRAY) {
                *_key = key;
                *key_idx_r = key_idx;
-               *value_r = set->value;
+
+               const char *inline_value;
+               if (!str_begins(set->value, SET_FILE_INLINE_PREFIX,
+                               &inline_value))
+                       *value_r = set->value;
+               else
+                       *value_r = t_strconcat("\n", inline_value, NULL);
                return 1;
        }