changeset 22672:d811474ef901

director: Replace USER command during handshake with "U" This clearly differentiates the two commands and allows extending the USER command with new parameters without mixing it up with the handshake-USER.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sun, 26 Nov 2017 01:14:01 +0200
parents ad943b175750
children 867c3905ac0b
files src/director/director-connection.c src/director/director.h
diffstat 2 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/director/director-connection.c	Sun Nov 26 01:06:43 2017 +0200
+++ b/src/director/director-connection.c	Sun Nov 26 01:14:01 2017 +0200
@@ -96,8 +96,9 @@
 #  error DIRECTOR_CONNECTION_PONG_TIMEOUT_MSECS is too low
 #endif
 
-#define CMD_IS_USER_HANDHAKE(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"
 
@@ -765,8 +766,6 @@
 	struct user *user;
 	bool forced;
 
-	/* NOTE: if more parameters are added, update also
-	   CMD_IS_USER_HANDHAKE() macro */
 	if (str_array_length(args) != 2 ||
 	    str_to_uint(args[0], &username_hash) < 0 ||
 	    net_addr2ip(args[1], &ip) < 0) {
@@ -1462,7 +1461,10 @@
 		return director_cmd_host_hand_start(conn, args) ? 1 : -1;
 	}
 
-	if (conn->in && strcmp(cmd, "USER") == 0 && CMD_IS_USER_HANDHAKE(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 */
@@ -2036,9 +2038,16 @@
 
 	i_assert(conn->version_received);
 
+	/* 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, 0);
-		str_append(str, "USER\t");
+		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);
--- a/src/director/director.h	Sun Nov 26 01:06:43 2017 +0200
+++ b/src/director/director.h	Sun Nov 26 01:14:01 2017 +0200
@@ -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. */