diff --git a/extensions/hurt.c b/extensions/hurt.c index 68615897..ca187346 100644 --- a/extensions/hurt.c +++ b/extensions/hurt.c @@ -311,7 +311,7 @@ mo_heal(struct Client *client_p, struct Client *source_p, return 0; } - if (is_valid_nick(parv[1])) + if (clean_nick(parv[1], 0)) { target_p = find_named_person(parv[1]); if (target_p == NULL) @@ -363,7 +363,7 @@ me_heal(struct Client *client_p, struct Client *source_p, if (parc < 2) return 0; - if (is_valid_nick(parv[1])) + if (clean_nick(parv[1], 0)) { target_p = find_person(parv[1]); if (target_p != NULL && MyConnect(target_p)) diff --git a/include/client.h b/include/client.h index 7f32b400..ddf64375 100644 --- a/include/client.h +++ b/include/client.h @@ -592,6 +592,8 @@ extern void error_exit_client(struct Client *, int); extern void count_local_client_memory(size_t * count, size_t * memory); extern void count_remote_client_memory(size_t * count, size_t * memory); +extern int clean_nick(const char *, int loc_client); + extern struct Client *find_chasing(struct Client *, const char *, int *); extern struct Client *find_person(const char *); extern struct Client *find_named_person(const char *); @@ -616,25 +618,4 @@ extern char *generate_uid(void); void allocate_away(struct Client *); void free_away(struct Client *); -static inline int -is_valid_nick(const char *nick) -{ - int len = 0; - - if(EmptyString(nick) || *nick == '-' || IsDigit(*nick)) - return 0; - - for(; *nick; nick++) - { - len++; - if(!IsNickChar(*nick)) - return 0; - } - - if(len >= NICKLEN) - return 0; - - return 1; -} - #endif /* INCLUDED_client_h */ diff --git a/modules/core/m_nick.c b/modules/core/m_nick.c index ff0878b4..a028a58c 100644 --- a/modules/core/m_nick.c +++ b/modules/core/m_nick.c @@ -92,7 +92,6 @@ DECLARE_MODULE_AV1(nick, NULL, NULL, nick_clist, NULL, NULL, "$Revision: 3518 $" static int change_remote_nick(struct Client *, struct Client *, time_t, const char *, int); -static int clean_nick(const char *, int loc_client); static int clean_username(const char *); static int clean_host(const char *); static int clean_uid(const char *uid, const char *sid); @@ -525,38 +524,6 @@ ms_save(struct Client *client_p, struct Client *source_p, int parc, const char * return 0; } -/* clean_nick() - * - * input - nickname to check - * output - 0 if erroneous, else 1 - * side effects - - */ -static int -clean_nick(const char *nick, int loc_client) -{ - int len = 0; - - /* nicks cant start with a digit or -, and must have a length */ - if(*nick == '-' || *nick == '\0') - return 0; - - if(loc_client && IsDigit(*nick)) - return 0; - - for(; *nick; nick++) - { - len++; - if(!IsNickChar(*nick)) - return 0; - } - - /* nicklen is +1 */ - if(len >= NICKLEN && (unsigned int)len >= ConfigFileEntry.nicklen) - return 0; - - return 1; -} - /* clean_username() * * input - username to check diff --git a/modules/m_monitor.c b/modules/m_monitor.c index aa003f2e..2c81d39c 100644 --- a/modules/m_monitor.c +++ b/modules/m_monitor.c @@ -114,7 +114,7 @@ add_monitor(struct Client *client_p, const char *nicks) return; } - if (!is_valid_nick(name)) + if (!clean_nick(name, 0)) continue; monptr = find_monitor(name, 1); diff --git a/modules/m_services.c b/modules/m_services.c index a1c93be6..9a51f64b 100644 --- a/modules/m_services.c +++ b/modules/m_services.c @@ -176,7 +176,7 @@ me_rsfnc(struct Client *client_p, struct Client *source_p, if(!MyClient(target_p)) return 0; - if(!is_valid_nick(parv[2])) + if(!clean_nick(parv[2], 0) || IsDigit(parv[2][0])) return 0; curts = atol(parv[4]); diff --git a/modules/m_signon.c b/modules/m_signon.c index ce79de81..f7fb8eb9 100644 --- a/modules/m_signon.c +++ b/modules/m_signon.c @@ -75,35 +75,6 @@ DECLARE_MODULE_AV1(signon, NULL, NULL, signon_clist, NULL, NULL, "$Revision: 119 #define USER_VALID 2 #define HOST_VALID 4 -static int -clean_nick(const char *nick) -{ - int len = 0; - - if(*nick == '-') - return 0; - - /* This is used to check logins, which are often - * numeric. Don't check for leading digits, if - * services wants to set someone's nick to something - * starting with a number, let it try. - * --gxti - */ - - for (; *nick; nick++) - { - len++; - if(!IsNickChar(*nick)) - return 0; - } - - /* nicklen is +1 */ - if(len >= NICKLEN) - return 0; - - return 1; -} - static int clean_username(const char *username) { @@ -164,7 +135,7 @@ me_svslogin(struct Client *client_p, struct Client *source_p, if(!MyClient(target_p) && !IsUnknown(target_p)) return 0; - if(clean_nick(parv[2])) + if(clean_nick(parv[2], 0)) { rb_strlcpy(nick, parv[2], NICKLEN + 1); valid |= NICK_VALID; @@ -203,7 +174,7 @@ me_svslogin(struct Client *client_p, struct Client *source_p, rb_strlcpy(login, parv[5], NICKLEN + 1); /* Login (mostly) follows nick rules. */ - if(*login && !clean_nick(login)) + if(*login && !clean_nick(login, 0)) return 0; if((exist_p = find_person(nick)) && target_p != exist_p) @@ -280,7 +251,7 @@ ms_signon(struct Client *client_p, struct Client *source_p, int newts, sameuser; char login[NICKLEN+1]; - if(!clean_nick(parv[1])) + if(!clean_nick(parv[1], 0)) { ServerStats.is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, @@ -322,7 +293,7 @@ ms_signon(struct Client *client_p, struct Client *source_p, login[0] = '\0'; else if(*parv[5] != '*') { - if (clean_nick(parv[5])) + if (clean_nick(parv[5], 0)) rb_strlcpy(login, parv[5], NICKLEN + 1); else return 0; diff --git a/src/client.c b/src/client.c index 64ab07f1..32dcefbb 100644 --- a/src/client.c +++ b/src/client.c @@ -787,6 +787,38 @@ remove_client_from_list(struct Client *client_p) } +/* clean_nick() + * + * input - nickname to check, flag for nick from local client + * output - 0 if erroneous, else 1 + * side effects - + */ +int +clean_nick(const char *nick, int loc_client) +{ + int len = 0; + + /* nicks cant start with a digit or -, and must have a length */ + if(*nick == '-' || *nick == '\0') + return 0; + + if(loc_client && IsDigit(*nick)) + return 0; + + for(; *nick; nick++) + { + len++; + if(!IsNickChar(*nick)) + return 0; + } + + /* nicklen is +1 */ + if(len >= NICKLEN && (unsigned int)len >= ConfigFileEntry.nicklen) + return 0; + + return 1; +} + /* * find_person - find person by (nick)name. * inputs - pointer to name