]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Use new var_expand
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 29 Aug 2024 10:56:07 +0000 (13:56 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:00 +0000 (10:40 +0200)
src/doveadm/doveadm-auth-server.c
src/doveadm/doveadm-auth.c
src/doveadm/doveadm-dsync.c
src/doveadm/doveadm-print-formatted.c
src/doveadm/doveadm-settings.c

index b673994b57111604a91c66ae51972dcb75df0423..7bca76fbd364eb6d411976b45b49870a0c4911f7 100644 (file)
@@ -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 {
index a5a5a217dec2e8f9d53a558ee4b575fe4beda4ce..59a68409e684b6413055b923d020d5aff3050762 100644 (file)
@@ -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));
index be043c130dbff82c3eb5223c0e7c5d843a0bcffb..58413ce9a8d93d8ac00db7a117a63dfea8b74f27 100644 (file)
@@ -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, &params, &error) < 0 ||
+                           var_expand_new(str2, *args, &static_params, &error) < 0) {
                                e_error(event,
                                        "Failed to expand dsync_remote_cmd=%s: %s",
                                        *args, error);
index 19540b950231529a9b7ef747198073f3b0f32bff..3ef9d3b5a66a00de253ff0db69dbb4f5933e1fd9 100644 (file)
@@ -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, &params, &error) < 0) {
                        i_error("Failed to expand print format '%s': %s",
                                ctx.format, error);
                }
index 773883a78ee26c4103686f59689d502bf7f137bd..5ffbfdaa01544fd985fa766d80fc5b0bc5d6bd1c 100644 (file)
@@ -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,