]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: config_parse_file() - Change expand_values parameter to enum
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 9 Jan 2023 14:26:02 +0000 (16:26 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 27 Jan 2023 13:01:47 +0000 (13:01 +0000)
src/config/config-connection.c
src/config/config-parser.c
src/config/config-parser.h
src/config/doveconf.c
src/config/main.c
src/config/test-config-parser.c

index e2225b6b0dc2b8a27ead071333964cbcf002cce4..30eeb06ac4634a53e3c301c1c08e737f01c47fea 100644 (file)
@@ -58,7 +58,7 @@ static int config_connection_request(struct config_connection *conn,
                const char *path, *error;
 
                path = master_service_get_config_path(master_service);
-               if (config_parse_file(path, TRUE, NULL, &error) <= 0) {
+               if (config_parse_file(path, CONFIG_PARSE_FLAG_EXPAND_VALUES, NULL, &error) <= 0) {
                        o_stream_nsend_str(conn->output,
                                t_strconcat("-", error, "\n", NULL));
                        return 0;
index 099b577a407585d96d689fc9d9db1eb64067c74f..b95d86e1d764d2db3c2d282b0e51b4f9d50f4f38 100644 (file)
@@ -997,7 +997,7 @@ void config_parser_apply_line(struct config_parser_context *ctx,
        }
 }
 
-int config_parse_file(const char *path, bool expand_values,
+int config_parse_file(const char *path, enum config_parse_flags flags,
                      const char *const *modules, const char **error_r)
 {
        struct input_stack root;
@@ -1039,7 +1039,7 @@ int config_parse_file(const char *path, bool expand_values,
        i_zero(&root);
        root.path = path;
        ctx.cur_input = &root;
-       ctx.expand_values = expand_values;
+       ctx.expand_values = (flags & CONFIG_PARSE_FLAG_EXPAND_VALUES) != 0;
        ctx.modules = modules;
        hash_table_create(&ctx.seen_settings, ctx.pool, 0, str_hash, strcmp);
 
index e0a0a5bea3329eb5f33be67f18a46509c554f67e..92ea73d1b3cbd41d7314877b38a7f23e847d1365 100644 (file)
@@ -5,6 +5,10 @@
 
 #define IS_WHITE(c) ((c) == ' ' || (c) == '\t')
 
+enum config_parse_flags {
+       CONFIG_PARSE_FLAG_EXPAND_VALUES = BIT(0),
+};
+
 struct config_module_parser {
        const struct setting_parser_info *root;
        struct setting_parser_context *parser;
@@ -18,7 +22,7 @@ extern struct module *modules;
 
 int config_parse_net(const char *value, struct ip_addr *ip_r,
                     unsigned int *bits_r, const char **error_r);
-int config_parse_file(const char *path, bool expand_values,
+int config_parse_file(const char *path, enum config_parse_flags flags,
                      const char *const *modules, const char **error_r)
        ATTR_NULL(3);
 
index dd75b8f2518f0b470e699d746b855baf4f1913fa..27bc3eab176d825bb4e7f9a375a96debff2b78ab 100644 (file)
@@ -965,8 +965,11 @@ int main(int argc, char *argv[])
                }
        }
 
+       enum config_parse_flags flags = 0;
+       if (expand_vars)
+               flags |= CONFIG_PARSE_FLAG_EXPAND_VALUES;
        if ((ret = config_parse_file(dump_defaults ? NULL : config_path,
-                                    expand_vars, NULL,
+                                    flags, NULL,
                                     &error)) == 0 &&
            access(EXAMPLE_CONFIG_DIR, X_OK) == 0) {
                i_fatal("%s (copy example configs from "EXAMPLE_CONFIG_DIR"/)",
index 13dc76d26403dbcc53a59c0ecfbcf498e287590c..1a5b8eb77729a837379aa8cae3feb555cd4499e3 100644 (file)
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
        config_parse_load_modules();
 
        path = master_service_get_config_path(master_service);
-       if (config_parse_file(path, TRUE, NULL, &error) <= 0)
+       if (config_parse_file(path, CONFIG_PARSE_FLAG_EXPAND_VALUES, NULL, &error) <= 0)
                i_fatal("%s", error);
 
        /* notify about our success only after successfully parsing the
index baf91a1d45488320c569c70e9751ae3db87ef85d..5503d3da802c7117c72268d2addfaf09c443d190 100644 (file)
@@ -117,7 +117,7 @@ static void test_config_parser(void)
        putenv("bar=test2");
        putenv("FOO$ENV:FOO=works");
 
-       test_assert(config_parse_file(TEST_CONFIG_FILE, TRUE, NULL, &error) == 1);
+       test_assert(config_parse_file(TEST_CONFIG_FILE, CONFIG_PARSE_FLAG_EXPAND_VALUES, NULL, &error) == 1);
        if (error != NULL)
                i_error("config_parse_file(): %s", error);
 
@@ -138,7 +138,7 @@ static void test_config_parser(void)
        test_assert_strcmp(set->protocols, "pop3 imap");
 
        /* try again unexpanded */
-       test_assert(config_parse_file(TEST_CONFIG_FILE, FALSE, NULL, &error) == 1);
+       test_assert(config_parse_file(TEST_CONFIG_FILE, 0, NULL, &error) == 1);
        set = settings_parser_get(config_module_parsers[0].parser);
 
        test_assert_strcmp(set->key, "value");