]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Fix allow-empty-mailbox-name handling
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 27 Feb 2017 17:04:55 +0000 (19:04 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 27 Feb 2017 17:28:09 +0000 (19:28 +0200)
It was supposed to be handled for metadata commands only.

Broken in 26c41874cf6019c3e39f0ed630b2a07a92b2635f

src/doveadm/doveadm-mail-mailbox-metadata.c
src/doveadm/doveadm-mail.c
src/doveadm/doveadm-mail.h

index 5abce9a60fbbf3c0c30fc341b8d64e0f790349b1..b53d903f35bbea6f3ecc8148698e54d750ec2b9d 100644 (file)
@@ -15,6 +15,7 @@ struct metadata_cmd_context {
        const char *key;
        struct mail_attribute_value value;
        bool empty_mailbox_name;
+       bool allow_empty_mailbox_name;
 };
 
 static int
@@ -27,7 +28,7 @@ cmd_mailbox_metadata_open_mailbox(struct metadata_cmd_context *mctx,
        mctx->empty_mailbox_name = mctx->mailbox[0] == '\0';
 
        if (mctx->empty_mailbox_name) {
-               if (!mctx->ctx.allow_empty_mailbox_name) {
+               if (!mctx->allow_empty_mailbox_name) {
                        i_error("Failed to %s: %s", op,
                                "mailbox name cannot be empty");
                        mctx->ctx.exit_code = EX_USAGE;
@@ -135,12 +136,29 @@ cmd_mailbox_metadata_set_init(struct doveadm_mail_cmd_context *_ctx,
        ctx->value.value = p_strdup(_ctx->pool, args[2]);
 }
 
+static bool
+cmd_mailbox_metadata_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
+{
+       struct metadata_cmd_context *ctx =
+               (struct metadata_cmd_context *)_ctx;
+
+       switch (c) {
+       case 's':
+               ctx->allow_empty_mailbox_name = TRUE;
+               break;
+       default:
+               return FALSE;
+       }
+       return TRUE;
+}
+
 static struct doveadm_mail_cmd_context *cmd_mailbox_metadata_set_alloc(void)
 {
        struct metadata_cmd_context *ctx;
 
        ctx = doveadm_mail_cmd_alloc(struct metadata_cmd_context);
        ctx->ctx.v.init = cmd_mailbox_metadata_set_init;
+       ctx->ctx.v.parse_arg = cmd_mailbox_metadata_parse_arg;
        ctx->ctx.v.run = cmd_mailbox_metadata_set_run;
        return &ctx->ctx;
 }
@@ -166,6 +184,7 @@ static struct doveadm_mail_cmd_context *cmd_mailbox_metadata_unset_alloc(void)
 
        ctx = doveadm_mail_cmd_alloc(struct metadata_cmd_context);
        ctx->ctx.v.init = cmd_mailbox_metadata_unset_init;
+       ctx->ctx.v.parse_arg = cmd_mailbox_metadata_parse_arg;
        ctx->ctx.v.run = cmd_mailbox_metadata_set_run;
        return &ctx->ctx;
 }
@@ -226,6 +245,7 @@ static struct doveadm_mail_cmd_context *cmd_mailbox_metadata_get_alloc(void)
 
        ctx = doveadm_mail_cmd_alloc(struct metadata_cmd_context);
        ctx->ctx.v.init = cmd_mailbox_metadata_get_init;
+       ctx->ctx.v.parse_arg = cmd_mailbox_metadata_parse_arg;
        ctx->ctx.v.run = cmd_mailbox_metadata_get_run;
        doveadm_print_init(DOVEADM_PRINT_TYPE_FLOW);
        return &ctx->ctx;
@@ -304,6 +324,7 @@ static struct doveadm_mail_cmd_context *cmd_mailbox_metadata_list_alloc(void)
 
        ctx = doveadm_mail_cmd_alloc(struct metadata_cmd_context);
        ctx->ctx.v.init = cmd_mailbox_metadata_list_init;
+       ctx->ctx.v.parse_arg = cmd_mailbox_metadata_parse_arg;
        ctx->ctx.v.run = cmd_mailbox_metadata_list_run;
        doveadm_print_init(DOVEADM_PRINT_TYPE_FLOW);
        return &ctx->ctx;
index c0b9e6be12ce9b0ae8243a16ae8b7f87491b6d12..26a5a2beb8a48a99df00a334f8a8eacc96538d6a 100644 (file)
@@ -1023,10 +1023,6 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(struct doveadm_cmd_context *cctx)
                        }
                        mctx->cmd_input = arg->value.v_istream;
                        i_stream_ref(mctx->cmd_input);
-               } else if (strcmp(arg->name, "allow-empty-mailbox-name") == 0) {
-                       /* allow an empty mailbox name - to access server
-                          attributes */
-                       mctx->allow_empty_mailbox_name = arg->value.v_bool;
 
                /* Keep all named special parameters above this line */
 
index 7295e69175d09cef66e3f4ec5b23640b30943eee..b1e935fef051ffd136beb64540731d5bed1653f3 100644 (file)
@@ -101,9 +101,6 @@ struct doveadm_mail_cmd_context {
        bool add_username_header:1;
        /* Running from CLI doveadm (not doveadm-server) */
        bool cli:1;
-
-       /* Allow empty mailbox name - to allow access to server attributes */
-       bool allow_empty_mailbox_name:1;
 };
 
 struct doveadm_mail_cmd {