dovecot-2.0: acl: Override mailbox list functions in mailbox_lis...

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 5 18:59:43 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/2311b5ca4d3f
changeset: 11944:2311b5ca4d3f
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 05 16:59:40 2010 +0100
description:
acl: Override mailbox list functions in mailbox_list_created hook.

diffstat:

 src/plugins/acl/acl-mailbox-list.c |  62 ++++++++++++++++--------------
 src/plugins/acl/acl-plugin.c       |   1 +
 src/plugins/acl/acl-plugin.h       |   1 +
 3 files changed, 35 insertions(+), 29 deletions(-)

diffs (113 lines):

diff -r ddf343de34a4 -r 2311b5ca4d3f src/plugins/acl/acl-mailbox-list.c
--- a/src/plugins/acl/acl-mailbox-list.c	Thu Aug 05 16:58:12 2010 +0100
+++ b/src/plugins/acl/acl-mailbox-list.c	Thu Aug 05 16:59:40 2010 +0100
@@ -516,32 +516,8 @@
 
 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;
-	struct acl_backend *backend;
-	struct mail_namespace *ns;
-	const char *current_username, *owner_username;
-	bool owner = TRUE;
-
-	owner_username = list->ns->user->username;
-	current_username = auser->master_user;
-	if (current_username == NULL)
-		current_username = owner_username;
-	else
-		owner = strcmp(current_username, owner_username) == 0;
-
-	/* 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,
-				   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. */
@@ -558,21 +534,49 @@
 	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)
 {
 	struct acl_user *auser = ACL_USER_CONTEXT(ns->user);
+	struct acl_mailbox_list *alist = ACL_LIST_CONTEXT(ns->list);
+	struct acl_backend *backend;
+	const char *current_username, *owner_username;
+	bool owner = TRUE;
+
+	owner_username = ns->user->username;
+	current_username = auser->master_user;
+	if (current_username == NULL)
+		current_username = owner_username;
+	else
+		owner = strcmp(current_username, owner_username) == 0;
+
+	/* 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. */
+	if (ns->type != NAMESPACE_PRIVATE)
+		owner = FALSE;
+
+	/* 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");
+	acl_storage_rights_ctx_init(&alist->rights, backend);
+}
+
+void acl_mailbox_list_created(struct mailbox_list *list)
+{
+	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 -r ddf343de34a4 -r 2311b5ca4d3f src/plugins/acl/acl-plugin.c
--- a/src/plugins/acl/acl-plugin.c	Thu Aug 05 16:58:12 2010 +0100
+++ b/src/plugins/acl/acl-plugin.c	Thu Aug 05 16:59:40 2010 +0100
@@ -11,6 +11,7 @@
 
 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 -r ddf343de34a4 -r 2311b5ca4d3f src/plugins/acl/acl-plugin.h
--- a/src/plugins/acl/acl-plugin.h	Thu Aug 05 16:58:12 2010 +0100
+++ b/src/plugins/acl/acl-plugin.h	Thu Aug 05 16:59:40 2010 +0100
@@ -39,6 +39,7 @@
 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);
 


More information about the dovecot-cvs mailing list