Block nicknames that are reserved for services

This patch introduces the new function Conf_NickIsBlocked() which checks
if a given nick name matches with the "service mask" of a configured server.
And Client_CheckNick() uses this information to deny such names for regular
IRC users.

So nick names intended for IRC services are more protected and can't be used
by regular users even when the "services pseudo-server" isn't connected to
the network.

But please note:

Up to now, there can be only one "ServiceMask" pattern per server, which
most probably blocks much more nick names than really required ...
So "ServiceMask" should allow more than one pattern which can be more
specific, and most probably it should be possible to block nick names in
the global server configuration as well.

Nick names introduced by other servers/services are never restricted.
This commit is contained in:
Alexander Barton 2012-08-26 12:33:21 +02:00
parent 9d8974d509
commit a6dd2e33c2
4 changed files with 34 additions and 1 deletions

View File

@ -905,6 +905,16 @@ Client_CheckNick(CLIENT *Client, char *Nick)
return false;
}
if (Client_Type(Client) != CLIENT_SERVER
&& Client_Type(Client) != CLIENT_SERVICE) {
/* Make sure that this isn't a restricted/forbidden nick name */
if (Conf_NickIsBlocked(Nick)) {
IRC_WriteStrClient(Client, ERR_FORBIDDENNICKNAME_MSG,
Client_ID(Client), Nick);
return false;
}
}
/* Nickname already registered? */
if (Client_Search(Nick)) {
IRC_WriteStrClient(Client, ERR_NICKNAMEINUSE_MSG,

View File

@ -651,6 +651,27 @@ Conf_NickIsService(int ConfServer, const char *Nick)
return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
}
/**
* Check if the given nick name is blocked for "normal client" use.
*
* @param ConfServer The server index or NONE to check all configured servers.
* @param Nick The nick name to check.
* @returns true if the given nick name belongs to an "IRC service".
*/
GLOBAL bool
Conf_NickIsBlocked(const char *Nick)
{
int i;
for(i = 0; i < MAX_SERVERS; i++) {
if (!Conf_Server[i].name[0])
continue;
if (Conf_NickIsService(i, Nick))
return true;
}
return false;
}
/**
* Initialize configuration settings with their default values.
*/

View File

@ -1,6 +1,6 @@
/*
* ngIRCd -- The Next Generation IRC Daemon
* Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
* Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -245,6 +245,7 @@ GLOBAL bool Conf_DisableServer PARAMS(( const char *Name ));
GLOBAL bool Conf_AddServer PARAMS(( const char *Name, UINT16 Port, const char *Host, const char *MyPwd, const char *PeerPwd ));
GLOBAL bool Conf_NickIsService PARAMS((int ConfServer, const char *Nick));
GLOBAL bool Conf_NickIsBlocked PARAMS((const char *Nick));
/* Password required by WEBIRC command */
GLOBAL char Conf_WebircPwd[CLIENT_PASS_LEN];

View File

@ -112,6 +112,7 @@
#define ERR_NONICKNAMEGIVEN_MSG "431 %s :No nickname given"
#define ERR_ERRONEUSNICKNAME_MSG "432 %s %s :Erroneous nickname"
#define ERR_NICKNAMETOOLONG_MSG "432 %s %s :Nickname too long, max. %u characters"
#define ERR_FORBIDDENNICKNAME_MSG "432 %s %s :Nickname is forbidden/blocked"
#define ERR_NICKNAMEINUSE_MSG "433 %s %s :Nickname already in use"
#define ERR_USERNOTINCHANNEL_MSG "441 %s %s %s :They aren't on that channel"
#define ERR_NOTONCHANNEL_MSG "442 %s %s :You are not on that channel"