]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Crashfixes for handling shared mailboxes for nonexistent users.
authorTimo Sirainen <tss@iki.fi>
Thu, 4 Apr 2013 19:49:38 +0000 (22:49 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 4 Apr 2013 19:49:38 +0000 (22:49 +0300)
src/lib-storage/index/shared/shared-storage.c
src/lib-storage/mail-user.c

index 3eca56c4f6602893ce083b99578f020759240cac..e17d912eb91bf440830c4e0876e914b7e42f90bc 100644 (file)
@@ -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 &&
index e84a191fbdb7c82f2977eead34756fe38c2356ab..b0ac752f92812f71fc0bec7527156b2882d696b8 100644 (file)
@@ -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);