dovecot-1.2: mail_user_*() now handles home directory lookups wh...

dovecot at dovecot.org dovecot at dovecot.org
Fri Nov 21 18:33:16 EET 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/03c418eadc8b
changeset: 8467:03c418eadc8b
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Nov 21 18:32:02 2008 +0200
description:
mail_user_*() now handles home directory lookups when necessary.
Namespace owner is now a pointer to struct mail_user rather than a string.

diffstat:

21 files changed, 162 insertions(+), 99 deletions(-)
src/deliver/deliver.c                           |   12 ++-
src/imap/client.c                               |    2 
src/imap/main.c                                 |    7 +
src/lib-storage/Makefile.am                     |    4 -
src/lib-storage/index/maildir/maildir-storage.c |    6 -
src/lib-storage/index/mbox/mbox-storage.c       |    6 -
src/lib-storage/index/shared/Makefile.am        |    1 
src/lib-storage/index/shared/shared-storage.c   |   68 +++----------------
src/lib-storage/index/shared/shared-storage.h   |    1 
src/lib-storage/mail-namespace.c                |   12 ++-
src/lib-storage/mail-namespace.h                |    4 -
src/lib-storage/mail-storage.c                  |    2 
src/lib-storage/mail-user.c                     |   81 +++++++++++++++++++++--
src/lib-storage/mail-user.h                     |   24 +++++-
src/plugins/acl/acl-lookup-dict.c               |    2 
src/plugins/convert/convert-plugin.c            |    2 
src/plugins/convert/convert-storage.c           |    6 +
src/plugins/convert/convert-tool.c              |    7 +
src/plugins/expire/expire-tool.c                |    7 +
src/pop3/client.c                               |    2 
src/pop3/main.c                                 |    5 +

diffs (truncated from 727 to 300 lines):

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 @@ 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();
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 @@ void client_destroy(struct client *clien
 		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 @@ 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);
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 @@ 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 \
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 @@ maildir_get_list_settings(struct mailbox
 	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
 
 		/* 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 @@ static const char *get_root_dir(struct m
 	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(struc
 {
 	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 @@ 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 \
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 @@ static int shared_create(struct mail_sto
 	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_locatio
 
 	/* 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 
 	};
 	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 
 		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 
 	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 
 	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
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 @@ struct shared_storage {


More information about the dovecot-cvs mailing list