From: Timo Sirainen Date: Tue, 3 Aug 2021 16:46:59 +0000 (+0300) Subject: config: Add exclude= settings to drop specific settings X-Git-Tag: 2.3.17~221 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4ea4a8560754468b86ec22e24ed4fc95a5a03fc0;p=thirdparty%2Fdovecot%2Fcore.git config: Add exclude= settings to drop specific settings --- diff --git a/src/config/config-connection.c b/src/config/config-connection.c index 5f299c81d2..bd3db86505 100644 --- a/src/config/config-connection.c +++ b/src/config/config-connection.c @@ -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; /* [] */ 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); diff --git a/src/config/config-request.c b/src/config/config-request.c index 9709615c94..00d0e50539 100644 --- a/src/config/config-request.c +++ b/src/config/config-request.c @@ -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; diff --git a/src/config/config-request.h b/src/config/config-request.h index c8a3fa24a8..c91e836e95 100644 --- a/src/config/config-request.h +++ b/src/config/config-request.h @@ -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); diff --git a/src/config/doveconf.c b/src/config/doveconf.c index dc18837c1c..821684867d 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -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);