Module: ngircd.git Branch: master Commit: a6dd2e33c2c9e60bbd286bb07a7a6273566dec7d URL: http://ngircd.barton.de/cgi-bin/gitweb.cgi?p=ngircd.git&a=commit;h=a6dd2...
Author: Alexander Barton alex@barton.de Date: Sun Aug 26 12:33:21 2012 +0200
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.
---
src/ngircd/client.c | 10 ++++++++++ src/ngircd/conf.c | 21 +++++++++++++++++++++ src/ngircd/conf.h | 3 ++- src/ngircd/messages.h | 1 + 4 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/ngircd/client.c b/src/ngircd/client.c index 2466c71..f163f72 100644 --- a/src/ngircd/client.c +++ b/src/ngircd/client.c @@ -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, diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c index 16ad98c..41b5469 100644 --- a/src/ngircd/conf.c +++ b/src/ngircd/conf.c @@ -652,6 +652,27 @@ Conf_NickIsService(int ConfServer, const char *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. */ static void diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h index 72c8039..8e66c07 100644 --- a/src/ngircd/conf.h +++ b/src/ngircd/conf.h @@ -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]; diff --git a/src/ngircd/messages.h b/src/ngircd/messages.h index 96ff2de..9ad6be1 100644 --- a/src/ngircd/messages.h +++ b/src/ngircd/messages.h @@ -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"
ngircd-commits@lists.barton.de