~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/config/config-parser.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2005-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
11
11
#include "service-settings.h"
12
12
#include "master-service.h"
13
13
#include "master-service-settings.h"
 
14
#include "master-service-ssl-settings.h"
14
15
#include "all-settings.h"
15
16
#include "old-set-parser.h"
16
17
#include "config-request.h"
337
338
{
338
339
        for (; p->root != NULL; p++) {
339
340
                /* skip checking settings we don't care about */
340
 
                if (*ctx->module != '\0' &&
341
 
                    !config_module_want_parser(ctx->root_parsers,
342
 
                                               ctx->module, p->root))
 
341
                if (!config_module_want_parser(ctx->root_parsers,
 
342
                                               ctx->modules, p->root))
343
343
                        continue;
344
344
 
345
345
                settings_parse_var_skip(p->parser);
399
399
 
400
400
        global_ssl_set = get_str_setting(parsers[0], "ssl", "");
401
401
        for (i = 0; i < count && ret == 0; i++) {
402
 
                if (config_filter_parsers_get(new_filter, tmp_pool, "",
 
402
                if (config_filter_parsers_get(new_filter, tmp_pool, NULL,
403
403
                                              &parsers[i]->filter,
404
404
                                              &tmp_parsers, &output,
405
405
                                              error_r) < 0) {
431
431
        int fd;
432
432
        ssize_t ret;
433
433
 
 
434
        *error_r = NULL;
 
435
 
434
436
        fd = open(path, O_RDONLY);
435
437
        if (fd == -1) {
436
438
                *error_r = t_strdup_printf("%s: Can't open file %s: %m",
443
445
                *error_r = t_strdup_printf("%s: read(%s) failed: %m",
444
446
                                           key, path);
445
447
        }
446
 
        (void)close(fd);
 
448
        i_close_fd(&fd);
447
449
        return ret < 0 ? -1 : 0;
448
450
}
449
451
 
685
687
        int ret;
686
688
 
687
689
        new_filter = config_filter_init(ctx->pool);
688
 
        (void)array_append_space(&ctx->all_parsers);
 
690
        array_append_zero(&ctx->all_parsers);
689
691
        config_filter_add_all(new_filter, array_idx(&ctx->all_parsers, 0));
690
692
 
691
693
        if (ctx->hide_errors)
729
731
{
730
732
        struct config_module_parser *l;
731
733
 
732
 
        if (*ctx->module == '\0')
 
734
        if (ctx->modules == NULL)
733
735
                return TRUE;
734
736
 
735
737
        for (l = ctx->cur_section->parsers; l->root != NULL; l++) {
736
738
                if (config_module_want_parser(ctx->root_parsers,
737
 
                                              ctx->module, l->root) &&
 
739
                                              ctx->modules, l->root) &&
738
740
                    settings_parse_is_valid_key(l->parser, key))
739
741
                        return TRUE;
740
742
        }
882
884
        }
883
885
}
884
886
 
885
 
int config_parse_file(const char *path, bool expand_values, const char *module,
886
 
                      const char **error_r)
 
887
int config_parse_file(const char *path, bool expand_values,
 
888
                      const char *const *modules, const char **error_r)
887
889
{
888
890
        struct input_stack root;
889
891
        struct config_parser_context ctx;
925
927
        root.path = path;
926
928
        ctx.cur_input = &root;
927
929
        ctx.expand_values = expand_values;
928
 
        ctx.module = module;
 
930
        ctx.modules = modules;
929
931
 
930
932
        p_array_init(&ctx.all_parsers, ctx.pool, 128);
931
933
        ctx.cur_section = p_new(ctx.pool, struct config_section_stack, 1);
981
983
        struct module_dir_load_settings mod_set;
982
984
        struct module *m;
983
985
        const struct setting_parser_info **roots;
984
 
        ARRAY_DEFINE(new_roots, const struct setting_parser_info *);
 
986
        ARRAY(const struct setting_parser_info *) new_roots;
985
987
        ARRAY_TYPE(service_settings) new_services;
986
988
        struct service_settings *const *services, *service_set;
987
989
        unsigned int i, count;
988
990
 
989
991
        memset(&mod_set, 0, sizeof(mod_set));
990
 
        mod_set.version = master_service_get_version_string(master_service);
 
992
        mod_set.abi_version = DOVECOT_ABI_VERSION;
991
993
        modules = module_dir_load(CONFIG_MODULE_DIR, NULL, &mod_set);
992
994
        module_dir_init(modules);
993
995
 
1001
1003
                                array_append(&new_roots, &roots[i], 1);
1002
1004
                }
1003
1005
 
1004
 
                service_set = module_get_symbol_quiet(m,
1005
 
                        t_strdup_printf("%s_service_settings", m->name));
1006
 
                if (service_set != NULL)
1007
 
                        array_append(&new_services, &service_set, 1);
 
1006
                services = module_get_symbol_quiet(m,
 
1007
                        t_strdup_printf("%s_service_settings_array", m->name));
 
1008
                if (services != NULL) {
 
1009
                        for (count = 0; services[count] != NULL; count++) ;
 
1010
                        array_append(&new_services, services, count);
 
1011
                } else {
 
1012
                        service_set = module_get_symbol_quiet(m,
 
1013
                                t_strdup_printf("%s_service_settings", m->name));
 
1014
                        if (service_set != NULL)
 
1015
                                array_append(&new_services, &service_set, 1);
 
1016
                }
1008
1017
        }
1009
1018
        if (array_count(&new_roots) > 0) {
1010
1019
                /* modules added new settings. add the defaults and start
1011
1020
                   using the new list. */
1012
1021
                for (i = 0; all_roots[i] != NULL; i++)
1013
1022
                        array_append(&new_roots, &all_roots[i], 1);
1014
 
                (void)array_append_space(&new_roots);
 
1023
                array_append_zero(&new_roots);
1015
1024
                all_roots = array_idx(&new_roots, 0);
1016
1025
        }
1017
1026
        if (array_count(&new_services) > 0) {
1046
1055
}
1047
1056
 
1048
1057
bool config_module_want_parser(struct config_module_parser *parsers,
1049
 
                               const char *module,
 
1058
                               const char *const *modules,
1050
1059
                               const struct setting_parser_info *root)
1051
1060
{
1052
1061
        struct config_module_parser *l;
1053
1062
 
1054
 
        if (strcmp(root->module_name, module) == 0)
 
1063
        if (modules == NULL)
1055
1064
                return TRUE;
1056
1065
        if (root == &master_service_setting_parser_info) {
1057
1066
                /* everyone wants master service settings */
1059
1068
        }
1060
1069
 
1061
1070
        for (l = parsers; l->root != NULL; l++) {
1062
 
                if (strcmp(l->root->module_name, module) != 0)
 
1071
                if (!str_array_find(modules, l->root->module_name))
1063
1072
                        continue;
1064
1073
 
1065
1074
                /* see if we can find a way to get from the original parser