# HG changeset patch # User Timo Sirainen # Date 1227285122 -7200 # Node ID 03c418eadc8b810af562ec448a31f35eb29bc089 # Parent 4553e28eb4f5b8d025812fe1b995f871ff27ad5e mail_user_*() now handles home directory lookups when necessary. Namespace owner is now a pointer to struct mail_user rather than a string. diff -r 4553e28eb4f5 -r 03c418eadc8b src/deliver/deliver.c --- a/src/deliver/deliver.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/deliver/deliver.c Fri Nov 21 18:32:02 2008 +0200 @@ -1058,18 +1058,21 @@ dict_drivers_register_builtin(); duplicate_init(); + mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL); mail_storage_init(); mail_storage_register_all(); mailbox_list_register_all(); module_dir_init(modules); - mail_user = mail_user_init(user, home); + mail_user = mail_user_init(user); + mail_user_set_home(mail_user, home); if (mail_namespaces_init(mail_user) < 0) i_fatal("Namespace initialization failed"); /* create a separate mail user for the internal namespace */ - raw_mail_user = mail_user_init(user, NULL); + raw_mail_user = mail_user_init(user); + mail_user_set_home(raw_mail_user, NULL); raw_ns = mail_namespaces_init_empty(raw_mail_user); raw_ns->flags |= NAMESPACE_FLAG_INTERNAL; @@ -1177,11 +1180,12 @@ mailbox_transaction_rollback(&t); mailbox_close(&box); - mail_user_deinit(&mail_user); - mail_user_deinit(&raw_mail_user); + mail_user_unref(&mail_user); + mail_user_unref(&raw_mail_user); module_dir_unload(&modules); mail_storage_deinit(); + mail_users_deinit(); duplicate_deinit(); dict_drivers_unregister_builtin(); diff -r 4553e28eb4f5 -r 03c418eadc8b src/imap/client.c --- a/src/imap/client.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/imap/client.c Fri Nov 21 18:32:02 2008 +0200 @@ -162,7 +162,7 @@ client_search_updates_free(client); mailbox_close(&client->mailbox); } - mail_user_deinit(&client->user); + mail_user_unref(&client->user); if (client->free_parser != NULL) imap_parser_destroy(&client->free_parser); diff -r 4553e28eb4f5 -r 03c418eadc8b src/imap/main.c --- a/src/imap/main.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/imap/main.c Fri Nov 21 18:32:02 2008 +0200 @@ -194,6 +194,7 @@ str_append(capability_string, CAPABILITY_STRING); dict_drivers_register_builtin(); + mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL); mail_storage_init(); mail_storage_register_all(); mailbox_list_register_all(); @@ -228,7 +229,8 @@ parse_workarounds(); - user = mail_user_init(username, home); + user = mail_user_init(username); + mail_user_set_home(user, home); if (mail_namespaces_init(user) < 0) i_fatal("Namespace initialization failed"); client = client_create(0, 1, user); @@ -271,7 +273,8 @@ module_dir_unload(&modules); commands_deinit(); - mail_storage_deinit(); + mail_storage_deinit(); + mail_users_deinit(); dict_drivers_unregister_builtin(); str_free(&capability_string); diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/Makefile.am --- a/src/lib-storage/Makefile.am Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/Makefile.am Fri Nov 21 18:32:02 2008 +0200 @@ -4,9 +4,11 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-auth \ -I$(top_srcdir)/src/lib-mail \ -I$(top_srcdir)/src/lib-imap \ - -I$(top_srcdir)/src/lib-index + -I$(top_srcdir)/src/lib-index \ + -DPKG_RUNDIR=\""$(rundir)"\" libstorage_a_SOURCES = \ mail.c \ diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/index/maildir/maildir-storage.c --- a/src/lib-storage/index/maildir/maildir-storage.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.c Fri Nov 21 18:32:02 2008 +0200 @@ -66,7 +66,7 @@ enum mail_storage_flags flags = storage->flags; struct mail_user *user = storage->ns->user; bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0; - const char *path; + const char *path, *home; *layout_r = MAILDIR_PLUSPLUS_DRIVER_NAME; @@ -82,8 +82,8 @@ /* we'll need to figure out the maildir location ourself. It's ~/Maildir unless we are chrooted. */ - if (user->home != NULL) { - path = t_strconcat(user->home, "/Maildir", NULL); + if (mail_user_get_home(user, &home) > 0) { + path = t_strconcat(home, "/Maildir", NULL); if (access(path, R_OK|W_OK|X_OK) == 0) { if (debug) { i_info("maildir: root exists (%s)", diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/index/mbox/mbox-storage.c --- a/src/lib-storage/index/mbox/mbox-storage.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/index/mbox/mbox-storage.c Fri Nov 21 18:32:02 2008 +0200 @@ -190,8 +190,7 @@ const char *home, *path; bool debug = (storage->flags & MAIL_STORAGE_FLAG_DEBUG) != 0; - home = storage->ns->user->home; - if (home != NULL) { + if (mail_user_get_home(storage->ns->user, &home) > 0) { path = t_strconcat(home, "/mail", NULL); if (access(path, R_OK|W_OK|X_OK) == 0) { if (debug) @@ -259,8 +258,7 @@ { const char *home, *path; - home = storage->ns->user->home; - if (home == NULL) { + if (mail_user_get_home(storage->ns->user, &home) <= 0) { *error_r = "Root mail directory not set and " "home directory is missing"; return NULL; diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/index/shared/Makefile.am --- a/src/lib-storage/index/shared/Makefile.am Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/index/shared/Makefile.am Fri Nov 21 18:32:02 2008 +0200 @@ -2,7 +2,6 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ - -I$(top_srcdir)/src/lib-auth \ -I$(top_srcdir)/src/lib-mail \ -I$(top_srcdir)/src/lib-imap \ -I$(top_srcdir)/src/lib-index \ diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/index/shared/shared-storage.c --- a/src/lib-storage/index/shared/shared-storage.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/index/shared/shared-storage.c Fri Nov 21 18:32:02 2008 +0200 @@ -4,7 +4,6 @@ #include "array.h" #include "str.h" #include "ioloop.h" -#include "auth-master.h" #include "var-expand.h" #include "index-storage.h" #include "shared-storage.h" @@ -105,53 +104,9 @@ return 0; } -static void shared_storage_destroy(struct mail_storage *_storage) -{ - struct shared_storage *storage = (struct shared_storage *)_storage; - - if (storage->auth_master_conn != NULL) - auth_master_deinit(&storage->auth_master_conn); - index_storage_destroy(_storage); -} - -static void shared_storage_auth_master_init(struct shared_storage *storage) -{ - const char *auth_socket_path; - bool debug; - - auth_socket_path = getenv("AUTH_SOCKET_PATH"); - if (auth_socket_path == NULL) { - auth_socket_path = t_strconcat(storage->base_dir, - "/auth-master", NULL); - } - - debug = (storage->storage.flags & MAIL_STORAGE_FLAG_DEBUG) != 0; - storage->auth_master_conn = auth_master_init(auth_socket_path, debug); -} - -static int -shared_storage_lookup_home(struct shared_storage *storage, - const char *user, const char **home_r) -{ - struct auth_user_reply reply; - pool_t userdb_pool; - int ret; - - if (storage->auth_master_conn == NULL) - shared_storage_auth_master_init(storage); - - userdb_pool = pool_alloconly_create("userdb lookup", 512); - ret = auth_master_user_lookup(storage->auth_master_conn, user, - AUTH_SERVICE_INTERNAL, - userdb_pool, &reply); - if (ret > 0) - *home_r = t_strdup(reply.home); - pool_unref(&userdb_pool); - return ret; -} - -static void get_nonexisting_user_location(struct shared_storage *storage, - string_t *location) +static void +get_nonexisting_user_location(struct shared_storage *storage, + const char *username, string_t *location) { /* user wasn't found. we'll still need to create the storage to avoid exposing which users exist and which don't. */ @@ -160,7 +115,8 @@ /* use a reachable but non-existing path as the mail root directory */ str_append(location, storage->base_dir); - str_append(location, PKG_RUNDIR"/user-not-found"); + str_append(location, "/user-not-found/"); + str_append(location, username); } int shared_storage_get_namespace(struct mail_storage *_storage, @@ -178,6 +134,7 @@ }; struct var_expand_table *tab; struct mail_namespace *ns; + struct mail_user *owner; const char *domain = NULL, *username = NULL, *userdomain = NULL; const char *name, *p, *next, **dest, *error; string_t *prefix, *location; @@ -250,16 +207,16 @@ return 0; } + owner = mail_user_init(userdomain); if (!var_has_key(storage->location, 'h')) ret = 1; else { /* we'll need to look up the user's home directory */ - ret = shared_storage_lookup_home(storage, userdomain, - &tab[3].value); - if (ret < 0) { + if ((ret = mail_user_get_home(owner, &tab[3].value)) < 0) { mail_storage_set_critical(_storage, "Namespace '%s': " "Could not lookup home for user %s", _storage->ns->prefix, userdomain); + mail_user_unref(&owner); return -1; } } @@ -269,7 +226,7 @@ ns->type = NAMESPACE_SHARED; ns->user = user; ns->prefix = i_strdup(str_c(prefix)); - ns->owner = i_strdup(userdomain); + ns->owner = owner; ns->flags = NAMESPACE_FLAG_LIST_PREFIX | NAMESPACE_FLAG_HIDDEN | NAMESPACE_FLAG_AUTOCREATED; ns->sep = _storage->ns->sep; @@ -278,11 +235,12 @@ if (ret > 0) var_expand(location, storage->location, tab); else - get_nonexisting_user_location(storage, location); + get_nonexisting_user_location(storage, userdomain, location); if (mail_storage_create(ns, NULL, str_c(location), _storage->flags, _storage->lock_method, &error) < 0) { mail_storage_set_critical(_storage, "Namespace '%s': %s", ns->prefix, error); + mail_namespace_destroy(ns); return -1; } mail_user_add_namespace(user, ns); @@ -354,7 +312,7 @@ NULL, shared_alloc, shared_create, - shared_storage_destroy, + index_storage_destroy, NULL, shared_mailbox_open, shared_mailbox_create diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/index/shared/shared-storage.h --- a/src/lib-storage/index/shared/shared-storage.h Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/index/shared/shared-storage.h Fri Nov 21 18:32:02 2008 +0200 @@ -12,7 +12,6 @@ const char *base_dir; const char *ns_prefix_pattern; const char *location; - struct auth_master_connection *auth_master_conn; struct mail_storage *storage_class; }; diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/mail-namespace.c --- a/src/lib-storage/mail-namespace.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/mail-namespace.c Fri Nov 21 18:32:02 2008 +0200 @@ -29,7 +29,8 @@ static void mail_namespace_free(struct mail_namespace *ns) { - i_free(ns->owner); + if (ns->owner != NULL) + mail_user_unref(&ns->owner); i_free(ns->prefix); i_free(ns); } @@ -63,7 +64,8 @@ if (type == NULL || *type == '\0' || strncmp(type, "private", 7) == 0) { ns->type = NAMESPACE_PRIVATE; - ns->owner = i_strdup(user->username); + ns->owner = user; + mail_user_ref(ns->owner); } else if (strncmp(type, "shared", 6) == 0) ns->type = NAMESPACE_SHARED; else if (strncmp(type, "public", 6) == 0) @@ -244,12 +246,13 @@ } ns = i_new(struct mail_namespace, 1); - ns->owner = i_strdup(user->username); ns->type = NAMESPACE_PRIVATE; ns->flags = NAMESPACE_FLAG_INBOX | NAMESPACE_FLAG_LIST_PREFIX | NAMESPACE_FLAG_SUBSCRIPTIONS; ns->prefix = i_strdup(""); ns->user = user; + ns->owner = user; + mail_user_ref(ns->owner); if (mail_storage_create(ns, NULL, mail, flags, lock_method, &error) < 0) { @@ -279,8 +282,9 @@ ns = i_new(struct mail_namespace, 1); ns->user = user; + ns->owner = user; + mail_user_ref(ns->owner); ns->prefix = i_strdup(""); - ns->owner = i_strdup(user->username); ns->flags = NAMESPACE_FLAG_INBOX | NAMESPACE_FLAG_LIST_PREFIX | NAMESPACE_FLAG_SUBSCRIPTIONS; user->namespaces = ns; diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/mail-namespace.h --- a/src/lib-storage/mail-namespace.h Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/mail-namespace.h Fri Nov 21 18:32:02 2008 +0200 @@ -38,10 +38,10 @@ char sep, real_sep, sep_str[3]; enum namespace_flags flags; - char *prefix, *owner; + char *prefix; size_t prefix_len; - struct mail_user *user; + struct mail_user *user, *owner; struct mailbox_list *list; /* FIXME: we should support multiple storages in one namespace */ struct mail_storage *storage; diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/mail-storage.c --- a/src/lib-storage/mail-storage.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/mail-storage.c Fri Nov 21 18:32:02 2008 +0200 @@ -228,7 +228,7 @@ return -1; } - home = ns->user->home; + (void)mail_user_get_home(ns->user, &home); if (home == NULL || *home == '\0') home = "(not set)"; *error_r = t_strdup_printf( diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/mail-user.c --- a/src/lib-storage/mail-user.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/mail-user.c Fri Nov 21 18:32:02 2008 +0200 @@ -2,19 +2,24 @@ #include "lib.h" #include "array.h" +#include "auth-master.h" #include "mail-namespace.h" #include "mail-user.h" +#include + struct mail_user_module_register mail_user_module_register = { 0 }; void (*hook_mail_user_created)(struct mail_user *user) = NULL; +static struct auth_master_connection *auth_master_conn; + static void mail_user_deinit_base(struct mail_user *user) { mail_namespaces_deinit(&user->namespaces); pool_unref(&user->pool); } -struct mail_user *mail_user_init(const char *username, const char *home) +struct mail_user *mail_user_init(const char *username) { struct mail_user *user; pool_t pool; @@ -24,8 +29,8 @@ pool = pool_alloconly_create("mail user", 512); user = p_new(pool, struct mail_user, 1); user->pool = pool; + user->refcount = 1; user->username = p_strdup_empty(pool, username); - user->home = p_strdup(pool, home); user->v.deinit = mail_user_deinit_base; p_array_init(&user->module_contexts, user->pool, 5); @@ -34,12 +39,28 @@ return user; } -void mail_user_deinit(struct mail_user **_user) +void mail_user_ref(struct mail_user *user) +{ + i_assert(user->refcount > 0); + + user->refcount++; +} + +void mail_user_unref(struct mail_user **_user) { struct mail_user *user = *_user; + i_assert(user->refcount > 0); + *_user = NULL; - user->v.deinit(user); + if (--user->refcount == 0) + user->v.deinit(user); +} + +void mail_user_set_home(struct mail_user *user, const char *home) +{ + user->_home = p_strdup(user->pool, home); + user->home_looked_up = TRUE; } void mail_user_add_namespace(struct mail_user *user, struct mail_namespace *ns) @@ -78,15 +99,61 @@ return path; } +int mail_user_get_home(struct mail_user *user, const char **home_r) +{ + struct auth_user_reply reply; + pool_t userdb_pool; + int ret; + + userdb_pool = pool_alloconly_create("userdb lookup", 512); + ret = auth_master_user_lookup(auth_master_conn, user->username, + AUTH_SERVICE_INTERNAL, + userdb_pool, &reply); + if (ret < 0) + *home_r = NULL; + else { + user->_home = ret == 0 ? NULL : + p_strdup(user->pool, reply.home); + user->home_looked_up = TRUE; + ret = user->_home != NULL ? 1 : 0; + *home_r = user->_home; + } + pool_unref(&userdb_pool); + return ret; +} + int mail_user_try_home_expand(struct mail_user *user, const char **pathp) { - const char *path = *pathp; + const char *home, *path = *pathp; + + if (!user->home_looked_up) { + if (mail_user_get_home(user, &home) < 0) + return -1; + } if (path[0] == '~' && (path[1] == '/' || path[1] == '\0')) { - if (user->home == NULL) + if (user->_home == NULL) return -1; - *pathp = t_strconcat(user->home, path + 1, NULL); + *pathp = t_strconcat(user->_home, path + 1, NULL); } return 0; } + +void mail_users_init(const char *auth_socket_path, bool debug) +{ + const char *base_dir; + + if (auth_socket_path == NULL) { + base_dir = getenv("BASE_DIR"); + if (base_dir == NULL) + base_dir = PKG_RUNDIR; + auth_socket_path = t_strconcat(base_dir, "/auth-master", NULL); + } + auth_master_conn = auth_master_init(auth_socket_path, debug); +} + +void mail_users_deinit(void) +{ + auth_master_deinit(&auth_master_conn); +} diff -r 4553e28eb4f5 -r 03c418eadc8b src/lib-storage/mail-user.h --- a/src/lib-storage/mail-user.h Fri Nov 21 17:41:59 2008 +0200 +++ b/src/lib-storage/mail-user.h Fri Nov 21 18:32:02 2008 +0200 @@ -10,14 +10,19 @@ struct mail_user { pool_t pool; struct mail_user_vfuncs v; + int refcount; const char *username; - const char *home; + /* don't access the home directly. It may be set lazily. */ + const char *_home; struct mail_namespace *namespaces; /* Module-specific contexts. See mail_storage_module_id. */ ARRAY_DEFINE(module_contexts, union mail_user_module_context *); + + /* Either home is set or there is no home for the user. */ + unsigned int home_looked_up:1; }; struct mail_user_module_register { @@ -33,8 +38,21 @@ /* Called after user has been created */ extern void (*hook_mail_user_created)(struct mail_user *user); -struct mail_user *mail_user_init(const char *username, const char *home); -void mail_user_deinit(struct mail_user **user); +void mail_users_init(const char *auth_socket_path, bool debug); +void mail_users_deinit(void); + +struct mail_user *mail_user_init(const char *username); +void mail_user_ref(struct mail_user *user); +void mail_user_unref(struct mail_user **user); + +/* Specify the user's home directory. This should be called also when it's + known that the user doesn't have a home directory to avoid the internal + lookup. */ +void mail_user_set_home(struct mail_user *user, const char *home); +/* Get the home directory for the user. Returns 1 if home directory looked up + successfully, 0 if there is no home directory (either user doesn't exist or + has no home directory) or -1 if lookup failed. */ +int mail_user_get_home(struct mail_user *user, const char **home_r); /* Add a new namespace to user's namespaces. */ void mail_user_add_namespace(struct mail_user *user, struct mail_namespace *ns); diff -r 4553e28eb4f5 -r 03c418eadc8b src/plugins/acl/acl-lookup-dict.c --- a/src/plugins/acl/acl-lookup-dict.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/plugins/acl/acl-lookup-dict.c Fri Nov 21 18:32:02 2008 +0200 @@ -127,7 +127,7 @@ str_truncate(id, 0); acl_lookup_dict_write_rights_id(id, &rights); str_append_c(id, '/'); - str_append(id, ns->owner); + str_append(id, ns->owner->username); id_dup = t_strdup(str_c(id)); array_append(ids, &id_dup, 1); } diff -r 4553e28eb4f5 -r 03c418eadc8b src/plugins/convert/convert-plugin.c --- a/src/plugins/convert/convert-plugin.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/plugins/convert/convert-plugin.c Fri Nov 21 18:32:02 2008 +0200 @@ -19,7 +19,7 @@ struct convert_settings set; memset(&set, 0, sizeof(set)); - if (namespaces->user->home == NULL) + if (mail_user_get_home(namespaces->user, &str) <= 0) i_fatal("convert plugin: HOME unset"); set.skip_broken_mailboxes = diff -r 4553e28eb4f5 -r 03c418eadc8b src/plugins/convert/convert-storage.c --- a/src/plugins/convert/convert-storage.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/plugins/convert/convert-storage.c Fri Nov 21 18:32:02 2008 +0200 @@ -397,7 +397,7 @@ struct dotlock *dotlock; enum mail_storage_flags src_flags; enum file_lock_method lock_method; - const char *path, *error; + const char *home, *path, *error; int ret; source_ns = mail_namespaces_init_empty(user); @@ -412,7 +412,9 @@ return 0; } - path = t_strconcat(user->home, "/"CONVERT_LOCK_FILENAME, NULL); + if (mail_user_get_home(user, &home) <= 0) + i_unreached(); + path = t_strconcat(home, "/"CONVERT_LOCK_FILENAME, NULL); dotlock_settings.use_excl_lock = (source_ns->storage->flags & MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0; diff -r 4553e28eb4f5 -r 03c418eadc8b src/plugins/convert/convert-tool.c --- a/src/plugins/convert/convert-tool.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/plugins/convert/convert-tool.c Fri Nov 21 18:32:02 2008 +0200 @@ -28,6 +28,7 @@ lib_init(); lib_signals_init(); random_init(); + mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL); mail_storage_init(); mail_storage_register_all(); mailbox_list_register_all(); @@ -48,7 +49,8 @@ } mail_storage_parse_env(&dest_flags, &lock_method); - user = mail_user_init(argv[1], argv[2]); + user = mail_user_init(argv[1]); + mail_user_set_home(user, argv[2]); dest_ns = mail_namespaces_init_empty(user); if (mail_storage_create(dest_ns, NULL, argv[4], @@ -64,10 +66,11 @@ i_error("Source storage not found"); else i_error("Internal failure"); - mail_user_deinit(&user); + mail_user_unref(&user); io_loop_destroy(&ioloop); mail_storage_deinit(); + mail_users_deinit(); lib_signals_deinit(); lib_deinit(); return ret <= 0 ? 1 : 0; diff -r 4553e28eb4f5 -r 03c418eadc8b src/plugins/expire/expire-tool.c --- a/src/plugins/expire/expire-tool.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/plugins/expire/expire-tool.c Fri Nov 21 18:32:02 2008 +0200 @@ -44,7 +44,8 @@ return 0; } - ctx->mail_user = mail_user_init(user, getenv("HOME")); + ctx->mail_user = mail_user_init(user); + mail_user_set_home(ctx->mail_user, getenv("HOME")); if (mail_namespaces_init(ctx->mail_user) < 0) return -1; return 1; @@ -52,7 +53,7 @@ static void user_deinit(struct expire_context *ctx) { - mail_user_deinit(&ctx->mail_user); + mail_user_unref(&ctx->mail_user); i_free_and_null(ctx->user); } @@ -190,6 +191,7 @@ int ret; dict_drivers_register_builtin(); + mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL); mail_storage_init(); mail_storage_register_all(); mailbox_list_register_all(); @@ -296,6 +298,7 @@ auth_master_deinit(&ctx.auth_conn); mail_storage_deinit(); + mail_users_deinit(); dict_drivers_unregister_builtin(); } diff -r 4553e28eb4f5 -r 03c418eadc8b src/pop3/client.c --- a/src/pop3/client.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/pop3/client.c Fri Nov 21 18:32:02 2008 +0200 @@ -272,7 +272,7 @@ } if (client->mailbox != NULL) mailbox_close(&client->mailbox); - mail_user_deinit(&client->user); + mail_user_unref(&client->user); i_free(client->message_sizes); i_free(client->deleted_bitmask); diff -r 4553e28eb4f5 -r 03c418eadc8b src/pop3/main.c --- a/src/pop3/main.c Fri Nov 21 17:41:59 2008 +0200 +++ b/src/pop3/main.c Fri Nov 21 18:32:02 2008 +0200 @@ -205,6 +205,7 @@ } dict_drivers_register_builtin(); + mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL); mail_storage_init(); mail_storage_register_all(); mailbox_list_register_all(); @@ -229,7 +230,8 @@ i_fatal("pop3_uidl_format setting doesn't contain any " "%% variables."); - user = mail_user_init(getenv("USER"), getenv("HOME")); + user = mail_user_init(getenv("USER")); + mail_user_set_home(user, getenv("HOME")); if (mail_namespaces_init(user) < 0) i_fatal("Namespace initialization failed"); @@ -261,6 +263,7 @@ module_dir_unload(&modules); mail_storage_deinit(); + mail_users_deinit(); dict_drivers_unregister_builtin(); lib_signals_deinit();