From: Sascha Wilde Date: Tue, 28 Oct 2008 11:42:22 +0000 (+0100) Subject: shared namespaces: new %%h variable, expanding to the traget users home. X-Git-Tag: 1.2.alpha4~117 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c2ee17c9c263efdc9c0a339c4836c3d43f5cd3d9;p=thirdparty%2Fdovecot%2Fcore.git shared namespaces: new %%h variable, expanding to the traget users home. --HG-- branch : HEAD --- diff --git a/src/imap/Makefile.am b/src/imap/Makefile.am index 3028683b32..6069a086a8 100644 --- a/src/imap/Makefile.am +++ b/src/imap/Makefile.am @@ -24,6 +24,7 @@ libs = \ $(STORAGE_LIBS) \ ../lib-imap/libimap.a \ ../lib-mail/libmail.a \ + ../lib-auth/libauth.a \ ../lib-dict/libdict.a \ ../lib-charset/libcharset.a \ ../lib/liblib.a \ diff --git a/src/lib-storage/index/shared/Makefile.am b/src/lib-storage/index/shared/Makefile.am index 708821a69b..98240ffbb8 100644 --- a/src/lib-storage/index/shared/Makefile.am +++ b/src/lib-storage/index/shared/Makefile.am @@ -2,11 +2,13 @@ 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 \ -I$(top_srcdir)/src/lib-storage \ - -I$(top_srcdir)/src/lib-storage/index + -I$(top_srcdir)/src/lib-storage/index \ + -DPKG_RUNDIR=\""$(rundir)"\" libstorage_shared_a_SOURCES = \ shared-list.c \ diff --git a/src/lib-storage/index/shared/shared-storage.c b/src/lib-storage/index/shared/shared-storage.c index 34866c4285..8477f9393a 100644 --- a/src/lib-storage/index/shared/shared-storage.c +++ b/src/lib-storage/index/shared/shared-storage.c @@ -3,9 +3,13 @@ #include "lib.h" #include "array.h" #include "str.h" +#include "ioloop.h" +#include "auth-master.h" #include "var-expand.h" #include "shared-storage.h" +#include + #define SHARED_LIST_CONTEXT(obj) \ MODULE_CONTEXT(obj, shared_mailbox_list_module) @@ -95,6 +99,49 @@ static int shared_create(struct mail_storage *_storage, const char *data, return 0; } +static const char *lookup_home(const char *user) +{ + const char *auth_socket; + const char *home = NULL; + struct auth_connection *conn; + struct auth_user_reply *reply; + pool_t userdb_pool; + struct ioloop *userdb_ioloop; + + auth_socket = getenv("AUTH_SOCKET_PATH"); + if (auth_socket == NULL) { + const char *base_dir = getenv("BASE_DIR"); + if (base_dir == NULL) + base_dir = PKG_RUNDIR; + auth_socket = t_strconcat(base_dir, "/auth-master", + NULL); + } + + userdb_pool = pool_alloconly_create("userdb lookup replys", 512); + userdb_ioloop = io_loop_create(); + conn = auth_master_init(auth_socket, getenv("DEBUG") != NULL); + reply = i_new(struct auth_user_reply, 1); + + switch (auth_master_user_lookup(conn, user, "shared-storage", userdb_pool, reply)) { + case -1: + /* Some error during lookup... */ + case 0: + /* User not found + FIXME: It might be a good idea to handle this special case... */ + break; + case 1: + home = i_strdup(reply->home); + } + + i_free(reply); + if (conn != NULL) + auth_master_deinit(conn); + io_loop_destroy(&userdb_ioloop); + pool_unref(&userdb_pool); + + return home; +} + int shared_storage_get_namespace(struct mail_storage *_storage, const char **_name, struct mail_namespace **ns_r) @@ -105,11 +152,12 @@ int shared_storage_get_namespace(struct mail_storage *_storage, { 'u', NULL }, { 'n', NULL }, { 'd', NULL }, + { 'h', NULL }, { '\0', NULL } }; struct var_expand_table *tab; struct mail_namespace *ns; - const char *domain = NULL, *username = NULL, *userdomain = NULL; + const char *domain = NULL, *username = NULL, *userdomain = NULL, *userhome = NULL; const char *name, *p, *next, **dest, *error; string_t *prefix, *location; @@ -159,6 +207,12 @@ int shared_storage_get_namespace(struct mail_storage *_storage, } } + userhome = lookup_home(userdomain); + if (userhome == NULL) { + i_error("Namespace '%s': could not lookup home for user %s", _storage->ns->prefix, userdomain); + return -1; + } + /* expand the namespace prefix and see if it already exists. this should normally happen only when the mailbox is being opened */ tab = t_malloc(sizeof(static_tab)); @@ -166,6 +220,7 @@ int shared_storage_get_namespace(struct mail_storage *_storage, tab[0].value = userdomain; tab[1].value = username; tab[2].value = domain; + tab[3].value = userhome; prefix = t_str_new(128); str_append(prefix, _storage->ns->prefix); var_expand(prefix, storage->ns_prefix_pattern, tab); diff --git a/src/plugins/convert/Makefile.am b/src/plugins/convert/Makefile.am index 92ccd40a3f..6c67808c7b 100644 --- a/src/plugins/convert/Makefile.am +++ b/src/plugins/convert/Makefile.am @@ -34,6 +34,7 @@ libs = \ $(STORAGE_LIBS) \ $(top_builddir)/src/lib-imap/libimap.a \ $(top_builddir)/src/lib-mail/libmail.a \ + $(top_builddir)/src/lib-auth/libauth.a \ $(top_builddir)/src/lib-charset/libcharset.a \ $(top_builddir)/src/lib/liblib.a diff --git a/src/plugins/expire/Makefile.am b/src/plugins/expire/Makefile.am index 15115a0211..4487923997 100644 --- a/src/plugins/expire/Makefile.am +++ b/src/plugins/expire/Makefile.am @@ -37,6 +37,7 @@ libs = \ $(STORAGE_LIBS) \ $(top_builddir)/src/lib-imap/libimap.a \ $(top_builddir)/src/lib-mail/libmail.a \ + $(top_builddir)/src/lib-auth/libauth.a \ $(top_builddir)/src/lib-dict/libdict.a \ $(top_builddir)/src/lib-auth/libauth.a \ $(top_builddir)/src/lib-charset/libcharset.a \ diff --git a/src/plugins/fts-squat/Makefile.am b/src/plugins/fts-squat/Makefile.am index 84aff13ed5..ac1fc738e1 100644 --- a/src/plugins/fts-squat/Makefile.am +++ b/src/plugins/fts-squat/Makefile.am @@ -37,6 +37,7 @@ libs = \ $(top_builddir)/src/lib-storage/list/libstorage_list.a \ $(top_builddir)/src/lib-imap/libimap.a \ $(top_builddir)/src/lib-mail/libmail.a \ + $(top_builddir)/src/lib-auth/libauth.a \ $(top_builddir)/src/lib-charset/libcharset.a \ $(top_builddir)/src/lib/liblib.a diff --git a/src/pop3/Makefile.am b/src/pop3/Makefile.am index b53d99a1be..0408b89b58 100644 --- a/src/pop3/Makefile.am +++ b/src/pop3/Makefile.am @@ -22,6 +22,7 @@ libs = \ $(STORAGE_LIBS) \ ../lib-imap/libimap.a \ ../lib-mail/libmail.a \ + ../lib-auth/libauth.a \ ../lib-dict/libdict.a \ ../lib-charset/libcharset.a \ ../lib/liblib.a \