dovecot-2.2: lib-storage: Fixed setting/getting server metadata.

dovecot at dovecot.org dovecot at dovecot.org
Mon May 4 20:29:34 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/986cbdfb887d
changeset: 18517:986cbdfb887d
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 04 23:27:42 2015 +0300
description:
lib-storage: Fixed setting/getting server metadata.
Also added a MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE() macro to make it a
bit easier to check if a key should be accessible to a user or not.

diffstat:

 src/lib-storage/index/index-attribute.c |   6 ++----
 src/lib-storage/mailbox-attribute.h     |  15 +++++++++++++--
 2 files changed, 15 insertions(+), 6 deletions(-)

diffs (51 lines):

diff -r 5f43c88e2c87 -r 986cbdfb887d src/lib-storage/index/index-attribute.c
--- a/src/lib-storage/index/index-attribute.c	Mon May 04 19:53:53 2015 +0300
+++ b/src/lib-storage/index/index-attribute.c	Mon May 04 23:27:42 2015 +0300
@@ -186,8 +186,7 @@
 	time_t ts = value->last_change != 0 ? value->last_change : ioloop_time;
 	int ret = 0;
 
-	if (strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT,
-		    strlen(MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT)) == 0) {
+	if (!MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key)) {
 		mail_storage_set_error(t->box->storage, MAIL_ERROR_PARAMS,
 			"Internal attributes cannot be changed directly");
 		return -1;
@@ -227,8 +226,7 @@
 
 	memset(value_r, 0, sizeof(*value_r));
 
-	if (strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT,
-		    strlen(MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT)) == 0)
+	if (!MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key))
 		return 0;
 
 	if (index_storage_get_dict(t->box, type, &dict, &mailbox_prefix) < 0)
diff -r 5f43c88e2c87 -r 986cbdfb887d src/lib-storage/mailbox-attribute.h
--- a/src/lib-storage/mailbox-attribute.h	Mon May 04 19:53:53 2015 +0300
+++ b/src/lib-storage/mailbox-attribute.h	Mon May 04 23:27:42 2015 +0300
@@ -11,11 +11,22 @@
    users cannot access these in any way. */
 #define MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT \
 	MAILBOX_ATTRIBUTE_PREFIX_DOVECOT"pvt/"
-/* Prefix used for server attributes in INBOX. INBOX deletion won't delete
-   any attributes under this prefix. */
+/* Server attributes are currently stored in INBOX under this private prefix.
+   They're under the pvt/ prefix so they won't be listed as regular INBOX
+   attributes, but unlike other pvt/ attributes it's actually possible to
+   access these attributes as regular users.
+
+   If INBOX is deleted, attributes under this prefix are preserved. */
 #define MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER \
 	MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT"server/"
 
+/* User can get/set all non-pvt/ attributes and also pvt/server/ attributes. */
+#define MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key) \
+	(strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT, \
+		 strlen(MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT)) != 0 || \
+	 strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER, \
+		 strlen(MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER)) == 0)
+
 enum mail_attribute_type {
 	MAIL_ATTRIBUTE_TYPE_PRIVATE,
 	MAIL_ATTRIBUTE_TYPE_SHARED


More information about the dovecot-cvs mailing list