From: Timo Sirainen Date: Thu, 5 Aug 2010 15:59:40 +0000 (+0100) Subject: acl: Override mailbox list functions in mailbox_list_created hook. X-Git-Tag: 2.0.rc5~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb433472848dddf0a42aa7252eda6721559a7c72;p=thirdparty%2Fdovecot%2Fcore.git acl: Override mailbox list functions in mailbox_list_created hook. --- diff --git a/src/plugins/acl/acl-mailbox-list.c b/src/plugins/acl/acl-mailbox-list.c index b5f429e0c5..b7a29a5112 100644 --- a/src/plugins/acl/acl-mailbox-list.c +++ b/src/plugins/acl/acl-mailbox-list.c @@ -516,15 +516,36 @@ static void acl_storage_rights_ctx_init(struct acl_storage_rights_context *ctx, static void acl_mailbox_list_init_default(struct mailbox_list *list) { - struct acl_user *auser = ACL_USER_CONTEXT(list->ns->user); struct mailbox_list_vfuncs *v = list->vlast; struct acl_mailbox_list *alist; + + if (list->mail_set->mail_full_filesystem_access) { + /* not necessarily, but safer to do this for now. */ + i_fatal("mail_full_filesystem_access=yes is " + "incompatible with ACLs"); + } + + alist = p_new(list->pool, struct acl_mailbox_list, 1); + alist->module_ctx.super = *v; + list->vlast = &alist->module_ctx.super; + v->iter_init = acl_mailbox_list_iter_init; + v->iter_next = acl_mailbox_list_iter_next; + v->iter_deinit = acl_mailbox_list_iter_deinit; + v->get_mailbox_name_status = acl_get_mailbox_name_status; + v->create_mailbox_dir = acl_mailbox_list_create_dir; + + MODULE_CONTEXT_SET(list, acl_mailbox_list_module, alist); +} + +void acl_mail_namespace_storage_added(struct mail_namespace *ns) +{ + struct acl_user *auser = ACL_USER_CONTEXT(ns->user); + struct acl_mailbox_list *alist = ACL_LIST_CONTEXT(ns->list); struct acl_backend *backend; - struct mail_namespace *ns; const char *current_username, *owner_username; bool owner = TRUE; - owner_username = list->ns->user->username; + owner_username = ns->user->username; current_username = auser->master_user; if (current_username == NULL) current_username = owner_username; @@ -534,45 +555,28 @@ static void acl_mailbox_list_init_default(struct mailbox_list *list) /* We don't care about the username for non-private mailboxes. It's used only when checking if we're the mailbox owner. We never are for shared/public mailboxes. */ - ns = mailbox_list_get_namespace(list); if (ns->type != NAMESPACE_PRIVATE) owner = FALSE; - backend = acl_backend_init(auser->acl_env, list, current_username, + /* we need to know the storage when initializing backend */ + backend = acl_backend_init(auser->acl_env, ns->list, current_username, auser->groups, owner); if (backend == NULL) i_fatal("ACL backend initialization failed"); - - if (list->mail_set->mail_full_filesystem_access) { - /* not necessarily, but safer to do this for now. */ - i_fatal("mail_full_filesystem_access=yes is " - "incompatible with ACLs"); - } - - alist = p_new(list->pool, struct acl_mailbox_list, 1); - alist->module_ctx.super = *v; - list->vlast = &alist->module_ctx.super; - v->iter_init = acl_mailbox_list_iter_init; - v->iter_next = acl_mailbox_list_iter_next; - v->iter_deinit = acl_mailbox_list_iter_deinit; - v->get_mailbox_name_status = acl_get_mailbox_name_status; - v->create_mailbox_dir = acl_mailbox_list_create_dir; - acl_storage_rights_ctx_init(&alist->rights, backend); - MODULE_CONTEXT_SET(list, acl_mailbox_list_module, alist); } -void acl_mail_namespace_storage_added(struct mail_namespace *ns) +void acl_mailbox_list_created(struct mailbox_list *list) { - struct acl_user *auser = ACL_USER_CONTEXT(ns->user); + struct acl_user *auser = ACL_USER_CONTEXT(list->ns->user); if (auser == NULL) { /* ACLs disabled for this user */ - } else if ((ns->flags & NAMESPACE_FLAG_NOACL) != 0) { + } else if ((list->ns->flags & NAMESPACE_FLAG_NOACL) != 0) { /* no ACL checks for internal namespaces (lda, shared) */ - if (ns->type == NAMESPACE_SHARED) - acl_mailbox_list_init_shared(ns->list); + if (list->ns->type == NAMESPACE_SHARED) + acl_mailbox_list_init_shared(list); } else { - acl_mailbox_list_init_default(ns->list); + acl_mailbox_list_init_default(list); } } diff --git a/src/plugins/acl/acl-plugin.c b/src/plugins/acl/acl-plugin.c index 6fbf70d2ab..8896cc3935 100644 --- a/src/plugins/acl/acl-plugin.c +++ b/src/plugins/acl/acl-plugin.c @@ -11,6 +11,7 @@ const char *acl_plugin_version = DOVECOT_VERSION; static struct mail_storage_hooks acl_mail_storage_hooks = { .mail_user_created = acl_mail_user_created, + .mailbox_list_created = acl_mailbox_list_created, .mail_namespace_storage_added = acl_mail_namespace_storage_added, .mailbox_allocated = acl_mailbox_allocated, .mail_allocated = acl_mail_allocated diff --git a/src/plugins/acl/acl-plugin.h b/src/plugins/acl/acl-plugin.h index 634f9897c6..deb8e40789 100644 --- a/src/plugins/acl/acl-plugin.h +++ b/src/plugins/acl/acl-plugin.h @@ -39,6 +39,7 @@ extern MODULE_CONTEXT_DEFINE(acl_user_module, &mail_user_module_register); extern MODULE_CONTEXT_DEFINE(acl_mailbox_list_module, &mailbox_list_module_register); +void acl_mailbox_list_created(struct mailbox_list *list); void acl_mail_namespace_storage_added(struct mail_namespace *ns); void acl_mail_user_created(struct mail_user *list);