]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_gecosban.cpp
6b14d9134520af253d37c8d6501f8383f0044bac
[user/henk/code/inspircd.git] / src / modules / m_gecosban.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015 Renegade334 <contact.caaeed4f@renegade334.me.uk>
5  *   Copyright (C) 2013, 2018, 2020 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
8  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27
28 class ModuleGecosBan : public Module
29 {
30  public:
31         Version GetVersion() CXX11_OVERRIDE
32         {
33                 return Version("Adds extended ban r: which checks whether users have a real name (gecos) matching the specified glob pattern.", VF_OPTCOMMON|VF_VENDOR);
34         }
35
36         ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE
37         {
38                 if ((mask.length() > 2) && (mask[1] == ':'))
39                 {
40                         if (mask[0] == 'r')
41                         {
42                                 if (InspIRCd::Match(user->GetRealName(), mask.substr(2)))
43                                         return MOD_RES_DENY;
44                         }
45                         else if (mask[0] == 'a')
46                         {
47                                 // Check that the user actually specified a real name.
48                                 const size_t divider = mask.find('+', 1);
49                                 if (divider == std::string::npos)
50                                         return MOD_RES_PASSTHRU;
51
52                                 // Check whether the user's mask matches.
53                                 if (!c->CheckBan(user, mask.substr(2, divider - 2)))
54                                         return MOD_RES_PASSTHRU;
55
56                                 // Check whether the user's real name matches.
57                                 if (InspIRCd::Match(user->GetRealName(), mask.substr(divider + 1)))
58                                         return MOD_RES_DENY;
59                         }
60                 }
61                 return MOD_RES_PASSTHRU;
62         }
63
64         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
65         {
66                 tokens["EXTBAN"].push_back('a');
67                 tokens["EXTBAN"].push_back('r');
68         }
69 };
70
71 MODULE_INIT(ModuleGecosBan)