]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveconf: When module is given, ignore checks for non-required settings.
authorTimo Sirainen <tss@iki.fi>
Thu, 25 Mar 2010 17:19:02 +0000 (19:19 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 25 Mar 2010 17:19:02 +0000 (19:19 +0200)
--HG--
branch : HEAD

src/config/config-connection.c
src/config/config-filter.c
src/config/config-parser-private.h
src/config/config-parser.c
src/config/config-parser.h
src/config/config-request.c
src/config/doveconf.c
src/config/main.c

index f78f44b69d0dd74256f94f6291b32e06d23b0d51..0a49bc8ee2eb74359c6bf4021859d3637f14aab6 100644 (file)
@@ -100,7 +100,7 @@ static int config_connection_request(struct config_connection *conn,
        if (strcmp(module, "master") == 0) {
                /* master reads configuration only when reloading settings */
                path = master_service_get_config_path(master_service);
-               if (config_parse_file(path, TRUE, &error) <= 0) {
+               if (config_parse_file(path, TRUE, "", &error) <= 0) {
                        o_stream_send_str(conn->output,
                                t_strconcat("ERROR ", error, "\n", NULL));
                        config_connection_destroy(conn);
index d661d8425b38b56c3b2c26191ef4e6eabfda0881..3adbd5f68b8ac80315266d6b7bcb1ae1c9d35578 100644 (file)
@@ -174,7 +174,8 @@ static bool have_changed_settings(const struct config_filter_parser *parser,
 
        for (i = 0; parser->parsers[i].root != NULL; i++) {
                if (*module != '\0' &&
-                   !config_module_want_parser(module, parser->parsers[i].root))
+                   !config_module_want_parser(config_module_parsers,
+                                              module, parser->parsers[i].root))
                        continue;
 
                changes = settings_parser_get_changes(parser->parsers[i].parser);
index 339668a2ee533dee053f22584f87073936ef3d41..efab0764651ebd1424cea754225e31e7cbf921a6 100644 (file)
@@ -36,6 +36,7 @@ struct input_stack {
 struct config_parser_context {
        pool_t pool;
        const char *path;
+       const char *module;
 
        ARRAY_DEFINE(all_parsers, struct config_filter_parser *);
        struct config_module_parser *root_parsers;
index eb01f2fe06c91efe935cc24eb41ad028581072b1..c7b2190015f5bf40b4d3c00a9db2498887840d68 100644 (file)
@@ -275,6 +275,11 @@ config_filter_parser_check(struct config_parser_context *ctx,
                           const struct config_module_parser *p,
                           const char **error_r)
 {
+       /* skip checking settings we don't care about */
+       if (*ctx->module != '\0' &&
+           !config_module_want_parser(ctx->root_parsers, ctx->module, p->root))
+               return 0;
+
        for (; p->root != NULL; p++) {
                settings_parse_var_skip(p->parser);
                if (!settings_parser_check(p->parser, ctx->pool, error_r))
@@ -603,6 +608,23 @@ config_get_value(struct config_section_stack *section, const char *key,
        return NULL;
 }
 
+static bool
+config_require_key(struct config_parser_context *ctx, const char *key)
+{
+       struct config_module_parser *l;
+
+       if (*ctx->module == '\0')
+               return TRUE;
+
+       for (l = ctx->cur_section->parsers; l->root != NULL; l++) {
+               if (config_module_want_parser(ctx->root_parsers,
+                                             ctx->module, l->root) &&
+                   settings_parse_is_valid_key(l->parser, key))
+                       return TRUE;
+       }
+       return FALSE;
+}
+
 static int config_write_value(struct config_parser_context *ctx,
                              enum config_line_type type,
                              const char *key, const char *value)
@@ -622,7 +644,8 @@ static int config_write_value(struct config_parser_context *ctx,
                        str_append_c(str, '<');
                        str_append(str, value);
                } else {
-                       if (str_append_file(str, key, value, &error) < 0) {
+                       if (str_append_file(str, key, value, &error) < 0 &&
+                           config_require_key(ctx, key)) {
                                /* file reading failed */
                                ctx->error = p_strdup(ctx->pool, error);
                                return -1;
@@ -737,7 +760,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, bool expand_values, const char *module,
                      const char **error_r)
 {
        struct input_stack root;
@@ -773,6 +796,7 @@ int config_parse_file(const char *path, bool expand_values,
        root.path = path;
        ctx.cur_input = &root;
        ctx.expand_values = expand_values;
+       ctx.module = module;
 
        p_array_init(&ctx.all_parsers, ctx.pool, 128);
        ctx.cur_section = p_new(ctx.pool, struct config_section_stack, 1);
@@ -883,7 +907,8 @@ static bool parsers_are_connected(const struct setting_parser_info *root,
        return FALSE;
 }
 
-bool config_module_want_parser(const char *module,
+bool config_module_want_parser(struct config_module_parser *parsers,
+                              const char *module,
                               const struct setting_parser_info *root)
 {
        struct config_module_parser *l;
@@ -895,7 +920,7 @@ bool config_module_want_parser(const char *module,
                return TRUE;
        }
 
-       for (l = config_module_parsers; l->root != NULL; l++) {
+       for (l = parsers; l->root != NULL; l++) {
                if (strcmp(l->root->module_name, module) != 0)
                        continue;
 
index aa2c3bd681eb641e5ed070c41b4db6e326b581a0..6029b5751cfef673c4efe5e5ec33f5af9eb3e145 100644 (file)
@@ -13,12 +13,13 @@ ARRAY_DEFINE_TYPE(config_module_parsers, struct config_module_parser *);
 extern struct config_module_parser *config_module_parsers;
 extern struct config_filter_context *config_filter;
 
-int config_parse_file(const char *path, bool expand_values,
+int config_parse_file(const char *path, bool expand_values, const char *module,
                      const char **error_r);
 
 void config_parse_load_modules(void);
 
-bool config_module_want_parser(const char *module,
+bool config_module_want_parser(struct config_module_parser *parsers,
+                              const char *module,
                               const struct setting_parser_info *root);
 
 #endif
index 2f49d859cf11f671a69586b8f343e969c2a9eb99..c650d4cffbb5bde7ba7676d2b98ab41fd51146c1 100644 (file)
@@ -367,7 +367,8 @@ int config_export_finish(struct config_export_context **_ctx)
        for (i = 0; ctx->parsers[i].root != NULL; i++) {
                parser = &ctx->parsers[i];
                if (*ctx->module != '\0' &&
-                   !config_module_want_parser(ctx->module, parser->root))
+                   !config_module_want_parser(config_module_parsers,
+                                              ctx->module, parser->root))
                        continue;
 
                settings_export(ctx, parser->root, FALSE,
index 87c786d9315992a5157c804cbfad464d91332b6d..60de398c652ea774f15d2169130740d83a9cc0d1 100644 (file)
@@ -517,7 +517,8 @@ int main(int argc, char *argv[])
        master_service_init_finish(master_service);
        config_parse_load_modules();
 
-       if ((ret = config_parse_file(config_path, expand_vars, &error)) == 0 &&
+       if ((ret = config_parse_file(config_path, expand_vars,
+                                    module, &error)) == 0 &&
            access(EXAMPLE_CONFIG_DIR, X_OK) == 0) {
                i_fatal("%s (copy example configs from "EXAMPLE_CONFIG_DIR"/)",
                        error);
index 08b295916903077fb3ac6809d4c725c7ef60fc38..741e20a3e55b042d35a64c2444db554bff3170d7 100644 (file)
@@ -30,7 +30,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, &error) <= 0)
+       if (config_parse_file(path, TRUE, "", &error) <= 0)
                i_fatal("%s", error);
 
        master_service_run(master_service, client_connected);