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_servprotect.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 Austhex style +k / UnrealIRCD +S services mode */
00017 
00020 class ServProtectMode : public ModeHandler
00021 {
00022  public:
00023         ServProtectMode(InspIRCd* Instance) : ModeHandler(Instance, 'k', 0, 0, false, MODETYPE_USER, true) { }
00024 
00025         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
00026         {
00027                 /* Because this returns MODEACTION_DENY all the time, there is only ONE 
00028                  * way to add this mode and that is at client introduction in the UID command,
00029                  * as this calls OnModeChange for each mode but disregards the return values.
00030                  * The mode cannot be manually added or removed, not even by a server or by a remote
00031                  * user or uline, which prevents its (ab)use as a kiddie 'god mode' on such networks.
00032                  * I'm sure if someone really wants to do that they can make a copy of this module
00033                  * that does the job. It won't be me though!
00034                  */
00035                 return MODEACTION_DENY;
00036         }
00037 
00038         bool NeedsOper() { return true; }
00039 };
00040 
00041 class ModuleServProtectMode : public Module
00042 {
00043 
00044         ServProtectMode* bm;
00045  public:
00046         ModuleServProtectMode(InspIRCd* Me)
00047                 : Module(Me)
00048         {
00049 
00050                 bm = new ServProtectMode(ServerInstance);
00051                 if (!ServerInstance->Modes->AddMode(bm))
00052                         throw ModuleException("Could not add new modes!");
00053                 Implementation eventlist[] = { I_OnWhois, I_OnKill, I_OnWhoisLine, I_OnRawMode, I_OnUserPreKick };
00054                 ServerInstance->Modules->Attach(eventlist, this, 5);
00055         }
00056 
00057 
00058         virtual ~ModuleServProtectMode()
00059         {
00060                 ServerInstance->Modes->DelMode(bm);
00061                 delete bm;
00062         }
00063 
00064         virtual Version GetVersion()
00065         {
00066                 return Version("$Id: m_servprotect.cpp 10622 2008-10-04 21:27:52Z brain $",VF_COMMON,API_VERSION);
00067         }
00068 
00069         virtual void OnWhois(User* src, User* dst)
00070         {
00071                 if (dst->IsModeSet('k'))
00072                 {
00073                         ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is an "+ServerInstance->Config->Network+" Service");
00074                 }
00075         }
00076 
00077         virtual int OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt, bool servermode)
00078         {
00079                 /* Check that the mode is not a server mode, it is being removed, the user making the change is local, there is a parameter,
00080                  * and the user making the change is not a uline
00081                  */
00082                 if (!servermode && !adding && chan && IS_LOCAL(user) && !param.empty() && !ServerInstance->ULine(user->server))
00083                 {
00084                         /* Check if the parameter is a valid nick/uuid
00085                          */
00086                         User *u = ServerInstance->FindNick(param);
00087                         if (u)
00088                         {
00089                                 /* The target user has +k set on themselves, and you are trying to remove a privilege mode the user has set on themselves.
00090                                  * This includes any prefix permission mode, even those registered in other modules, e.g. +qaohv. Using ::ModeString()
00091                                  * here means that the number of modes is restricted to only modes the user has, limiting it to as short a loop as possible.
00092                                  */
00093                                 if (u->IsModeSet('k') && ServerInstance->Modes->ModeString(u, chan, false).find(mode) != std::string::npos)
00094                                 {
00095                                         /* BZZZT, Denied! */
00096                                         user->WriteNumeric(482, "%s %s :You are not permitted to remove privileges from %s services", user->nick.c_str(), chan->name.c_str(), ServerInstance->Config->Network);
00097                                         return ACR_DENY;
00098                                 }
00099                         }
00100                 }
00101                 /* Mode allowed */
00102                 return 0;
00103         }
00104 
00105         virtual int OnKill(User* src, User* dst, const std::string &reason)
00106         {
00107                 if (src == NULL)
00108                         return 0;
00109 
00110                 if (dst->IsModeSet('k'))
00111                 {
00112                         src->WriteNumeric(485, "%s :You are not permitted to kill %s services!", src->nick.c_str(), ServerInstance->Config->Network);
00113                         ServerInstance->SNO->WriteToSnoMask('A', std::string(src->nick)+" tried to kill service "+dst->nick+" ("+reason+")");
00114                         return 1;
00115                 }
00116                 return 0;
00117         }
00118 
00119         virtual int OnUserPreKick(User *src, User *dst, Channel *c, const std::string &reason)
00120         {
00121                 if (dst->IsModeSet('k'))
00122                 {
00123                         src->WriteNumeric(484, "%s %s :You are not permitted to kick services", src->nick.c_str(), c->name.c_str());
00124                         return 1;
00125                 }
00126 
00127                 return 0;
00128         }
00129 
00130         virtual int OnWhoisLine(User* src, User* dst, int &numeric, std::string &text)
00131         {
00132                 return ((src != dst) && (numeric == 319) && dst->IsModeSet('k'));
00133         }
00134 };
00135 
00136 
00137 MODULE_INIT(ModuleServProtectMode)