[dovecot-cvs] dovecot/src/plugins/acl acl-api-private.h, 1.2, 1.3 acl-api.c, 1.2, 1.3 acl-backend.c, 1.3, 1.4

cras at dovecot.org cras at dovecot.org
Fri Aug 4 19:28:30 EEST 2006


Update of /var/lib/cvs/dovecot/src/plugins/acl
In directory talvi:/tmp/cvs-serv19344

Modified Files:
	acl-api-private.h acl-api.c acl-backend.c 
Log Message:
If .DEFAULT file exists in global ACL root directory, use it as the default
ACLs for all mailboxes.



Index: acl-api-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/acl/acl-api-private.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- acl-api-private.h	28 Feb 2006 12:38:20 -0000	1.2
+++ acl-api-private.h	4 Aug 2006 16:28:28 -0000	1.3
@@ -31,7 +31,9 @@
 
 	struct mail_storage *storage;
 	struct acl_cache *cache;
-	struct acl_mask *default_rights;
+
+	struct acl_object *default_aclobj;
+	struct acl_mask *default_aclmask;
 
 	struct acl_backend_vfuncs v;
 };

Index: acl-api.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/acl/acl-api.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- acl-api.c	28 Feb 2006 12:38:20 -0000	1.2
+++ acl-api.c	4 Aug 2006 16:28:28 -0000	1.3
@@ -31,22 +31,39 @@
 	aclobj->backend->v.object_deinit(aclobj);
 }
 
+static int acl_backend_get_default_rights(struct acl_backend *backend,
+					  const struct acl_mask **mask_r)
+{
+	if (backend->v.object_refresh_cache(backend->default_aclobj) < 0)
+		return -1;
+
+	*mask_r = acl_cache_get_my_rights(backend->cache, "");
+	if (*mask_r == NULL)
+		*mask_r = backend->default_aclmask;
+	return 0;
+}
+
 int acl_object_have_right(struct acl_object *aclobj, unsigned int right_idx)
 {
+	struct acl_backend *backend = aclobj->backend;
 	const struct acl_mask *have_mask;
 	unsigned int mask_idx;
 
 	if (*aclobj->name == '\0') {
 		/* we want to look up default rights */
-		have_mask = aclobj->backend->default_rights;
+		if (acl_backend_get_default_rights(backend, &have_mask) < 0)
+			return -1;
 	} else {
-		if (aclobj->backend->v.object_refresh_cache(aclobj) < 0)
+		if (backend->v.object_refresh_cache(aclobj) < 0)
 			return -1;
 
-		have_mask = acl_cache_get_my_rights(aclobj->backend->cache,
+		have_mask = acl_cache_get_my_rights(backend->cache,
 						    aclobj->name);
-		if (have_mask == NULL)
-			have_mask = aclobj->backend->default_rights;
+		if (have_mask == NULL) {
+			if (acl_backend_get_default_rights(backend,
+							   &have_mask) < 0)
+				return -1;
+		}
 	}
 
 	mask_idx = right_idx / CHAR_BIT;
@@ -58,6 +75,7 @@
 int acl_object_get_my_rights(struct acl_object *aclobj, pool_t pool,
                              const char *const **rights_r)
 {
+	struct acl_backend *backend = aclobj->backend;
 	const struct acl_mask *mask;
 	const char *const *names;
 	const char **buf, **rights;
@@ -65,21 +83,24 @@
 
 	if (*aclobj->name == '\0') {
 		/* we want to look up default rights */
-		mask = aclobj->backend->default_rights;
+		if (acl_backend_get_default_rights(backend, &mask) < 0)
+			return -1;
 	} else {
-		if (aclobj->backend->v.object_refresh_cache(aclobj) < 0)
+		if (backend->v.object_refresh_cache(aclobj) < 0)
 			return -1;
 
-		mask = acl_cache_get_my_rights(aclobj->backend->cache,
+		mask = acl_cache_get_my_rights(backend->cache,
 					       aclobj->name);
-		if (mask == NULL)
-			mask = aclobj->backend->default_rights;
+		if (mask == NULL) {
+			if (acl_backend_get_default_rights(backend, &mask) < 0)
+				return -1;
+		}
 	}
 
 	if (!pool->datastack_pool)
 		t_push();
 
-	names = acl_cache_get_names(aclobj->backend->cache, &names_count);
+	names = acl_cache_get_names(backend->cache, &names_count);
 	buf = t_new(const char *, (mask->size * CHAR_BIT) + 1);
 	count = 0;
 	for (i = 0, name_idx = 0; i < mask->size; i++) {

Index: acl-backend.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/acl/acl-backend.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- acl-backend.c	24 Jun 2006 21:03:13 -0000	1.3
+++ acl-backend.c	4 Aug 2006 16:28:28 -0000	1.4
@@ -50,7 +50,7 @@
 
 	storage_owner = owner_username != NULL &&
 		strcmp(acl_username, owner_username) == 0;
-	backend->default_rights =
+	backend->default_aclmask =
 		acl_cache_mask_init(backend->cache, backend->pool,
 				    storage_owner ? owner_mailbox_rights :
 				    non_owner_mailbox_rights);
@@ -63,6 +63,8 @@
 		qsort(backend->groups, group_count, sizeof(const char *),
 		      strcmp_p);
 	}
+
+	backend->default_aclobj = acl_object_init_from_name(backend, "");
 	return backend;
 }
 
@@ -72,6 +74,7 @@
 
 	*_backend = NULL;
 
+	acl_object_deinit(&backend->default_aclobj);
 	acl_cache_deinit(&backend->cache);
 	backend->v.deinit(backend);
 }



More information about the dovecot-cvs mailing list