[dovecot-cvs] dovecot/src/master login-process.c, 1.80, 1.81 master-login-interface.h, 1.8, 1.9

tss at dovecot.org tss at dovecot.org
Wed Oct 11 13:17:30 UTC 2006


Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv12421/master

Modified Files:
	login-process.c master-login-interface.h 
Log Message:
Send inode number in login requests and verify that they match.



Index: login-process.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/login-process.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- login-process.c	8 Oct 2006 21:46:25 -0000	1.80
+++ login-process.c	11 Oct 2006 12:17:27 -0000	1.81
@@ -18,6 +18,7 @@
 
 #include <unistd.h>
 #include <syslog.h>
+#include <sys/stat.h>
 
 struct login_process {
 	struct login_group *group;
@@ -283,55 +284,95 @@
 	return FALSE;
 }
 
-static void login_process_input(void *context)
+static int
+login_read_request(struct login_process *p, struct master_login_request *req,
+		   int *client_fd_r)
 {
-	struct login_process *p = context;
-	struct auth_process *auth_process;
-	struct login_auth_request *authreq;
-	struct master_login_request req;
-	int client_fd;
+	struct stat st;
 	ssize_t ret;
 
-	if (p->group == NULL) {
-		/* we want to read the group */
-		if (!login_process_read_group(p))
-			login_process_destroy(p);
-		return;
-	}
+	*client_fd_r = -1;
 
-	ret = fd_read(p->fd, &req, sizeof(req), &client_fd);
-	if (ret >= (ssize_t)sizeof(req.version) &&
-	    req.version != MASTER_LOGIN_PROTOCOL_VERSION) {
+	ret = fd_read(p->fd, req, sizeof(*req), client_fd_r);
+	if (ret >= (ssize_t)sizeof(req->version) &&
+	    req->version != MASTER_LOGIN_PROTOCOL_VERSION) {
 		i_error("login: Protocol version mismatch "
 			"(mixed old and new binaries?)");
-		login_process_destroy(p);
-		return;
+		return -1;
 	}
 
-	if (ret != sizeof(req)) {
+	if (ret != sizeof(*req)) {
 		if (ret == 0) {
 			/* disconnected, ie. the login process died */
 		} else if (ret > 0) {
-			/* req wasn't fully read */
-			i_error("login: fd_read() couldn't read all req");
+			/* request wasn't fully read */
+			i_error("login: fd_read() returned partial %d", ret);
 		} else {
 			if (errno == EAGAIN)
-				return;
+				return 0;
 
 			i_error("login: fd_read() failed: %m");
 		}
+		return -1;
+	}
+
+	if (req->ino == (ino_t)-1) {
+		if (*client_fd_r != -1) {
+			i_error("login: Notification request sent "
+				"a file descriptor");
+			return -1;
+		}
+		return 1;
+	}
 
+	if (*client_fd_r == -1) {
+		i_error("login: Login request missing a file descriptor");
+		return -1;
+	}
+
+	if (fstat(*client_fd_r, &st) < 0) {
+		i_error("login: fstat(mail client) failed: %m");
+		return -1;
+	}
+
+	if (st.st_ino != req->ino) {
+		i_error("login: Login request inode mismatch: %s != %s",
+			dec2str(st.st_ino), dec2str(req->ino));
+		return -1;
+	}
+	return 1;
+}
+
+static void login_process_input(void *context)
+{
+	struct login_process *p = context;
+	struct auth_process *auth_process;
+	struct login_auth_request *authreq;
+	struct master_login_request req;
+	int client_fd;
+	ssize_t ret;
+
+	if (p->group == NULL) {
+		/* we want to read the group */
+		if (!login_process_read_group(p))
+			login_process_destroy(p);
+		return;
+	}
+
+	ret = login_read_request(p, &req, &client_fd);
+	if (ret == 0)
+		return;
+	if (ret < 0) {
 		if (client_fd != -1) {
 			if (close(client_fd) < 0)
-				i_error("close(mail client) failed: %m");
+				i_error("login: close(mail client) failed: %m");
 		}
-
 		login_process_destroy(p);
 		return;
 	}
 
-	if (client_fd == -1) {
-		/* just a notification that the login process */
+	if (req.ino == (ino_t)-1) {
+		/* state notification */
 		enum master_login_state state = req.tag;
 
 		if (!p->initialized) {

Index: master-login-interface.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/master-login-interface.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- master-login-interface.h	6 Aug 2006 20:05:36 -0000	1.8
+++ master-login-interface.h	11 Oct 2006 12:17:27 -0000	1.9
@@ -9,7 +9,7 @@
 
 /* Increase the version number every time master_login_request
    (or something else) is changed. */
-#define MASTER_LOGIN_PROTOCOL_VERSION 2
+#define MASTER_LOGIN_PROTOCOL_VERSION 3
 
 enum master_login_state {
 	/* process is accepting new connections */
@@ -31,6 +31,8 @@
 	uint32_t auth_pid;
 	uint32_t auth_id;
 
+	ino_t ino;
+
 	struct ip_addr local_ip, remote_ip;
 };
 



More information about the dovecot-cvs mailing list