From: Egor Date: Thu, 25 Jan 2024 03:01:37 +0000 (+0200) Subject: don't allow deauthing with USER command X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=6e2b1aaa0f6dd717d808230b1644026128e1bd25;p=patchyircd.git don't allow deauthing with USER command --- diff --git a/src/irc.c b/src/irc.c index 08f2af6..ffb611e 100644 --- a/src/irc.c +++ b/src/irc.c @@ -409,23 +409,25 @@ saslcleanup: } else if(strcmp(command, "USER") == 0) { if (argc < 4) return err_needmoreparams(client, command), sendbuf(client), 0; - // set username if (is_registered(client)) return err_alreadyregistered(client), sendbuf(client), 0; - free(client->username); - size_t ulen = strlen(args[0]); - client->username = malloc(ulen+2); - if (!client->username) - abort(); - client->umode &= ~UMODE_REGISTERED; - client->username[0] = '~'; - memcpy(client->username + 1, args[0], ulen+1); + // set username, but only if we didn't auth yet + if (!client->username || client->username[0] == '~') { + free(client->username); + size_t ulen = strlen(args[0]); + client->username = malloc(ulen+2); + if (!client->username) + abort(); + client->umode &= ~UMODE_REGISTERED; + client->username[0] = '~'; + memcpy(client->username + 1, args[0], ulen+1); + } // set realname - free(client->realname); // ditto + free(client->realname); client->realname = mystrdup(args[3]); if (!client->realname) abort(); - // Send welcome + // proceed with registration newUser(client); } else if(strcmp(command, "PASS") == 0) { if (is_registered(client))