]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Fixed sending command -parameters to doveadm-server
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 26 May 2016 16:13:40 +0000 (19:13 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 27 May 2016 08:35:43 +0000 (11:35 +0300)
src/doveadm/doveadm-mail.c

index 39faca2d98f9c6946b65f22788a2b606656024c9..ca89a94c8cf2a12b9137f1fd5b381766250852a6 100644 (file)
@@ -924,11 +924,9 @@ void
 doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
 {
        struct doveadm_mail_cmd_context *mctx;
-       const char *wildcard_user, *username_args[3] = { NULL, NULL, NULL };
+       const char *wildcard_user;
        const char *fieldstr;
-       unsigned int username_args_count;
-
-       ARRAY_TYPE(const_string) pargv;
+       ARRAY_TYPE(const_string) pargv, full_args;
        int i;
        struct doveadm_mail_cmd mail_cmd = {
                cctx->cmd->mail_cmd, cctx->cmd->name, cctx->cmd->usage
@@ -944,6 +942,7 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
        mctx->cur_username = cctx->username;
        mctx->iterate_all_users = FALSE;
        wildcard_user = NULL;
+       p_array_init(&full_args, mctx->pool, 8);
        p_array_init(&pargv, mctx->pool, 8);
 
        for(i=0;i<cctx->argc;i++) {
@@ -954,7 +953,8 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
 
                if (strcmp(arg->name, "all-users") == 0) {
                        mctx->iterate_all_users = arg->value.v_bool;
-                       username_args[0] = "-A";
+                       fieldstr = "-A";
+                       array_append(&full_args, &fieldstr, 1);
                } else if (strcmp(arg->name, "socket-path") == 0) {
                        doveadm_settings->doveadm_socket_path = arg->value.v_string;
                        if (doveadm_settings->doveadm_worker_count == 0)
@@ -962,8 +962,10 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
                } else if (strcmp(arg->name, "user") == 0) {
                        mctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
                        mctx->cur_username = arg->value.v_string;
-                       username_args[0] = "-u";
-                       username_args[1] = arg->value.v_string;
+
+                       fieldstr = "-u";
+                       array_append(&full_args, &fieldstr, 1);
+                       array_append(&full_args, &arg->value.v_string, 1);
                        if (strchr(mctx->cur_username, '*') != NULL ||
                            strchr(mctx->cur_username, '?') != NULL) {
                                wildcard_user = mctx->cur_username;
@@ -975,8 +977,10 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
                        mctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
                        wildcard_user = "*";
                        mctx->users_list_input = arg->value.v_istream;
-                       username_args[0] = "-F";
-                       username_args[1] = ""; /* value doesn't really matter */
+                       fieldstr = "-F";
+                       array_append(&full_args, &fieldstr, 1);
+                       fieldstr = ""; /* value doesn't really matter */
+                       array_append(&full_args, &fieldstr, 1);
                        i_stream_ref(mctx->users_list_input);
                } else if (strcmp(arg->name, "field") == 0 ||
                           strcmp(arg->name, "flag") == 0) {
@@ -1001,8 +1005,15 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
                /* Keep all named special parameters above this line */
 
                } else if (mctx->v.parse_arg != NULL && arg->short_opt != '\0') {
+                       const char *short_opt_str = p_strdup_printf(
+                               mctx->pool, "-%c", arg->short_opt);
+
                        optarg = (char*)arg->value.v_string;
                        mctx->v.parse_arg(mctx, arg->short_opt);
+
+                       array_append(&full_args, &short_opt_str, 1);
+                       if (arg->type == CMD_PARAM_STR)
+                               array_append(&full_args, &arg->value.v_string, 1);
                } else if ((arg->flags & CMD_PARAM_FLAG_POSITIONAL) != 0) {
                        /* feed this into pargv */
                        if (arg->type == CMD_PARAM_ARRAY)
@@ -1018,14 +1029,13 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
        }
 
        array_append_zero(&pargv);
-       /* -A, -u and -F parameters need to be included in full_args so that
-          they're sent to doveadm-server. This is needed so that
-          doveadm-server returns the username header when needed. */
-       username_args_count = str_array_length(username_args);
-       if (username_args_count > 0)
-               array_insert(&pargv, 0, username_args, username_args_count);
-       mctx->args = array_idx(&pargv, username_args_count);
-       mctx->full_args = array_idx(&pargv, 0);
+       /* All the -parameters need to be included in full_args so that
+          they're sent to doveadm-server. */
+       unsigned int args_pos = array_count(&full_args);
+       array_append_array(&full_args, &pargv);
+
+       mctx->args = array_idx(&full_args, args_pos);
+       mctx->full_args = array_idx(&full_args, 0);
        mctx->cli = cctx->cli;
 
        doveadm_mail_cmd_exec(mctx, cctx, wildcard_user);