2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
25 #include "modules/ssl.h"
30 ERR_SECUREONLYCHAN = 489
33 /** Handle channel mode +z
35 class SSLMode : public ModeHandler
38 UserCertificateAPI API;
40 SSLMode(Module* Creator)
41 : ModeHandler(Creator, "sslonly", 'z', PARAM_NONE, MODETYPE_CHANNEL)
46 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
50 if (!channel->IsModeSet(this))
55 return MODEACTION_DENY;
57 const Channel::MemberMap& userlist = channel->GetUsers();
58 for (Channel::MemberMap::const_iterator i = userlist.begin(); i != userlist.end(); ++i)
60 ssl_cert* cert = API->GetCertificate(i->first);
61 if (!cert && !i->first->server->IsULine())
63 source->WriteNumeric(ERR_ALLMUSTSSL, channel->name, "all members of the channel must be connected via SSL");
64 return MODEACTION_DENY;
68 channel->SetMode(this, true);
69 return MODEACTION_ALLOW;
73 return MODEACTION_DENY;
78 if (channel->IsModeSet(this))
80 channel->SetMode(this, false);
81 return MODEACTION_ALLOW;
84 return MODEACTION_DENY;
89 class ModuleSSLModes : public Module
100 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
102 if(chan && chan->IsModeSet(sslm))
107 ssl_cert* cert = sslm.API->GetCertificate(user);
111 return MOD_RES_PASSTHRU;
116 user->WriteNumeric(ERR_SECUREONLYCHAN, cname, "Cannot join channel; SSL users only (+z)");
121 return MOD_RES_PASSTHRU;
124 ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE
126 if ((mask.length() > 2) && (mask[0] == 'z') && (mask[1] == ':'))
131 ssl_cert* cert = sslm.API->GetCertificate(user);
132 if (cert && InspIRCd::Match(cert->GetFingerprint(), mask.substr(2)))
135 return MOD_RES_PASSTHRU;
138 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
140 tokens["EXTBAN"].push_back('z');
143 Version GetVersion() CXX11_OVERRIDE
145 return Version("Provides channel mode +z to allow for Secure/SSL only channels", VF_VENDOR);
149 MODULE_INIT(ModuleSSLModes)