Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8372:469fc16380da HEAD
shared namespaces: new %%h variable, expanding to the traget users home.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Tue, 28 Oct 2008 12:42:22 +0100 |
parents | b46cf0979768 |
children | 9524ec6e14fc |
files | src/imap/Makefile.am src/lib-storage/index/shared/Makefile.am src/lib-storage/index/shared/shared-storage.c src/plugins/convert/Makefile.am src/plugins/expire/Makefile.am src/plugins/fts-squat/Makefile.am src/pop3/Makefile.am |
diffstat | 7 files changed, 64 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/imap/Makefile.am Sat Nov 01 14:55:28 2008 +0200 +++ b/src/imap/Makefile.am Tue Oct 28 12:42:22 2008 +0100 @@ -24,6 +24,7 @@ $(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 \
--- a/src/lib-storage/index/shared/Makefile.am Sat Nov 01 14:55:28 2008 +0200 +++ b/src/lib-storage/index/shared/Makefile.am Tue Oct 28 12:42:22 2008 +0100 @@ -2,11 +2,13 @@ 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 \
--- a/src/lib-storage/index/shared/shared-storage.c Sat Nov 01 14:55:28 2008 +0200 +++ b/src/lib-storage/index/shared/shared-storage.c Tue Oct 28 12:42:22 2008 +0100 @@ -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 <stdlib.h> + #define SHARED_LIST_CONTEXT(obj) \ MODULE_CONTEXT(obj, shared_mailbox_list_module) @@ -95,6 +99,49 @@ 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 @@ { '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 @@ } } + 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 @@ 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);
--- a/src/plugins/convert/Makefile.am Sat Nov 01 14:55:28 2008 +0200 +++ b/src/plugins/convert/Makefile.am Tue Oct 28 12:42:22 2008 +0100 @@ -34,6 +34,7 @@ $(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
--- a/src/plugins/expire/Makefile.am Sat Nov 01 14:55:28 2008 +0200 +++ b/src/plugins/expire/Makefile.am Tue Oct 28 12:42:22 2008 +0100 @@ -37,6 +37,7 @@ $(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 \
--- a/src/plugins/fts-squat/Makefile.am Sat Nov 01 14:55:28 2008 +0200 +++ b/src/plugins/fts-squat/Makefile.am Tue Oct 28 12:42:22 2008 +0100 @@ -37,6 +37,7 @@ $(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