[dovecot-cvs] dovecot/src/auth Makefile.am, 1.36, 1.37 auth-client-connection.c, 1.17, 1.18 auth-client-connection.h, 1.3, 1.4 auth-client-interface.h, 1.9, 1.10 auth-master-connection.c, 1.14, 1.15 auth-master-connection.h, 1.5, 1.6 auth-master-interface.h, 1.6, 1.7

cras at dovecot.org cras at dovecot.org
Tue Oct 19 03:51:23 EEST 2004


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv16627/auth

Modified Files:
	Makefile.am auth-client-connection.c auth-client-connection.h 
	auth-client-interface.h auth-master-connection.c 
	auth-master-connection.h 
Added Files:
	auth-master-interface.h 
Log Message:
Added VERSION command and checking to authentication protocol.



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/Makefile.am,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- Makefile.am	15 Oct 2004 23:12:52 -0000	1.36
+++ Makefile.am	19 Oct 2004 00:51:21 -0000	1.37
@@ -69,6 +69,7 @@
 noinst_HEADERS = \
 	auth-client-connection.h \
 	auth-client-interface.h \
+	auth-master-interface.h \
 	auth-master-connection.h \
 	auth-module.h \
 	db-ldap.h \

Index: auth-client-connection.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-client-connection.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- auth-client-connection.c	18 Oct 2004 23:03:55 -0000	1.17
+++ auth-client-connection.c	19 Oct 2004 00:51:21 -0000	1.18
@@ -361,6 +361,24 @@
 		return;
 	}
 
+	if (!conn->version_received) {
+		line = i_stream_next_line(conn->input);
+		if (line == NULL)
+			return;
+
+		/* make sure the major version matches */
+		if (strncmp(line, "VERSION\t", 8) != 0 ||
+		    atoi(t_strcut(line + 8, '.')) !=
+		    AUTH_CLIENT_PROTOCOL_MAJOR_VERSION) {
+			i_error("Authentication client %u "
+				"not compatible with this server "
+				"(mixed old and new binaries?)", conn->pid);
+			auth_client_connection_destroy(conn);
+			return;
+		}
+		conn->version_received = TRUE;
+	}
+
 	conn->refcount++;
 	while ((line = i_stream_next_line(conn->input)) != NULL) {
 		t_push();
@@ -419,7 +437,9 @@
 	master->clients = conn;
 
 	str = t_str_new(128);
-	str_printfa(str, "SPID\t%u\nCUID\t%u\nDONE\n",
+	str_printfa(str, "VERSION\t%u.%u\nSPID\t%u\nCUID\t%u\nDONE\n",
+                    AUTH_CLIENT_PROTOCOL_MAJOR_VERSION,
+                    AUTH_CLIENT_PROTOCOL_MINOR_VERSION,
 		    master->pid, conn->connect_uid);
 
 	iov[0].iov_base = str_data(mech_handshake);

Index: auth-client-connection.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-client-connection.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- auth-client-connection.h	13 Oct 2004 16:38:32 -0000	1.3
+++ auth-client-connection.h	19 Oct 2004 00:51:21 -0000	1.4
@@ -18,6 +18,7 @@
 
 	unsigned int pid;
 	unsigned int connect_uid;
+	unsigned int version_received:1;
 };
 
 struct auth_client_connection *

Index: auth-client-interface.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-client-interface.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- auth-client-interface.h	13 Oct 2004 16:38:32 -0000	1.9
+++ auth-client-interface.h	19 Oct 2004 00:51:21 -0000	1.10
@@ -1,6 +1,11 @@
 #ifndef __AUTH_CLIENT_INTERFACE_H
 #define __AUTH_CLIENT_INTERFACE_H
 
+/* Major version changes are not backwards compatible,
+   minor version numbers can be ignored. */
+#define AUTH_CLIENT_PROTOCOL_MAJOR_VERSION 1
+#define AUTH_CLIENT_PROTOCOL_MINOR_VERSION 0
+
 #define AUTH_CLIENT_MAX_LINE_LENGTH 8192
 #define AUTH_REQUEST_TIMEOUT 120
 

Index: auth-master-connection.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-master-connection.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- auth-master-connection.c	15 Oct 2004 23:12:52 -0000	1.14
+++ auth-master-connection.c	19 Oct 2004 00:51:21 -0000	1.15
@@ -10,6 +10,7 @@
 #include "network.h"
 #include "mech.h"
 #include "userdb.h"
+#include "auth-master-interface.h"
 #include "auth-client-connection.h"
 #include "auth-master-connection.h"
 
@@ -168,6 +169,23 @@
 		return;
 	}
 
+	if (!conn->version_received) {
+		line = i_stream_next_line(conn->input);
+		if (line == NULL)
+			return;
+
+		/* make sure the major version matches */
+		if (strncmp(line, "VERSION\t", 8) != 0 ||
+		    atoi(t_strcut(line + 8, '.')) !=
+		    AUTH_MASTER_PROTOCOL_MAJOR_VERSION) {
+			i_error("Master not compatible with this server "
+				"(mixed old and new binaries?)");
+			auth_master_connection_close(conn);
+			return;
+		}
+		conn->version_received = TRUE;
+	}
+
 	while ((line = i_stream_next_line(conn->input)) != NULL) {
 		t_push();
 		if (strncmp(line, "REQUEST\t", 8) == 0)
@@ -241,10 +259,11 @@
 
 void auth_master_connection_send_handshake(struct auth_master_connection *conn)
 {
-	/* just a note to master that we're ok. if we die before, it means
-	   we're broken and a simple restart most likely won't help. */
-	if (conn->output != NULL)
-		master_send(conn, "SPID\t%u", conn->pid);
+	if (conn->output != NULL) {
+		master_send(conn, "VERSION\t%u.%u\n",
+			    AUTH_MASTER_PROTOCOL_MAJOR_VERSION,
+                            AUTH_MASTER_PROTOCOL_MINOR_VERSION);
+	}
 }
 
 static void auth_master_connection_close(struct auth_master_connection *conn)

Index: auth-master-connection.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-master-connection.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- auth-master-connection.h	13 Oct 2004 16:38:32 -0000	1.5
+++ auth-master-connection.h	19 Oct 2004 00:51:21 -0000	1.6
@@ -14,6 +14,7 @@
 	struct auth_client_connection *clients;
 	struct timeout *to_clients;
 
+	unsigned int version_received:1;
 	unsigned int destroyed:1;
 };
 




More information about the dovecot-cvs mailing list