From: Timo Sirainen Date: Wed, 8 Nov 2017 12:04:12 +0000 (+0200) Subject: doveadm-server: Add client_connection_tcp.preauthenticated X-Git-Tag: 2.3.0.rc1~490 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4addf3fa0e86065e0d23101de2332f3ef13d439b;p=thirdparty%2Fdovecot%2Fcore.git doveadm-server: Add client_connection_tcp.preauthenticated --- diff --git a/src/doveadm/client-connection-tcp.c b/src/doveadm/client-connection-tcp.c index 65239322c3..eb34085937 100644 --- a/src/doveadm/client-connection-tcp.c +++ b/src/doveadm/client-connection-tcp.c @@ -34,6 +34,7 @@ struct client_connection_tcp { struct ssl_iostream *ssl_iostream; bool handshaked:1; + bool preauthenticated:1; bool authenticated:1; bool io_setup:1; bool use_multiplex:1; @@ -566,18 +567,23 @@ client_connection_tcp_init_ssl(struct client_connection_tcp *conn) return 0; } -static void -client_connection_tcp_send_auth_handshake(struct client_connection_tcp * - 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_tcp_send_auth_handshake(struct client_connection_tcp *conn) +{ + if (conn->preauthenticated) { /* no need for client to authenticate */ conn->authenticated = TRUE; o_stream_nsend(conn->output, "+\n", 2); @@ -642,7 +648,9 @@ client_connection_tcp_create(int fd, int listen_fd, bool ssl) return NULL; } } - client_connection_tcp_send_auth_handshake(conn, listen_fd); + conn->preauthenticated = + client_connection_is_preauthenticated(listen_fd); + client_connection_tcp_send_auth_handshake(conn); client_connection_set_proctitle(&conn->conn, ""); return &conn->conn;