return FALSE;
}
+static bool
+setting_value_can_check(const char *value, bool expand_values)
+{
+ if (strstr(value, "%{") != NULL)
+ return FALSE;
+
+ if (!expand_values) {
+ if (strstr(value, "$SET:") != NULL ||
+ strstr(value, "$ENV:") != NULL)
+ return FALSE;
+ }
+ return TRUE;
+}
+
static int
settings_value_check(struct config_parser_context *ctx,
const struct setting_parser_info *info,
switch (def->type) {
case SET_BOOL: {
bool b;
- if (strchr(value, '%') != NULL)
+ if (!setting_value_can_check(value, ctx->expand_values))
break;
if (str_parse_get_bool(value, &b, &error) < 0) {
ctx->error = p_strdup(ctx->pool, error);
case SET_UINTMAX: {
uintmax_t num;
- if (strchr(value, '%') != NULL)
+ if (!setting_value_can_check(value, ctx->expand_values))
break;
if (str_to_uintmax(value, &num) < 0) {
ctx->error = p_strdup_printf(ctx->pool,
case SET_UINT_OCT:
if (*value == '0') {
unsigned long long octal;
- if (strchr(value, '%') != NULL)
+ if (!setting_value_can_check(value, ctx->expand_values))
break;
if (str_to_ullong_oct(value, &octal) < 0) {
ctx->error = p_strconcat(ctx->pool,
case SET_UINT: {
unsigned int num;
- if (strchr(value, '%') != NULL)
+ if (!setting_value_can_check(value, ctx->expand_values))
break;
if (settings_value_is_unlimited(value))
break;
}
case SET_TIME: {
unsigned int interval;
- if (strchr(value, '%') != NULL)
+ if (!setting_value_can_check(value, ctx->expand_values))
break;
if (settings_value_is_unlimited(value))
break;
}
case SET_TIME_MSECS: {
unsigned int interval;
- if (strchr(value, '%') != NULL)
+ if (!setting_value_can_check(value, ctx->expand_values))
break;
if (settings_value_is_unlimited(value))
break;
}
case SET_SIZE: {
uoff_t size;
- if (strchr(value, '%') != NULL)
+ if (!setting_value_can_check(value, ctx->expand_values))
break;
if (settings_value_is_unlimited(value))
break;
}
case SET_IN_PORT: {
in_port_t port;
- if (strchr(value, '%') != NULL)
+ if (!setting_value_can_check(value, ctx->expand_values))
break;
if (net_str2port_zero(value, &port) < 0) {
ctx->error = p_strdup_printf(ctx->pool,
break;
case SET_ENUM:
/* get the available values from default string */
- if (strchr(value, '%') != NULL)
+ if (!setting_value_can_check(value, ctx->expand_values))
break;
i_assert(info->defaults != NULL);
const char *const *default_value =
bool b;
if (strchr(key, SETTINGS_SEPARATOR) != NULL) {
- if (strchr(value, '%') == NULL &&
+ if (setting_value_can_check(value, ctx->expand_values) &&
str_parse_get_bool(value, &b, &error) < 0) {
ctx->error = p_strdup(ctx->pool, error);
return -1;
}
void config_fill_set_parser(struct setting_parser_context *parser,
- const struct config_module_parser *p)
+ const struct config_module_parser *p,
+ bool expand_values)
{
if (p->change_counters == NULL)
return;
const char *value = p->settings[i].str;
if (p->info->defines[i].type != SET_STR_NOVARS &&
p->info->defines[i].type != SET_FILE &&
- strchr(p->settings[i].str, '%') != NULL) {
+ !setting_value_can_check(p->settings[i].str,
+ expand_values)) {
/* We don't know what the variables would
expand to. */
value = set_value_unknown;
struct setting_parser_context *tmp_parser =
settings_parser_init(tmp_pool, p->info,
settings_parser_flags);
- if (default_p != NULL)
- config_fill_set_parser(tmp_parser, default_p);
- config_fill_set_parser(tmp_parser, p);
+ if (default_p != NULL) {
+ config_fill_set_parser(tmp_parser, default_p,
+ ctx->expand_values);
+ }
+ config_fill_set_parser(tmp_parser, p, ctx->expand_values);
T_BEGIN {
ok = settings_parser_check(tmp_parser, tmp_pool,
event, &error);
config_parsed_get_module_parsers(config);
struct setting_parser_context *set_parser =
settings_parser_init(pool, p->info, 0);
- config_fill_set_parser(set_parser, p);
+ config_fill_set_parser(set_parser, p, TRUE);
const struct test_settings *set = settings_parser_get_set(set_parser);
test_assert_strcmp(set->key, "value");
test_assert_strcmp(set->key2, "\\$escape \\escape \\\"escape\\\"");
p_clear(pool);
p = config_parsed_get_module_parsers(config);
set_parser = settings_parser_init(pool, p->info, 0);
- config_fill_set_parser(set_parser, p);
+ config_fill_set_parser(set_parser, p, TRUE);
set = settings_parser_get_set(set_parser);
test_assert_strcmp(set->key, "value");