Skip to content

Commit

Permalink
lib-storage: Remove user namespaces on hook error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmouse authored and sirainen committed Jul 12, 2017
1 parent 6009336 commit 93cb580
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/lib-storage/mail-namespace.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 93cb580

Please sign in to comment.