]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Block nicknames that are reserved for services
authorAlexander Barton <alex@barton.de>
Sun, 26 Aug 2012 10:33:21 +0000 (12:33 +0200)
committerAlexander Barton <alex@barton.de>
Sun, 26 Aug 2012 10:33:21 +0000 (12:33 +0200)
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
src/ngircd/conf.c
src/ngircd/conf.h
src/ngircd/messages.h

index 2466c7175a3bd11eb52000a62e03baf355d56196..f163f72c371e2a84121a84d178c3552530109b3d 100644 (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,
index 16ad98c21a40c185cc5b371f387e0372a3ee2cbe..41b5469a8140f4c5a07d1874dd6d048fcbf6ae3b 100644 (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.
  */
index 72c80390642c905759f56ed27f378c6c4024d413..8e66c07c3c671f3ecf119fc50f6fc313cdaa5307 100644 (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];
index 96ff2dea2cc8ab431eef03adb084e7f16d1e3f69..9ad6be1763d569f7af3b486e3620930f15127516 100644 (file)
 #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"