bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */
6347bb65e93c27f1bf4330786447c9ab0cab4dbfTimo SirainenARRAY_DEFINE_TYPE(setting_parser_info_p, const struct setting_parser_info *);
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainenstatic const enum settings_parser_flags settings_parser_flags =
94163c620a8880024d0e8bbb503c788159fa222bTimo Sirainenstruct config_module_parser *config_module_parsers;
0171540a6764f714b8b753ba209ec9a83c213d25Timo Sirainenvoid (*hook_config_parser_begin)(struct config_parser_context *ctx);
0df566822360dd8ca963864a51a8bd56054c3331Timo Sirainenint (*hook_config_parser_end)(struct config_parser_context *ctx,
0df566822360dd8ca963864a51a8bd56054c3331Timo Sirainen const char **error_r);
6347bb65e93c27f1bf4330786447c9ab0cab4dbfTimo Sirainenstatic ARRAY_TYPE(service_settings) services_free_at_deinit = ARRAY_INIT;
6347bb65e93c27f1bf4330786447c9ab0cab4dbfTimo Sirainenstatic ARRAY_TYPE(setting_parser_info_p) roots_free_at_deinit = ARRAY_INIT;
28cb56e6957f06717e876cecb7aabc820fdf632eTimo Sirainenstatic const char *info_type_name_find(const struct setting_parser_info *info)
28cb56e6957f06717e876cecb7aabc820fdf632eTimo Sirainen unsigned int i;
28cb56e6957f06717e876cecb7aabc820fdf632eTimo Sirainen for (i = 0; info->defines[i].key != NULL; i++) {
28cb56e6957f06717e876cecb7aabc820fdf632eTimo Sirainen if (info->defines[i].offset == info->type_offset)
28cb56e6957f06717e876cecb7aabc820fdf632eTimo Sirainen i_panic("setting parser: Invalid type_offset value");
36175032e12e7dfe67f92ee7c2065fdc6865aefdTimo Sirainenstatic int config_add_type(struct setting_parser_context *parser,
28cb56e6957f06717e876cecb7aabc820fdf632eTimo Sirainen const char *p;
36175032e12e7dfe67f92ee7c2065fdc6865aefdTimo Sirainen /* section inside strlist */
096e109f9f332bc758ca5e22ec64337379c5f231Timo Sirainen ret = settings_parse_keyvalue(parser, str_c(str), section_name);
33ef806e0d378a0b2326cd939714c9070502d1e5Timo Sirainenconfig_parser_is_in_localremote(struct config_section_stack *section)
33ef806e0d378a0b2326cd939714c9070502d1e5Timo Sirainen const struct config_filter *filter = §ion->filter;
33ef806e0d378a0b2326cd939714c9070502d1e5Timo Sirainen return filter->local_name != NULL || filter->local_bits > 0 ||
e3d797bc851dc90fb88e68ae715c204d0f46e6ffTimo Sirainensection_stack_write(string_t *str, struct config_section_stack *section)
e3d797bc851dc90fb88e68ae715c204d0f46e6ffTimo Sirainen if (!section->is_filter && section->key != NULL)
e3d797bc851dc90fb88e68ae715c204d0f46e6ffTimo Sirainenstatic const char *
e3d797bc851dc90fb88e68ae715c204d0f46e6ffTimo Sirainenget_setting_full_path(struct config_parser_context *ctx, const char *key)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenint config_apply_line(struct config_parser_context *ctx, const char *key,
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen for (l = ctx->cur_section->parsers; l->root != NULL; l++) {
33ef806e0d378a0b2326cd939714c9070502d1e5Timo Sirainen /* FIXME: remove once auth does support these. */
33ef806e0d378a0b2326cd939714c9070502d1e5Timo Sirainen if (strcmp(l->root->module_name, "auth") == 0 &&
33ef806e0d378a0b2326cd939714c9070502d1e5Timo Sirainen config_parser_is_in_localremote(ctx->cur_section)) {
33ef806e0d378a0b2326cd939714c9070502d1e5Timo Sirainen "Auth settings not supported inside local/remote blocks: ",
36175032e12e7dfe67f92ee7c2065fdc6865aefdTimo Sirainen if (config_add_type(l->parser, line, section_name) < 0) {
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen } else if (ret < 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->error = settings_parser_get_error(l->parser);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->error = p_strconcat(ctx->pool, "Unknown setting: ",
bbc30fd4fa86723f6a72309ad3a2a96f34eabd6cTimo Sirainenstatic const char *
bbc30fd4fa86723f6a72309ad3a2a96f34eabd6cTimo Sirainenfix_relative_path(const char *path, struct input_stack *input)
bbc30fd4fa86723f6a72309ad3a2a96f34eabd6cTimo Sirainen const char *p;
bbc30fd4fa86723f6a72309ad3a2a96f34eabd6cTimo Sirainen return t_strconcat(t_strdup_until(input->path, p+1), path, NULL);
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen for (count = 0; all_roots[count] != NULL; count++) ;
94163c620a8880024d0e8bbb503c788159fa222bTimo Sirainen dest = p_new(pool, struct config_module_parser, count + 1);
1358e2c58ce29231485a5cfa454756d429ad3d2cTimo Sirainen for (i = 0; i < count; i++) {
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen dest[i].parser = settings_parser_init(pool, all_roots[i],
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_add_new_parser(struct config_parser_context *ctx)
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen struct config_section_stack *cur_section = ctx->cur_section;
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen parser = p_new(ctx->pool, struct config_filter_parser, 1);
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen parser->parsers = cur_section->prev == NULL ? ctx->root_parsers :
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_add_new_section(struct config_parser_context *ctx)
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen section = p_new(ctx->pool, struct config_section_stack, 1);
1618629fd55e914c8d2e28fc01b8264613f00a99Timo Sirainen section->open_path = p_strdup(ctx->pool, ctx->cur_input->path);
1618629fd55e914c8d2e28fc01b8264613f00a99Timo Sirainen section->open_linenum = ctx->cur_input->linenum;
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_filter_parser_find(struct config_parser_context *ctx,
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen struct config_filter_parser *parser = *parsers;
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen if (config_filters_equal(&parser->filter, filter))
de44e83f4b5e366e57e973b26f2eb0ad26984945Timo Sirainenint config_parse_net(const char *value, struct ip_addr *ip_r,
08e7163a8d12979119fa56c92676af4ba6304f1aTimo Sirainen const char *p;
08e7163a8d12979119fa56c92676af4ba6304f1aTimo Sirainen if (net_parse_range(value, ip_r, bits_r) == 0)
08e7163a8d12979119fa56c92676af4ba6304f1aTimo Sirainen ret = net_gethostbyname(value, &ips, &ip_count);
08e7163a8d12979119fa56c92676af4ba6304f1aTimo Sirainen *error_r = t_strdup_printf("gethostbyname(%s) failed: %s",
6a865d46c3704c7d9781f5f249d87796ec5d3591Timo Sirainen i_warning("gethostbyname(%s) took %d seconds",
059b4bb561737ce8e15620149140b122021929c9Timo Sirainen else if (str_to_uint(p, &bits) == 0 && bits <= max_bits)
059b4bb561737ce8e15620149140b122021929c9Timo Sirainen *error_r = t_strdup_printf("Invalid network mask: %s", p);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_filter_add_new_filter(struct config_parser_context *ctx,
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen struct config_filter *filter = &ctx->cur_section->filter;
dbd93ca6319a01fdea82853e8b4bd4b226d796f0Timo Sirainen struct config_filter *parent = &ctx->cur_section->prev->filter;
0df899feada1f406122d7658894c77eeb10225a3Timo Sirainen ctx->error = "Nested protocol { protocol { .. } } block not allowed";
0df899feada1f406122d7658894c77eeb10225a3Timo Sirainen ctx->error = "remote { local { .. } } not allowed (use local { remote { .. } } instead)";
0df899feada1f406122d7658894c77eeb10225a3Timo Sirainen ctx->error = "protocol { local { .. } } not allowed (use local { protocol { .. } } instead)";
0df899feada1f406122d7658894c77eeb10225a3Timo Sirainen ctx->error = "local_name { local { .. } } not allowed (use local { local_name { .. } } instead)";
7c2b57939462fc2022d7e7f7aecd768ec1a8ba38Timo Sirainen else if (config_parse_net(value, &filter->local_net,
dbd93ca6319a01fdea82853e8b4bd4b226d796f0Timo Sirainen else if (parent->local_bits > filter->local_bits ||
0df899feada1f406122d7658894c77eeb10225a3Timo Sirainen ctx->error = "local net1 { local net2 { .. } } requires net2 to be inside net1";
7c2b57939462fc2022d7e7f7aecd768ec1a8ba38Timo Sirainen filter->local_host = p_strdup(ctx->pool, value);
0df899feada1f406122d7658894c77eeb10225a3Timo Sirainen ctx->error = "remote { local_name { .. } } not allowed (use local_name { remote { .. } } instead)";
0df899feada1f406122d7658894c77eeb10225a3Timo Sirainen ctx->error = "protocol { local_name { .. } } not allowed (use local_name { protocol { .. } } instead)";
41942258112e4131de96b6a4399c1a8ac83a23cbTimo Sirainen filter->local_name = p_strdup(ctx->pool, value);
0df899feada1f406122d7658894c77eeb10225a3Timo Sirainen ctx->error = "protocol { remote { .. } } not allowed (use remote { protocol { .. } } instead)";
7c2b57939462fc2022d7e7f7aecd768ec1a8ba38Timo Sirainen else if (config_parse_net(value, &filter->remote_net,
dbd93ca6319a01fdea82853e8b4bd4b226d796f0Timo Sirainen else if (parent->remote_bits > filter->remote_bits ||
0df899feada1f406122d7658894c77eeb10225a3Timo Sirainen ctx->error = "remote net1 { remote net2 { .. } } requires net2 to be inside net1";
7c2b57939462fc2022d7e7f7aecd768ec1a8ba38Timo Sirainen filter->remote_host = p_strdup(ctx->pool, value);
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen parser = config_filter_parser_find(ctx, filter);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_filter_parser_check(struct config_parser_context *ctx,
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen const char **error_r)
e982ce57ae92ab7ac22496357219697676fab731Timo Sirainen /* skip checking settings we don't care about */
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainen if (!config_module_want_parser(ctx->root_parsers,
33bd898e7756b289e65f43133312d9637afc1371Timo Sirainen ok = settings_parser_check(p->parser, ctx->pool, &error);
6407c617c37ddf87a8d21745bc95d826c62200a4Timo Sirainenstatic const char *
f637b33bb82d56c0546eb08cefcbd7617d885232Timo Sirainenget_str_setting(struct config_filter_parser *parser, const char *key,
6407c617c37ddf87a8d21745bc95d826c62200a4Timo Sirainen for (; module_parser->parser != NULL; module_parser++) {
6407c617c37ddf87a8d21745bc95d826c62200a4Timo Sirainen set_value = settings_parse_get_value(module_parser->parser,
f637b33bb82d56c0546eb08cefcbd7617d885232Timo Sirainen settings_parse_is_changed(module_parser->parser, key)) {
6407c617c37ddf87a8d21745bc95d826c62200a4Timo Sirainen i_assert(set_type == SET_STR || set_type == SET_ENUM);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_all_parsers_check(struct config_parser_context *ctx,
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen const char **error_r)
1618629fd55e914c8d2e28fc01b8264613f00a99Timo Sirainen "Missing '}' (section started at %s:%u)",
33bd898e7756b289e65f43133312d9637afc1371Timo Sirainen tmp_pool = pool_alloconly_create(MEMPOOL_GROWING"config parsers check", 1024*64);
1358e2c58ce29231485a5cfa454756d429ad3d2cTimo Sirainen parsers = array_get(&ctx->all_parsers, &count);
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen i_assert(count > 0 && parsers[count-1] == NULL);
f637b33bb82d56c0546eb08cefcbd7617d885232Timo Sirainen global_ssl_set = get_str_setting(parsers[0], "ssl", "");
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainen if (config_filter_parsers_get(new_filter, tmp_pool, NULL,
f637b33bb82d56c0546eb08cefcbd7617d885232Timo Sirainen ssl_set = get_str_setting(parsers[i], "ssl", global_ssl_set);
f637b33bb82d56c0546eb08cefcbd7617d885232Timo Sirainen strcmp(global_ssl_set, "no") == 0 && !ssl_warned) {
6407c617c37ddf87a8d21745bc95d826c62200a4Timo Sirainen i_warning("SSL is disabled because global ssl=no, "
6ed1e82824590b514201d9db84ba96bdfc832dd5Timo Sirainen ret = config_filter_parser_check(ctx, tmp_parsers, error_r);
1b33e848e84e6f74aa0e3339c32fa96bc15102a2Timo Sirainenstr_append_file(string_t *str, const char *key, const char *path,
1b33e848e84e6f74aa0e3339c32fa96bc15102a2Timo Sirainen const char **error_r)
1b33e848e84e6f74aa0e3339c32fa96bc15102a2Timo Sirainen *error_r = t_strdup_printf("%s: Can't open file %s: %m",
1b33e848e84e6f74aa0e3339c32fa96bc15102a2Timo Sirainen while ((ret = read(fd, buf, sizeof(buf))) > 0)
1b33e848e84e6f74aa0e3339c32fa96bc15102a2Timo Sirainen *error_r = t_strdup_printf("%s: read(%s) failed: %m",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic int settings_add_include(struct config_parser_context *ctx, const char *path,
a78d5bd9772681a232de56b3dd6acefee66cc71bTimo Sirainen for (tmp = ctx->cur_input; tmp != NULL; tmp = tmp->prev) {
a78d5bd9772681a232de56b3dd6acefee66cc71bTimo Sirainen *error_r = t_strdup_printf("Recursive include file: %s", path);
a78d5bd9772681a232de56b3dd6acefee66cc71bTimo Sirainen *error_r = t_strdup_printf("Couldn't open include file %s: %m",
66d7dd2a37123a332f19bfa83ea58521f9853d01Timo Sirainen new_input = p_new(ctx->pool, struct input_stack, 1);
bace943c67e6cd14ce6c994f533d82a3caad5bf1Timo Sirainen new_input->input = i_stream_create_fd_autoclose(&fd, (size_t)-1);
a78d5bd9772681a232de56b3dd6acefee66cc71bTimo Sirainen i_stream_set_return_partial_line(new_input->input, TRUE);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainensettings_include(struct config_parser_context *ctx, const char *pattern,
a78d5bd9772681a232de56b3dd6acefee66cc71bTimo Sirainen unsigned int i;
a78d5bd9772681a232de56b3dd6acefee66cc71bTimo Sirainen switch (glob(pattern, GLOB_BRACE, NULL, &globbers)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->error = "glob() failed: Not enough memory";
19557f192d37cd54a1a090a8a26d9d47265e4413Aki Tuomi /* iterate through the different files matching the globbing */
460fc973318e28c32d53c5696a5835b56a9527a9Timo Sirainen if (settings_add_include(ctx, globbers.gl_pathv[i-1],
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (settings_add_include(ctx, pattern, ignore_errors, &error) < 0) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenconfig_parse_line(struct config_parser_context *ctx,
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen /* @UNSAFE: line is modified */
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen /* skip whitespace */
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen /* ignore comments or empty lines */
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen /* strip away comments. pretty kludgy way really.. */
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen if (*p == '\0')
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen } else if (*p == '#') {
25e480bc781fdbcbee1d8b88ccdef163c0c63b0fTimo Sirainen "Ambiguous '#' character in line, treating it as comment. "
25e480bc781fdbcbee1d8b88ccdef163c0c63b0fTimo Sirainen "Add a space before it to remove this warning.",
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen /* remove whitespace from end of line */
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen /* continues in next line */
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen /* a) key = value
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen b) section_type [section_name] {
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen while (!IS_WHITE(*line) && *line != '\0' && *line != '=')
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen /* b) + errors */
3c3777721b56e065fac99a0f34e4cef4f293b517Timo Sirainen /* get section name */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic int config_parse_finish(struct config_parser_context *ctx, const char **error_r)
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen config_filter_add_all(new_filter, array_idx(&ctx->all_parsers, 0));
c45852c0ee568ae95360002363f21a147bf6c7abTimo Sirainen else if ((ret = config_all_parsers_check(ctx, new_filter, &error)) < 0) {
637ec4c33b4715737a41f7e58c9b6d1f693c27e2Timo Sirainen *error_r = t_strdup_printf("Error in configuration file %s: %s",
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainenstatic const void *
19ddb3a08a51e533a8f793b1d9beebd87c201d10Timo Sirainenconfig_get_value(struct config_section_stack *section, const char *key,
92a9ff5e799adf9bffb8831576d84eb84b8ef09aTimo Sirainen bool expand_parent, enum setting_type *type_r)
92a9ff5e799adf9bffb8831576d84eb84b8ef09aTimo Sirainen for (l = section->parsers; l->root != NULL; l++) {
7a5e2e937f0f388465c2938645ee971b4fd01bf1Timo Sirainen value = settings_parse_get_value(l->parser, key, type_r);
19ddb3a08a51e533a8f793b1d9beebd87c201d10Timo Sirainen if (!expand_parent || section->prev == NULL ||
19ddb3a08a51e533a8f793b1d9beebd87c201d10Timo Sirainen /* not changed by this parser. maybe parent has. */
a402b3c01073c1b11fe3c83aae4e3bc5c7d40360Timo Sirainenconfig_require_key(struct config_parser_context *ctx, const char *key)
a402b3c01073c1b11fe3c83aae4e3bc5c7d40360Timo Sirainen for (l = ctx->cur_section->parsers; l->root != NULL; l++) {
a402b3c01073c1b11fe3c83aae4e3bc5c7d40360Timo Sirainen if (config_module_want_parser(ctx->root_parsers,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenstatic int config_write_value(struct config_parser_context *ctx,
3fae65c7973bd0327191c2c4e9c9bcd48f24f59bTimo Sirainen full_key = t_strndup(str_data(ctx->str), str_len(str)-1);
098e1a7aef39722fd2d4b4e4535eb9e6aedd1ef2Timo Sirainen /* don't even try to open the file */
9e28e13ae8dc7cf7e9ff82d07392db8a6e941495Timo Sirainen path = fix_relative_path(value, ctx->cur_input);
3fae65c7973bd0327191c2c4e9c9bcd48f24f59bTimo Sirainen if (str_append_file(str, full_key, path, &error) < 0) {
9e28e13ae8dc7cf7e9ff82d07392db8a6e941495Timo Sirainen /* file reading failed */
d581fe1755bcfc0f42020178376ec65e2f8ced4bTimo Sirainen /* expand_parent=TRUE for "key = $key stuff".
d581fe1755bcfc0f42020178376ec65e2f8ced4bTimo Sirainen we'll always expand it so that doveconf -n can give
d581fe1755bcfc0f42020178376ec65e2f8ced4bTimo Sirainen usable output */
19ddb3a08a51e533a8f793b1d9beebd87c201d10Timo Sirainen var_value = config_get_value(ctx->cur_section, var_name,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen "Unknown variable: $",
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen "Invalid variable: $",
87404eae4581d7ef834f490507503e59a500066eTimo Sirainenconfig_parser_check_warnings(struct config_parser_context *ctx, const char *key)
87404eae4581d7ef834f490507503e59a500066eTimo Sirainen first_pos = hash_table_lookup(ctx->seen_settings, str_c(ctx->str));
87404eae4581d7ef834f490507503e59a500066eTimo Sirainen /* changing a root setting. if we've already seen it inside
87404eae4581d7ef834f490507503e59a500066eTimo Sirainen filters, log a warning. */
cb445bd4e32a2aae17a97a87bd74f57caec25449Timo Sirainen i_warning("%s line %u: Global setting %s won't change the setting inside an earlier filter at %s "
cb445bd4e32a2aae17a97a87bd74f57caec25449Timo Sirainen "(if this is intentional, avoid this warning by moving the global setting before %s)",
87404eae4581d7ef834f490507503e59a500066eTimo Sirainen ctx->cur_input->path, ctx->cur_input->linenum,
87404eae4581d7ef834f490507503e59a500066eTimo Sirainen first_pos = p_strdup_printf(ctx->pool, "%s line %u",
87404eae4581d7ef834f490507503e59a500066eTimo Sirainen ctx->cur_input->path, ctx->cur_input->linenum);
87404eae4581d7ef834f490507503e59a500066eTimo Sirainen hash_table_insert(ctx->seen_settings, path, first_pos);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainenvoid config_parser_apply_line(struct config_parser_context *ctx,
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_write_value(ctx, type, key, value) < 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen (void)config_apply_line(ctx, key, str_c(ctx->str), NULL);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen ctx->cur_section = config_add_new_section(ctx);
e3d797bc851dc90fb88e68ae715c204d0f46e6ffTimo Sirainen ctx->cur_section->key = p_strdup(ctx->pool, key);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_filter_add_new_filter(ctx, key, value)) {
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen /* new filter */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen /* new config section */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen /* no section name, use a counter */
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen section_name = dec2str(ctx->section_counter++);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen section_name = settings_section_escape(value);
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen if (config_apply_line(ctx, key, str_c(ctx->str), value) < 0)
b28a1c61a5d262fd16b46bebe47dbfb90ac9c5fcTimo Sirainen (void)settings_include(ctx, fix_relative_path(value, ctx->cur_input),
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainenint config_parse_file(const char *path, bool expand_values,
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainen const char *const *modules, const char **error_r)
c45852c0ee568ae95360002363f21a147bf6c7abTimo Sirainen *error_r = t_strdup_printf("open(%s) failed: %m", path);
33bd898e7756b289e65f43133312d9637afc1371Timo Sirainen ctx.pool = pool_alloconly_create(MEMPOOL_GROWING"config file parser", 1024*256);
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen for (count = 0; all_roots[count] != NULL; count++) ;
94163c620a8880024d0e8bbb503c788159fa222bTimo Sirainen p_new(ctx.pool, struct config_module_parser, count+1);
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen for (i = 0; i < count; i++) {
87404eae4581d7ef834f490507503e59a500066eTimo Sirainen hash_table_create(&ctx.seen_settings, ctx.pool, 0, str_hash, strcmp);
13be7f7215efe02d020e9d823772861df98b82bdTimo Sirainen p_array_init(&ctx.all_parsers, ctx.pool, 128);
13be7f7215efe02d020e9d823772861df98b82bdTimo Sirainen ctx.cur_section = p_new(ctx.pool, struct config_section_stack, 1);
bace943c67e6cd14ce6c994f533d82a3caad5bf1Timo Sirainen i_stream_create_fd_autoclose(&fd, (size_t)-1) :
1358e2c58ce29231485a5cfa454756d429ad3d2cTimo Sirainen i_stream_set_return_partial_line(ctx.cur_input->input, TRUE);
33bd898e7756b289e65f43133312d9637afc1371Timo Sirainen if (hook_config_parser_begin != NULL) T_BEGIN {
1358e2c58ce29231485a5cfa454756d429ad3d2cTimo Sirainen while ((line = i_stream_read_next_line(ctx.cur_input->input)) != NULL) {
25e480bc781fdbcbee1d8b88ccdef163c0c63b0fTimo Sirainen type = config_parse_line(&ctx, line, full_line,
d461a91e5eb2270e77f4276f0268ba1eede6a08dTimo Sirainen handled = old_settings_handle(&ctx, type, key, value);
66d7dd2a37123a332f19bfa83ea58521f9853d01Timo Sirainen config_parser_apply_line(&ctx, type, key, value);
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen "Error in configuration file %s line %d: %s",
12ab808b472ed51923945efac4156a380bd58d57Timo Sirainen struct service_settings *const *services, *service_set;
9ba7e76c20be775f368254e3059a6189fe789f16Timo Sirainen modules = module_dir_load(CONFIG_MODULE_DIR, NULL, &mod_set);
1ab2295a9258fe032bc9cb38909e902b40353282Timo Sirainen t_strdup_printf("%s_service_settings_array", m->name));
1ab2295a9258fe032bc9cb38909e902b40353282Timo Sirainen for (count = 0; services[count] != NULL; count++) ;
1ab2295a9258fe032bc9cb38909e902b40353282Timo Sirainen t_strdup_printf("%s_service_settings", m->name));
fc4b301e2dd86c096b9c41ad1b011b752fffd570Timo Sirainen /* modules added new settings. add the defaults and start
fc4b301e2dd86c096b9c41ad1b011b752fffd570Timo Sirainen using the new list. */
12ab808b472ed51923945efac4156a380bd58d57Timo Sirainen /* module added new services. update the defaults. */
12ab808b472ed51923945efac4156a380bd58d57Timo Sirainen services = array_get(default_services, &count);
12ab808b472ed51923945efac4156a380bd58d57Timo Sirainen for (i = 0; i < count; i++)
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainenstatic bool parsers_are_connected(const struct setting_parser_info *root,
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainen const struct setting_parser_info *p;
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainen /* we're trying to find info or its parents from root's dependencies. */
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainen for (dep = root->dependencies; *dep != NULL; dep++) {
a402b3c01073c1b11fe3c83aae4e3bc5c7d40360Timo Sirainenbool config_module_want_parser(struct config_module_parser *parsers,
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainen const char *const *modules,
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainen if (root == &master_service_setting_parser_info) {
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainen /* everyone wants master service settings */
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainen if (!str_array_find(modules, l->root->module_name))
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainen /* see if we can find a way to get from the original parser
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainen to this parser */