Skip to content

Commit

Permalink
s_user: reject invalid usernames before anything else
Browse files Browse the repository at this point in the history
This way invalid characters in usernames only appear in this snote, and
all other rejection snotes will always have clean usernames.
  • Loading branch information
dwfreed committed Jun 13, 2024
1 parent 246ae21 commit beffef4
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions ircd/s_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,32 @@ register_local_user(struct Client *client_p, struct Client *source_p)
if(source_p->preClient->auth.cid)
return -1;

/* valid user name check */

if(!valid_username(source_p->username))
{
sendto_realops_snomask(SNO_REJ, L_NETWIDE,
"Invalid username: %s (%s@%s)",
source_p->name, source_p->username, source_p->host);

const char *illegal_name_long_client_message = ConfigFileEntry.illegal_name_long_client_message;
const char *illegal_name_short_client_message = ConfigFileEntry.illegal_name_short_client_message;

if (illegal_name_long_client_message == NULL)
illegal_name_long_client_message = "Your username is invalid. Please make sure that your username contains "
"only alphanumeric characters.";
if (illegal_name_short_client_message == NULL)
illegal_name_short_client_message = "Invalid username";

ServerStats.is_ref++;
sendto_one_notice(source_p, ":*** %s", illegal_name_long_client_message);
sprintf(tmpstr2, "%s [%s]", illegal_name_short_client_message, source_p->username);
exit_client(client_p, source_p, &me, tmpstr2);
return (CLIENT_EXITED);
}

/* end of valid user name check */

/* Set firsttime here so that post_registration_delay works from registration,
* rather than initial connection. */
source_p->localClient->firsttime = client_p->localClient->last = rb_current_time();
Expand Down Expand Up @@ -593,32 +619,6 @@ register_local_user(struct Client *client_p, struct Client *source_p)
if(authd_check(client_p, source_p))
return CLIENT_EXITED;

/* valid user name check */

if(!valid_username(source_p->username))
{
sendto_realops_snomask(SNO_REJ, L_NETWIDE,
"Invalid username: %s (%s@%s)",
source_p->name, source_p->username, source_p->host);

const char *illegal_name_long_client_message = ConfigFileEntry.illegal_name_long_client_message;
const char *illegal_name_short_client_message = ConfigFileEntry.illegal_name_short_client_message;

if (illegal_name_long_client_message == NULL)
illegal_name_long_client_message = "Your username is invalid. Please make sure that your username contains "
"only alphanumeric characters.";
if (illegal_name_short_client_message == NULL)
illegal_name_short_client_message = "Invalid username";

ServerStats.is_ref++;
sendto_one_notice(source_p, ":*** %s", illegal_name_long_client_message);
sprintf(tmpstr2, "%s [%s]", illegal_name_short_client_message, source_p->username);
exit_client(client_p, source_p, &me, tmpstr2);
return (CLIENT_EXITED);
}

/* end of valid user name check */

/* Store original hostname -- jilles */
rb_strlcpy(source_p->orighost, source_p->host, HOSTLEN + 1);

Expand Down

0 comments on commit beffef4

Please sign in to comment.