From: Timo Sirainen Date: Thu, 16 Sep 2021 15:05:04 +0000 (+0300) Subject: acl: Consistently determine whether ACL files are in control or mailbox directory X-Git-Tag: 2.3.17~114 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f63bda4db5bd38fab9ed0326e215289ad3a2cf95;p=thirdparty%2Fdovecot%2Fcore.git acl: Consistently determine whether ACL files are in control or mailbox directory Add mail_storage_get_acl_list_path_type() that is used for it. This fixes ACL inheritance with obox. --- diff --git a/src/plugins/acl/acl-backend-vfile-acllist.c b/src/plugins/acl/acl-backend-vfile-acllist.c index e960795d0a..507430f9bb 100644 --- a/src/plugins/acl/acl-backend-vfile-acllist.c +++ b/src/plugins/acl/acl-backend-vfile-acllist.c @@ -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; diff --git a/src/plugins/acl/acl-backend-vfile.c b/src/plugins/acl/acl-backend-vfile.c index cc93b3561c..16666bd688 100644 --- a/src/plugins/acl/acl-backend-vfile.c +++ b/src/plugins/acl/acl-backend-vfile.c @@ -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); diff --git a/src/plugins/acl/acl-backend-vfile.h b/src/plugins/acl/acl-backend-vfile.h index 1fa4d16afc..9c487e956e 100644 --- a/src/plugins/acl/acl-backend-vfile.h +++ b/src/plugins/acl/acl-backend-vfile.h @@ -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