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 "m_override.h"
17 /* $ModDesc: Provides support for unreal-style oper-override */
19 typedef std::map<std::string,std::string> override_t;
21 class ModuleOverride : public Module
28 int OverOps, OverDeops, OverVoices, OverDevoices, OverHalfops, OverDehalfops;
32 ModuleOverride(InspIRCd* Me)
35 // read our config options (main config file)
37 ServerInstance->SNO->EnableSnomask('G', "GODMODE");
38 if (!ServerInstance->Modules->PublishFeature("Override", this))
40 throw ModuleException("m_override: Unable to publish feature 'Override'");
42 OverriddenMode = OverOther = false;
43 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
44 Implementation eventlist[] = { I_OnRehash, I_OnAccessCheck, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPostCommand, I_OnPreTopicChange, I_OnRequest };
45 ServerInstance->Modules->Attach(eventlist, this, 8);
48 virtual void OnRehash(User* user)
50 // on a rehash we delete our classes for good measure and create them again.
51 ConfigReader Conf(ServerInstance);
53 // re-read our config options on a rehash
54 NoisyOverride = Conf.ReadFlag("override", "noisy", 0);
55 RequireKey = Conf.ReadFlag("override", "requirekey", 0);
59 for (int j =0; j < Conf.Enumerate("type"); j++)
61 std::string typen = Conf.ReadValue("type","name",j);
62 std::string tokenlist = Conf.ReadValue("type","override",j);
63 overrides[typen] = tokenlist;
68 virtual void OnPostCommand(const std::string &command, const std::vector<std::string> ¶meters, User *user, CmdResult result, const std::string &original_line)
72 if ((irc::string(command.c_str()) == "MODE") && (result == CMD_SUCCESS) && !ServerInstance->Modes->GetLastParse().empty())
74 std::string msg = std::string(user->nick)+" overriding modes: "+ServerInstance->Modes->GetLastParse()+" [Detail: ";
76 msg += ConvToStr(OverOps)+" op"+(OverOps != 1 ? "s" : "")+", ";
78 msg += ConvToStr(OverDeops)+" deop"+(OverDeops != 1 ? "s" : "")+", ";
80 msg += ConvToStr(OverVoices)+" voice"+(OverVoices != 1 ? "s" : "")+", ";
82 msg += ConvToStr(OverDevoices)+" devoice"+(OverDevoices != 1 ? "s" : "")+", ";
84 msg += ConvToStr(OverHalfops)+" halfop"+(OverHalfops != 1 ? "s" : "")+", ";
86 msg += ConvToStr(OverDehalfops)+" dehalfop"+(OverDehalfops != 1 ? "s" : "")+", ";
89 msg.replace(msg.length()-2, 2, 1, ']');
90 ServerInstance->SNO->WriteGlobalSno('G',msg);
93 OverriddenMode = OverOther = false;
94 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
98 virtual void On005Numeric(std::string &output)
100 output.append(" OVERRIDE");
103 virtual bool CanOverride(User* source, const char* token)
105 // checks to see if the oper's type has <type:override>
106 override_t::iterator j = overrides.find(source->oper);
108 if (j != overrides.end())
110 // its defined or * is set, return its value as a boolean for if the token is set
111 return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
114 // its not defined at all, count as false
119 virtual ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
121 if (IS_LOCAL(source) && IS_OPER(source) && CanOverride(source, "TOPIC"))
123 if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE))
125 ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name));
129 return MOD_RES_ALLOW;
132 return MOD_RES_PASSTHRU;
135 virtual ModResult OnUserPreKick(User* source, User* user, Channel* chan, const std::string &reason)
137 if (IS_OPER(source) && CanOverride(source,"KICK"))
139 // If the kicker's status is less than the target's, or the kicker's status is less than or equal to voice
140 if ((chan->GetPrefixValue(source) < chan->GetPrefixValue(user)) || (chan->GetPrefixValue(source) <= VOICE_VALUE))
142 ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to kick "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
144 return MOD_RES_ALLOW;
146 return MOD_RES_PASSTHRU;
149 virtual ModResult OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
151 if (!IS_OPER(source))
152 return MOD_RES_PASSTHRU;
153 if (!source || !channel)
154 return MOD_RES_PASSTHRU;
157 if (channel->HasUser(source))
158 mode = channel->GetPrefixValue(source);
159 bool over_this = false;
164 if (mode < OP_VALUE && CanOverride(source,"MODEDEOP"))
171 if (mode < OP_VALUE && CanOverride(source,"MODEOP"))
178 if (mode < HALFOP_VALUE && CanOverride(source,"MODEVOICE"))
185 if (mode < HALFOP_VALUE && CanOverride(source,"MODEDEVOICE"))
192 if (mode < OP_VALUE && CanOverride(source,"MODEHALFOP"))
199 if (mode < OP_VALUE && CanOverride(source,"MODEDEHALFOP"))
205 case AC_GENERAL_MODE:
207 std::string modes = ServerInstance->Modes->GetLastParse();
208 bool ohv_only = (modes.find_first_not_of("+-ohv") == std::string::npos);
210 if (mode < HALFOP_VALUE && (ohv_only || CanOverride(source,"OTHERMODE")))
222 OverriddenMode = true;
223 return MOD_RES_ALLOW;
227 return MOD_RES_PASSTHRU;
231 virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
233 if (IS_LOCAL(user) && IS_OPER(user))
237 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
239 irc::string x(chan->name.c_str());
240 if (!user->IsInvited(x))
242 if (RequireKey && keygiven != "override")
244 // Can't join normally -- must use a special key to bypass restrictions
245 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
246 return MOD_RES_PASSTHRU;
250 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
251 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +i on "+std::string(cname));
253 return MOD_RES_ALLOW;
256 if ((chan->modes[CM_KEY]) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
258 if (RequireKey && keygiven != "override")
260 // Can't join normally -- must use a special key to bypass restrictions
261 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
262 return MOD_RES_PASSTHRU;
266 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
267 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +k on "+std::string(cname));
268 return MOD_RES_ALLOW;
271 if ((chan->modes[CM_LIMIT]) && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
273 if (RequireKey && keygiven != "override")
275 // Can't join normally -- must use a special key to bypass restrictions
276 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
277 return MOD_RES_PASSTHRU;
281 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
282 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +l on "+std::string(cname));
283 return MOD_RES_ALLOW;
286 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
288 if (RequireKey && keygiven != "override")
290 // Can't join normally -- must use a special key to bypass restrictions
291 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
292 return MOD_RES_PASSTHRU;
296 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
297 ServerInstance->SNO->WriteGlobalSno('G',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
298 return MOD_RES_ALLOW;
302 return MOD_RES_PASSTHRU;
305 virtual const char* OnRequest(Request* request)
307 if(strcmp(OVRREQID, request->GetId()) == 0)
309 OVRrequest* req = static_cast<OVRrequest*>(request);
310 return this->CanOverride(req->requser,req->reqtoken.c_str()) ? "yes":"";
315 virtual ~ModuleOverride()
317 ServerInstance->Modules->UnpublishFeature("Override");
318 ServerInstance->SNO->DisableSnomask('G');
321 virtual Version GetVersion()
323 return Version("$Id$",VF_VENDOR,API_VERSION);
327 MODULE_INIT(ModuleOverride)