]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Add exclude=<name> settings to drop specific settings
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 3 Aug 2021 16:46:59 +0000 (19:46 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 10 Aug 2021 09:35:01 +0000 (11:35 +0200)
src/config/config-connection.c
src/config/config-request.c
src/config/config-request.h
src/config/doveconf.c

index 5f299c81d24f994be4debc6383a64a093e9503bb..bd3db86505d3e58c07965972b5b956464ab6296a 100644 (file)
@@ -72,10 +72,12 @@ static int config_connection_request(struct config_connection *conn,
        struct config_filter filter;
        const char *path, *error, *module, *const *wanted_modules;
        ARRAY(const char *) modules;
+       ARRAY(const char *) exclude_settings;
        bool is_master = FALSE;
 
        /* [<args>] */
        t_array_init(&modules, 4);
+       t_array_init(&exclude_settings, 4);
        i_zero(&filter);
        for (; *args != NULL; args++) {
                if (str_begins(*args, "service="))
@@ -85,6 +87,9 @@ static int config_connection_request(struct config_connection *conn,
                        if (strcmp(module, "master") == 0)
                                is_master = TRUE;
                        array_push_back(&modules, &module);
+               } else if (str_begins(*args, "exclude=")) {
+                       const char *value = *args + 8;
+                       array_push_back(&exclude_settings, &value);
                } else if (str_begins(*args, "lname="))
                        filter.local_name = *args + 6;
                else if (str_begins(*args, "lip=")) {
@@ -104,6 +109,7 @@ static int config_connection_request(struct config_connection *conn,
        array_append_zero(&modules);
        wanted_modules = array_count(&modules) == 1 ? NULL :
                array_front(&modules);
+       array_append_zero(&exclude_settings);
 
        if (is_master) {
                /* master reads configuration only when reloading settings */
@@ -118,7 +124,10 @@ static int config_connection_request(struct config_connection *conn,
 
        o_stream_cork(conn->output);
 
-       ctx = config_export_init(wanted_modules, CONFIG_DUMP_SCOPE_SET, 0,
+       ctx = config_export_init(wanted_modules,
+                                array_count(&exclude_settings) == 1 ? NULL :
+                                array_front(&exclude_settings),
+                                CONFIG_DUMP_SCOPE_SET, 0,
                                 config_request_output, conn->output);
        config_export_by_filter(ctx, &filter);
        config_export_get_output(ctx, &output);
index 9709615c9454cb5bb8643fef77732d815b804570..00d0e50539e21d4572395f7c6253c5394d0a817d 100644 (file)
@@ -23,6 +23,7 @@ struct config_export_context {
        void *context;
 
        const char *const *modules;
+       const char *const *exclude_settings;
        enum config_dump_flags flags;
        const struct config_module_parser *parsers;
        struct config_module_parser *dup_parsers;
@@ -227,6 +228,10 @@ settings_export(struct config_export_context *ctx,
        bool dump, dump_default = FALSE;
 
        for (def = info->defines; def->key != NULL; def++) {
+               if (ctx->exclude_settings != NULL &&
+                   str_array_find(ctx->exclude_settings, def->key))
+                       continue;
+
                value = CONST_PTR_OFFSET(set, def->offset);
                default_value = info->defaults == NULL ? NULL :
                        CONST_PTR_OFFSET(info->defaults, def->offset);
@@ -373,7 +378,9 @@ settings_export(struct config_export_context *ctx,
 }
 
 struct config_export_context *
-config_export_init(const char *const *modules, enum config_dump_scope scope,
+config_export_init(const char *const *modules,
+                  const char *const *exclude_settings,
+                  enum config_dump_scope scope,
                   enum config_dump_flags flags,
                   config_request_callback_t *callback, void *context)
 {
@@ -385,6 +392,8 @@ config_export_init(const char *const *modules, enum config_dump_scope scope,
        ctx->pool = pool;
 
        ctx->modules = modules == NULL ? NULL : p_strarray_dup(pool, modules);
+       ctx->exclude_settings = exclude_settings == NULL ? NULL :
+               p_strarray_dup(pool, exclude_settings);
        ctx->flags = flags;
        ctx->callback = callback;
        ctx->context = context;
index c8a3fa24a8c53df8888a8dc0ab23f20d4a50df7c..c91e836e95877bd63b07b4f913764eb703ef0bfa 100644 (file)
@@ -42,7 +42,9 @@ bool config_export_type(string_t *str, const void *value,
                        enum setting_type type, bool dump_default,
                        bool *dump_r) ATTR_NULL(3);
 struct config_export_context *
-config_export_init(const char *const *modules, enum config_dump_scope scope,
+config_export_init(const char *const *modules,
+                  const char *const *exclude_settings,
+                  enum config_dump_scope scope,
                   enum config_dump_flags flags,
                   config_request_callback_t *callback, void *context)
        ATTR_NULL(1, 5);
index dc18837c1c66dd0dcfc593728414ffd79d93d504..821684867d74020c10a99d76577137c5b682034c 100644 (file)
@@ -154,7 +154,7 @@ config_dump_human_init(const char *const *modules, enum config_dump_scope scope,
                flags |= CONFIG_DUMP_FLAG_CHECK_SETTINGS;
        if (in_section)
                flags |= CONFIG_DUMP_FLAG_IN_SECTION;
-       ctx->export_ctx = config_export_init(modules, scope, flags,
+       ctx->export_ctx = config_export_init(modules, NULL, scope, flags,
                                             config_request_get_strings, ctx);
        return ctx;
 }
@@ -998,7 +998,7 @@ int main(int argc, char *argv[])
        if (simple_output) {
                struct config_export_context *ctx;
 
-               ctx = config_export_init(wanted_modules, scope,
+               ctx = config_export_init(wanted_modules, NULL, scope,
                                         CONFIG_DUMP_FLAG_CHECK_SETTINGS,
                                         config_request_simple_stdout,
                                         setting_name_filters);
@@ -1032,7 +1032,7 @@ int main(int argc, char *argv[])
        } else {
                struct config_export_context *ctx;
 
-               ctx = config_export_init(wanted_modules, CONFIG_DUMP_SCOPE_SET,
+               ctx = config_export_init(wanted_modules, NULL, CONFIG_DUMP_SCOPE_SET,
                                         CONFIG_DUMP_FLAG_CHECK_SETTINGS,
                                         config_request_putenv, NULL);
                config_export_by_filter(ctx, &filter);