dovecot-2.2: lib-storage: Crashfixes for handling shared mailbox...

dovecot at dovecot.org dovecot at dovecot.org
Thu Apr 4 22:52:51 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/9891526c2def
changeset: 16174:9891526c2def
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Apr 04 22:49:38 2013 +0300
description:
lib-storage: Crashfixes for handling shared mailboxes for nonexistent users.

diffstat:

 src/lib-storage/index/shared/shared-storage.c |   4 +-
 src/lib-storage/mail-user.c                   |  30 +++++++++++++-------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diffs (96 lines):

diff -r 0f88312ef951 -r 9891526c2def src/lib-storage/index/shared/shared-storage.c
--- a/src/lib-storage/index/shared/shared-storage.c	Thu Apr 04 22:09:02 2013 +0300
+++ b/src/lib-storage/index/shared/shared-storage.c	Thu Apr 04 22:49:38 2013 +0300
@@ -320,8 +320,8 @@
 
 	/* We need to create a prefix="" namespace for the owner */
 	if (mail_namespaces_init_location(owner, str_c(location), &error) < 0) {
+		/* owner gets freed by namespace deinit */
 		mail_namespace_destroy(new_ns);
-		mail_user_unref(&owner);
 		return -1;
 	}
 
@@ -329,8 +329,8 @@
 				MAIL_STORAGE_FLAG_NO_AUTOVERIFY, &error) < 0) {
 		mailbox_list_set_critical(list, "Namespace '%s': %s",
 					  new_ns->prefix, error);
+		/* owner gets freed by namespace deinit */
 		mail_namespace_destroy(new_ns);
-		mail_user_unref(&owner);
 		return -1;
 	}
 	if ((new_ns->flags & NAMESPACE_FLAG_UNUSABLE) == 0 &&
diff -r 0f88312ef951 -r 9891526c2def src/lib-storage/mail-user.c
--- a/src/lib-storage/mail-user.c	Thu Apr 04 22:09:02 2013 +0300
+++ b/src/lib-storage/mail-user.c	Thu Apr 04 22:49:38 2013 +0300
@@ -70,15 +70,15 @@
 	return user;
 }
 
-static int
-mail_user_expand_plugins_envs(struct mail_user *user, const char **error_r)
+static void
+mail_user_expand_plugins_envs(struct mail_user *user)
 {
 	const char **envs, *home;
 	string_t *str;
 	unsigned int i, count;
 
 	if (!array_is_created(&user->set->plugin_envs))
-		return 0;
+		return;
 
 	str = t_str_new(256);
 	envs = array_get_modifiable(&user->set->plugin_envs, &count);
@@ -87,17 +87,16 @@
 		if (user->_home == NULL &&
 		    var_has_key(envs[i+1], 'h', "home") &&
 		    mail_user_get_home(user, &home) <= 0) {
-			*error_r = t_strdup_printf(
+			user->error = p_strdup_printf(user->pool,
 				"userdb didn't return a home directory, "
 				"but plugin setting %s used it (%%h): %s",
 				envs[i], envs[i+1]);
-			return -1;
+			return;
 		}
 		str_truncate(str, 0);
 		var_expand(str, envs[i+1], mail_user_var_expand_table(user));
 		envs[i+1] = p_strdup(user->pool, str_c(str));
 	}
-	return 0;
 }
 
 int mail_user_init(struct mail_user *user, const char **error_r)
@@ -115,20 +114,21 @@
 			    user->pool, mail_user_var_expand_table(user));
 
 	if (need_home_dir && mail_user_get_home(user, &home) <= 0) {
-		*error_r = t_strdup_printf(
+		user->error = p_strdup_printf(user->pool,
 			"userdb didn't return a home directory, "
 			"but %s used it (%%h): %s", key, value);
-		return -1;
 	}
+	mail_user_expand_plugins_envs(user);
 
-	if (mail_user_expand_plugins_envs(user, error_r) < 0)
-		return -1;
+	/* autocreated users for shared mailboxes need to be fully initialized
+	   if they don't exist, since they're going to be used anyway */
+	if (user->error == NULL || user->nonexistent) {
+		mail_set = mail_user_set_get_storage_set(user);
+		user->mail_debug = mail_set->mail_debug;
 
-	mail_set = mail_user_set_get_storage_set(user);
-	user->mail_debug = mail_set->mail_debug;
-
-	user->initialized = TRUE;
-	hook_mail_user_created(user);
+		user->initialized = TRUE;
+		hook_mail_user_created(user);
+	}
 
 	if (user->error != NULL) {
 		*error_r = t_strdup(user->error);


More information about the dovecot-cvs mailing list