]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 27 Feb 2017 17:55:51 +0000 (19:55 +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 0d7f78427e9dcaee1c0b6e2a3c9419bf126ddb1d..b00f24f7772ccb9527f58f7af0e25f4f9b003100 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;
 }
@@ -230,6 +249,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;
@@ -308,6 +328,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 5243896675f98732f7ac524f2e35e9dff2045395..e53c6695aa897d4e24e85d6c1c70821d21adb624 100644 (file)
@@ -1024,10 +1024,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 0094fdf8572e722937a3171f503632506048f132..494cf6c4dae9eb21516968bcd6217a9df15b9b7c 100644 (file)
@@ -101,9 +101,6 @@ struct doveadm_mail_cmd_context {
        unsigned int add_username_header:1;
        /* Running from CLI doveadm (not doveadm-server) */
        unsigned int cli:1;
-
-       /* Allow empty mailbox name - to allow access to server attributes */
-       unsigned int allow_empty_mailbox_name:1;
 };
 
 struct doveadm_mail_cmd {