[dovecot-cvs] dovecot/src/login client.c,1.11,1.12 client.h,1.4,1.5 common.h,1.1.1.1,1.2 main.c,1.5,1.6 master.c,1.3,1.4 master.h,1.3,1.4 ssl-proxy.c,1.17,1.18

cras at procontrol.fi cras at procontrol.fi
Sat Nov 16 07:21:23 EET 2002


Update of /home/cvs/dovecot/src/login
In directory danu:/tmp/cvs-serv15320/src/login

Modified Files:
	client.c client.h common.h main.c master.c master.h 
	ssl-proxy.c 
Log Message:
Finally support for handling each login connection in it's own process.
Enabled by default. Also a few bugfixes to master process.



Index: client.c
===================================================================
RCS file: /home/cvs/dovecot/src/login/client.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- client.c	6 Nov 2002 06:26:35 -0000	1.11
+++ client.c	16 Nov 2002 05:21:21 -0000	1.12
@@ -271,6 +271,8 @@
         client->last_input = ioloop_time;
 	hash_insert(clients, client, client);
 
+	main_ref();
+
 	client_send_line(client, "* OK " PACKAGE " ready.");
 	return client;
 }
@@ -312,6 +314,8 @@
 	i_free(client->tag);
 	i_free(client->plain_login);
 	i_free(client);
+
+	main_unref();
 	return FALSE;
 }
 
@@ -353,10 +357,9 @@
 	hash_foreach(clients, client_hash_check_idle, NULL);
 }
 
-void clients_init(void)
+unsigned int clients_get_count(void)
 {
-	clients = hash_create(default_pool, 128, NULL, NULL);
-	to_idle = timeout_add(1000, idle_timeout, NULL);
+	return hash_size(clients);
 }
 
 static void client_hash_destroy(void *key, void *value __attr_unused__,
@@ -365,9 +368,20 @@
 	client_destroy(key, NULL);
 }
 
-void clients_deinit(void)
+void clients_destroy_all(void)
 {
 	hash_foreach(clients, client_hash_destroy, NULL);
+}
+
+void clients_init(void)
+{
+	clients = hash_create(default_pool, 128, NULL, NULL);
+	to_idle = timeout_add(1000, idle_timeout, NULL);
+}
+
+void clients_deinit(void)
+{
+	clients_destroy_all();
 	hash_destroy(clients);
 
 	timeout_remove(to_idle);

Index: client.h
===================================================================
RCS file: /home/cvs/dovecot/src/login/client.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- client.h	13 Oct 2002 23:49:12 -0000	1.4
+++ client.h	16 Nov 2002 05:21:21 -0000	1.5
@@ -37,6 +37,9 @@
 int client_read(Client *client);
 void client_input(void *context, int fd, IO io);
 
+unsigned int clients_get_count(void);
+void clients_destroy_all(void);
+
 void clients_init(void);
 void clients_deinit(void);
 

Index: common.h
===================================================================
RCS file: /home/cvs/dovecot/src/login/common.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- common.h	9 Aug 2002 09:15:55 -0000	1.1.1.1
+++ common.h	16 Nov 2002 05:21:21 -0000	1.2
@@ -7,8 +7,10 @@
 typedef struct _Client Client;
 typedef struct _AuthRequest AuthRequest;
 
-extern IOLoop ioloop;
 extern int disable_plaintext_auth;
 extern unsigned int max_logging_users;
+
+void main_ref(void);
+void main_unref(void);
 
 #endif

Index: main.c
===================================================================
RCS file: /home/cvs/dovecot/src/login/main.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- main.c	8 Oct 2002 23:18:12 -0000	1.5
+++ main.c	16 Nov 2002 05:21:21 -0000	1.6
@@ -10,13 +10,33 @@
 #include "ssl-proxy.h"
 
 #include <stdlib.h>
+#include <unistd.h>
 #include <syslog.h>
 
-IOLoop ioloop;
 int disable_plaintext_auth;
 unsigned int max_logging_users;
 
+static IOLoop ioloop;
 static IO io_imap, io_imaps;
+static int main_refcount;
+static int process_per_connection, closing_down;
+
+void main_ref(void)
+{
+	main_refcount++;
+}
+
+void main_unref(void)
+{
+	if (--main_refcount == 0) {
+		/* nothing to do, quit */
+		io_loop_stop(ioloop);
+	} else if (closing_down && clients_get_count() == 0) {
+		/* last login finished, close all communications
+		   to master process */
+		master_close();
+	}
+}
 
 static void sig_quit(int signo __attr_unused__)
 {
@@ -33,6 +53,23 @@
 	if (fd == -1)
 		return;
 
+	if (process_per_connection) {
+		if (close(listen_fd) < 0)
+			i_fatal("can't close() listen handle");
+
+		if (io_imap != NULL) {
+			io_remove(io_imap);
+			io_imap = NULL;
+		}
+		if (io_imaps != NULL) {
+			io_remove(io_imaps);
+			io_imaps = NULL;
+		}
+
+		closing_down = TRUE;
+		master_notify_finished();
+	}
+
 	(void)client_create(fd, &addr);
 }
 
@@ -79,9 +116,13 @@
 	}
 
 	disable_plaintext_auth = getenv("DISABLE_PLAINTEXT_AUTH") != NULL;
+        process_per_connection = getenv("PROCESS_PER_CONNECTION") != NULL;
 
 	value = getenv("MAX_LOGGING_USERS");
 	max_logging_users = value == NULL ? 0 : strtoul(value, NULL, 10);
+
+        closing_down = FALSE;
+	main_refcount = 0;
 
 	/* Initialize SSL proxy before dropping privileges so it can read
 	   the certificate and private key file. */

Index: master.c
===================================================================
RCS file: /home/cvs/dovecot/src/login/master.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- master.c	6 Nov 2002 14:20:50 -0000	1.3
+++ master.c	16 Nov 2002 05:21:21 -0000	1.4
@@ -5,6 +5,9 @@
 #include "network.h"
 #include "fdpass.h"
 #include "master.h"
+#include "client.h"
+
+#include <unistd.h>
 
 typedef struct _WaitingRequest WaitingRequest;
 
@@ -86,6 +89,29 @@
 	push_request(req.id, callback, context);
 }
 
+void master_notify_finished(void)
+{
+	MasterRequest req;
+
+	memset(&req, 0, sizeof(req));
+
+	/* sending -1 as fd does the notification */
+	if (fd_send(LOGIN_MASTER_SOCKET_FD,
+		    -1, &req, sizeof(req)) != sizeof(req))
+		i_fatal("fd_send() failed: %m");
+}
+
+void master_close(void)
+{
+	clients_destroy_all();
+
+	(void)close(LOGIN_MASTER_SOCKET_FD);
+	io_remove(io_master);
+	io_master = NULL;
+
+	main_unref();
+}
+
 static void master_input(void *context __attr_unused__, int fd,
 			 IO io __attr_unused__)
 {
@@ -94,8 +120,8 @@
 	ret = net_receive(fd, master_buf + master_pos,
 			  sizeof(master_buf) - master_pos);
 	if (ret < 0) {
-		/* master died, kill ourself too */
-		io_loop_stop(ioloop);
+		/* master died, kill all clients logging in */
+		master_close();
 		return;
 	}
 
@@ -110,6 +136,8 @@
 
 void master_init(void)
 {
+	main_ref();
+
 	requests = NULL;
 	next_request = &requests;
 
@@ -126,5 +154,7 @@
 		i_free(requests);
 		requests = next;
 	}
-	io_remove(io_master);
+
+	if (io_master != NULL)
+		io_remove(io_master);
 }

Index: master.h
===================================================================
RCS file: /home/cvs/dovecot/src/login/master.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- master.h	6 Nov 2002 14:20:50 -0000	1.3
+++ master.h	16 Nov 2002 05:21:21 -0000	1.4
@@ -10,6 +10,12 @@
 			 unsigned char cookie[AUTH_COOKIE_SIZE], IPADDR *ip,
 			 MasterCallback callback, void *context);
 
+/* Notify master that we're not listening for new connections anymore. */
+void master_notify_finished(void);
+
+/* Close connection to master process */
+void master_close(void);
+
 void master_init(void);
 void master_deinit(void);
 

Index: ssl-proxy.c
===================================================================
RCS file: /home/cvs/dovecot/src/login/ssl-proxy.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- ssl-proxy.c	14 Oct 2002 21:19:21 -0000	1.17
+++ ssl-proxy.c	16 Nov 2002 05:21:21 -0000	1.18
@@ -125,6 +125,8 @@
 		io_remove(proxy->io_plain);
 
 	i_free(proxy);
+
+	main_unref();
 	return FALSE;
 }
 
@@ -230,26 +232,6 @@
 	proxy->io_plain = io_add(proxy->fd_ssl, IO_WRITE, plain_output, proxy);
 }
 
-static GNUTLS_STATE initialize_state(void)
-{
-	GNUTLS_STATE state;
-
-	gnutls_init(&state, GNUTLS_SERVER);
-
-	gnutls_protocol_set_priority(state, protocol_priority);
-	gnutls_cipher_set_priority(state, cipher_priority);
-	gnutls_compression_set_priority(state, comp_priority);
-	gnutls_kx_set_priority(state, kx_priority);
-	gnutls_mac_set_priority(state, mac_priority);
-
-	gnutls_cred_set(state, GNUTLS_CRD_CERTIFICATE, x509_cred);
-
-	/*gnutls_certificate_server_set_request(state, GNUTLS_CERT_REQUEST);*/
-
-	gnutls_dh_set_prime_bits(state, DH_BITS);
-	return state;
-}
-
 static void ssl_handshake(void *context, int fd __attr_unused__,
 			  IO io __attr_unused__)
 {
@@ -284,6 +266,26 @@
 	}
 }
 
+static GNUTLS_STATE initialize_state(void)
+{
+	GNUTLS_STATE state;
+
+	gnutls_init(&state, GNUTLS_SERVER);
+
+	gnutls_protocol_set_priority(state, protocol_priority);
+	gnutls_cipher_set_priority(state, cipher_priority);
+	gnutls_compression_set_priority(state, comp_priority);
+	gnutls_kx_set_priority(state, kx_priority);
+	gnutls_mac_set_priority(state, mac_priority);
+
+	gnutls_cred_set(state, GNUTLS_CRD_CERTIFICATE, x509_cred);
+
+	/*gnutls_certificate_server_set_request(state, GNUTLS_CERT_REQUEST);*/
+
+	gnutls_dh_set_prime_bits(state, DH_BITS);
+	return state;
+}
+
 int ssl_proxy_new(int fd)
 {
         SSLProxy *proxy;
@@ -316,6 +318,7 @@
 	if (!ssl_proxy_destroy(proxy))
 		return -1;
 
+        main_ref();
 	return sfd[1];
 }
 




More information about the dovecot-cvs mailing list