From 1bde37fbf9a8c3ac0d18f06c81282168aa7c31df Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Thu, 29 Aug 2024 13:56:07 +0300 Subject: [PATCH] doveadm: Use new var_expand --- src/doveadm/doveadm-auth-server.c | 9 ++++----- src/doveadm/doveadm-auth.c | 9 ++++----- src/doveadm/doveadm-dsync.c | 27 +++++++++++++++++---------- src/doveadm/doveadm-print-formatted.c | 12 ++++++------ src/doveadm/doveadm-settings.c | 2 +- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/doveadm/doveadm-auth-server.c b/src/doveadm/doveadm-auth-server.c index b673994b57..7bca76fbd3 100644 --- a/src/doveadm/doveadm-auth-server.c +++ b/src/doveadm/doveadm-auth-server.c @@ -4,7 +4,7 @@ #include "ioloop.h" #include "array.h" #include "str.h" -#include "var-expand.h" +#include "var-expand-new.h" #include "wildcard-match.h" #include "settings-parser.h" #include "master-service.h" @@ -295,10 +295,9 @@ cmd_user_mail_input(struct mail_storage_service_ctx *storage_service, json_output, userdb_fields, show_field); } else { string_t *str = t_str_new(128); - if (var_expand_with_funcs(str, expand_field, - mail_user_var_expand_table(user), - mail_user_var_expand_func_table, user, - &error) <= 0) { + const struct var_expand_params *params = + mail_user_var_expand_params(user); + if (var_expand_new(str, expand_field, params, &error) < 0) { json_ostream_nwritef_string(json_output, "error", "Failed to expand field: %s", error); } else { diff --git a/src/doveadm/doveadm-auth.c b/src/doveadm/doveadm-auth.c index a5a5a217de..59a68409e6 100644 --- a/src/doveadm/doveadm-auth.c +++ b/src/doveadm/doveadm-auth.c @@ -8,7 +8,7 @@ #include "hex-binary.h" #include "str.h" #include "strescape.h" -#include "var-expand.h" +#include "var-expand-new.h" #include "wildcard-match.h" #include "dsasl-client.h" #include "settings-parser.h" @@ -724,10 +724,9 @@ cmd_user_mail_input(struct mail_storage_service_ctx *storage_service, cmd_user_mail_print_fields(input, user, userdb_fields, show_field); } else { string_t *str = t_str_new(128); - if (var_expand_with_funcs(str, expand_field, - mail_user_var_expand_table(user), - mail_user_var_expand_func_table, user, - &error) <= 0) { + const struct var_expand_params *params = + mail_user_var_expand_params(user); + if (var_expand_new(str, expand_field, params, &error) < 0) { e_error(event, "Failed to expand %s: %s", expand_field, error); } else { printf("%s\n", str_c(str)); diff --git a/src/doveadm/doveadm-dsync.c b/src/doveadm/doveadm-dsync.c index be043c130d..58413ce9a8 100644 --- a/src/doveadm/doveadm-dsync.c +++ b/src/doveadm/doveadm-dsync.c @@ -15,7 +15,7 @@ #include "strescape.h" #include "str-parse.h" #include "env-util.h" -#include "var-expand.h" +#include "var-expand-new.h" #include "process-title.h" #include "settings.h" #include "imap-util.h" @@ -267,11 +267,14 @@ static const char *const * get_ssh_cmd_args(const char *host, const char *login, const char *mail_user, struct event *event) { - static struct var_expand_table static_tab[] = { - { 'u', NULL, "user" }, - { '\0', NULL, "login" }, - { '\0', NULL, "host" }, - { '\0', NULL, NULL } + static const struct var_expand_table static_tab[] = { + { .key = "user", .value = NULL }, + { .key = "login", .value = NULL }, + { .key = "host", .value = NULL }, + VAR_EXPAND_TABLE_END + }; + static const struct var_expand_params static_params = { + .table = static_tab }; struct var_expand_table *tab; ARRAY_TYPE(const_string) cmd_args; @@ -284,6 +287,10 @@ get_ssh_cmd_args(const char *host, const char *login, const char *mail_user, tab[0].value = mail_user; tab[1].value = login; tab[2].value = host; + const struct var_expand_params params = { + .table = tab, + .event = event, + }; t_array_init(&cmd_args, 8); str = t_str_new(128); @@ -293,13 +300,13 @@ get_ssh_cmd_args(const char *host, const char *login, const char *mail_user, if (strchr(*args, '%') == NULL) value = *args; else { - /* some automation: if parameter's all %variables - expand to empty, but the %variable isn't the only + /* some automation: if parameter's all %{variables} + expand to empty, but the %{variable} isn't the only text in the parameter, skip it. */ str_truncate(str, 0); str_truncate(str2, 0); - if (var_expand_with_table(str, *args, tab, &error) <= 0 || - var_expand_with_table(str2, *args, static_tab, &error) <= 0) { + if (var_expand_new(str, *args, ¶ms, &error) < 0 || + var_expand_new(str2, *args, &static_params, &error) < 0) { e_error(event, "Failed to expand dsync_remote_cmd=%s: %s", *args, error); diff --git a/src/doveadm/doveadm-print-formatted.c b/src/doveadm/doveadm-print-formatted.c index 19540b9502..3ef9d3b5a6 100644 --- a/src/doveadm/doveadm-print-formatted.c +++ b/src/doveadm/doveadm-print-formatted.c @@ -8,7 +8,7 @@ #include "doveadm-print.h" #include "doveadm-print-private.h" #include "client-connection.h" -#include "var-expand.h" +#include "var-expand-new.h" struct doveadm_print_formatted_context { pool_t pool; @@ -40,8 +40,7 @@ doveadm_print_formatted_header(const struct doveadm_print_header *hdr) { struct var_expand_table entry; i_zero(&entry); - entry.key = '\0'; - entry.long_key = p_strdup(ctx.pool, hdr->key); + entry.key = p_strdup(ctx.pool, hdr->key); entry.value = NULL; array_push_back(&ctx.headers, &entry); } @@ -63,9 +62,10 @@ static void doveadm_print_formatted_print(const char *value) entry->value = value; if (ctx.idx >= array_count(&ctx.headers)) { - if (var_expand_with_table(ctx.buf, ctx.format, - array_front(&ctx.headers), - &error) <= 0) { + const struct var_expand_params params = { + .table = array_front(&ctx.headers), + }; + if (var_expand_new(ctx.buf, ctx.format, ¶ms, &error) < 0) { i_error("Failed to expand print format '%s': %s", ctx.format, error); } diff --git a/src/doveadm/doveadm-settings.c b/src/doveadm/doveadm-settings.c index 773883a78e..5ffbfdaa01 100644 --- a/src/doveadm/doveadm-settings.c +++ b/src/doveadm/doveadm-settings.c @@ -99,7 +99,7 @@ const struct doveadm_settings doveadm_default_settings = { .doveadm_password = "", .doveadm_allowed_commands = ARRAY_INIT, .dsync_alt_char = "_", - .dsync_remote_cmd = "ssh -l%{login} %{host} doveadm dsync-server -u%u -U", + .dsync_remote_cmd = "ssh -l%{login} %{host} doveadm dsync-server -u%{user} -U", .dsync_features = "", .dsync_hashed_headers = "Date Message-ID", .dsync_commit_msgs_interval = 100, -- 2.47.3