Skip to content

Commit

Permalink
doveadm-server: Drop privileges only temporarily when running mail co…
Browse files Browse the repository at this point in the history
…mmands.

This allows running mail commands for multiple users within the same doveadm
connection.
  • Loading branch information
sirainen committed Feb 29, 2016
1 parent ec862f5 commit 9990080
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/doveadm/doveadm-mail.c
Expand Up @@ -584,6 +584,10 @@ doveadm_mail_cmd_exec(struct doveadm_mail_cmd_context *ctx,

if (ctx->cur_username == NULL)
i_fatal_status(EX_USAGE, "USER environment is missing and -u option not used");
if (!ctx->cli) {
/* we may access multiple users */
ctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP;
}

memset(&cctx, 0, sizeof(cctx));
cctx.username = ctx->cur_username;
Expand Down Expand Up @@ -631,6 +635,7 @@ doveadm_mail_cmd(const struct doveadm_mail_cmd *cmd, int argc, char *argv[])

ctx = doveadm_mail_cmdline_init(cmd);
ctx->full_args = (const void *)(argv + 1);
ctx->cli = TRUE;

getopt_args = "AF:S:u:";
/* keep context's getopt_args first in case it contains '+' */
Expand Down Expand Up @@ -1000,6 +1005,7 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
array_append_zero(&pargv);
mctx->args = array_idx(&pargv, 0);
mctx->full_args = mctx->args;
mctx->cli = cctx->cli;

doveadm_mail_cmd_exec(mctx, wildcard_user);
doveadm_mail_cmd_free(mctx);
Expand Down
2 changes: 2 additions & 0 deletions src/doveadm/doveadm-mail.h
Expand Up @@ -97,6 +97,8 @@ struct doveadm_mail_cmd_context {
unsigned int iterate_single_user:1;
/* We're going through all users (not set for wildcard usernames) */
unsigned int iterate_all_users:1;
/* Running from CLI doveadm (not doveadm-server) */
unsigned int cli:1;
};

struct doveadm_mail_cmd {
Expand Down

0 comments on commit 9990080

Please sign in to comment.