dovecot-2.0-sslstream: Redesigned how login process passes conne...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:55:15 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/4fe8c4382712
changeset: 10102:4fe8c4382712
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 19 21:42:09 2009 -0400
description:
Redesigned how login process passes connections to mail processes and changed related APIs.
Master process is no longer in the middle.

diffstat:

46 files changed, 1468 insertions(+), 1592 deletions(-)
doc/example-config/conf.d/master.conf   |   24 +-
src/auth/Makefile.am                    |    1 
src/auth/auth-client-connection.c       |    4 
src/auth/auth-client-connection.h       |    2 
src/auth/auth-master-connection.c       |    6 
src/auth/auth-master-interface.h        |   11 
src/auth/main.c                         |    5 
src/doveadm/doveadm.c                   |    1 
src/dsync/dsync.c                       |    1 
src/imap/imap-client.c                  |    2 
src/imap/imap-client.h                  |    2 
src/imap/main.c                         |  255 ++++++++++++++--------
src/lda/main.c                          |    1 
src/lib-master/Makefile.am              |    4 
src/lib-master/master-auth.c            |  324 ++++++++++++++--------------
src/lib-master/master-auth.h            |   72 +++++-
src/lib-master/master-interface.h       |   54 ----
src/lib-master/master-login-auth.c      |  290 +++++++++++++++++++++++++
src/lib-master/master-login-auth.h      |   18 +
src/lib-master/master-login.c           |  205 ++++++++++++++++++
src/lib-master/master-login.h           |   25 ++
src/lib-master/master-service-private.h |    3 
src/lib-master/master-service.c         |   68 +++++-
src/lib-master/master-service.h         |    4 
src/lib-storage/mail-storage-service.c  |  121 ++++++----
src/lib-storage/mail-storage-service.h  |    2 
src/login-common/client-common.c        |    2 
src/login-common/common.h               |    1 
src/login-common/main.c                 |   13 -
src/login-common/sasl-server.c          |    6 
src/master/Makefile.am                  |    4 
src/master/main.c                       |   35 ---
src/master/master-settings.c            |   40 ++-
src/master/master-settings.h            |   13 +
src/master/service-auth-server.c        |  269 -----------------------
src/master/service-auth-server.h        |    9 
src/master/service-auth-source.c        |  308 ---------------------------
src/master/service-auth-source.h        |   17 -
src/master/service-monitor.c            |   67 +++++
src/master/service-process.c            |  349 +------------------------------
src/master/service-process.h            |   46 ----
src/master/service.c                    |   90 ++++---
src/master/service.h                    |   30 +-
src/pop3/main.c                         |  252 ++++++++++++++--------
src/pop3/pop3-client.c                  |    2 
src/pop3/pop3-client.h                  |    2 

diffs (truncated from 4166 to 300 lines):

diff -r 33c448ce13f9 -r 4fe8c4382712 doc/example-config/conf.d/master.conf
--- a/doc/example-config/conf.d/master.conf	Mon Oct 19 18:34:00 2009 -0400
+++ b/doc/example-config/conf.d/master.conf	Mon Oct 19 21:42:09 2009 -0400
@@ -32,7 +32,6 @@ service anvil {
 }
 
 service auth {
-  type = auth
   executable = dovecot-auth
 
   # default
@@ -52,6 +51,11 @@ service auth {
     path = auth-userdb
     mode = 0600
   }
+
+  unix_listener {
+    path = auth-master
+    mode = 0600
+  }
 }
 
 service auth-worker {
@@ -65,9 +69,8 @@ service auth-worker {
 
 service imap-login {
   protocol = imap
-  type = auth-source
+  type = login
   executable = imap-login
-  auth_dest_service = imap
 
   inet_listener {
     port = 143
@@ -104,13 +107,18 @@ service imap {
   # Most of the memory goes to mmap()ing files. You may need to increase this
   # limit if you have huge mailboxes.
   #vsz_limit = 256
+
+  service_count = 1
+  unix_listener {
+    path = login/imap
+    mode = 0666
+  }
 }
 
 service pop3-login {
   protocol = pop3
-  type = auth-source
+  type = login
   executable = pop3-login
-  auth_dest_service = pop3
 
   inet_listener {
     port = 110
@@ -130,6 +138,12 @@ service pop3 {
 service pop3 {
   protocol = pop3
   executable = pop3
+
+  service_count = 1
+  unix_listener {
+    path = login/pop3
+    mode = 0666
+  }
 }
 
 service lmtp {
diff -r 33c448ce13f9 -r 4fe8c4382712 src/auth/Makefile.am
--- a/src/auth/Makefile.am	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/auth/Makefile.am	Mon Oct 19 21:42:09 2009 -0400
@@ -109,7 +109,6 @@ headers = \
 	auth-cache.h \
 	auth-client-connection.h \
 	auth-common.h \
-	auth-master-interface.h \
 	auth-master-connection.h \
 	mech-otp-skey-common.h \
 	mech-plain-common.h \
diff -r 33c448ce13f9 -r 4fe8c4382712 src/auth/auth-client-connection.c
--- a/src/auth/auth-client-connection.c	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/auth/auth-client-connection.c	Mon Oct 19 21:42:09 2009 -0400
@@ -116,9 +116,7 @@ auth_client_input_cpid(struct auth_clien
         conn->refcount++;
 	conn->request_handler =
 		auth_request_handler_create(conn->auth,
-			auth_callback, conn,
-			array_count(&auth_master_connections) != 0 ?
-			auth_master_request_callback : NULL);
+			auth_callback, conn, auth_master_request_callback);
 	auth_request_handler_set(conn->request_handler, conn->connect_uid, pid);
 
 	conn->pid = pid;
diff -r 33c448ce13f9 -r 4fe8c4382712 src/auth/auth-client-connection.h
--- a/src/auth/auth-client-connection.h	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/auth/auth-client-connection.h	Mon Oct 19 21:42:09 2009 -0400
@@ -1,7 +1,7 @@
 #ifndef AUTH_CLIENT_CONNECTION_H
 #define AUTH_CLIENT_CONNECTION_H
 
-#include "master-interface.h"
+#include "master-auth.h"
 
 struct auth_client_connection {
 	struct auth *auth;
diff -r 33c448ce13f9 -r 4fe8c4382712 src/auth/auth-master-connection.c
--- a/src/auth/auth-master-connection.c	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/auth/auth-master-connection.c	Mon Oct 19 21:42:09 2009 -0400
@@ -15,8 +15,8 @@
 #include "master-service.h"
 #include "userdb.h"
 #include "userdb-blocking.h"
+#include "master-interface.h"
 #include "auth-request-handler.h"
-#include "auth-master-interface.h"
 #include "auth-client-connection.h"
 #include "auth-master-connection.h"
 
@@ -502,7 +502,6 @@ void auth_master_connection_destroy(stru
         struct auth_master_connection *conn = *_conn;
         struct auth_master_connection *const *masters;
 	unsigned int i, count;
-	bool service_connection = conn->fd != MASTER_AUTH_FD;
 
 	*_conn = NULL;
 	if (conn->destroyed)
@@ -529,8 +528,7 @@ void auth_master_connection_destroy(stru
 		conn->fd = -1;
 	}
 
-	if (service_connection)
-		master_service_client_connection_destroyed(master_service);
+	master_service_client_connection_destroyed(master_service);
 	auth_master_connection_unref(&conn);
 }
 
diff -r 33c448ce13f9 -r 4fe8c4382712 src/auth/auth-master-interface.h
--- a/src/auth/auth-master-interface.h	Mon Oct 19 18:34:00 2009 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-#ifndef AUTH_MASTER_INTERFACE_H
-#define AUTH_MASTER_INTERFACE_H
-
-#include "master-interface.h"
-
-/* Major version changes are not backwards compatible,
-   minor version numbers can be ignored. */
-#define AUTH_MASTER_PROTOCOL_MAJOR_VERSION 1
-#define AUTH_MASTER_PROTOCOL_MINOR_VERSION 1
-
-#endif
diff -r 33c448ce13f9 -r 4fe8c4382712 src/auth/main.c
--- a/src/auth/main.c	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/auth/main.c	Mon Oct 19 21:42:09 2009 -0400
@@ -11,13 +11,13 @@
 #include "module-dir.h"
 #include "randgen.h"
 #include "master-service.h"
+#include "master-interface.h"
 #include "password-scheme.h"
 #include "mech.h"
 #include "auth.h"
 #include "auth-request-handler.h"
 #include "auth-worker-server.h"
 #include "auth-worker-client.h"
-#include "auth-master-interface.h"
 #include "auth-master-connection.h"
 #include "auth-client-connection.h"
 
@@ -86,9 +86,6 @@ static void main_init(void)
 		/* workers have only a single connection from the master
 		   auth process */
 		master_service_set_client_limit(master_service, 1);
-	} else if (getenv("MASTER_AUTH_FD") != NULL) {
-		(void)auth_master_connection_create(auth, MASTER_AUTH_FD,
-						    FALSE);
 	}
 }
 
diff -r 33c448ce13f9 -r 4fe8c4382712 src/doveadm/doveadm.c
--- a/src/doveadm/doveadm.c	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/doveadm/doveadm.c	Mon Oct 19 21:42:09 2009 -0400
@@ -98,6 +98,7 @@ int main(int argc, char *argv[])
 	argc -= optind;
 	argv += optind;
 
+	master_service_init_finish(master_service);
 	if (!doveadm_try_run(cmd_name, argc, argv) &&
 	    !doveadm_mail_try_run(cmd_name, argc, argv))
 		usage();
diff -r 33c448ce13f9 -r 4fe8c4382712 src/dsync/dsync.c
--- a/src/dsync/dsync.c	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/dsync/dsync.c	Mon Oct 19 21:42:09 2009 -0400
@@ -112,6 +112,7 @@ int main(int argc, char *argv[])
 	}
 	if (optind != argc)
 		usage();
+	master_service_init_finish(master_service);
 
 	memset(&input, 0, sizeof(input));
 	input.username = username;
diff -r 33c448ce13f9 -r 4fe8c4382712 src/imap/imap-client.c
--- a/src/imap/imap-client.c	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/imap/imap-client.c	Mon Oct 19 21:42:09 2009 -0400
@@ -21,7 +21,7 @@ extern struct mail_storage_callbacks mai
 extern struct mail_storage_callbacks mail_storage_callbacks;
 struct imap_module_register imap_module_register = { 0 };
 
-static struct client *imap_clients = NULL;
+struct client *imap_clients = NULL;
 
 static void client_idle_timeout(struct client *client)
 {
diff -r 33c448ce13f9 -r 4fe8c4382712 src/imap/imap-client.h
--- a/src/imap/imap-client.h	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/imap/imap-client.h	Mon Oct 19 21:42:09 2009 -0400
@@ -146,6 +146,8 @@ struct client {
 	unsigned int modseqs_sent_since_sync:1;
 };
 
+extern struct client *imap_clients;
+
 /* Create new client with specified input/output handles. socket specifies
    if the handle is a socket. */
 struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
diff -r 33c448ce13f9 -r 4fe8c4382712 src/imap/main.c
--- a/src/imap/main.c	Mon Oct 19 18:34:00 2009 -0400
+++ b/src/imap/main.c	Mon Oct 19 21:42:09 2009 -0400
@@ -9,8 +9,9 @@
 #include "restrict-access.h"
 #include "fd-close-on-exec.h"
 #include "process-title.h"
+#include "master-interface.h"
 #include "master-service.h"
-#include "master-interface.h"
+#include "master-login.h"
 #include "mail-user.h"
 #include "mail-storage-service.h"
 #include "imap-commands.h"
@@ -21,18 +22,25 @@
 #include <unistd.h>
 
 #define IS_STANDALONE() \
-        (getenv("CLIENT_INPUT") == NULL)
+        (getenv(MASTER_UID_ENV) == NULL)
+
+static const struct setting_parser_info *set_roots[] = {
+	&imap_setting_parser_info,
+	NULL
+};
+static struct master_login *master_login = NULL;
+static enum mail_storage_service_flags storage_service_flags = 0;
+static bool user_initialized = FALSE;
 
 void (*hook_client_created)(struct client **client) = NULL;
 
-static void client_add_input(struct client *client, const char *input)
-{
-	buffer_t *buf;
+static void client_add_input(struct client *client, const buffer_t *buf)
+{
+	struct ostream *output;
 	const char *tag;
 	unsigned int data_pos;
 	bool send_untagged_capability = FALSE;
 
-	buf = input == NULL ? NULL : t_base64_decode_str(input);
 	if (buf != NULL && buf->used > 0) {
 		tag = t_strndup(buf->data, buf->used);
 		switch (*tag) {
@@ -55,6 +63,9 @@ static void client_add_input(struct clie
 		tag = getenv("IMAPLOGINTAG");
 	}
 
+	output = client->output;
+	o_stream_ref(output);
+	o_stream_cork(output);
 	if (tag == NULL) {
 		client_send_line(client, t_strconcat(
 			"* PREAUTH [CAPABILITY ",
@@ -63,68 +74,141 @@ static void client_add_input(struct clie
 	} else if (send_untagged_capability) {
 		/* client doesn't seem to understand tagged capabilities. send
 		   untagged instead and hope that it works. */
-		o_stream_cork(client->output);
 		client_send_line(client, t_strconcat("* CAPABILITY ",
 			str_c(client->capability_string), NULL));
 		client_send_line(client, t_strconcat(tag, " OK Logged in", NULL));
-		o_stream_uncork(client->output);
 	} else {
 		client_send_line(client, t_strconcat(
 			tag, " OK [CAPABILITY ",
 			str_c(client->capability_string), "] Logged in", NULL));
 	}
 	(void)client_handle_input(client);
-}
-
-static void main_init(const struct imap_settings *set, struct mail_user *user,
-		      bool dump_capability)
+	o_stream_uncork(output);


More information about the dovecot-cvs mailing list