Skip to content

Commit

Permalink
doveadm: mail: Removed redundant cur_username field from struct dovea…
Browse files Browse the repository at this point in the history
…dm_mail_cmd_context.
  • Loading branch information
stephanbosch committed Oct 24, 2017
1 parent 2ff59d5 commit e16f28d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
7 changes: 3 additions & 4 deletions src/doveadm/client-connection.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/doveadm/doveadm-dsync.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
24 changes: 9 additions & 15 deletions src/doveadm/doveadm-mail.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 '+' */
Expand All @@ -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':
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/doveadm/doveadm-mail.h
Expand Up @@ -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;
Expand Down

0 comments on commit e16f28d

Please sign in to comment.