]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sslmodes.cpp
Add the override keyword in places that it is missing.
[user/henk/code/inspircd.git] / src / modules / m_sslmodes.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8  *   Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
9  *
10  * This file is part of InspIRCd.  InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 #include "inspircd.h"
25 #include "modules/ssl.h"
26
27 enum
28 {
29         // From UnrealIRCd.
30         ERR_SECUREONLYCHAN = 489
31 };
32
33 /** Handle channel mode +z
34  */
35 class SSLMode : public ModeHandler
36 {
37  public:
38         UserCertificateAPI API;
39
40         SSLMode(Module* Creator)
41                 : ModeHandler(Creator, "sslonly", 'z', PARAM_NONE, MODETYPE_CHANNEL)
42                 , API(Creator)
43         {
44         }
45
46         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
47         {
48                 if (adding)
49                 {
50                         if (!channel->IsModeSet(this))
51                         {
52                                 if (IS_LOCAL(source))
53                                 {
54                                         if (!API)
55                                                 return MODEACTION_DENY;
56
57                                         const Channel::MemberMap& userlist = channel->GetUsers();
58                                         for (Channel::MemberMap::const_iterator i = userlist.begin(); i != userlist.end(); ++i)
59                                         {
60                                                 ssl_cert* cert = API->GetCertificate(i->first);
61                                                 if (!cert && !i->first->server->IsULine())
62                                                 {
63                                                         source->WriteNumeric(ERR_ALLMUSTSSL, channel->name, "all members of the channel must be connected via SSL");
64                                                         return MODEACTION_DENY;
65                                                 }
66                                         }
67                                 }
68                                 channel->SetMode(this, true);
69                                 return MODEACTION_ALLOW;
70                         }
71                         else
72                         {
73                                 return MODEACTION_DENY;
74                         }
75                 }
76                 else
77                 {
78                         if (channel->IsModeSet(this))
79                         {
80                                 channel->SetMode(this, false);
81                                 return MODEACTION_ALLOW;
82                         }
83
84                         return MODEACTION_DENY;
85                 }
86         }
87 };
88
89 class ModuleSSLModes : public Module
90 {
91
92         SSLMode sslm;
93
94  public:
95         ModuleSSLModes()
96                 : sslm(this)
97         {
98         }
99
100         ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
101         {
102                 if(chan && chan->IsModeSet(sslm))
103                 {
104                         if (!sslm.API)
105                                 return MOD_RES_DENY;
106
107                         ssl_cert* cert = sslm.API->GetCertificate(user);
108                         if (cert)
109                         {
110                                 // Let them in
111                                 return MOD_RES_PASSTHRU;
112                         }
113                         else
114                         {
115                                 // Deny
116                                 user->WriteNumeric(ERR_SECUREONLYCHAN, cname, "Cannot join channel; SSL users only (+z)");
117                                 return MOD_RES_DENY;
118                         }
119                 }
120
121                 return MOD_RES_PASSTHRU;
122         }
123
124         ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE
125         {
126                 if ((mask.length() > 2) && (mask[0] == 'z') && (mask[1] == ':'))
127                 {
128                         if (!sslm.API)
129                                 return MOD_RES_DENY;
130
131                         ssl_cert* cert = sslm.API->GetCertificate(user);
132                         if (cert && InspIRCd::Match(cert->GetFingerprint(), mask.substr(2)))
133                                 return MOD_RES_DENY;
134                 }
135                 return MOD_RES_PASSTHRU;
136         }
137
138         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
139         {
140                 tokens["EXTBAN"].push_back('z');
141         }
142
143         Version GetVersion() CXX11_OVERRIDE
144         {
145                 return Version("Provides channel mode +z to allow for Secure/SSL only channels", VF_VENDOR);
146         }
147 };
148
149 MODULE_INIT(ModuleSSLModes)