[dovecot-cvs] dovecot/src/imap-login client-authenticate.c,1.4,1.5 client.c,1.7,1.8 client.h,1.3,1.4

cras at procontrol.fi cras at procontrol.fi
Wed Mar 5 00:38:10 EET 2003


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

Modified Files:
	client-authenticate.c client.c client.h 
Log Message:
login: Wait until we're connected to auth process before executing command
from client.

inetd usage: --group=name can now specify which login group to use. Default
is the binary name before '-' character (ie. imap or pop3).



Index: client-authenticate.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap-login/client-authenticate.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- client-authenticate.c	2 Feb 2003 10:53:43 -0000	1.4
+++ client-authenticate.c	4 Mar 2003 22:38:07 -0000	1.5
@@ -130,6 +130,7 @@
 			      master_callback, &error)) {
 	case -1:
 		/* login failed */
+                client->authenticating = FALSE;
 		client_auth_abort(client, error);
 		break;
 
@@ -143,6 +144,7 @@
 	default:
 		/* success, we should be able to log in. if we fail, just
 		   disconnect the client. */
+                client->authenticating = FALSE;
 		client_send_tagline(client, "OK Logged in.");
 	}
 }
@@ -183,6 +185,7 @@
 			io_remove(client->common.io);
 			client->common.io = NULL;
 		}
+                client->authenticating = TRUE;
 		return TRUE;
 	} else {
 		client_send_tagline(client, t_strconcat(
@@ -204,6 +207,7 @@
 			      master_callback, &error)) {
 	case -1:
 		/* login failed */
+                client->authenticating = FALSE;
 		client_auth_abort(client, error);
 		break;
 
@@ -214,6 +218,7 @@
 	default:
 		/* success, we should be able to log in. if we fail, just
 		   disconnect the client. */
+                client->authenticating = FALSE;
 		client_send_tagline(client, "OK Logged in.");
 	}
 }
@@ -303,6 +308,7 @@
 			io_remove(client->common.io);
 		client->common.io = io_add(client->common.fd, IO_READ,
 					   client_auth_input, client);
+                client->authenticating = TRUE;
 	} else {
 		client_send_tagline(client, t_strconcat(
 			"NO Authentication failed: ", error, NULL));

Index: client.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap-login/client.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- client.c	23 Feb 2003 19:44:47 -0000	1.7
+++ client.c	4 Mar 2003 22:38:07 -0000	1.8
@@ -12,6 +12,7 @@
 #include "imap-parser.h"
 #include "client.h"
 #include "client-authenticate.h"
+#include "auth-connection.h"
 #include "ssl-proxy.h"
 
 /* max. size of one parameter in line */
@@ -184,10 +185,13 @@
 	return FALSE;
 }
 
-static void client_handle_input(struct imap_client *client)
+static int client_handle_input(struct imap_client *client)
 {
 	struct imap_arg *args;
 
+	if (client->authenticating)
+		return FALSE; /* wait until authentication is finished */
+
 	if (client->cmd_finished) {
 		/* clear the previous command from memory. don't do this
 		   immediately after handling command since we need the
@@ -199,7 +203,7 @@
 		/* remove \r\n */
 		if (client->skip_line) {
 			if (!client_skip_line(client))
-				return;
+				return TRUE;
                         client->skip_line = FALSE;
 		}
 
@@ -209,23 +213,23 @@
 	if (client->cmd_tag == NULL) {
                 client->cmd_tag = imap_parser_read_word(client->parser);
 		if (client->cmd_tag == NULL)
-			return; /* need more data */
+			return FALSE; /* need more data */
 	}
 
 	if (client->cmd_name == NULL) {
                 client->cmd_name = imap_parser_read_word(client->parser);
 		if (client->cmd_name == NULL)
-			return; /* need more data */
+			return FALSE; /* need more data */
 	}
 
 	switch (imap_parser_read_args(client->parser, 0, 0, &args)) {
 	case -1:
 		/* error */
 		client_destroy(client, NULL);
-		return;
+		return TRUE;
 	case -2:
 		/* not enough data */
-		return;
+		return FALSE;
 	}
 	client->skip_line = TRUE;
 
@@ -236,13 +240,14 @@
 				"* BYE Too many invalid IMAP commands.");
 			client_destroy(client, "Disconnected: "
 				       "Too many invalid commands");
-			return;
+			return FALSE;
 		} 
 		client_send_tagline(client,
 			"BAD Error in IMAP command received by server.");
 	}
 
 	client->cmd_finished = TRUE;
+	return TRUE;
 }
 
 int client_read(struct imap_client *client)
@@ -272,10 +277,19 @@
 	if (!client_read(client))
 		return;
 
+	if (!auth_is_connected()) {
+		/* we're not yet connected to auth process -
+		   don't allow any commands */
+		client_send_line(client,
+			"* OK Waiting for authentication process to respond..");
+		client->input_blocked = TRUE;
+		return;
+	}
+
 	client_ref(client);
 
 	o_stream_cork(client->output);
-	client_handle_input(client);
+	while (client_handle_input(client)) ;
 
 	if (client_unref(client))
 		o_stream_flush(client->output);
@@ -452,6 +466,22 @@
 unsigned int clients_get_count(void)
 {
 	return hash_size(clients);
+}
+
+static void client_hash_check_io(void *key, void *value __attr_unused__,
+				 void *context __attr_unused__)
+{
+	struct imap_client *client = key;
+
+	if (client->input_blocked) {
+		client->input_blocked = FALSE;
+		client_input(client);
+	}
+}
+
+void clients_notify_auth_process(void)
+{
+	hash_foreach(clients, client_hash_check_io, NULL);
 }
 
 static void client_hash_destroy(void *key, void *value __attr_unused__,

Index: client.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap-login/client.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- client.h	11 Feb 2003 16:56:36 -0000	1.3
+++ client.h	4 Mar 2003 22:38:07 -0000	1.4
@@ -25,6 +25,8 @@
 	unsigned int tls:1;
 	unsigned int cmd_finished:1;
 	unsigned int skip_line:1;
+	unsigned int input_blocked:1;
+	unsigned int authenticating:1;
 	unsigned int destroyed:1;
 };
 
@@ -40,9 +42,6 @@
 
 int client_read(struct imap_client *client);
 void client_input(void *context);
-
-unsigned int clients_get_count(void);
-void clients_destroy_all(void);
 
 void clients_init(void);
 void clients_deinit(void);




More information about the dovecot-cvs mailing list