]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: mail: Removed redundant cur_username field from struct doveadm_mail_cmd_context.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 10 Oct 2017 13:58:33 +0000 (15:58 +0200)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 24 Oct 2017 20:29:18 +0000 (22:29 +0200)
src/doveadm/client-connection.c
src/doveadm/doveadm-dsync.c
src/doveadm/doveadm-mail.c
src/doveadm/doveadm-mail.h

index 560e8352e3a54ba59e596a9dd4ac397c59076b5f..e7eb1a7e951cd2daddfc33b8ba95c1b594e4ad03 100644 (file)
@@ -168,7 +168,6 @@ doveadm_mail_cmd_server_parse(const struct doveadm_mail_cmd *cmd,
        mctx->cctx = cctx;
        mctx->full_args = argv+1;
        mctx->proxying = TRUE;
-       mctx->cur_username = cctx->username;
        mctx->service_flags |=
                MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT |
                MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
@@ -213,9 +212,9 @@ doveadm_mail_cmd_server_parse(const struct doveadm_mail_cmd *cmd,
        }
        mctx->args = argv+optind;
 
-       if (mctx->cur_username != NULL) {
-               if (strchr(mctx->cur_username, '*') != NULL ||
-                   strchr(mctx->cur_username, '?') != NULL) {
+       if (cctx->username != NULL) {
+               if (strchr(cctx->username, '*') != NULL ||
+                   strchr(cctx->username, '?') != NULL) {
                        add_username_header = TRUE;
                }
        }
index 9e9442d6c7332242a3b868d5c5a3aba2bfa2e0ee..e602a7389ab5535bc122d0a76730fe2b93d137f6 100644 (file)
@@ -137,6 +137,7 @@ static void remote_error_input(struct dsync_cmd_context *ctx)
 static void
 run_cmd(struct dsync_cmd_context *ctx, const char *const *args)
 {
+       struct doveadm_cmd_context *cctx = ctx->ctx.cctx;
        int fd_in[2], fd_out[2], fd_err[2];
 
        ctx->remote_cmd_args = p_strarray_dup(ctx->ctx.pool, args);
@@ -178,7 +179,7 @@ run_cmd(struct dsync_cmd_context *ctx, const char *const *args)
 
        if (ctx->remote_user_prefix) {
                const char *prefix =
-                       t_strdup_printf("%s\n", ctx->ctx.cur_username);
+                       t_strdup_printf("%s\n", cctx->username);
                if (write_full(ctx->fd_out, prefix, strlen(prefix)) < 0)
                        i_fatal("write(remote out) failed: %m");
        }
@@ -798,6 +799,7 @@ dsync_connect_tcp(struct dsync_cmd_context *ctx,
                  const struct mail_storage_settings *mail_set,
                  const char *target, bool ssl, const char **error_r)
 {
+       struct doveadm_cmd_context *cctx = ctx->ctx.cctx;
        struct doveadm_server *server;
        struct server_connection *conn;
        struct ioloop *ioloop;
@@ -833,9 +835,9 @@ dsync_connect_tcp(struct dsync_cmd_context *ctx,
        if (doveadm_debug)
                str_append_c(cmd, 'D');
        str_append_c(cmd, '\t');
-       str_append_tabescaped(cmd, ctx->ctx.cur_username);
+       str_append_tabescaped(cmd, cctx->username);
        str_append(cmd, "\tdsync-server\t-u");
-       str_append_tabescaped(cmd, ctx->ctx.cur_username);
+       str_append_tabescaped(cmd, cctx->username);
        if (ctx->replicator_notify)
                str_append(cmd, "\t-U");
        str_append_c(cmd, '\n');
@@ -870,6 +872,8 @@ parse_location(struct dsync_cmd_context *ctx,
               const char *location,
               const char *const **remote_cmd_args_r, const char **error_r)
 {
+       struct doveadm_cmd_context *cctx = ctx->ctx.cctx;
+
        if (strncmp(location, "tcp:", 4) == 0) {
                /* TCP connection to remote dsync */
                ctx->remote_name = location+4;
@@ -897,7 +901,7 @@ parse_location(struct dsync_cmd_context *ctx,
                return 0;
        }
        *remote_cmd_args_r =
-               parse_ssh_location(ctx->remote_name, ctx->ctx.cur_username);
+               parse_ssh_location(ctx->remote_name, cctx->username);
        return 0;
 }
 
@@ -906,6 +910,7 @@ static int cmd_dsync_prerun(struct doveadm_mail_cmd_context *_ctx,
                            const char **error_r)
 {
        struct dsync_cmd_context *ctx = (struct dsync_cmd_context *)_ctx;
+       struct doveadm_cmd_context *cctx = _ctx->cctx;
        const char *const *remote_cmd_args = NULL;
        const struct mail_user_settings *user_set;
        const struct mail_storage_settings *mail_set;
@@ -933,7 +938,7 @@ static int cmd_dsync_prerun(struct doveadm_mail_cmd_context *_ctx,
                /* if we're executing remotely, give -u parameter if we also
                   did a userdb lookup. */
                if ((_ctx->service_flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0)
-                       username = _ctx->cur_username;
+                       username = cctx->username;
 
                if (!mirror_get_remote_cmd(ctx, username, &remote_cmd_args)) {
                        /* it's a mail_location */
index 5a75e3575b50ed11ae29a99eb430b327758812da..06096b5d7bf030c7d423f4b21a6380e70fc96554 100644 (file)
@@ -450,7 +450,6 @@ int doveadm_mail_single_user(struct doveadm_mail_cmd_context *ctx,
        i_assert(cctx->username != NULL);
 
        doveadm_cctx_to_storage_service_input(cctx, &ctx->storage_service_input);
-       ctx->cur_username = cctx->username;
        ctx->storage_service = mail_storage_service_init(master_service, NULL,
                                                         ctx->service_flags);
        ctx->v.init(ctx, ctx->args);
@@ -495,7 +494,6 @@ doveadm_mail_all_users(struct doveadm_mail_cmd_context *ctx,
                                continue;
                }
                cctx->username = user;
-               ctx->cur_username = user;
                doveadm_print_sticky("username", user);
                T_BEGIN {
                        ret = doveadm_mail_next_user(ctx, &error);
@@ -613,7 +611,7 @@ doveadm_mail_cmd_exec(struct doveadm_mail_cmd_context *ctx,
        }
 
        if (ctx->iterate_single_user) {
-               if (ctx->cur_username == NULL)
+               if (cctx->username == NULL)
                        i_fatal_status(EX_USAGE, "USER environment is missing and -u option not used");
                if (!cli) {
                        /* we may access multiple users */
@@ -665,11 +663,11 @@ doveadm_mail_cmd(const struct doveadm_mail_cmd *cmd, int argc, char *argv[])
 
        i_zero(&cctx);
        cctx.conn_type = CLIENT_CONNECTION_TYPE_CLI;
+       cctx.username = getenv("USER");
 
        ctx = doveadm_mail_cmdline_init(cmd);
        ctx->cctx = &cctx;
        ctx->full_args = (const void *)(argv + 1);
-       ctx->cur_username = getenv("USER");
 
        getopt_args = "AF:S:u:";
        /* keep context's getopt_args first in case it contains '+' */
@@ -691,11 +689,11 @@ doveadm_mail_cmd(const struct doveadm_mail_cmd *cmd, int argc, char *argv[])
                case 'u':
                        ctx->service_flags |=
                                MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
-                       ctx->cur_username = optarg;
-                       if (strchr(ctx->cur_username, '*') != NULL ||
-                           strchr(ctx->cur_username, '?') != NULL) {
-                               wildcard_user = ctx->cur_username;
-                               ctx->cur_username = NULL;
+                       cctx.username = optarg;
+                       if (strchr(cctx.username, '*') != NULL ||
+                           strchr(cctx.username, '?') != NULL) {
+                               wildcard_user = cctx.username;
+                               cctx.username = NULL;
                        }
                        break;
                case 'F':
@@ -717,7 +715,6 @@ doveadm_mail_cmd(const struct doveadm_mail_cmd *cmd, int argc, char *argv[])
                               cmd->name, argv[0]);
        }
        ctx->args = (const void *)argv;
-       cctx.username = ctx->cur_username;
        doveadm_mail_cmd_exec(ctx, wildcard_user);
        doveadm_mail_cmd_free(ctx);
 }
@@ -981,7 +978,6 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
                mctx = doveadm_mail_cmdline_init(&mail_cmd);
        }
        mctx->cctx = cctx;
-       mctx->cur_username = cctx->username;
        mctx->iterate_all_users = FALSE;
        wildcard_user = NULL;
        p_array_init(&full_args, mctx->pool, 8);
@@ -1007,7 +1003,7 @@ 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;
                        if (!tcp_server)
-                               mctx->cur_username = arg->value.v_string;
+                               cctx->username = arg->value.v_string;
 
                        fieldstr = "-u";
                        array_append(&full_args, &fieldstr, 1);
@@ -1018,10 +1014,8 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
                                        mctx->add_username_header = TRUE;
                                else {
                                        wildcard_user = arg->value.v_string;
-                                       mctx->cur_username = NULL;
+                                       cctx->username = NULL;
                                }
-                       } else if (!tcp_server) {
-                               cctx->username = mctx->cur_username;
                        }
                } else if (strcmp(arg->name, "user-file") == 0) {
                        mctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
index a1ec1ab63de3aa908727ee116c2398560cd80823..960705052be4f497632901721fa61cef8df107a4 100644 (file)
@@ -76,7 +76,6 @@ struct doveadm_mail_cmd_context {
        struct mail_search_args *search_args;
        struct istream *users_list_input;
 
-       const char *cur_username;
        struct mail_storage_service_user *cur_service_user;
        struct mail_user *cur_mail_user;
        struct doveadm_mail_cmd_vfuncs v;