dovecot-2.0: Added initial implementation of a director process ...

dovecot at dovecot.org dovecot at dovecot.org
Wed May 19 10:57:07 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/5f350b5ff6d9
changeset: 11321:5f350b5ff6d9
user:      Timo Sirainen <tss at iki.fi>
date:      Wed May 19 09:56:49 2010 +0200
description:
Added initial implementation of a director process (for NFS users).
There are still some unimplemented features and bugs. Also changing mail
server list doesn't yet make sure that other directors won't assign the
same user to a different server at the same time.

diffstat:

 .hgignore                                  |    1 +
 configure.in                               |    1 +
 doc/example-config/conf.d/10-director.conf |   41 +
 src/Makefile.am                            |    1 +
 src/director/Makefile.am                   |   38 +
 src/director/auth-connection.c             |  127 ++++++
 src/director/auth-connection.h             |   22 +
 src/director/director-connection.c         |  735 +++++++++++++++++++++++++++++++++++
 src/director/director-connection.h         |   20 +
 src/director/director-host.c               |  138 ++++++
 src/director/director-host.h               |   48 ++
 src/director/director-request.c            |  106 +++++
 src/director/director-request.h            |   14 +
 src/director/director-settings.c           |   81 +++
 src/director/director-settings.h           |   15 +
 src/director/director.c                    |  209 +++++++++
 src/director/director.h                    |   88 ++++
 src/director/doveadm-connection.c          |  193 +++++++++
 src/director/doveadm-connection.h          |   10 +
 src/director/login-connection.c            |  211 ++++++++++
 src/director/login-connection.h            |   13 +
 src/director/mail-host.c                   |  182 ++++++++
 src/director/mail-host.h                   |   28 +
 src/director/main.c                        |  178 ++++++++
 src/director/user-directory.c              |  191 +++++++++
 src/director/user-directory.h              |   47 ++
 src/doveadm/Makefile.am                    |    1 +
 src/doveadm/doveadm-director.c             |  208 +++++++++
 src/doveadm/doveadm.c                      |    1 +
 src/doveadm/doveadm.h                      |    1 +
 30 files changed, 2949 insertions(+), 0 deletions(-)

diffs (truncated from 3104 to 300 lines):

diff -r 1753fe048fee -r 5f350b5ff6d9 .hgignore
--- a/.hgignore	Wed May 19 09:52:36 2010 +0200
+++ b/.hgignore	Wed May 19 09:56:49 2010 +0200
@@ -61,6 +61,7 @@
 src/config/doveconf
 src/lda/dovecot-lda
 src/dict/dict
+src/director/director
 src/dns/dns-client
 src/doveadm/doveadm
 src/dsync/dsync
diff -r 1753fe048fee -r 5f350b5ff6d9 configure.in
--- a/configure.in	Wed May 19 09:52:36 2010 +0200
+++ b/configure.in	Wed May 19 09:56:49 2010 +0200
@@ -2659,6 +2659,7 @@
 src/log/Makefile
 src/lmtp/Makefile
 src/dict/Makefile
+src/director/Makefile
 src/dns/Makefile
 src/imap/Makefile
 src/imap-login/Makefile
diff -r 1753fe048fee -r 5f350b5ff6d9 doc/example-config/conf.d/10-director.conf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/example-config/conf.d/10-director.conf	Wed May 19 09:56:49 2010 +0200
@@ -0,0 +1,41 @@
+##
+## Director-specific settings.
+##
+
+# Director can be used by Dovecot proxy to keep a temporary user -> mail server
+# mapping. As long as user has simultaneous connections, the user is always
+# redirected to the same server. Each proxy server is running its own director
+# process, and the directors are communicating the state to each others.
+# Directors are mainly useful with NFS-like setups.
+
+# List of IPs or hostnames to all director servers, including ourself.
+# Ports can be specified as ip:port. The default port is the same as
+# what director service's inet_listener is using.
+director_servers = 
+
+# List of IPs or hostnames to all backend mail servers. Ranges are allowed
+# too, like 10.0.0.10-10.0.0.30.
+director_mail_servers = 
+
+# How long to redirect users to a specific server after it no longer has
+# any connections.
+director_user_expire = 15 min
+
+# To enable director service, uncomment the mode and assign a port.
+service director {
+  unix_listener login/director {
+    #mode = 0666
+  }
+  inet_listener {
+    #port = 
+  }
+}
+
+# Enable director for the wanted login services by telling them to
+# connect to director socket instead of the default login socket:
+service imap-login {
+  #executable = imap-login director
+}
+service pop3-login {
+  #executable = pop3-login director
+}
diff -r 1753fe048fee -r 5f350b5ff6d9 src/Makefile.am
--- a/src/Makefile.am	Wed May 19 09:52:36 2010 +0200
+++ b/src/Makefile.am	Wed May 19 09:56:49 2010 +0200
@@ -33,6 +33,7 @@
 	lmtp \
 	log \
 	config \
+	director \
 	util \
 	doveadm \
 	dsync \
diff -r 1753fe048fee -r 5f350b5ff6d9 src/director/Makefile.am
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/director/Makefile.am	Wed May 19 09:56:49 2010 +0200
@@ -0,0 +1,38 @@
+pkglibexecdir = $(libexecdir)/dovecot
+
+pkglibexec_PROGRAMS = director
+
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/src/lib \
+	-I$(top_srcdir)/src/lib-auth \
+	-I$(top_srcdir)/src/lib-settings \
+	-I$(top_srcdir)/src/lib-master \
+	-DPKG_RUNDIR=\""$(rundir)"\"
+
+director_LDADD = $(LIBDOVECOT)
+director_DEPENDENCIES = $(LIBDOVECOT_DEPS)
+
+director_SOURCES = \
+	main.c \
+	auth-connection.c \
+	director.c \
+	director-connection.c \
+	director-host.c \
+	director-request.c \
+	director-settings.c \
+	doveadm-connection.c \
+	login-connection.c \
+	mail-host.c \
+	user-directory.c
+
+noinst_HEADERS = \
+	auth-connection.h \
+	director.h \
+	director-connection.h \
+	director-host.h \
+	director-request.h \
+	director-settings.h \
+	doveadm-connection.h \
+	login-connection.h \
+	mail-host.h \
+	user-directory.h
diff -r 1753fe048fee -r 5f350b5ff6d9 src/director/auth-connection.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/director/auth-connection.c	Wed May 19 09:56:49 2010 +0200
@@ -0,0 +1,127 @@
+/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "ioloop.h"
+#include "istream.h"
+#include "ostream.h"
+#include "network.h"
+#include "llist.h"
+#include "safe-memset.h"
+#include "auth-client-interface.h"
+#include "auth-connection.h"
+
+#include <unistd.h>
+
+struct auth_connection {
+	struct auth_connection *prev, *next;
+
+	char *path;
+	int fd;
+	struct io *io;
+	struct istream *input;
+	struct ostream *output;
+
+	auth_input_callback *callback;
+	void *context;
+};
+
+static struct auth_connection *auth_connections;
+
+static void auth_connection_input(struct auth_connection *conn)
+{
+	char *line;
+
+	switch (i_stream_read(conn->input)) {
+	case 0:
+		return;
+	case -1:
+		/* disconnected */
+		auth_connection_deinit(&conn);
+		return;
+	case -2:
+		/* buffer full */
+		i_error("BUG: Auth server sent us more than %d bytes",
+			(int)AUTH_CLIENT_MAX_LINE_LENGTH);
+		auth_connection_deinit(&conn);
+		return;
+	}
+
+	while ((line = i_stream_next_line(conn->input)) != NULL) {
+		T_BEGIN {
+			conn->callback(line, conn->context);
+			safe_memset(line, 0, strlen(line));
+		} T_END;
+	}
+}
+
+struct auth_connection *auth_connection_init(const char *path)
+{
+	struct auth_connection *conn;
+ 
+	conn = i_new(struct auth_connection, 1);
+	conn->fd = -1;
+	conn->path = i_strdup(path);
+	DLLIST_PREPEND(&auth_connections, conn);
+	return conn;
+}
+
+void auth_connection_set_callback(struct auth_connection *conn,
+				  auth_input_callback *callback, void *context)
+{
+	conn->callback = callback;
+	conn->context = context;
+}
+
+int auth_connection_connect(struct auth_connection *conn)
+{
+	i_assert(conn->fd == -1);
+
+	conn->fd = net_connect_unix_with_retries(conn->path, 1000);
+	if (conn->fd == -1) {
+		i_error("connect(%s) failed: %m", conn->path);
+		return -1;
+	}
+
+	conn->input = i_stream_create_fd(conn->fd, AUTH_CLIENT_MAX_LINE_LENGTH,
+					 FALSE);
+	conn->output = o_stream_create_fd(conn->fd, (size_t)-1, FALSE);
+	conn->io = io_add(conn->fd, IO_READ, auth_connection_input, conn);
+	return 0;
+}
+
+void auth_connection_deinit(struct auth_connection **_conn)
+{
+	struct auth_connection *conn = *_conn;
+
+	*_conn = NULL;
+
+	DLLIST_REMOVE(&auth_connections, conn);
+	if (conn->fd != -1) {
+		io_remove(&conn->io);
+		i_stream_unref(&conn->input);
+		o_stream_unref(&conn->output);
+
+		if (close(conn->fd) < 0)
+			i_error("close(auth connection) failed: %m");
+		conn->callback(NULL, conn->context);
+	}
+	i_free(conn->path);
+	i_free(conn);
+}
+
+void auth_connection_send(struct auth_connection *conn,
+			  const void *data, size_t size)
+{
+	i_assert(conn->fd != -1);
+
+	(void)o_stream_send(conn->output, data, size);
+}
+
+void auth_connections_deinit(void)
+{
+	while (auth_connections != NULL) {
+		struct auth_connection *conn = auth_connections;
+
+		auth_connection_deinit(&conn);
+	}
+}
diff -r 1753fe048fee -r 5f350b5ff6d9 src/director/auth-connection.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/director/auth-connection.h	Wed May 19 09:56:49 2010 +0200
@@ -0,0 +1,22 @@
+#ifndef AUTH_CONNECTION_H
+#define AUTH_CONNECTION_H
+
+/* Called for each input line. This is also called with line=NULL if
+   connection gets disonnected. */
+typedef void auth_input_callback(const char *line, void *context);
+
+struct auth_connection *auth_connection_init(const char *path);
+void auth_connection_deinit(struct auth_connection **conn);
+
+void auth_connection_set_callback(struct auth_connection *conn,
+				  auth_input_callback *callback, void *context);
+
+/* Start connecting. Returns 0 if ok, -1 if connect failed. */
+int auth_connection_connect(struct auth_connection *conn);
+/* Send data to auth connection. */
+void auth_connection_send(struct auth_connection *conn,
+			  const void *data, size_t size);
+
+void auth_connections_deinit(void);
+
+#endif
diff -r 1753fe048fee -r 5f350b5ff6d9 src/director/director-connection.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/director/director-connection.c	Wed May 19 09:56:49 2010 +0200
@@ -0,0 +1,735 @@
+/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "ioloop.h"
+#include "array.h"
+#include "network.h"
+#include "istream.h"
+#include "ostream.h"
+#include "str.h"
+#include "mail-host.h"
+#include "director.h"
+#include "director-host.h"
+#include "director-request.h"
+#include "user-directory.h"
+#include "director-connection.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+


More information about the dovecot-cvs mailing list