changeset 9177:8faf1cc19bd7 HEAD

acl: When creating a new child mailbox, copy parent's ACLs to it.
author Timo Sirainen <tss@iki.fi>
date Sat, 27 Jun 2009 23:15:58 -0400
parents fcebba0f438f
children 86c32eb84dfa
files src/plugins/acl/acl-storage.c
diffstat 1 files changed, 31 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 	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 @@
 		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)