From 7b64db32b95286235612eebb5d37d296a49306f7 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 4 Apr 2013 22:49:38 +0300 Subject: [PATCH] lib-storage: Crashfixes for handling shared mailboxes for nonexistent users. --- src/lib-storage/index/shared/shared-storage.c | 4 +-- src/lib-storage/mail-user.c | 30 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/lib-storage/index/shared/shared-storage.c b/src/lib-storage/index/shared/shared-storage.c index 3eca56c4f6..e17d912eb9 100644 --- a/src/lib-storage/index/shared/shared-storage.c +++ b/src/lib-storage/index/shared/shared-storage.c @@ -320,8 +320,8 @@ int shared_storage_get_namespace(struct mail_namespace **_ns, /* 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 @@ int shared_storage_get_namespace(struct mail_namespace **_ns, 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 --git a/src/lib-storage/mail-user.c b/src/lib-storage/mail-user.c index e84a191fbd..b0ac752f92 100644 --- a/src/lib-storage/mail-user.c +++ b/src/lib-storage/mail-user.c @@ -70,15 +70,15 @@ struct mail_user *mail_user_alloc(const char *username, 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 @@ mail_user_expand_plugins_envs(struct mail_user *user, const char **error_r) 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 @@ int mail_user_init(struct mail_user *user, const char **error_r) 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; - - mail_set = mail_user_set_get_storage_set(user); - user->mail_debug = mail_set->mail_debug; + /* 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; - 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); -- 2.47.3