From 7a3b52b8f9c6261ea912d9c96b20d815f782be5b Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 16 Mar 2016 16:34:32 +1100 Subject: [PATCH] doveadm sync: Don't allow -R parameter. -R implicitly enabled doveadm backup mode, which wasn't supposed to happen. --- src/doveadm/doveadm-dsync.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/doveadm/doveadm-dsync.c b/src/doveadm/doveadm-dsync.c index c53bf86c3e..af5748e2d7 100644 --- a/src/doveadm/doveadm-dsync.c +++ b/src/doveadm/doveadm-dsync.c @@ -38,7 +38,7 @@ #include #include -#define DSYNC_COMMON_GETOPT_ARGS "+1a:dDEfg:l:m:n:NO:Pr:Rs:t:T:Ux:" +#define DSYNC_COMMON_GETOPT_ARGS "+1a:dDEfg:l:m:n:NO:Pr:s:t:T:Ux:" #define DSYNC_REMOTE_CMD_EXIT_WAIT_SECS 30 /* The broken_char is mainly set to get a proper error message when trying to convert a mailbox with a name that can't be used properly translated between @@ -1042,13 +1042,9 @@ cmd_mailbox_dsync_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c) return TRUE; } -static struct doveadm_mail_cmd_context *cmd_dsync_alloc(void) +static void cmd_dsync_init_common(struct dsync_cmd_context *ctx) { - struct dsync_cmd_context *ctx; - - ctx = doveadm_mail_cmd_alloc(struct dsync_cmd_context); ctx->io_timeout_secs = DSYNC_DEFAULT_IO_STREAM_TIMEOUT_SECS; - ctx->ctx.getopt_args = DSYNC_COMMON_GETOPT_ARGS; ctx->ctx.v.parse_arg = cmd_mailbox_dsync_parse_arg; ctx->ctx.v.preinit = cmd_dsync_preinit; ctx->ctx.v.init = cmd_dsync_init; @@ -1060,18 +1056,27 @@ static struct doveadm_mail_cmd_context *cmd_dsync_alloc(void) DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE); p_array_init(&ctx->exclude_mailboxes, ctx->ctx.pool, 4); p_array_init(&ctx->namespace_prefixes, ctx->ctx.pool, 4); +} + +static struct doveadm_mail_cmd_context *cmd_dsync_alloc(void) +{ + struct dsync_cmd_context *ctx; + + ctx = doveadm_mail_cmd_alloc(struct dsync_cmd_context); + ctx->ctx.getopt_args = DSYNC_COMMON_GETOPT_ARGS; + cmd_dsync_init_common(ctx); return &ctx->ctx; } static struct doveadm_mail_cmd_context *cmd_dsync_backup_alloc(void) { - struct doveadm_mail_cmd_context *_ctx; struct dsync_cmd_context *ctx; - _ctx = cmd_dsync_alloc(); - ctx = (struct dsync_cmd_context *)_ctx; + ctx = doveadm_mail_cmd_alloc(struct dsync_cmd_context); ctx->backup = TRUE; - return _ctx; + ctx->ctx.getopt_args = DSYNC_COMMON_GETOPT_ARGS"R"; + cmd_dsync_init_common(ctx); + return &ctx->ctx; } static int @@ -1182,7 +1187,7 @@ static struct doveadm_mail_cmd_context *cmd_dsync_server_alloc(void) struct doveadm_mail_cmd cmd_dsync_mirror = { cmd_dsync_alloc, "sync", - "[-1fPRU] [-l ] [-r ] [-m ] [-g ] [-n | -N] [-x ] [-s ] -d|" + "[-1fPU] [-l ] [-r ] [-m ] [-g ] [-n | -N] [-x ] [-s ] -d|" }; struct doveadm_mail_cmd cmd_dsync_backup = { cmd_dsync_backup_alloc, "backup", -- 2.47.3