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 4620255 commit 62e860d
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 @@ -409,6 +409,32 @@ register_local_user(struct Client *client_p, struct Client *source_p)
else
rb_strlcpy(notildeusername, source_p->username, sizeof notildeusername);

/* 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 */

if((status = check_client(client_p, source_p, notildeusername)) < 0)
return (CLIENT_EXITED);

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 62e860d

Please sign in to comment.