]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail_user_*() now handles home directory lookups when necessary.
authorTimo Sirainen <tss@iki.fi>
Fri, 21 Nov 2008 16:32:02 +0000 (18:32 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 21 Nov 2008 16:32:02 +0000 (18:32 +0200)
Namespace owner is now a pointer to struct mail_user rather than a string.

--HG--
branch : HEAD

21 files changed:
src/deliver/deliver.c
src/imap/client.c
src/imap/main.c
src/lib-storage/Makefile.am
src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/index/shared/Makefile.am
src/lib-storage/index/shared/shared-storage.c
src/lib-storage/index/shared/shared-storage.h
src/lib-storage/mail-namespace.c
src/lib-storage/mail-namespace.h
src/lib-storage/mail-storage.c
src/lib-storage/mail-user.c
src/lib-storage/mail-user.h
src/plugins/acl/acl-lookup-dict.c
src/plugins/convert/convert-plugin.c
src/plugins/convert/convert-storage.c
src/plugins/convert/convert-tool.c
src/plugins/expire/expire-tool.c
src/pop3/client.c
src/pop3/main.c

index 42a900e9f8ae3f1ac001d3d87a737de578df0c08..b097426cfde8b5ac2059624914a9a2705c6904a9 100644 (file)
@@ -1058,18 +1058,21 @@ int main(int argc, char *argv[])
 
        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 @@ int main(int argc, char *argv[])
        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();
index 8a7c141f03b4e11082b5bf86b930276b4f0dfc6e..073c834cbf0ae323888b156bcca9ff6a14422ec3 100644 (file)
@@ -162,7 +162,7 @@ void client_destroy(struct client *client, const char *reason)
                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);
index 0bd6fdda39549c49ecc923ecfd5358c8641f97c1..8984be8799acf174e893bf2919690875c2eebde5 100644 (file)
@@ -194,6 +194,7 @@ static void main_init(void)
        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 @@ static void main_init(void)
 
         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 @@ static void main_deinit(void)
 
        module_dir_unload(&modules);
        commands_deinit();
-        mail_storage_deinit();
+       mail_storage_deinit();
+       mail_users_deinit();
        dict_drivers_unregister_builtin();
 
        str_free(&capability_string);
index 65164851858611f58d95d748bae616ed76b6fec8..237430e7cc556e24fbebe04e46af8f4f6f24f3ad 100644 (file)
@@ -4,9 +4,11 @@ noinst_LIBRARIES = libstorage.a
 
 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 \
index d739ca3b53dfb738c7c7d77e4b9cc6e5a34a1af9..d5fcf17a8760d44ba9b44709cb78a439b713ff12 100644 (file)
@@ -66,7 +66,7 @@ maildir_get_list_settings(struct mailbox_list_settings *list_set,
        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 @@ maildir_get_list_settings(struct mailbox_list_settings *list_set,
 
                /* 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)",
index 8828dd33281c6d181089453267375dd9a506def3..f5f96a7b2889d18da5122211d5fb301353c6ad02 100644 (file)
@@ -190,8 +190,7 @@ static const char *get_root_dir(struct mail_storage *storage)
        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 @@ static const char *create_root_dir(struct mail_storage *storage,
 {
        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;
index 98240ffbb8460202d829e487b22c96c65ac03c74..ea6616d5766ce4b56388f37852f39b25e98b3b81 100644 (file)
@@ -2,7 +2,6 @@ noinst_LIBRARIES = libstorage_shared.a
 
 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 \
index ab889aeb21ef57ffdaf5a2d629cc86c7a93a5ec6..78392b4bdcc06787600c15064fd612e12de21c45 100644 (file)
@@ -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 @@ static int shared_create(struct mail_storage *_storage, const char *data,
        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 @@ static void get_nonexisting_user_location(struct shared_storage *storage,
 
        /* 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 @@ int shared_storage_get_namespace(struct mail_storage *_storage,
        };
        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 @@ int shared_storage_get_namespace(struct mail_storage *_storage,
                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 @@ int shared_storage_get_namespace(struct mail_storage *_storage,
        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 @@ int shared_storage_get_namespace(struct mail_storage *_storage,
        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 @@ struct mail_storage shared_storage = {
                NULL,
                shared_alloc,
                shared_create,
-               shared_storage_destroy,
+               index_storage_destroy,
                NULL,
                shared_mailbox_open,
                shared_mailbox_create
index 1a021c5624304e824a6c7242cd193ef8574c9222..2dfcd29c78781a43253f626a6c0db983ca3700f8 100644 (file)
@@ -12,7 +12,6 @@ struct shared_storage {
        const char *base_dir;
        const char *ns_prefix_pattern;
        const char *location;
-       struct auth_master_connection *auth_master_conn;
 
        struct mail_storage *storage_class;
 };
index 6149b50249572e105067b45ea03e16e8e6c32e47..a262a12140096274205c0f745095c45acbe0c6a2 100644 (file)
@@ -29,7 +29,8 @@ void mail_namespace_init_storage(struct mail_namespace *ns)
 
 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 @@ namespace_add_env(const char *data, unsigned int num,
 
        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 @@ int mail_namespaces_init(struct mail_user *user)
        }
 
        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 @@ mail_namespaces_init_empty(struct mail_user *user)
 
        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;
index f931e51c4d8b5b8deebff4b6a0d3745ac5fc5223..0cd6b94c8044fdd4683ff0802d19dd60959ad5a3 100644 (file)
@@ -38,10 +38,10 @@ struct mail_namespace {
        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;
index dd66bba6861b69436d5e2dded62a4d2d3684dfed..121a92317d9d5bb8f5e9227000b1c9b8a5c68d60 100644 (file)
@@ -228,7 +228,7 @@ int mail_storage_create(struct mail_namespace *ns, const char *driver,
                        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(
index c975c7c71e53f9c7d7e89bbf6f3bda13f160f7e3..d8735e9b3e18ff618bc697650342fec827fed1bb 100644 (file)
@@ -2,19 +2,24 @@
 
 #include "lib.h"
 #include "array.h"
+#include "auth-master.h"
 #include "mail-namespace.h"
 #include "mail-user.h"
 
+#include <stdlib.h>
+
 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 @@ struct mail_user *mail_user_init(const char *username, const char *home)
        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 @@ struct mail_user *mail_user_init(const char *username, const char *home)
        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 @@ const char *mail_user_home_expand(struct mail_user *user, const char *path)
        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);
+}
index 97d9f8d704e5a288c3a28bdb5028fda7e9135deb..bb9edf51253e2b4180a8b712286497e138984319 100644 (file)
@@ -10,14 +10,19 @@ struct mail_user_vfuncs {
 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 @@ extern struct mail_user_module_register mail_user_module_register;
 /* 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);
index aec9550823c361aeb240c6e01c02156019a2ae11..fb3212188523ffb210f67cea4a7364fefb7682f0 100644 (file)
@@ -127,7 +127,7 @@ static int acl_lookup_dict_rebuild_add_backend(struct mail_namespace *ns,
                                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);
                        }
index e099566c7aa15bd494ae5c0af5bd934db18350e1..558c1fd3add9c79a3ddf5bd97f3987bd2730e26a 100644 (file)
@@ -19,7 +19,7 @@ static void convert_mail_storage(struct mail_namespace *namespaces,
        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 =
index a57482abd44368d551e15cfc0ea7c5c715fb5ae0..cfc3b10eb8969b1223fb1fdda9919cc7f13ee63a 100644 (file)
@@ -397,7 +397,7 @@ int convert_storage(const char *source_data,
        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 @@ int convert_storage(const char *source_data,
                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;
index ad88687aeb22a6940398995f1d628c1dc2e47222..0df96467d0579b76bcbefd6af4d7def79c6d25ca 100644 (file)
@@ -28,6 +28,7 @@ int main(int argc, const char *argv[])
        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 @@ int main(int argc, const char *argv[])
        }
 
        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 @@ int main(int argc, const char *argv[])
                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;
index d8bf039e5c3cc6c190bbf2bde8754af9cc38b644..43d9753fb5af3c46edbec5e71aaa0facbe34839d 100644 (file)
@@ -44,7 +44,8 @@ static int user_init(struct expire_context *ctx, const char *user)
                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 int user_init(struct expire_context *ctx, const char *user)
 
 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 @@ static void expire_run(bool testrun)
        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 @@ static void expire_run(bool testrun)
        auth_master_deinit(&ctx.auth_conn);
 
        mail_storage_deinit();
+       mail_users_deinit();
        dict_drivers_unregister_builtin();
 }
 
index 0d5e679356095a16ccb78c7e491ac41b823223a4..fd7683e22747a28086a50ef5869293a935c06aca 100644 (file)
@@ -272,7 +272,7 @@ void client_destroy(struct client *client, const char *reason)
        }
        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);
index 449194a12d340e8a62f8a1f796bbc50af9ecf96c..aa75fa530ace9c0c38c206b632648a3d900a0c10 100644 (file)
@@ -205,6 +205,7 @@ static bool main_init(void)
        }
 
        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 @@ static bool main_init(void)
                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 @@ static void main_deinit(void)
 
        module_dir_unload(&modules);
        mail_storage_deinit();
+       mail_users_deinit();
        dict_drivers_unregister_builtin();
 
        lib_signals_deinit();