The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_sslmodes.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 
00016 /* $ModDesc: Provides support for unreal-style channel mode +z */
00017 
00018 static char* dummy;
00019 
00022 class SSLMode : public ModeHandler
00023 {
00024  public:
00025         SSLMode(InspIRCd* Instance) : ModeHandler(Instance, 'z', 0, 0, false, MODETYPE_CHANNEL, false) { }
00026 
00027         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
00028         {
00029                 if (adding)
00030                 {
00031                         if (!channel->IsModeSet('z'))
00032                         {
00033                                 if (IS_LOCAL(source))
00034                                 {
00035                                         CUList* userlist = channel->GetUsers();
00036                                         for(CUList::iterator i = userlist->begin(); i != userlist->end(); i++)
00037                                         {
00038                                                 if(!i->first->GetExt("ssl", dummy) && !ServerInstance->ULine(i->first->server))
00039                                                 {
00040                                                         source->WriteNumeric(ERR_ALLMUSTSSL, "%s %s :all members of the channel must be connected via SSL", source->nick.c_str(), channel->name.c_str());
00041                                                         return MODEACTION_DENY;
00042                                                 }
00043                                         }
00044                                 }
00045                                 channel->SetMode('z',true);
00046                                 return MODEACTION_ALLOW;
00047                         }
00048                         else
00049                         {
00050                                 return MODEACTION_DENY;
00051                         }
00052                 }
00053                 else
00054                 {
00055                         if (channel->IsModeSet('z'))
00056                         {
00057                                 channel->SetMode('z',false);
00058                                 return MODEACTION_ALLOW;
00059                         }
00060 
00061                         return MODEACTION_DENY;
00062                 }
00063         }
00064 };
00065 
00066 class ModuleSSLModes : public Module
00067 {
00068 
00069         SSLMode* sslm;
00070 
00071  public:
00072         ModuleSSLModes(InspIRCd* Me)
00073                 : Module(Me)
00074         {
00075 
00076 
00077                 sslm = new SSLMode(ServerInstance);
00078                 if (!ServerInstance->Modes->AddMode(sslm))
00079                         throw ModuleException("Could not add new modes!");
00080                 Implementation eventlist[] = { I_OnUserPreJoin };
00081                 ServerInstance->Modules->Attach(eventlist, this, 1);
00082         }
00083 
00084 
00085         virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
00086         {
00087                 if(chan && chan->IsModeSet('z'))
00088                 {
00089                         if(user->GetExt("ssl", dummy))
00090                         {
00091                                 // Let them in
00092                                 return 0;
00093                         }
00094                         else
00095                         {
00096                                 // Deny
00097                                 user->WriteServ( "489 %s %s :Cannot join channel; SSL users only (+z)", user->nick.c_str(), cname);
00098                                 return 1;
00099                         }
00100                 }
00101 
00102                 return 0;
00103         }
00104 
00105         virtual ~ModuleSSLModes()
00106         {
00107                 ServerInstance->Modes->DelMode(sslm);
00108                 delete sslm;
00109         }
00110 
00111         virtual Version GetVersion()
00112         {
00113                 return Version("$Id: m_sslmodes.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_COMMON | VF_VENDOR, API_VERSION);
00114         }
00115 };
00116 
00117 
00118 MODULE_INIT(ModuleSSLModes)
00119