From 6cd50869c2e33044f424050c0ae08fdeafee56fe Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Mon, 6 Nov 2023 11:07:01 +0200 Subject: [PATCH 1/3] Allow emails as usernames --- common/network/GetAPIMessager.cxx | 2 +- common/rfb/VNCSConnectionST.cxx | 4 ++-- common/rfb/VNCServerST.cxx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/network/GetAPIMessager.cxx b/common/network/GetAPIMessager.cxx index 17e53cd..dfc739e 100644 --- a/common/network/GetAPIMessager.cxx +++ b/common/network/GetAPIMessager.cxx @@ -550,7 +550,7 @@ void GetAPIMessager::netGetBottleneckStats(char *buf, uint32_t len) { const char *id = it->first.c_str(); const char *data = it->second.c_str(); - const char *at = strchr(id, '@'); + const char *at = strrchr(id, '@'); if (!at) continue; diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 3c0f3a9..c7eef87 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -88,7 +88,7 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s, wordfree(&wexp); user[0] = '\0'; - const char *at = strchr(peerEndpoint.buf, '@'); + const char *at = strrchr(peerEndpoint.buf, '@'); if (at && at - peerEndpoint.buf > 1 && at - peerEndpoint.buf < 32) { memcpy(user, peerEndpoint.buf, at - peerEndpoint.buf); user[at - peerEndpoint.buf] = '\0'; @@ -1635,7 +1635,7 @@ void VNCSConnectionST::sendStats(const bool toClient) { void VNCSConnectionST::handleFrameStats(rdr::U32 all, rdr::U32 render) { if (server->apimessager) { - const char *at = strchr(peerEndpoint.buf, '@'); + const char *at = strrchr(peerEndpoint.buf, '@'); if (!at) at = peerEndpoint.buf; else diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 9c1d64e..ffd186a 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -814,7 +814,7 @@ static void upgradeClientToUdp(const network::GetAPIMessager::action_data &act, inet_ntop(AF_INET, &act.udp.ip, buf, 32); const char * const who = (*ci)->getPeerEndpoint(); - const char *start = strchr(who, '@'); + const char *start = strrchr(who, '@'); if (!start) continue; start++; From 73c3bda8cd14ea2882b1f6b5065dc38ec219182c Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Mon, 6 Nov 2023 13:59:37 +0200 Subject: [PATCH 2/3] Fix off-by-one in username length check --- common/network/websocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/network/websocket.c b/common/network/websocket.c index 816eb2e..6aa6e90 100644 --- a/common/network/websocket.c +++ b/common/network/websocket.c @@ -1794,7 +1794,7 @@ ws_ctx_t *do_handshake(int sock, char * const ip) { if (resppw && *resppw) resppw++; if (settings.passwdfile) { - if (resppw && *resppw && resppw - response < 32) { + if (resppw && *resppw && resppw - response < USERNAME_LEN + 1) { char pwbuf[4096]; struct kasmpasswd_t *set = readkasmpasswd(settings.passwdfile); if (!set->num) { From fb7570709a623b6da7ab88c74cfc498174ccfc33 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Mon, 6 Nov 2023 15:22:23 +0200 Subject: [PATCH 3/3] Extend username limit to 128-1 --- common/network/websocket.c | 3 +-- common/network/websocket.h | 3 ++- common/rfb/VNCSConnectionST.cxx | 2 +- common/rfb/VNCSConnectionST.h | 4 +++- unix/kasmvncpasswd/kasmpasswd.h | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/common/network/websocket.c b/common/network/websocket.c index 6aa6e90..706c342 100644 --- a/common/network/websocket.c +++ b/common/network/websocket.c @@ -33,7 +33,6 @@ #include /* sha1 hash */ #include "websocket.h" #include "jsonescape.h" -#include "kasmpasswd.h" #include /* @@ -1756,7 +1755,7 @@ ws_ctx_t *do_handshake(int sock, char * const ip) { } unsigned char owner = 0; - char inuser[32] = "-"; + char inuser[USERNAME_LEN] = "-"; if (!settings.disablebasicauth) { const char *hdr = strstr(handshake, "Authorization: Basic "); if (!hdr) { diff --git a/common/network/websocket.h b/common/network/websocket.h index b5fc674..e9e8153 100644 --- a/common/network/websocket.h +++ b/common/network/websocket.h @@ -2,6 +2,7 @@ #include #include "GetAPIEnums.h" #include "datelog.h" +#include "kasmpasswd.h" #define BUFSIZE 65536 #define DBUFSIZE (BUFSIZE * 3) / 4 - 20 @@ -57,7 +58,7 @@ typedef struct { char *tin_buf; char *tout_buf; - char user[32]; + char user[USERNAME_LEN]; char ip[64]; } ws_ctx_t; diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index c7eef87..511e12c 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -89,7 +89,7 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s, user[0] = '\0'; const char *at = strrchr(peerEndpoint.buf, '@'); - if (at && at - peerEndpoint.buf > 1 && at - peerEndpoint.buf < 32) { + if (at && at - peerEndpoint.buf > 1 && at - peerEndpoint.buf < USERNAME_LEN) { memcpy(user, peerEndpoint.buf, at - peerEndpoint.buf); user[at - peerEndpoint.buf] = '\0'; } diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h index 654f44e..24d1863 100644 --- a/common/rfb/VNCSConnectionST.h +++ b/common/rfb/VNCSConnectionST.h @@ -35,6 +35,8 @@ #include #include +#include "kasmpasswd.h" + namespace rfb { class VNCServerST; @@ -318,7 +320,7 @@ namespace rfb { rdr::U64 bstats_total[BS_NUM]; struct timeval connStart; - char user[32]; + char user[USERNAME_LEN]; char kasmpasswdpath[4096]; bool needsPermCheck; diff --git a/unix/kasmvncpasswd/kasmpasswd.h b/unix/kasmvncpasswd/kasmpasswd.h index c6cbed0..ada8d03 100644 --- a/unix/kasmvncpasswd/kasmpasswd.h +++ b/unix/kasmvncpasswd/kasmpasswd.h @@ -6,7 +6,7 @@ extern "C" { #endif struct kasmpasswd_entry_t { - char user[32]; + char user[128]; char password[128]; unsigned char read : 1; unsigned char write : 1;