changeset 19525:5b5c36bc38e0

dsync: Don't restrict what mailbox names can be created (except basic sanity checks) The mailbox names already exist on the other side, so we don't want to add arbitrary limits to them.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 28 Dec 2015 06:49:29 -0500
parents 3df66d89a87a
children e0bd9253121b
files src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h
diffstat 4 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c	Wed Dec 23 11:48:12 2015 +0200
+++ b/src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c	Mon Dec 28 06:49:29 2015 -0500
@@ -164,6 +164,7 @@
 		box = mailbox_alloc(change->ns->list, change->full_name, 0);
 		break;
 	}
+	mailbox_skip_create_name_restrictions(box, TRUE);
 	switch (change->type) {
 	case DSYNC_MAILBOX_TREE_SYNC_TYPE_CREATE_BOX:
 		ret = sync_create_box(brain, box, change->mailbox_guid,
@@ -192,6 +193,7 @@
 	case DSYNC_MAILBOX_TREE_SYNC_TYPE_RENAME:
 		destbox = mailbox_alloc(change->ns->list,
 					change->rename_dest_name, 0);
+		mailbox_skip_create_name_restrictions(destbox, TRUE);
 		ret = mailbox_rename(box, destbox);
 		func_name = "mailbox_rename";
 		mailbox_free(&destbox);
--- a/src/lib-storage/mail-storage-private.h	Wed Dec 23 11:48:12 2015 +0200
+++ b/src/lib-storage/mail-storage-private.h	Mon Dec 28 06:49:29 2015 -0500
@@ -380,6 +380,8 @@
 	unsigned int mail_cache_disabled:1;
 	/* Update first_saved field to mailbox list index. */
 	unsigned int update_first_saved:1;
+	/* mailbox_verify_create_name() only checks for mailbox_verify_name() */
+	unsigned int skip_create_name_restrictions:1;
 };
 
 struct mail_vfuncs {
--- a/src/lib-storage/mail-storage.c	Wed Dec 23 11:48:12 2015 +0200
+++ b/src/lib-storage/mail-storage.c	Mon Dec 28 06:49:29 2015 -0500
@@ -962,6 +962,11 @@
 	return FALSE;
 }
 
+void mailbox_skip_create_name_restrictions(struct mailbox *box, bool set)
+{
+	box->skip_create_name_restrictions = set;
+}
+
 int mailbox_verify_create_name(struct mailbox *box)
 {
 	char sep = mail_namespace_get_sep(box->list->ns);
@@ -973,6 +978,8 @@
 	   visible to users, while storage name may be a fixed length GUID. */
 	if (mailbox_verify_name(box) < 0)
 		return -1;
+	if (box->skip_create_name_restrictions)
+		return 0;
 	if (mailbox_name_has_control_chars(box->vname)) {
 		mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS,
 			"Control characters not allowed in new mailbox names");
--- a/src/lib-storage/mail-storage.h	Wed Dec 23 11:48:12 2015 +0200
+++ b/src/lib-storage/mail-storage.h	Mon Dec 28 06:49:29 2015 -0500
@@ -481,6 +481,11 @@
 /* Returns TRUE if the mailbox is user's INBOX or another user's shared INBOX */
 bool mailbox_is_any_inbox(struct mailbox *box);
 
+/* Change mailbox_verify_create_name() to not verify new mailbox name
+   restrictions (but still check that it's a valid existing name). This is
+   mainly used by dsync to make sure the sync works even though the original
+   name isn't valid anymore. */
+void mailbox_skip_create_name_restrictions(struct mailbox *box, bool set);
 /* Returns -1 if mailbox_create() is guaranteed to fail because the mailbox
    name is invalid, 0 not. The error message contains a reason. */
 int mailbox_verify_create_name(struct mailbox *box);