]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Remove user namespaces on hook error
authorAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 11 Jul 2017 07:45:16 +0000 (10:45 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 12 Jul 2017 22:00:47 +0000 (01:00 +0300)
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.

src/lib-storage/mail-namespace.c

index c1a8f68eef02de032c78b9f8143a55b589ac75a1..26bc961c4239f429c1d8326dbc7a47a587749b15 100644 (file)
@@ -370,26 +370,30 @@ int mail_namespaces_init_finish(struct mail_namespace *namespaces,
        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);
-               while (namespaces != NULL) {
-                       ns = namespaces;
-                       namespaces = ns->next;
-                       mail_namespace_free(ns);
-               }
-               return -1;
+               namespaces->user->error =
+                       t_strconcat("namespace configuration error: ",
+                                   *error_r, NULL);
        }
-       mail_user_add_namespace(namespaces->user, &namespaces);
 
-       T_BEGIN {
-               hook_mail_namespaces_created(namespaces);
-       } T_END;
+       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;
+                       mail_namespace_free(ns);
+               }
                return -1;
        }
+
        namespaces->user->namespaces_created = TRUE;
        return 0;
 }