]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
shared namespaces: new %%h variable, expanding to the traget users home.
authorSascha Wilde <wilde@intevation.de>
Tue, 28 Oct 2008 11:42:22 +0000 (12:42 +0100)
committerSascha Wilde <wilde@intevation.de>
Tue, 28 Oct 2008 11:42:22 +0000 (12:42 +0100)
--HG--
branch : HEAD

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

index 3028683b32ff12204fc89ee14e0951f9f45183d1..6069a086a8dbaaefbdad31f799fcb902868327fd 100644 (file)
@@ -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 \
index 708821a69bec6480b27021f4a03c4199a62c33e3..98240ffbb8460202d829e487b22c96c65ac03c74 100644 (file)
@@ -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 \
index 34866c4285215e2add78e69f13c2fb227a1fe65e..8477f9393aebd9b7432b6af8d2967353384db170 100644 (file)
@@ -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 @@ 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);
index 92ccd40a3fe5b2dfae9d2bdfc6b9cac3936fb5e9..6c67808c7b239bcdda77dd60692077420f6eda6e 100644 (file)
@@ -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
 
index 15115a021121aa8fc028536dd2d512d954397542..448792399793c1e9f77c4fe2876f48f5e02593ec 100644 (file)
@@ -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 \
index 84aff13ed51705a10a8fb76a5e2b696a478e654c..ac1fc738e17cdf2092b655c80e78227de73277ba 100644 (file)
@@ -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
 
index b53d99a1be32294b59d3232b03a81c6b48cae985..0408b89b5834a4f0f2175c5200f22789240ede0b 100644 (file)
@@ -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 \