dovecot-1.2: shared namespaces: new %%h variable, expanding to t...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Nov 1 15:12:20 EET 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/469fc16380da
changeset: 8372:469fc16380da
user: Sascha Wilde <wilde at intevation.de>
date: Tue Oct 28 12:42:22 2008 +0100
description:
shared namespaces: new %%h variable, expanding to the traget users home.
diffstat:
7 files changed, 64 insertions(+), 2 deletions(-)
src/imap/Makefile.am | 1
src/lib-storage/index/shared/Makefile.am | 4 +
src/lib-storage/index/shared/shared-storage.c | 57 ++++++++++++++++++++++++-
src/plugins/convert/Makefile.am | 1
src/plugins/expire/Makefile.am | 1
src/plugins/fts-squat/Makefile.am | 1
src/pop3/Makefile.am | 1
diffs (174 lines):
diff -r b46cf0979768 -r 469fc16380da src/imap/Makefile.am
--- 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 @@ 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 -r b46cf0979768 -r 469fc16380da src/lib-storage/index/shared/Makefile.am
--- 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 @@ 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 -r b46cf0979768 -r 469fc16380da src/lib-storage/index/shared/shared-storage.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,8 +3,12 @@
#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_sto
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
{ '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
}
}
+ 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
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 -r b46cf0979768 -r 469fc16380da src/plugins/convert/Makefile.am
--- 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 @@ 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 -r b46cf0979768 -r 469fc16380da src/plugins/expire/Makefile.am
--- 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 @@ 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 -r b46cf0979768 -r 469fc16380da src/plugins/fts-squat/Makefile.am
--- 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 @@ 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 -r b46cf0979768 -r 469fc16380da src/pop3/Makefile.am
--- a/src/pop3/Makefile.am Sat Nov 01 14:55:28 2008 +0200
+++ b/src/pop3/Makefile.am Tue Oct 28 12:42:22 2008 +0100
@@ -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 \
More information about the dovecot-cvs
mailing list