]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
acl: Override mailbox list functions in mailbox_list_created hook.
authorTimo Sirainen <tss@iki.fi>
Thu, 5 Aug 2010 15:59:40 +0000 (16:59 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 5 Aug 2010 15:59:40 +0000 (16:59 +0100)
src/plugins/acl/acl-mailbox-list.c
src/plugins/acl/acl-plugin.c
src/plugins/acl/acl-plugin.h

index b5f429e0c54287eecb2edddf8afe25457bee2389..b7a29a51125081f210541ea6c084f92ff1eeec2e 100644 (file)
@@ -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);
        }
 }
index 6fbf70d2abb94110adbc0a271758d06c20e0528d..8896cc393513b5d4f5f3dc59cf75e38b4c279c3c 100644 (file)
@@ -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
index 634f9897c636353ce878245929b996e6cb4040f8..deb8e40789010da5c79e34ed39eb2e28ee18cf7c 100644 (file)
@@ -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);