dovecot-1.2: acl: When creating a new child mailbox, copy parent...

dovecot at dovecot.org dovecot at dovecot.org
Sun Jun 28 06:32:54 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/8faf1cc19bd7
changeset: 9177:8faf1cc19bd7
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Jun 27 23:15:58 2009 -0400
description:
acl: When creating a new child mailbox, copy parent's ACLs to it.

diffstat:

1 file changed, 31 insertions(+), 2 deletions(-)
src/plugins/acl/acl-storage.c |   33 +++++++++++++++++++++++++++++++--

diffs (50 lines):

diff -r fcebba0f438f -r 8faf1cc19bd7 src/plugins/acl/acl-storage.c
--- a/src/plugins/acl/acl-storage.c	Sat Jun 27 22:25:35 2009 -0400
+++ b/src/plugins/acl/acl-storage.c	Sat Jun 27 23:15:58 2009 -0400
@@ -139,6 +139,30 @@ acl_mailbox_open(struct mail_storage *st
 	return acl_mailbox_open_box(box);
 }
 
+static void acl_mailbox_copy_acls_from_parent(struct mail_storage *storage,
+					     const char *name)
+{
+	struct acl_mail_storage *astorage = ACL_CONTEXT(storage);
+	struct acl_object *parent_aclobj, *child_aclobj;
+	struct acl_object_list_iter *iter;
+	struct acl_rights_update update;
+
+	memset(&update, 0, sizeof(update));
+	update.modify_mode = ACL_MODIFY_MODE_REPLACE;
+	update.neg_modify_mode = ACL_MODIFY_MODE_REPLACE;
+
+	child_aclobj = acl_object_init_from_name(astorage->rights.backend,
+						 storage, name);
+	parent_aclobj = acl_object_init_from_parent(astorage->rights.backend,
+						    storage, name);
+	iter = acl_object_list_init(parent_aclobj);
+	while (acl_object_list_next(iter, &update.rights) > 0)
+		(void)acl_object_update(child_aclobj, &update);
+	acl_object_list_deinit(&iter);
+	acl_object_deinit(&parent_aclobj);
+	acl_object_deinit(&child_aclobj);
+}
+
 static int acl_mailbox_create(struct mail_storage *storage, const char *name,
 			      bool directory)
 {
@@ -163,8 +187,13 @@ static int acl_mailbox_create(struct mai
 		return -1;
 	}
 
-	return astorage->module_ctx.super.
-		mailbox_create(storage, name, directory);
+	if (astorage->module_ctx.super.
+	    		mailbox_create(storage, name, directory) < 0)
+		return -1;
+
+	if (!directory)
+		acl_mailbox_copy_acls_from_parent(storage, name);
+	return 0;
 }
 
 void acl_mail_storage_created(struct mail_storage *storage)


More information about the dovecot-cvs mailing list