changeset 2791:b12e61e55c01 HEAD

Put SPID back, it's needed for standalone dovecot-auth.
author Timo Sirainen <tss@iki.fi>
date Wed, 20 Oct 2004 20:49:02 +0300
parents 02c0b8d532c2
children 7cc03b8278a8
files src/auth/auth-master-connection.c src/master/auth-process.c
diffstat 2 files changed, 34 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/auth-master-connection.c	Wed Oct 20 20:07:32 2004 +0300
+++ b/src/auth/auth-master-connection.c	Wed Oct 20 20:49:02 2004 +0300
@@ -261,9 +261,9 @@
 void auth_master_connection_send_handshake(struct auth_master_connection *conn)
 {
 	if (conn->output != NULL) {
-		master_send(conn, "VERSION\t%u.%u\n",
+		master_send(conn, "VERSION\t%u.%u\nSPID\t%u\n",
 			    AUTH_MASTER_PROTOCOL_MAJOR_VERSION,
-                            AUTH_MASTER_PROTOCOL_MINOR_VERSION);
+                            AUTH_MASTER_PROTOCOL_MINOR_VERSION, conn->pid);
 	}
 }
 
--- a/src/master/auth-process.c	Wed Oct 20 20:07:32 2004 +0300
+++ b/src/master/auth-process.c	Wed Oct 20 20:49:02 2004 +0300
@@ -46,6 +46,7 @@
 	struct hash_table *requests;
 
 	unsigned int external:1;
+	unsigned int version_received:1;
 	unsigned int initialized:1;
 	unsigned int in_auth_reply:1;
 };
@@ -136,6 +137,33 @@
 }
 
 static int
+auth_process_input_spid(struct auth_process *process, const char *args)
+{
+	unsigned int pid;
+
+	if (process->initialized) {
+		i_error("BUG: Authentication server re-handshaking");
+		return FALSE;
+	}
+
+	pid = (unsigned int)strtoul(args, NULL, 10);
+	if (pid == 0) {
+		i_error("BUG: Authentication server said it's PID 0");
+		return FALSE;
+	}
+
+	if (process->pid != 0 && process->pid != (pid_t)pid) {
+		i_error("BUG: Authentication server sent invalid SPID "
+			"(%u != %s)", pid, dec2str(process->pid));
+		return FALSE;
+	}
+
+	process->pid = pid;
+        process->initialized = TRUE;
+	return TRUE;
+}
+
+static int
 auth_process_input_fail(struct auth_process *process, const char *args)
 {
 	void *context;
@@ -182,7 +210,7 @@
 		return;
 	}
 
-	if (!process->initialized) {
+	if (!process->version_received) {
 		line = i_stream_next_line(process->input);
 		if (line == NULL)
 			return;
@@ -197,7 +225,7 @@
 			auth_process_destroy(process);
 			return;
 		}
-		process->initialized = TRUE;
+		process->version_received = TRUE;
 	}
 
 	while ((line = i_stream_next_line(process->input)) != NULL) {
@@ -208,6 +236,8 @@
 			ret = auth_process_input_notfound(process, line + 9);
 		else if (strncmp(line, "FAIL\t", 5) == 0)
 			ret = auth_process_input_fail(process, line + 5);
+		else if (strncmp(line, "SPID\t", 5) == 0)
+			ret = auth_process_input_spid(process, line + 5);
 		else
 			ret = TRUE;
 		t_pop();