dovecot-2.2: acl: Optionally get default ACL's for private/share...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 6 14:59:37 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/714dfc072d60
changeset: 16328:714dfc072d60
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 06 14:59:27 2013 +0300
description:
acl: Optionally get default ACL's for private/shared namespaces from user's INBOX.
This probably should be the default always, but better not break anyone's
existing setup until v2.3.0. So for now there's a setting for this:
plugin { acl_defaults_from_inbox = yes }

diffstat:

 src/plugins/acl/acl-api-private.h   |   1 +
 src/plugins/acl/acl-backend-vfile.c |   2 +-
 src/plugins/acl/acl-backend.c       |  31 +++++++++++++++++++++++++------
 3 files changed, 27 insertions(+), 7 deletions(-)

diffs (76 lines):

diff -r 11712979c8ab -r 714dfc072d60 src/plugins/acl/acl-api-private.h
--- a/src/plugins/acl/acl-api-private.h	Mon May 06 14:58:55 2013 +0300
+++ b/src/plugins/acl/acl-api-private.h	Mon May 06 14:59:27 2013 +0300
@@ -81,6 +81,7 @@
 const char *const *
 acl_backend_mask_get_names(struct acl_backend *backend,
 			   const struct acl_mask *mask, pool_t pool);
+struct acl_object *acl_backend_get_default_object(struct acl_backend *backend);
 int acl_backend_get_default_rights(struct acl_backend *backend,
 				   const struct acl_mask **mask_r);
 void acl_rights_write_id(string_t *dest, const struct acl_rights *right);
diff -r 11712979c8ab -r 714dfc072d60 src/plugins/acl/acl-backend-vfile.c
--- a/src/plugins/acl/acl-backend-vfile.c	Mon May 06 14:58:55 2013 +0300
+++ b/src/plugins/acl/acl-backend-vfile.c	Mon May 06 14:59:27 2013 +0300
@@ -284,7 +284,7 @@
 	}
 	if (parent == NULL) {
 		/* use the root */
-		parent = "";
+		parent = acl_backend_get_default_object(backend)->name;
 	}
 	return acl_backend_vfile_object_init(backend, parent);
 }
diff -r 11712979c8ab -r 714dfc072d60 src/plugins/acl/acl-backend.c
--- a/src/plugins/acl/acl-backend.c	Mon May 06 14:58:55 2013 +0300
+++ b/src/plugins/acl/acl-backend.c	Mon May 06 14:59:27 2013 +0300
@@ -4,6 +4,7 @@
 #include "hash.h"
 #include "mail-storage-settings.h"
 #include "mailbox-list.h"
+#include "mail-namespace.h"
 #include "mail-user.h"
 #include "acl-cache.h"
 #include "acl-api-private.h"
@@ -157,17 +158,35 @@
 	return acl_cache_right_lookup(backend->cache, right);
 }
 
+struct acl_object *acl_backend_get_default_object(struct acl_backend *backend)
+{
+	struct mail_user *user = mailbox_list_get_user(backend->list);
+	struct mail_namespace *ns = mailbox_list_get_namespace(backend->list);
+	const char *default_name = "";
+
+	if (backend->default_aclobj != NULL)
+		return backend->default_aclobj;
+
+	/* FIXME: this should probably be made default in v2.3 */
+	if (mail_user_plugin_getenv(user, "acl_defaults_from_inbox") != NULL) {
+		if (ns->type == MAIL_NAMESPACE_TYPE_PRIVATE ||
+		    ns->type == MAIL_NAMESPACE_TYPE_SHARED)
+			default_name = "INBOX";
+	}
+	backend->default_aclobj =
+		acl_object_init_from_name(backend, default_name);
+	return backend->default_aclobj;
+}
+
 int acl_backend_get_default_rights(struct acl_backend *backend,
 				   const struct acl_mask **mask_r)
 {
-	if (backend->default_aclobj == NULL) {
-		backend->default_aclobj =
-			acl_object_init_from_name(backend, "");
-	}
-	if (backend->v.object_refresh_cache(backend->default_aclobj) < 0)
+	struct acl_object *aclobj = acl_backend_get_default_object(backend);
+
+	if (backend->v.object_refresh_cache(aclobj) < 0)
 		return -1;
 
-	*mask_r = acl_cache_get_my_rights(backend->cache, "");
+	*mask_r = acl_cache_get_my_rights(backend->cache, aclobj->name);
 	if (*mask_r == NULL)
 		*mask_r = backend->default_aclmask;
 	return 0;


More information about the dovecot-cvs mailing list