]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
acl: Consistently determine whether ACL files are in control or mailbox directory
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 16 Sep 2021 15:05:04 +0000 (18:05 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 17 Sep 2021 16:14:13 +0000 (16:14 +0000)
Add mail_storage_get_acl_list_path_type() that is used for it. This fixes
ACL inheritance with obox.

src/plugins/acl/acl-backend-vfile-acllist.c
src/plugins/acl/acl-backend-vfile.c
src/plugins/acl/acl-backend-vfile.h

index e960795d0a7c9c34ad001b3f4ae09a0d9cec32b9..507430f9bb1a238fde89477226876a74c9e2a106 100644 (file)
@@ -50,8 +50,7 @@ static bool acl_list_get_root_dir(struct acl_backend_vfile *backend,
                return FALSE;
 
        storage = mailbox_list_get_namespace(backend->backend.list)->storage;
-       type = (storage->class_flags & MAIL_STORAGE_CLASS_FLAG_NO_ROOT) != 0 ?
-               MAILBOX_LIST_PATH_TYPE_CONTROL : MAILBOX_LIST_PATH_TYPE_DIR;
+       type = mail_storage_get_acl_list_path_type(storage);
        if (!mailbox_list_get_root_path(backend->backend.list, type, &rootdir))
                return FALSE;
        *type_r = type;
index cc93b3561c48729a22f6cd63b5e25e4c0a410cc6..16666bd6884ada0754377373a255ad6cf0e26571 100644 (file)
@@ -122,9 +122,7 @@ acl_backend_vfile_get_local_dir(struct acl_backend *backend,
                return NULL;
        i_assert(list == ns->list);
 
-       type = mail_storage_is_mailbox_file(storage) ||
-               (storage->class_flags & MAIL_STORAGE_CLASS_FLAG_NO_ROOT) != 0 ?
-               MAILBOX_LIST_PATH_TYPE_CONTROL : MAILBOX_LIST_PATH_TYPE_MAILBOX;
+       type = mail_storage_get_acl_list_path_type(storage);
        if (name == NULL) {
                if (!mailbox_list_get_root_path(list, type, &dir))
                        return NULL;
@@ -224,6 +222,8 @@ acl_backend_vfile_has_acl(struct acl_backend *_backend, const char *name)
        struct acl_backend_vfile *backend =
                (struct acl_backend_vfile *)_backend;
        struct acl_backend_vfile_validity *old_validity, new_validity;
+       struct mailbox_list *list;
+       struct mail_storage *storage;
        const char *path, *local_path, *global_path, *dir, *vname = "";
        const char *error;
        int ret;
@@ -237,8 +237,14 @@ acl_backend_vfile_has_acl(struct acl_backend *_backend, const char *name)
        /* See if the mailbox exists. If we wanted recursive lookups we could
           skip this, but at least for now we assume that if an existing
           mailbox has no ACL it's equivalent to default ACLs. */
-       if (mailbox_list_get_path(_backend->list, name,
-                                 MAILBOX_LIST_PATH_TYPE_MAILBOX, &path) <= 0)
+       vname = *name == '\0' ? "" :
+               mailbox_list_get_vname(_backend->list, name);
+       list = _backend->list;
+       if (mailbox_list_get_storage(&list, vname, &storage) < 0)
+               ret = -1;
+       else if (mailbox_list_get_path(_backend->list, name,
+                       mail_storage_get_acl_list_path_type(storage),
+                       &path) <= 0)
                ret = -1;
        else {
                ret = acl_backend_vfile_exists(backend, path,
@@ -248,8 +254,6 @@ acl_backend_vfile_has_acl(struct acl_backend *_backend, const char *name)
        if (ret == 0 &&
            (*name == '\0' ||
             mailbox_list_is_valid_name(_backend->list, name, &error))) {
-               vname = *name == '\0' ? "" :
-                       mailbox_list_get_vname(_backend->list, name);
                dir = acl_backend_vfile_get_local_dir(_backend, name, vname);
                if (dir != NULL) {
                        local_path = t_strconcat(dir, "/", name, NULL);
index 1fa4d16afc0b2e88cd28b76743e9135de62a1486..9c487e956e20ccd59d590b7024fea9380c1bc2f7 100644 (file)
@@ -2,6 +2,7 @@
 #define ACL_BACKEND_VFILE_H
 
 #include "acl-api-private.h"
+#include "mail-storage-private.h"
 
 #define ACL_FILENAME "dovecot-acl"
 #define ACLLIST_FILENAME "dovecot-acl-list"
@@ -71,4 +72,18 @@ int acl_backend_vfile_nonowner_lookups_rebuild(struct acl_backend *backend);
 int acl_backend_vfile_object_get_mtime(struct acl_object *aclobj,
                                       time_t *mtime_r);
 
+static inline enum mailbox_list_path_type
+mail_storage_get_acl_list_path_type(struct mail_storage *storage)
+{
+       if (mail_storage_is_mailbox_file(storage)) {
+               /* mailbox is a directory (e.g. mbox) */
+               return MAILBOX_LIST_PATH_TYPE_CONTROL;
+       }
+       if ((storage->class_flags & MAIL_STORAGE_CLASS_FLAG_NO_ROOT) != 0) {
+               /* there is no local mailbox directory */
+               return MAILBOX_LIST_PATH_TYPE_CONTROL;
+       }
+       return MAILBOX_LIST_PATH_TYPE_MAILBOX;
+}
+
 #endif