]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-urlauth: imap-urlauth-worker - Perform client-to-server VERSION handshake in...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 21 Feb 2023 02:27:39 +0000 (03:27 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 24 Mar 2023 07:14:54 +0000 (07:14 +0000)
src/imap-urlauth/imap-urlauth-worker.c

index 5b6cf6a0d416b21853a653245535628675e6eb7d..63b345a41fd2dc4cb5615d762da1a3a712525243 100644 (file)
@@ -756,6 +756,30 @@ static int client_ctrl_read_fds(struct client *client)
        return 1;
 }
 
+static int client_ctrl_handshake(struct client *client)
+{
+       if (client->version_received)
+               return 1;
+
+       const char *line;
+
+       line = i_stream_next_line(client->conn_ctrl.input);
+       if (line == NULL)
+               return 0;
+
+       if (!version_string_verify(line, "imap-urlauth-worker",
+                       IMAP_URLAUTH_WORKER_PROTOCOL_MAJOR_VERSION)) {
+               e_error(client->event,
+                       "imap-urlauth-worker client not compatible with this server "
+                       "(mixed old and new binaries?) %s", line);
+               client_abort(client, "Control session aborted: Version mismatch");
+               return -1;
+       }
+
+       client->version_received = TRUE;
+       return 1;
+}
+
 static void client_ctrl_input(struct connection *_conn)
 {
        struct client *client = container_of(_conn, struct client, conn_ctrl);
@@ -767,23 +791,8 @@ static void client_ctrl_input(struct connection *_conn)
 
        if (connection_input_read(&client->conn_ctrl) < 0)
                return;
-
-       if (!client->version_received) {
-               line = i_stream_next_line(client->conn_ctrl.input);
-               if (line == NULL)
-                       return;
-
-               if (!version_string_verify(line, "imap-urlauth-worker",
-                               IMAP_URLAUTH_WORKER_PROTOCOL_MAJOR_VERSION)) {
-                       e_error(client->event,
-                               "imap-urlauth-worker client not compatible with this server "
-                               "(mixed old and new binaries?) %s", line);
-                       client_abort(client, "Control session aborted: Version mismatch");
-                       return;
-               }
-
-               client->version_received = TRUE;
-       }
+       if (client_ctrl_handshake(client) <= 0)
+               return;
 
        if (client->conn.fd_in == -1 || client->conn.fd_out == -1) {
                if ((ret = client_ctrl_read_fds(client)) <= 0) {