Reduce clean_nick() code duplication further.

Side effect: hurt and monitor now allow nicks starting with a digit.
This commit is contained in:
Jilles Tjoelker 2015-12-13 00:22:21 +01:00
parent e1fda0d81e
commit 2d28539c68
7 changed files with 42 additions and 91 deletions

View file

@ -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))

View file

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

View file

@ -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

View file

@ -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);

View file

@ -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]);

View file

@ -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;

View file

@ -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