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"
27 /** Handle channel mode +z
29 class SSLMode : public ModeHandler
32 UserCertificateAPI API;
34 SSLMode(Module* Creator)
35 : ModeHandler(Creator, "sslonly", 'z', PARAM_NONE, MODETYPE_CHANNEL)
40 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
44 if (!channel->IsModeSet(this))
49 return MODEACTION_DENY;
51 const Channel::MemberMap& userlist = channel->GetUsers();
52 for (Channel::MemberMap::const_iterator i = userlist.begin(); i != userlist.end(); ++i)
54 ssl_cert* cert = API->GetCertificate(i->first);
55 if (!cert && !i->first->server->IsULine())
57 source->WriteNumeric(ERR_ALLMUSTSSL, "%s :all members of the channel must be connected via SSL", channel->name.c_str());
58 return MODEACTION_DENY;
62 channel->SetMode(this, true);
63 return MODEACTION_ALLOW;
67 return MODEACTION_DENY;
72 if (channel->IsModeSet(this))
74 channel->SetMode(this, false);
75 return MODEACTION_ALLOW;
78 return MODEACTION_DENY;
83 class ModuleSSLModes : public Module
94 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
96 if(chan && chan->IsModeSet(sslm))
101 ssl_cert* cert = sslm.API->GetCertificate(user);
105 return MOD_RES_PASSTHRU;
110 user->WriteNumeric(489, "%s :Cannot join channel; SSL users only (+z)", cname.c_str());
115 return MOD_RES_PASSTHRU;
118 ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE
120 if ((mask.length() > 2) && (mask[0] == 'z') && (mask[1] == ':'))
125 ssl_cert* cert = sslm.API->GetCertificate(user);
126 if (cert && InspIRCd::Match(cert->GetFingerprint(), mask.substr(2)))
129 return MOD_RES_PASSTHRU;
132 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
134 tokens["EXTBAN"].push_back('z');
137 Version GetVersion() CXX11_OVERRIDE
139 return Version("Provides channel mode +z to allow for Secure/SSL only channels", VF_VENDOR);
143 MODULE_INIT(ModuleSSLModes)