]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-acl: Split acl_mailbox_open_as_admin
authorMarkus Valentin <markus.valentin@open-xchange.com>
Thu, 20 May 2021 11:47:55 +0000 (13:47 +0200)
committermarkus.valentin <markus.valentin@open-xchange.com>
Wed, 26 May 2021 10:15:09 +0000 (10:15 +0000)
This allows easier implementation of the imap-acl proxying.

src/plugins/imap-acl/imap-acl-plugin.c

index b86f8ac5d9d7294aa54fe90b1d3a9f1d49173865..7df70de9cf0fe69e1295eddea3f1604793260ad8 100644 (file)
@@ -63,32 +63,23 @@ const char *imap_acl_plugin_version = DOVECOT_ABI_VERSION;
 static struct module *imap_acl_module;
 static imap_client_created_func_t *next_hook_client_created;
 
-static struct mailbox *
-acl_mailbox_open_as_admin(struct client_command_context *cmd, const char *name)
+static int
+acl_mailbox_open_allocated_as_admin(struct client_command_context *cmd,
+                                   struct mailbox *box, const char *name)
 {
-       struct mail_namespace *ns;
-       struct mailbox *box;
        enum mailbox_existence existence = MAILBOX_EXISTENCE_NONE;
        int ret;
 
        if (ACL_USER_CONTEXT(cmd->client->user) == NULL) {
                client_send_command_error(cmd, "ACLs disabled.");
-               return NULL;
+               return 0;
        }
 
-       ns = client_find_namespace(cmd, &name);
-       if (ns == NULL)
-               return NULL;
-
-       /* Force opening the mailbox so that we can give a nicer error message
-          if mailbox isn't selectable but is listable. */
-       box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_READONLY |
-                           MAILBOX_FLAG_IGNORE_ACLS);
        if (mailbox_exists(box, TRUE, &existence) == 0 &&
            existence == MAILBOX_EXISTENCE_SELECT) {
                ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_ADMIN);
                if (ret > 0)
-                       return box;
+                       return ret;
        }
 
        /* mailbox doesn't exist / not an administrator. */
@@ -100,8 +91,33 @@ acl_mailbox_open_as_admin(struct client_command_context *cmd, const char *name)
        } else {
                client_send_tagline(cmd, "NO "ERROR_NOT_ADMIN);
        }
-       mailbox_free(&box);
-       return NULL;
+       return 0;
+}
+
+static struct mailbox *
+acl_mailbox_open_as_admin(struct client_command_context *cmd, const char *name)
+{
+       struct mail_namespace *ns;
+       struct mailbox *box;
+
+       if (ACL_USER_CONTEXT(cmd->client->user) == NULL) {
+               client_send_command_error(cmd, "ACLs disabled.");
+               return NULL;
+       }
+
+       ns = client_find_namespace(cmd, &name);
+       if (ns == NULL)
+               return NULL;
+
+       /* Force opening the mailbox so that we can give a nicer error message
+          if mailbox isn't selectable but is listable. */
+       box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_READONLY |
+                           MAILBOX_FLAG_IGNORE_ACLS);
+       if (acl_mailbox_open_allocated_as_admin(cmd, box, name) <= 0) {
+               mailbox_free(&box);
+               return NULL;
+       }
+       return box;
 }
 
 static const struct imap_acl_letter_map *