]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
acl: Move attribute rights checking to its own function
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Jan 2020 13:43:11 +0000 (15:43 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 23 Jan 2020 12:36:05 +0000 (12:36 +0000)
src/plugins/acl/acl-attributes.c
src/plugins/acl/acl-mailbox.c
src/plugins/acl/acl-storage.h

index f0d3177de49fca4b0a020b4aaeff3b91a01c8dcf..515ff422616fba3b40420fa0b003a469150b5bdc 100644 (file)
@@ -111,13 +111,6 @@ static int acl_have_attribute_rights(struct mailbox *box)
                return 1;
        }
 
-       /* RFC 5464:
-
-          When the ACL extension [RFC4314] is present, users can only set and
-          retrieve private or shared mailbox annotations on a mailbox on which
-          they have the "l" right and any one of the "r", "s", "w", "i", or "p"
-          rights.
-       */
        ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_LOOKUP);
        if (ret <= 0) {
                if (ret < 0)
@@ -127,17 +120,7 @@ static int acl_have_attribute_rights(struct mailbox *box)
                return -1;
        }
 
-       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_READ) > 0)
-               return 0;
-       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_SEEN) > 0)
-               return 0;
-       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE) > 0)
-               return 0;
-       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_INSERT) > 0)
-               return 0;
-       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_POST) > 0)
-               return 0;
-       return -1;
+       return acl_mailbox_have_extra_attribute_rights(box) ? 0 : -1;
 }
 
 int acl_attribute_set(struct mailbox_transaction_context *t,
index 13ba0557d7475e6a4daf29634f68ae17f58599c3..fabaa06410825a954ad0b4008b76b2689adbe0e0 100644 (file)
@@ -487,6 +487,28 @@ static int acl_mailbox_exists(struct mailbox *box, bool auto_boxes,
        return 0;
 }
 
+bool acl_mailbox_have_extra_attribute_rights(struct mailbox *box)
+{
+       /* RFC 5464:
+
+          When the ACL extension [RFC4314] is present, users can only set and
+          retrieve private or shared mailbox annotations on a mailbox on which
+          they have the "l" right and any one of the "r", "s", "w", "i", or "p"
+          rights.
+       */
+       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_READ) > 0)
+               return TRUE;
+       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_SEEN) > 0)
+               return TRUE;
+       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE) > 0)
+               return TRUE;
+       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_INSERT) > 0)
+               return TRUE;
+       if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_POST) > 0)
+               return TRUE;
+       return FALSE;
+}
+
 static int acl_mailbox_open_check_acl(struct mailbox *box)
 {
        struct acl_mailbox *abox = ACL_CONTEXT_REQUIRE(box);
index 5f7df621720d29e4bd21be30eae18587eb3ef51a..8be4c269b4b00ca0a6d6496ab68498ffcff19ec3 100644 (file)
@@ -28,6 +28,10 @@ struct acl_object *acl_mailbox_get_aclobj(struct mailbox *box);
    sets storage error. */
 int acl_mailbox_right_lookup(struct mailbox *box, unsigned int right_idx);
 
+/* Returns TRUE if mailbox has the necessary extra ACL for accessing
+   attributes. The caller must have checked the LOOKUP right already. */
+bool acl_mailbox_have_extra_attribute_rights(struct mailbox *box);
+
 int acl_mailbox_update_acl(struct mailbox_transaction_context *t,
                           const struct acl_rights_update *update);