]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Apply setting_parser_info.default_settings to default config
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 7 Jun 2023 08:23:04 +0000 (11:23 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:09 +0000 (12:34 +0200)
src/config/config-parser.c
src/config/settings-get.pl

index a615f6f917495f00f60d608a34f1e4241fc85126..859b40ebdcdd5677f086f60ceb6ac9ab92676ab2 100644 (file)
@@ -234,6 +234,25 @@ static void config_parser_add_services(struct config_parser_context *ctx,
        } T_END;
 }
 
+static void config_parser_add_info_defaults(struct config_parser_context *ctx,
+                                           const struct setting_parser_info *info)
+{
+       if (info->default_settings == NULL)
+               return;
+
+       config_parser_set_change_counter(ctx, CONFIG_PARSER_CHANGE_INTERNAL);
+       for (unsigned int i = 0; info->default_settings[i].key != NULL; i++) {
+               if (config_apply_line(ctx, info->default_settings[i].key,
+                                     info->default_settings[i].value, NULL) < 0) {
+                       i_panic("Failed to add default setting %s=%s for struct %s: %s",
+                               info->default_settings[i].key,
+                               info->default_settings[i].value,
+                               info->name, ctx->error);
+               }
+       }
+       config_parser_set_change_counter(ctx, CONFIG_PARSER_CHANGE_EXPLICIT);
+}
+
 static bool
 config_parser_is_in_localremote(struct config_section_stack *section)
 {
@@ -1856,8 +1875,11 @@ int config_parse_file(const char *path, enum config_parse_flags flags,
                i_stream_create_from_data("", 0);
        i_stream_set_return_partial_line(ctx.cur_input->input, TRUE);
        old_settings_init(&ctx);
-       if ((flags & CONFIG_PARSE_FLAG_NO_DEFAULTS) == 0)
+       if ((flags & CONFIG_PARSE_FLAG_NO_DEFAULTS) == 0) {
                config_parser_add_services(&ctx, service_info_idx);
+               for (i = 0; i < count; i++)
+                       config_parser_add_info_defaults(&ctx, all_infos[i]);
+       }
        if (hook_config_parser_begin != NULL &&
            (flags & CONFIG_PARSE_FLAG_EXTERNAL_HOOKS) != 0) T_BEGIN {
                hook_config_parser_begin(&ctx);
index f29dc850acf1f20542e5b6d3221d18ea5470bc1b..3e58abc0c449a08ece3b999b0ea0970397d262f7 100755 (executable)
@@ -52,7 +52,8 @@ foreach my $file (@ARGV) {
     if ($state eq "root") {
       if (/struct .*_settings \{/ ||
           /struct setting_define.*\{/ ||
-          /struct .*_default_settings = \{/) {
+          /struct .*_default_settings = \{/ ||
+          /struct setting_keyvalue.*_default_settings_keyvalue\[\] = \{/) {
         # settings-related structure - copy.
         $state = "copy-to-end-of-block";
       } elsif (/^struct service_settings (.*) = \{/) {