1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "transport.h"
17 /* $ModDesc: Provides support for unreal-style channel mode +z */
19 /** Handle channel mode +z
21 class SSLMode : public ModeHandler
24 SSLMode(Module* Creator) : ModeHandler(Creator, 'z', PARAM_NONE, MODETYPE_CHANNEL) { }
26 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
30 if (!channel->IsModeSet('z'))
34 const UserMembList* userlist = channel->GetUsers();
35 for(UserMembCIter i = userlist->begin(); i != userlist->end(); i++)
37 BufferedSocketCertificateRequest req(i->first, creator, i->first->GetIOHook());
39 if(!req.cert && !ServerInstance->ULine(i->first->server))
41 source->WriteNumeric(ERR_ALLMUSTSSL, "%s %s :all members of the channel must be connected via SSL", source->nick.c_str(), channel->name.c_str());
42 return MODEACTION_DENY;
46 channel->SetMode('z',true);
47 return MODEACTION_ALLOW;
51 return MODEACTION_DENY;
56 if (channel->IsModeSet('z'))
58 channel->SetMode('z',false);
59 return MODEACTION_ALLOW;
62 return MODEACTION_DENY;
67 class ModuleSSLModes : public Module
76 if (!ServerInstance->Modes->AddMode(&sslm))
77 throw ModuleException("Could not add new modes!");
78 Implementation eventlist[] = { I_OnUserPreJoin, I_OnCheckBan, I_On005Numeric };
79 ServerInstance->Modules->Attach(eventlist, this, 3);
82 ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
84 if(chan && chan->IsModeSet('z'))
86 BufferedSocketCertificateRequest req(user, this, user->GetIOHook());
91 return MOD_RES_PASSTHRU;
96 user->WriteServ( "489 %s %s :Cannot join channel; SSL users only (+z)", user->nick.c_str(), cname);
101 return MOD_RES_PASSTHRU;
104 ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
106 if (mask[0] == 'z' && mask[1] == ':')
108 BufferedSocketCertificateRequest req(user, this, user->GetIOHook());
110 if (req.cert && InspIRCd::Match(req.cert->GetFingerprint(), mask.substr(2)))
113 return MOD_RES_PASSTHRU;
120 void On005Numeric(std::string &output)
122 ServerInstance->AddExtBanChar('z');
127 return Version("Provides support for unreal-style channel mode +z", VF_COMMON | VF_VENDOR, API_VERSION);
132 MODULE_INIT(ModuleSSLModes)