string_t *username_val = t_str_new(strlen(username_value));
if (auth_request_var_expand(username_req, req->db->set.username_format, req->auth_request, escape_none, &error) <= 0 ||
- var_expand(username_val, req->db->set.username_format, table, &error) <= 0) {
+ var_expand_with_table(username_val, req->db->set.username_format,
+ table, &error) <= 0) {
*error_r = t_strdup_printf("var_expand(%s) failed: %s",
req->db->set.username_format, error);
*result_r = PASSDB_RESULT_INTERNAL_FAILURE;
const char *error;
dest = t_str_new(256);
- if (var_expand(dest, path, empty_table, &error) <= 0)
+ if (var_expand_with_table(dest, path, empty_table, &error) <= 0)
i_unreached();
path = str_c(dest);
}
auth_request_escape_func_t *escape_func ATTR_UNUSED,
const char **error_r ATTR_UNUSED)
{
- return var_expand(dest, str, auth_request_var_expand_static_tab, error_r);
+ return var_expand_with_table(dest, str,
+ auth_request_var_expand_static_tab,
+ error_r);
}
static void test_auth_cache_parse_key(void)
const char *error;
str_truncate(str, 0);
- test_assert(var_expand(str, input, tab, &error) == 1);
+ test_assert(var_expand_with_table(str, input, tab, &error) == 1);
return strspn(str_c(str), "\n0") == str_len(str);
}
test_begin("auth request var expand short and long");
tab = auth_request_get_var_expand_table(&test_request, test_escape);
- test_assert(var_expand(str, test_input_short, tab, &error) == 1);
+ test_assert(var_expand_with_table(str, test_input_short, tab, &error) == 1);
test_assert(strcmp(str_c(str), test_output) == 0);
str_truncate(str, 0);
- test_assert(var_expand(str, test_input_long, tab, &error) == 1);
+ test_assert(var_expand_with_table(str, test_input_long, tab, &error) == 1);
test_assert(strcmp(str_c(str), test_output) == 0);
/* test with empty input that it won't crash */
test_request.userdb_lookup = FALSE;
test_request.fields.conn_secured = AUTH_REQUEST_CONN_SECURED_NONE;
test_request.fields.valid_client_cert = FALSE;
- test_assert(var_expand(str, test_input,
+ test_assert(var_expand_with_table(str, test_input,
auth_request_get_var_expand_table(&test_request, test_escape),
&error) == 1);
test_assert(strcmp(str_c(str), "40\n\n\n") == 0);
test_request.fields.valid_client_cert = TRUE;
str_truncate(str, 0);
- test_assert(var_expand(str, test_input,
+ test_assert(var_expand_with_table(str, test_input,
auth_request_get_var_expand_table(&test_request, test_escape),
&error) == 1);
test_assert(strcmp(str_c(str), "41\nsecured\nvalid\n") == 0);
test_begin("auth request var expand long-only");
- test_assert(var_expand(str, test_input,
+ test_assert(var_expand_with_table(str, test_input,
auth_request_get_var_expand_table(&test_request, test_escape),
&error) == 1);
test_assert(strcmp(str_c(str), test_output) == 0);
for (i = 0; i < N_ELEMENTS(tests); i++) {
test_request.fields.user = t_strdup_noconst(tests[i].username);
str_truncate(str, 0);
- test_assert(var_expand(str, test_input,
+ test_assert(var_expand_with_table(str, test_input,
auth_request_get_var_expand_table(&test_request, test_escape),
&error) == 1);
test_assert_idx(strcmp(str_c(str), tests[i].output) == 0, i);
text in the parameter, skip it. */
str_truncate(str, 0);
str_truncate(str2, 0);
- if (var_expand(str, *args, tab, &error) <= 0 ||
- var_expand(str2, *args, static_tab, &error) <= 0) {
+ if (var_expand_with_table(str, *args, tab, &error) <= 0 ||
+ var_expand_with_table(str2, *args, static_tab, &error) <= 0) {
e_error(event,
"Failed to expand dsync_remote_cmd=%s: %s",
*args, error);
entry->value = value;
if (ctx.idx >= array_count(&ctx.headers)) {
- if (var_expand(ctx.buf, ctx.format, array_front(&ctx.headers), &error) <= 0) {
+ if (var_expand_with_table(ctx.buf, ctx.format,
+ array_front(&ctx.headers),
+ &error) <= 0) {
i_error("Failed to expand print format '%s': %s",
ctx.format, error);
}
array_append_zero(&exp);
- if (var_expand(query_r, template, array_front(&exp), &error) <= 0) {
+ if (var_expand_with_table(query_r, template,
+ array_front(&exp), &error) <= 0) {
*error_r = t_strdup_printf("Failed to expand %s: %s", template, error);
return FALSE;
}
str = t_str_new(256);
tab = mail_deliver_ctx_get_log_var_expand_table(ctx, msg);
- if (var_expand(str, ctx->set->deliver_log_format, tab, &error) <= 0) {
+ if (var_expand_with_table(str, ctx->set->deliver_log_format,
+ tab, &error) <= 0) {
e_error(ctx->event,
"Failed to expand deliver_log_format=%s: %s",
ctx->set->deliver_log_format, error);
ctx->dsn ? "delivery-status" : "disposition-notification",
boundary);
str_append(str, "Subject: ");
- if (var_expand(str, ctx->set->rejection_subject,
- vtable, &error) <= 0) {
+ if (var_expand_with_table(str, ctx->set->rejection_subject,
+ vtable, &error) <= 0) {
e_error(ctx->event,
"Failed to expand rejection_subject=%s: %s",
ctx->set->rejection_subject, error);
str_append(str, "Content-Disposition: inline\r\n");
str_append(str, "Content-Transfer-Encoding: 8bit\r\n\r\n");
- if (var_expand(str, ctx->set->rejection_reason,
- vtable, &error) <= 0) {
+ if (var_expand_with_table(str, ctx->set->rejection_reason,
+ vtable, &error) <= 0) {
e_error(ctx->event,
"Failed to expand rejection_reason=%s: %s",
ctx->set->rejection_reason, error);
key = *envs;
else {
key = t_strdup_until(*envs, value++);
- if (var_expand(expanded, value, table, &error) <= 0)
+ if (var_expand_with_table(expanded, value, table,
+ &error) <= 0)
i_fatal("Cannot expand variable %s", value);
if (str_len(expanded) > 0) {
value = str_c(expanded);
const char *error;
int fd;
- if (var_expand(path, db->set->metrics_path, tab, &error) <= 0) {
+ if (var_expand_with_table(path, db->set->metrics_path,
+ tab, &error) <= 0) {
e_error(db->api.event, "Failed to expand metrics_path=%s: %s",
db->set->metrics_path, error);
return;
prefix = t_str_new(128);
str_append(prefix, ns->prefix);
- if (var_expand(prefix, storage->ns_prefix_pattern, tab, &error) <= 0) {
+ if (var_expand_with_table(prefix, storage->ns_prefix_pattern, tab,
+ &error) <= 0) {
mailbox_list_set_critical(list,
"Failed to expand namespace prefix '%s': %s",
storage->ns_prefix_pattern, error);
test_begin("var_expand - ranges");
for (i = 0; i < N_ELEMENTS(tests); i++) {
str_truncate(str, 0);
- test_assert(var_expand(str, tests[i].in, table, &error) == tests[i].ret);
+ test_assert(var_expand_with_table(str, tests[i].in, table, &error) == tests[i].ret);
test_assert(strcmp(tests[i].out, str_c(str)) == 0);
}
test_end();
test_begin("var_expand - builtin");
for (i = 0; i < N_ELEMENTS(tests); i++) {
str_truncate(str, 0);
- test_assert_idx(var_expand(str, tests[i].in, table, &error) == tests[i].ret, i);
+ test_assert_idx(var_expand_with_table(str, tests[i].in, table, &error) == tests[i].ret, i);
test_assert_strcmp_idx(tests[i].out, str_c(str), i);
}
test_end();
int ret;
error = NULL;
str_truncate(dest, 0);
- ret = var_expand(dest, tests[i].in, table, &error);
+ ret = var_expand_with_table(dest, tests[i].in, table, &error);
test_assert_idx(tests[i].ret == ret, i);
test_assert_idx(strcmp(tests[i].out, str_c(dest)) == 0, i);
}
const struct var_expand_test *test = &tests[i];
const char *error ATTR_UNUSED;
str_truncate(dest, 0);
- int ret = var_expand(dest, test->in, table, &error);
+ int ret = var_expand_with_table(dest, test->in, table, &error);
test_assert_cmp_idx(ret, ==, test->ret, i);
test_assert_strcmp_idx(str_c(dest), test->out, i);
}
struct utsname utsname_result;
if (uname(&utsname_result) == 0) {
str_truncate(dest, 0);
- test_assert(var_expand(dest, "%{system:os}", table, &error) == 1);
+ test_assert(var_expand_with_table(dest, "%{system:os}", table, &error) == 1);
test_assert(strcmp(utsname_result.sysname, str_c(dest)) == 0);
str_truncate(dest, 0);
- test_assert(var_expand(dest, "%{system:os-version}", table, &error) == 1);
+ test_assert(var_expand_with_table(dest, "%{system:os-version}", table, &error) == 1);
test_assert(strcmp(utsname_result.release, str_c(dest)) == 0);
}
for (size_t i = 0; i < N_ELEMENTS(tests); i++) {
str_truncate(dest, 0);
- ret = var_expand(dest, tests[i].in, table, &error);
+ ret = var_expand_with_table(dest, tests[i].in, table, &error);
test_assert_idx(tests[i].ret == ret, i);
test_assert_idx(strcmp(tests[i].out, str_c(dest)) == 0, i);
}
/* Make sure invalid keys are rejected. */
str_truncate(dest, 0);
- test_assert(var_expand(dest, "%{dovecot:invalid}", table, &error) == 0);
+ test_assert(var_expand_with_table(dest, "%{dovecot:invalid}", table, &error) == 0);
test_assert(strcmp(error, "Unsupported dovecot key 'invalid'") == 0);
test_end();
return final_ret;
}
-int var_expand(string_t *dest, const char *str,
- const struct var_expand_table *table, const char **error_r)
+int var_expand_with_table(string_t *dest, const char *str,
+ const struct var_expand_table *table,
+ const char **error_r)
{
return var_expand_with_funcs(dest, str, table, NULL, NULL, error_r);
}
contained invalid/unknown %variables, -1 if one of the functions returned
temporary error. Even in case of errors the dest string is still written as
fully as possible. */
-int var_expand(string_t *dest, const char *str,
- const struct var_expand_table *table,
- const char **error_r);
-/* Like var_expand(), but support also callback functions for
+int var_expand_with_table(string_t *dest, const char *str,
+ const struct var_expand_table *table,
+ const char **error_r);
+/* Like var_expand_with_table(), but support also callback functions for
variable expansion. */
int var_expand_with_funcs(string_t *dest, const char *str,
const struct var_expand_table *table,
/* username is added even if it's empty */
} else {
str_truncate(str2, 0);
- if (var_expand(str2, *e, login_var_expand_empty_tab,
- &error) <= 0) {
+ if (var_expand_with_table(str2, *e,
+ login_var_expand_empty_tab,
+ &error) <= 0) {
/* we just logged this error above. no need
to do it again. */
}
};
str_truncate(str, 0);
- if (var_expand(str, client->set->login_log_format, tab, &error) <= 0) {
+ if (var_expand_with_table(str, client->set->login_log_format, tab,
+ &error) <= 0) {
/* NOTE: Don't log via client->event - it would cause
recursion */
i_error("Failed to expand login_log_format=%s: %s",
};
str_truncate(path, 0);
- return var_expand(path, l->set.fileset.set->path, var_table, error_r);
+ return var_expand_with_table(path, l->set.fileset.set->path, var_table,
+ error_r);
}
static void
};
str = t_str_new(128);
- if (var_expand(str, sstorage->ns_prefix_pattern, tab, &error) <= 0) {
+ if (var_expand_with_table(str, sstorage->ns_prefix_pattern, tab,
+ &error) <= 0) {
e_error(storage->event,
"Failed to expand namespace prefix %s: %s",
sstorage->ns_prefix_pattern, error);
const char *key =
t_strdup_printf(NOTIFY_STATUS_KEY, mailbox_get_vname(box));
string_t *dest = t_str_new(64);
- if (var_expand(dest, nuser->set->notify_status_value, values, &error) <= 0) {
+ if (var_expand_with_table(dest, nuser->set->notify_status_value,
+ values, &error) <= 0) {
e_error(box->event, "notify-status: var_expand(%s) failed: %s",
nuser->set->notify_status_value, error);
} else {
for(i=0; i < N_ELEMENTS(test_cases); i++) T_BEGIN {
const char *error;
string_t *dest = t_str_new(32);
- int ret = var_expand(dest, test_cases[i].input, table, &error);
+ int ret = var_expand_with_table(dest, test_cases[i].input,
+ table, &error);
if (ret < 0) {
if (test_cases[i].expect_ret == -1)
i_info("Expected: var_expand(%s): %s", test_cases[i].input, error);
str_truncate(input, 0);
str_truncate(output, 0);
- test_assert_idx(var_expand(input, "%{encrypt;algo=aes-128-cbc,key=%{key}:decrypted}", table, &error) == 1, i);
+ test_assert_idx(var_expand_with_table(input, "%{encrypt;algo=aes-128-cbc,key=%{key}:decrypted}", table, &error) == 1, i);
table[5].value = str_c(input);
- test_assert_idx(var_expand(output, "%{decrypt;algo=aes-128-cbc,key=%{key}:encrypted2}", table, &error) == 1, i);
+ test_assert_idx(var_expand_with_table(output, "%{decrypt;algo=aes-128-cbc,key=%{key}:encrypted2}", table, &error) == 1, i);
test_assert_idx(strcmp(str_c(output), table[4].value)==0, i);
};
};
const char *error;
- if (var_expand(str, client->mail_set->pop3_uidl_format,
- tab, &error) <= 0) {
+ if (var_expand_with_table(str, client->mail_set->pop3_uidl_format,
+ tab, &error) <= 0) {
e_error(client->event,
"UIDL: Failed to expand pop3_uidl_format=%s: %s",
client->mail_set->pop3_uidl_format, error);
{ '\0', NULL, NULL }
};
string_t *str = t_str_new(128);
- if (var_expand(str, group_by->discrete_modifier, table, &error) < 0) {
+ if (var_expand_with_table(str, group_by->discrete_modifier,
+ table, &error) < 0) {
i_error("Failed to expand discrete modifier for %s: %s",
group_by->field, error);
}
};
const char *error;
string_t *str = t_str_new(128);
- if (var_expand(str, group_by->discrete_modifier, table, &error) <= 0) {
+ if (var_expand_with_table(str, group_by->discrete_modifier,
+ table, &error) <= 0) {
*error_r = t_strdup_printf(
"Failed to expand discrete modifier for %s: %s",
group_by->field, error);