]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
director: Replace USER command during handshake with "U"
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 25 Nov 2017 23:14:01 +0000 (01:14 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 25 Nov 2017 23:14:01 +0000 (01:14 +0200)
This clearly differentiates the two commands and allows extending the USER
command with new parameters without mixing it up with the handshake-USER.

src/director/director-connection.c
src/director/director.h

index e764c6779ec0b2f4da99fef818282c47ba247146..67fe394b3c211b03a9946ea97f5da13eae2e26a7 100644 (file)
@@ -92,8 +92,9 @@
 #  error DIRECTOR_CONNECTION_PONG_TIMEOUT_MSECS is too low
 #endif
 
-#define CMD_IS_USER_HANDSHAKE(args) \
-       (str_array_length(args) > 2)
+#define CMD_IS_USER_HANDSHAKE(minor_version, args) \
+       ((minor_version) < DIRECTOR_VERSION_HANDSHAKE_U_CMD && \
+        str_array_length(args) > 2)
 
 #define DIRECTOR_OPT_CONSISTENT_HASHING "consistent-hashing"
 
@@ -761,8 +762,6 @@ director_cmd_user(struct director_connection *conn,
        struct user *user;
        bool forced;
 
-       /* NOTE: if more parameters are added, update also
-          CMD_IS_USER_HANDSHAKE() macro */
        if (str_array_length(args) != 2 ||
            str_to_uint(args[0], &username_hash) < 0 ||
            net_addr2ip(args[1], &ip) < 0) {
@@ -1460,7 +1459,10 @@ director_connection_handle_handshake(struct director_connection *conn,
                return director_cmd_host_hand_start(conn, args) ? 1 : -1;
        }
 
-       if (conn->in && strcmp(cmd, "USER") == 0 && CMD_IS_USER_HANDSHAKE(args))
+       if (conn->in &&
+           (strcmp(cmd, "U") == 0 ||
+            (strcmp(cmd, "USER") == 0 &&
+             CMD_IS_USER_HANDSHAKE(conn->minor_version, args))))
                return director_handshake_cmd_user(conn, args) ? 1 : -1;
 
        /* both get DONE */
@@ -2034,9 +2036,16 @@ static int director_connection_send_users(struct director_connection *conn)
 
        i_assert(conn->version_received);
 
-       while ((user = director_iterate_users_next(conn->user_iter)) != NULL) {
-               str_truncate(str, 0);
+       /* with new versions use "U" for sending the handshake users, because
+          otherwise their parameters may look identical and can't be
+          distinguished. */
+       if (director_connection_get_minor_version(conn) >= DIRECTOR_VERSION_HANDSHAKE_U_CMD)
+               str_append(str, "U\t");
+       else
                str_append(str, "USER\t");
+       size_t cmd_prefix_len = str_len(str);
+       while ((user = director_iterate_users_next(conn->user_iter)) != NULL) {
+               str_truncate(str, cmd_prefix_len);
                str_append(str, dec2str_buf(dec_buf, user->username_hash));
                str_append_c(str, '\t');
                str_append(str, user->host->ip_str);
index 2f582aa661abc4aa46048c4a1b47e2806d50417d..1f99823920d3c350783fcb9ae70361bf9ae26d0d 100644 (file)
@@ -6,7 +6,7 @@
 
 #define DIRECTOR_VERSION_NAME "director"
 #define DIRECTOR_VERSION_MAJOR 1
-#define DIRECTOR_VERSION_MINOR 8
+#define DIRECTOR_VERSION_MINOR 9
 
 /* weak users supported in protocol */
 #define DIRECTOR_VERSION_WEAK_USERS 1
@@ -26,6 +26,8 @@
 #define DIRECTOR_VERSION_TAGS_V2 7
 /* user-kick-alt supported */
 #define DIRECTOR_VERSION_USER_KICK_ALT 8
+/* Users are sent as "U" command in handshake */
+#define DIRECTOR_VERSION_HANDSHAKE_U_CMD 9
 
 /* Minimum time between even attempting to communicate with a director that
    failed due to a protocol error. */