]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Support tracking setting changes for named filter paths
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Sun, 2 Mar 2025 10:13:17 +0000 (12:13 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 5 Mar 2025 18:20:36 +0000 (20:20 +0200)
src/config/config-dump-full.c
src/config/config-filter.c
src/config/config-filter.h
src/config/config-request.c
src/config/config-request.h
src/config/doveconf.c
src/config/old-set-parser.c
src/config/old-set-parser.h

index 2032fa2415d5560c6ea13475455ef1241588eeed..e6784b99218dcef48a9d5d4c1aa9ebc8f33280d8 100644 (file)
@@ -538,11 +538,13 @@ config_dump_full_sections(struct config_dump_full_context *ctx,
                        export_ctx = config_export_init(
                                CONFIG_DUMP_SCOPE_SET_AND_DEFAULT_OVERRIDES,
                                0, ctx->dovecot_config_version,
+                               config_filter_get_path_prefix(&filter->filter),
                                config_dump_full_stdout_callback, &dump_ctx);
                } else {
                        export_ctx = config_export_init(
                                CONFIG_DUMP_SCOPE_SET_AND_DEFAULT_OVERRIDES,
                                0, ctx->dovecot_config_version,
+                               config_filter_get_path_prefix(&filter->filter),
                                config_dump_full_callback, &dump_ctx);
                }
                config_export_set_module_parsers(export_ctx,
@@ -620,12 +622,12 @@ int config_dump_full(struct config_parsed *config,
        if (dest == CONFIG_DUMP_FULL_DEST_STDOUT) {
                export_ctx = config_export_init(
                                CONFIG_DUMP_SCOPE_SET_AND_DEFAULT_OVERRIDES,
-                               flags, dovecot_config_version,
+                               flags, dovecot_config_version, "",
                                config_dump_full_stdout_callback, &dump_ctx);
        } else {
                export_ctx = config_export_init(
                                CONFIG_DUMP_SCOPE_SET_AND_DEFAULT_OVERRIDES,
-                               flags, dovecot_config_version,
+                               flags, dovecot_config_version, "",
                                config_dump_full_callback, &dump_ctx);
        }
        struct config_filter_parser *filter_parser =
index 717b739ffc3ac2de5037b49abc36732e57ee6abe..48f2cd4c7491c2ce904b48d031306743c9906aad 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
+#include "str.h"
 #include "crc32.h"
 #include "settings-parser.h"
 #include "master-service-settings.h"
@@ -206,3 +207,23 @@ bool config_filter_is_empty_defaults(const struct config_filter *filter)
 {
        return config_filters_equal(filter, &empty_defaults_filter);
 }
+
+static void
+config_filter_get_path_str(string_t **path, const struct config_filter *filter)
+{
+       if (filter->parent != NULL)
+               config_filter_get_path_str(path, filter->parent);
+       if (filter->filter_name != NULL) {
+               if (*path == NULL)
+                       *path = t_str_new(128);
+               str_append(*path, filter->filter_name);
+               str_append_c(*path, '/');
+       }
+}
+
+const char *config_filter_get_path_prefix(const struct config_filter *filter)
+{
+       string_t *path = NULL;
+       config_filter_get_path_str(&path, filter);
+       return path == NULL ? "" : str_c(path);
+}
index 4d6186b6977ad961dc734533701183a25b5a5923..40eb404d73383655370c000ec8edb0f80114b730 100644 (file)
@@ -93,4 +93,7 @@ bool config_filter_is_empty(const struct config_filter *filter);
    default_settings=TRUE. */
 bool config_filter_is_empty_defaults(const struct config_filter *filter);
 
+/* Return path prefix of named [list] filters. */
+const char *config_filter_get_path_prefix(const struct config_filter *filter);
+
 #endif
index bb2ff067f35e9c137cbb833548b20e6eeca3c9fd..1c79e3703997a137a85bbe6929e7c4507a14c803 100644 (file)
@@ -19,6 +19,7 @@ struct config_export_context {
        HASH_TABLE(const char *, const char *) keys;
        enum config_dump_scope scope;
        const char *dovecot_config_version;
+       const char *path_prefix;
 
        config_request_callback_t *callback;
        void *context;
@@ -230,8 +231,14 @@ settings_export(struct config_export_context *ctx,
                        if (module_parser->change_counters[define_idx] <= CONFIG_PARSER_CHANGE_DEFAULTS) {
                                /* Setting isn't explicitly set. We need to see
                                   if its default has changed. */
+                               const char *key_with_path = def->key;
+                               if (ctx->path_prefix[0] != '\0') {
+                                       key_with_path = t_strconcat(
+                                               ctx->path_prefix, def->key, NULL);
+                               }
                                if (old_settings_default(ctx->dovecot_config_version,
-                                                        def->key, &old_default)) {
+                                                        def->key, key_with_path,
+                                                        &old_default)) {
                                        default_str = t_str_new(strlen(old_default));
                                        str_append(default_str, old_default);
                                        default_changed = TRUE;
@@ -384,7 +391,7 @@ settings_export(struct config_export_context *ctx,
 struct config_export_context *
 config_export_init(enum config_dump_scope scope,
                   enum config_dump_flags flags,
-                  const char *dovecot_config_version,
+                  const char *dovecot_config_version, const char *path_prefix,
                   config_request_callback_t *callback, void *context)
 {
        struct config_export_context *ctx;
@@ -399,6 +406,7 @@ config_export_init(enum config_dump_scope scope,
        ctx->context = context;
        ctx->scope = scope;
        ctx->dovecot_config_version = p_strdup(pool, dovecot_config_version);
+       ctx->path_prefix = p_strdup(pool, path_prefix);
        ctx->value = str_new(pool, 256);
        if ((ctx->flags & CONFIG_DUMP_FLAG_DEDUPLICATE_KEYS) != 0)
                hash_table_create(&ctx->keys, ctx->pool, 0, str_hash, strcmp);
index 72951a055b9cbc21e4fd20f570fa4f7f8a58f1c8..1b5c83612b0ac6114c56fc1c0e59101295de7139 100644 (file)
@@ -53,11 +53,11 @@ bool config_export_type(string_t *str, const void *value,
 struct config_export_context *
 config_export_init(enum config_dump_scope scope,
                   enum config_dump_flags flags,
-                  const char *dovecot_config_version,
+                  const char *dovecot_config_version, const char *path_prefix,
                   config_request_callback_t *callback, void *context)
        ATTR_NULL(1, 5);
-#define config_export_init(scope, flags, version, callback, context) \
-       config_export_init(scope, flags, version, \
+#define config_export_init(scope, flags, version, path_prefix, callback, context) \
+       config_export_init(scope, flags, version, path_prefix, \
                (config_request_callback_t *)callback, \
                TRUE ? context : CALLBACK_TYPECHECK(callback, \
                        void (*)(const struct config_export_setting *, typeof(context))))
index fd429bf546aad4f30c83df53433101ce341cff61..6925cd2ec31e8f13999eb98e8e2987132fe85c00 100644 (file)
@@ -189,8 +189,9 @@ config_dump_human_init(enum config_dump_scope scope,
 
        flags = CONFIG_DUMP_FLAG_DEDUPLICATE_KEYS;
        ctx->export_ctx = config_export_init(scope, flags,
-                                            dovecot_config_version,
-                                            config_request_get_strings, ctx);
+               dovecot_config_version,
+               config_filter_get_path_prefix(&filter_parser->filter),
+               config_request_get_strings, ctx);
        config_export_set_module_parsers(ctx->export_ctx,
                                         filter_parser->module_parsers);
        return ctx;
index 2515f2163c2677d7d490af194670887d24202b0c..0d2255d20afe3e96c601449aa02c936b07ea7f48 100644 (file)
@@ -73,7 +73,8 @@ void old_settings_handle(struct config_parser_context *ctx,
 }
 
 bool old_settings_default(const char *dovecot_config_version,
-                         const char *key, const char **old_default_r)
+                         const char *key, const char *key_with_path,
+                         const char **old_default_r)
 {
        struct settings_history *history = settings_history_get();
        const struct setting_history_default *def;
@@ -84,7 +85,8 @@ bool old_settings_default(const char *dovecot_config_version,
        array_foreach(&history->defaults, def) {
                if (version_cmp(def->version, dovecot_config_version) <= 0)
                        break;
-               if (strcmp(def->key, key) == 0) {
+               if (strcmp(def->key, key) == 0 ||
+                   strcmp(def->key, key_with_path) == 0) {
                        *old_default_r = def->old_value;
                        return TRUE;
                }
index 000f9c9fa837e91dc7c9be77d490467df44ab5ab..baeb80ef014729c0c0153c557d101efe09e5d2da 100644 (file)
@@ -8,6 +8,7 @@ struct config_parser_context;
 void old_settings_handle(struct config_parser_context *ctx,
                         struct config_line *line);
 bool old_settings_default(const char *dovecot_config_version,
-                         const char *key, const char **old_default_r);
+                         const char *key, const char *key_with_path,
+                         const char **old_default_r);
 
 #endif