]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-settings, config: Use set_value_unknown for checking settings with %variables
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 28 Dec 2023 20:43:45 +0000 (15:43 -0500)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:10 +0000 (12:34 +0200)
config process runs [ext_]check_func()s, but it can't expand %variables.
So when config sees that there are %variables in a string, it assigns the
value to "set_value_unknown" pointer. The check_func()s can then skip
checking the validity of settings that point to set_value_unknown.

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

index 92b8738a14a09c0c08f817b1cd61a40ceed1cd08..9e36d1b179a3fc2e6e06c855662bd4c89a173897 100644 (file)
@@ -1125,11 +1125,19 @@ config_module_parser_get_set_parser(const struct config_module_parser *p,
                        } T_END;
                        break;
                }
-               default:
+               default: {
+                       const char *value = p->settings[i].str;
+                       if (p->info->defines[i].type != SET_STR_NOVARS &&
+                           strchr(p->settings[i].str, '%') != NULL) {
+                               /* We don't know what the variables would
+                                  expand to. */
+                               value = set_value_unknown;
+                       }
                        (void)settings_parse_keyidx_value_nodup(parser, i,
-                               p->info->defines[i].key, p->settings[i].str);
+                               p->info->defines[i].key, value);
                        break;
                }
+               }
        }
        return parser;
 }
index cc5b9413ecb8c16cf85ac03d8c703d124c949536..19006bd388991534d61c0c5898add91edd6c0d89 100644 (file)
@@ -25,6 +25,8 @@ struct setting_parser_context {
        char *error;
 };
 
+const char *set_value_unknown = "UNKNOWN_VALUE_WITH_VARIABLES";
+
 #ifdef DEBUG
 static const char *boollist_eol_sentry = "boollist-eol";
 #endif
@@ -460,6 +462,11 @@ settings_parse(struct setting_parser_context *ctx,
        const void *ptr2;
        const char *error;
 
+       if (value == set_value_unknown) {
+               /* setting value is unknown - preserve the exact pointer */
+               dup_value = FALSE;
+       }
+
        i_free(ctx->error);
 
        while (def->type == SET_ALIAS) {
index 9e10e9f151407581f520f1720daf3db2633349c4..e52edb2f5d44e0e0f854cc6b0544c3e43a0a8ed4 100644 (file)
@@ -149,6 +149,11 @@ enum settings_parser_flags {
 
 struct setting_parser_context;
 
+/* If a string setting value has this pointer, it means the setting isn't
+   actually known because it contained %{variables}. [ext_]check_func() can use
+   this to not give early errors when the variable value isn't known. */
+extern const char *set_value_unknown;
+
 struct setting_parser_context *
 settings_parser_init(pool_t set_pool, const struct setting_parser_info *root,
                     enum settings_parser_flags flags);