From: Timo Sirainen Date: Thu, 16 Sep 2021 16:13:09 +0000 (+0300) Subject: acl: acl_backend_vfile_has_acl() - Open mailbox to check if it exists X-Git-Tag: 2.3.17~111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4f765652f06352fe9d56fa273604c6e7f2218cca;p=thirdparty%2Fdovecot%2Fcore.git acl: acl_backend_vfile_has_acl() - Open mailbox to check if it exists This is a bit more expensive than the previous behavior, but it's done only when creating or renaming mailboxes which are pretty rare operations. This fixes copying parent ACLs with obox when the parent mailbox doesn't exist in local metacache. --- diff --git a/src/plugins/acl/acl-backend-vfile.c b/src/plugins/acl/acl-backend-vfile.c index 6c5da88da8..8d70303c30 100644 --- a/src/plugins/acl/acl-backend-vfile.c +++ b/src/plugins/acl/acl-backend-vfile.c @@ -222,9 +222,7 @@ 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, *global_path, *vname = ""; + const char *global_path, *vname; int ret; old_validity = acl_cache_get_validity(_backend->cache, name); @@ -239,21 +237,16 @@ acl_backend_vfile_has_acl(struct acl_backend *_backend, const char *name) If not, check if the mailbox exists. */ 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 { + struct mailbox *box = + mailbox_alloc(_backend->list, vname, + MAILBOX_FLAG_READONLY | MAILBOX_FLAG_IGNORE_ACLS); + if (backend->global_path == NULL) { + /* global ACLs disabled */ ret = 0; - } - - if (ret == 0 && backend->global_path != NULL) { + } else { if (_backend->global_file != NULL) { ret = acl_global_file_refresh(_backend->global_file); - if (ret == 0 && acl_global_file_have_any(_backend->global_file, vname)) + if (ret == 0 && acl_global_file_have_any(_backend->global_file, box->vname)) ret = 1; } else { global_path = t_strconcat(backend->global_path, "/", name, NULL); @@ -262,12 +255,26 @@ acl_backend_vfile_has_acl(struct acl_backend *_backend, const char *name) } } - if (ret == 0) { - ret = acl_backend_vfile_exists(backend, path, - &new_validity.mailbox_validity); + if (ret != 0) { + /* error / global ACL found */ + } else if (mailbox_open(box) == 0) { + /* mailbox exists */ + ret = 1; + } else { + enum mail_error error; + const char *errstr = + mailbox_get_last_internal_error(box, &error); + if (error == MAIL_ERROR_NOTFOUND) + ret = 0; + else { + e_error(box->event, "acl: Failed to open mailbox: %s", + errstr); + ret = -1; + } } acl_cache_set_validity(_backend->cache, name, &new_validity); + mailbox_free(&box); return ret > 0; } diff --git a/src/plugins/acl/acl-backend-vfile.h b/src/plugins/acl/acl-backend-vfile.h index 9c487e956e..c5aaa25649 100644 --- a/src/plugins/acl/acl-backend-vfile.h +++ b/src/plugins/acl/acl-backend-vfile.h @@ -20,7 +20,6 @@ struct acl_vfile_validity { struct acl_backend_vfile_validity { struct acl_vfile_validity global_validity, local_validity; - struct acl_vfile_validity mailbox_validity; }; struct acl_object_vfile {