dovecot-2.2: If prefix="" namespace isn't defined, autocreate it...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 29 22:03:36 EET 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/b52f4852e5f8
changeset: 15355:b52f4852e5f8
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 29 22:03:25 2012 +0200
description:
If prefix="" namespace isn't defined, autocreate it as an unusable namespace.
This avoids having to handle mail_namespace_find() errors all over the
place. Instead now the mailbox accesses will simply fail.

diffstat:

 configure.ac                                       |   2 +-
 src/doveadm/doveadm-mail-copymove.c                |   5 --
 src/doveadm/doveadm-mail-import.c                  |  15 +------
 src/doveadm/doveadm-mail-mailbox.c                 |  29 -------------
 src/doveadm/doveadm-mail.c                         |   5 --
 src/doveadm/doveadm-mailbox-list-iter.c            |   5 +-
 src/doveadm/dsync/doveadm-dsync.c                  |   4 -
 src/doveadm/dsync/dsync-brain.c                    |   6 --
 src/imap/cmd-list.c                                |   2 -
 src/imap/imap-commands-util.c                      |   5 +-
 src/indexer/master-connection.c                    |   5 --
 src/lib-imap-storage/imap-msgpart-url.c            |   5 --
 src/lib-lda/mail-deliver.c                         |   6 --
 src/lib-storage/fail-mail-storage.c                |   8 ++-
 src/lib-storage/mail-namespace.c                   |  47 ++++++++++++++++++++-
 src/lib-storage/mail-namespace.h                   |  19 +++++---
 src/lib-storage/mail-storage.c                     |   2 -
 src/plugins/acl/acl-mailbox-list.c                 |   4 +
 src/plugins/acl/doveadm-acl.c                      |  10 ----
 src/plugins/autocreate/autocreate-plugin.c         |   2 +-
 src/plugins/pop3-migration/pop3-migration-plugin.c |   5 --
 src/plugins/quota/quota-storage.c                  |   4 +-
 src/plugins/snarf/snarf-plugin.c                   |   5 --
 src/plugins/trash/trash-plugin.c                   |  10 ++--
 src/pop3/pop3-client.c                             |   2 +-
 25 files changed, 83 insertions(+), 129 deletions(-)

diffs (truncated from 581 to 300 lines):

diff -r 62519d9334a5 -r b52f4852e5f8 configure.ac
--- a/configure.ac	Mon Oct 29 21:54:51 2012 +0200
+++ b/configure.ac	Mon Oct 29 22:03:25 2012 +0200
@@ -250,7 +250,7 @@
 	mail_storages="shared `echo "$withval"|sed 's/,/ /g'`" ],
 	mail_storages="shared mdbox sdbox maildir mbox cydir")
 AC_SUBST(mail_storages)
-mail_storages="$mail_storages imapc_stub pop3c_stub raw"
+mail_storages="$mail_storages imapc_stub pop3c_stub raw fail"
 # drop duplicates
 duplicates=`(for i in $mail_storages; do echo $i; done)|sort|uniq -d|xargs echo`
 if test "$duplicates" != ""; then
diff -r 62519d9334a5 -r b52f4852e5f8 src/doveadm/doveadm-mail-copymove.c
--- a/src/doveadm/doveadm-mail-copymove.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/doveadm/doveadm-mail-copymove.c	Mon Oct 29 22:03:25 2012 +0200
@@ -103,11 +103,6 @@
 	int ret = 0;
 
 	ns = mail_namespace_find(user->namespaces, ctx->destname);
-	if (ns == NULL) {
-		i_fatal_status(DOVEADM_EX_NOTFOUND,
-			       "Can't find namespace for: %s", ctx->destname);
-	}
-
 	destbox = mailbox_alloc(ns->list, ctx->destname, MAILBOX_FLAG_SAVEONLY);
 	if (mailbox_open(destbox) < 0) {
 		i_error("Can't open mailbox '%s': %s", ctx->destname,
diff -r 62519d9334a5 -r b52f4852e5f8 src/doveadm/doveadm-mail-import.c
--- a/src/doveadm/doveadm-mail-import.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/doveadm/doveadm-mail-import.c	Mon Oct 29 22:03:25 2012 +0200
@@ -30,21 +30,10 @@
 	if (*ctx->dest_parent != '\0') {
 		/* prefix destination mailbox name with given parent mailbox */
 		ns = mail_namespace_find(user->namespaces, ctx->dest_parent);
-		if (ns == NULL) {
-			i_error("Can't find namespace for parent mailbox %s",
-				ctx->dest_parent);
-			doveadm_mail_failed_error(&ctx->ctx, MAIL_ERROR_NOTFOUND);
-			return -1;
-		}
 		name = t_strdup_printf("%s%c%s", ctx->dest_parent,
 				       mail_namespace_get_sep(ns), name);
-	}
-
-	ns = mail_namespace_find(user->namespaces, name);
-	if (ns == NULL) {
-		i_error("Can't find namespace for mailbox %s", name);
-		doveadm_mail_failed_error(&ctx->ctx, MAIL_ERROR_NOTFOUND);
-		return -1;
+	} else {
+		ns = mail_namespace_find(user->namespaces, name);
 	}
 
 	box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_SAVEONLY);
diff -r 62519d9334a5 -r b52f4852e5f8 src/doveadm/doveadm-mail-mailbox.c
--- a/src/doveadm/doveadm-mail-mailbox.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/doveadm/doveadm-mail-mailbox.c	Mon Oct 29 22:03:25 2012 +0200
@@ -202,11 +202,6 @@
 		bool directory = FALSE;
 
 		ns = mail_namespace_find(user->namespaces, name);
-		if (ns == NULL) {
-			i_fatal_status(DOVEADM_EX_NOTFOUND,
-				       "Can't find namespace for: %s", name);
-		}
-
 		len = strlen(name);
 		if (len > 0 && name[len-1] == mail_namespace_get_sep(ns)) {
 			name = t_strndup(name, len-1);
@@ -276,9 +271,6 @@
 	const char *pattern, *child_name;
 
 	ns = mail_namespace_find(user->namespaces, name);
-	if (ns == NULL)
-		return 0;
-
 	pattern = t_strdup_printf("%s%c*", name, mail_namespace_get_sep(ns));
 	iter = mailbox_list_iter_init(ns->list, pattern,
 				      MAILBOX_LIST_ITER_RETURN_NO_FLAGS);
@@ -320,13 +312,6 @@
 		const char *name = *namep;
 
 		ns = mail_namespace_find(user->namespaces, name);
-		if (ns == NULL) {
-			i_error("Can't find namespace for: %s", name);
-			doveadm_mail_failed_error(_ctx, MAIL_ERROR_NOTFOUND);
-			ret = -1;
-			continue;
-		}
-
 		box = mailbox_alloc(ns->list, name, 0);
 		storage = mailbox_get_storage(box);
 		if (mailbox_delete(box) < 0) {
@@ -409,16 +394,7 @@
 	int ret = 0;
 
 	oldns = mail_namespace_find(user->namespaces, oldname);
-	if (oldns == NULL) {
-		i_fatal_status(DOVEADM_EX_NOTFOUND,
-			       "Can't find namespace for: %s", oldname);
-	}
 	newns = mail_namespace_find(user->namespaces, newname);
-	if (newns == NULL) {
-		i_fatal_status(DOVEADM_EX_NOTFOUND,
-			       "Can't find namespace for: %s", newname);
-	}
-
 	oldbox = mailbox_alloc(oldns->list, oldname, 0);
 	newbox = mailbox_alloc(newns->list, newname, 0);
 	if (mailbox_rename(oldbox, newbox) < 0) {
@@ -484,11 +460,6 @@
 		const char *name = *namep;
 
 		ns = mail_namespace_find(user->namespaces, name);
-		if (ns == NULL) {
-			i_fatal_status(DOVEADM_EX_NOTFOUND,
-				       "Can't find namespace for: %s", name);
-		}
-
 		box = mailbox_alloc(ns->list, name, 0);
 		if (mailbox_set_subscribed(box, ctx->ctx.subscriptions) < 0) {
 			i_error("Can't %s mailbox %s: %s", name,
diff -r 62519d9334a5 -r b52f4852e5f8 src/doveadm/doveadm-mail.c
--- a/src/doveadm/doveadm-mail.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/doveadm/doveadm-mail.c	Mon Oct 29 22:03:25 2012 +0200
@@ -143,11 +143,6 @@
 	}
 
 	ns = mail_namespace_find(user->namespaces, mailbox);
-	if (ns == NULL) {
-		i_fatal_status(DOVEADM_EX_NOTFOUND,
-			       "Can't find namespace for mailbox %s", mailbox);
-	}
-
 	return mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_IGNORE_ACLS);
 }
 
diff -r 62519d9334a5 -r b52f4852e5f8 src/doveadm/doveadm-mailbox-list-iter.c
--- a/src/doveadm/doveadm-mailbox-list-iter.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/doveadm/doveadm-mailbox-list-iter.c	Mon Oct 29 22:03:25 2012 +0200
@@ -173,10 +173,7 @@
 		iter->info.vname = patterns[iter->pattern_idx++];
 		iter->info.ns = mail_namespace_find(iter->user->namespaces,
 						    iter->info.vname);
-		if (iter->info.ns != NULL)
-			return &iter->info;
-		/* FIXME: maybe fail?.. or just wait for v2.2 to get rid of
-		   this error condition */
+		return &iter->info;
 	}
 
 	while ((info = mailbox_list_iter_next(iter->iter)) != NULL) {
diff -r 62519d9334a5 -r b52f4852e5f8 src/doveadm/dsync/doveadm-dsync.c
--- a/src/doveadm/dsync/doveadm-dsync.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/doveadm/dsync/doveadm-dsync.c	Mon Oct 29 22:03:25 2012 +0200
@@ -328,10 +328,6 @@
 	if (ctx->namespace_prefix != NULL) {
 		sync_ns = mail_namespace_find(user->namespaces,
 					      ctx->namespace_prefix);
-		if (sync_ns == NULL) {
-			i_fatal("Namespace prefix=%s doesn't exist",
-				ctx->namespace_prefix);
-		}
 	}
 
 	if (!ctx->remote)
diff -r 62519d9334a5 -r b52f4852e5f8 src/doveadm/dsync/dsync-brain.c
--- a/src/doveadm/dsync/dsync-brain.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/doveadm/dsync/dsync-brain.c	Mon Oct 29 22:03:25 2012 +0200
@@ -165,12 +165,6 @@
 	if (ibc_set->sync_ns_prefix != NULL) {
 		brain->sync_ns = mail_namespace_find(brain->user->namespaces,
 						     ibc_set->sync_ns_prefix);
-		if (brain->sync_ns == NULL) {
-			i_error("Requested sync namespace prefix=%s doesn't exist",
-				ibc_set->sync_ns_prefix);
-			brain->failed = TRUE;
-			return TRUE;
-		}
 	}
 	i_assert(brain->sync_type == DSYNC_BRAIN_SYNC_TYPE_UNKNOWN);
 	brain->sync_type = ibc_set->sync_type;
diff -r 62519d9334a5 -r b52f4852e5f8 src/imap/cmd-list.c
--- a/src/imap/cmd-list.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/imap/cmd-list.c	Mon Oct 29 22:03:25 2012 +0200
@@ -284,8 +284,6 @@
 		return patterns;
 
 	ns = mail_namespace_find(ctx->user->namespaces, ref);
-	if (ns == NULL)
-		return patterns;
 
 	t_array_init(&full_patterns, 16);
 	for (pat = patterns; *pat != NULL; pat++) {
diff -r 62519d9334a5 -r b52f4852e5f8 src/imap/imap-commands-util.c
--- a/src/imap/imap-commands-util.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/imap/imap-commands-util.c	Mon Oct 29 22:03:25 2012 +0200
@@ -28,7 +28,10 @@
 	}
 
 	ns = mail_namespace_find(namespaces, str_c(utf8_name));
-	if (ns == NULL) {
+	if ((ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0 &&
+	    ns->prefix_len == 0) {
+		/* this matched only the autocreated prefix="" namespace.
+		   give a nice human-readable error message */
 		client_send_tagline(cmd, t_strdup_printf(
 			"NO Client tried to access nonexistent namespace. "
 			"(Mailbox name should probably be prefixed with: %s)",
diff -r 62519d9334a5 -r b52f4852e5f8 src/indexer/master-connection.c
--- a/src/indexer/master-connection.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/indexer/master-connection.c	Mon Oct 29 22:03:25 2012 +0200
@@ -125,11 +125,6 @@
 	int ret;
 
 	ns = mail_namespace_find(user->namespaces, mailbox);
-	if (ns == NULL) {
-		i_error("Namespace not found for mailbox %s: ", mailbox);
-		return -1;
-	}
-
 	box = mailbox_alloc(ns->list, mailbox, 0);
 	ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path);
 	if (ret <= 0) {
diff -r 62519d9334a5 -r b52f4852e5f8 src/lib-imap-storage/imap-msgpart-url.c
--- a/src/lib-imap-storage/imap-msgpart-url.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/lib-imap-storage/imap-msgpart-url.c	Mon Oct 29 22:03:25 2012 +0200
@@ -124,11 +124,6 @@
 
 	/* find mailbox namespace */
 	ns = mail_namespace_find(mpurl->user->namespaces, mpurl->mailbox);
-	if (ns == NULL) {
-		*error_r = "Nonexistent mailbox namespace";
-		*error_code_r = MAIL_ERROR_NOTFOUND;
-		return 0;
-	}
 
 	/* open mailbox */
 	if (mpurl->selected_box != NULL &&
diff -r 62519d9334a5 -r b52f4852e5f8 src/lib-lda/mail-deliver.c
--- a/src/lib-lda/mail-deliver.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/lib-lda/mail-deliver.c	Mon Oct 29 22:03:25 2012 +0200
@@ -164,12 +164,6 @@
 	}
 
 	ns = mail_namespace_find(ctx->user->namespaces, name);
-	if (ns == NULL) {
-		*error_str_r = "Unknown namespace";
-		*error_r = MAIL_ERROR_PARAMS;
-		return -1;
-	}
-
 	if (strcmp(name, ns->prefix) == 0 &&
 	    (ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0) {
 		/* delivering to a namespace prefix means we actually want to
diff -r 62519d9334a5 -r b52f4852e5f8 src/lib-storage/fail-mail-storage.c
--- a/src/lib-storage/fail-mail-storage.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/lib-storage/fail-mail-storage.c	Mon Oct 29 22:03:25 2012 +0200
@@ -19,6 +19,10 @@
 	return storage;
 }
 
+static void fail_storage_destroy(struct mail_storage *storage ATTR_UNUSED)
+{
+}
+
 static void
 fail_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
 			      struct mailbox_list_settings *set)
@@ -31,13 +35,13 @@
 
 struct mail_storage fail_storage = {
 	.name = "fail",
-	.class_flags = 0,
+	.class_flags = MAIL_STORAGE_CLASS_FLAG_NO_ROOT,
 
 	.v = {
 		NULL,
 		fail_storage_alloc,
 		NULL,
-		NULL,
+		fail_storage_destroy,
 		NULL,
 		fail_storage_get_list_settings,
 		NULL,
diff -r 62519d9334a5 -r b52f4852e5f8 src/lib-storage/mail-namespace.c
--- a/src/lib-storage/mail-namespace.c	Mon Oct 29 21:54:51 2012 +0200
+++ b/src/lib-storage/mail-namespace.c	Mon Oct 29 22:03:25 2012 +0200
@@ -12,6 +12,25 @@
 
 #include <stdlib.h>
 
+static struct mail_namespace_settings prefixless_ns_unexpanded_set = {
+	.name = "",
+	.type = "private",
+	.separator = "",
+	.prefix = "0",
+	.location = "0fail::LAYOUT=none",
+	.alias_for = NULL,
+


More information about the dovecot-cvs mailing list