changeset 22748:597c668f887a

doveadm-server: Add client_connection.preauthenticated
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 08 Nov 2017 14:04:12 +0200
parents 01e96a26135c
children 7c10968dc541
files src/doveadm/client-connection.c src/doveadm/client-connection.h
diffstat 2 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/client-connection.c	Tue Oct 31 23:37:44 2017 +0200
+++ b/src/doveadm/client-connection.c	Wed Nov 08 14:04:12 2017 +0200
@@ -596,18 +596,23 @@
 	return 0;
 }
 
-static void
-client_connection_send_auth_handshake(struct client_connection *
-				      conn, int listen_fd)
+static bool
+client_connection_is_preauthenticated(int listen_fd)
 {
 	const char *listen_path;
 	struct stat st;
 
 	/* we'll have to do this with stat(), because at least in Linux
 	   fstat() always returns mode as 0777 */
-	if (net_getunixname(listen_fd, &listen_path) == 0 &&
-	    stat(listen_path, &st) == 0 && S_ISSOCK(st.st_mode) &&
-	    (st.st_mode & 0777) == 0600) {
+	return net_getunixname(listen_fd, &listen_path) == 0 &&
+		stat(listen_path, &st) == 0 && S_ISSOCK(st.st_mode) &&
+		(st.st_mode & 0777) == 0600;
+}
+
+static void
+client_connection_send_auth_handshake(struct client_connection *conn)
+{
+	if (conn->preauthenticated) {
 		/* no need for client to authenticate */
 		conn->authenticated = TRUE;
 		o_stream_nsend(conn->output, "+\n", 2);
@@ -665,7 +670,10 @@
 			return NULL;
 		}
 	}
-	client_connection_send_auth_handshake(conn, listen_fd);
+	conn->preauthenticated =
+		client_connection_is_preauthenticated(listen_fd);
+	client_connection_send_auth_handshake(conn);
+
 	client_connection_set_proctitle(conn, "");
 
 	return conn;
--- a/src/doveadm/client-connection.h	Tue Oct 31 23:37:44 2017 +0200
+++ b/src/doveadm/client-connection.h	Wed Nov 08 14:04:12 2017 +0200
@@ -21,6 +21,7 @@
 	const struct doveadm_settings *set;
 
 	unsigned int handshaked:1;
+	unsigned int preauthenticated:1;
 	unsigned int authenticated:1;
 	unsigned int io_setup:1;
 	unsigned int use_multiplex:1;