]> PatchyGit - patchyircd.git/commitdiff
don't allow deauthing with USER command
authorEgor <egor@patchysicp.xyz>
Thu, 25 Jan 2024 03:01:37 +0000 (05:01 +0200)
committerEgor <egor@patchysicp.xyz>
Thu, 25 Jan 2024 03:01:37 +0000 (05:01 +0200)
src/irc.c

index 08f2af6..ffb611e 100644 (file)
--- 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))