changeset 22332:2c3691145654

lib-storage: Remove user namespaces on hook error If there is a hook error during namespaces added remove the namespaces from user. This avoids attempts to use the namespaces later on without proper initialization.
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Tue, 11 Jul 2017 10:45:16 +0300
parents 0ec61a44ed7b
children 6af385105911
files src/lib-storage/mail-namespace.c
diffstat 1 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-namespace.c	Tue Jul 11 10:26:38 2017 +0300
+++ b/src/lib-storage/mail-namespace.c	Tue Jul 11 10:45:16 2017 +0300
@@ -370,8 +370,22 @@
 	if (namespaces->user->autocreated) {
 		/* e.g. raw user - don't check namespaces' validity */
 	} else if (!namespaces_check(namespaces, error_r)) {
-		*error_r = t_strconcat("namespace configuration error: ",
-				       *error_r, NULL);
+		namespaces->user->error =
+			t_strconcat("namespace configuration error: ",
+				    *error_r, NULL);
+	}
+
+	if (namespaces->user->error == NULL) {
+		mail_user_add_namespace(namespaces->user, &namespaces);
+		T_BEGIN {
+			hook_mail_namespaces_created(namespaces);
+		} T_END;
+	}
+
+	/* allow namespace hooks to return failure via the user error */
+	if (namespaces->user->error != NULL) {
+		namespaces->user->namespaces = NULL;
+		*error_r = t_strdup(namespaces->user->error);
 		while (namespaces != NULL) {
 			ns = namespaces;
 			namespaces = ns->next;
@@ -379,17 +393,7 @@
 		}
 		return -1;
 	}
-	mail_user_add_namespace(namespaces->user, &namespaces);
 
-	T_BEGIN {
-		hook_mail_namespaces_created(namespaces);
-	} T_END;
-
-	/* allow namespace hooks to return failure via the user error */
-	if (namespaces->user->error != NULL) {
-		*error_r = t_strdup(namespaces->user->error);
-		return -1;
-	}
 	namespaces->user->namespaces_created = TRUE;
 	return 0;
 }