/* 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;
}
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 &&
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);
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)
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);