]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm-server: Add client_connection_tcp.preauthenticated
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 8 Nov 2017 12:04:12 +0000 (14:04 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 8 Nov 2017 12:05:57 +0000 (14:05 +0200)
src/doveadm/client-connection-tcp.c

index 65239322c347c322dcef41ed2fc7836aff292869..eb340859376220c74f904565142ce71174d47496 100644 (file)
@@ -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;