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
31 // read our config options (main config file)
33 ServerInstance->SNO->EnableSnomask('G', "GODMODE");
34 if (!ServerInstance->Modules->PublishFeature("Override", this))
36 throw ModuleException("m_override: Unable to publish feature 'Override'");
38 Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange, I_OnRequest };
39 ServerInstance->Modules->Attach(eventlist, this, 7);
42 void OnRehash(User* user)
44 // on a rehash we delete our classes for good measure and create them again.
47 // re-read our config options on a rehash
48 NoisyOverride = Conf.ReadFlag("override", "noisy", 0);
49 RequireKey = Conf.ReadFlag("override", "requirekey", 0);
53 for (int j =0; j < Conf.Enumerate("type"); j++)
55 std::string typen = Conf.ReadValue("type","name",j);
56 std::string tokenlist = Conf.ReadValue("type","override",j);
57 overrides[typen] = tokenlist;
61 void On005Numeric(std::string &output)
63 output.append(" OVERRIDE");
66 bool CanOverride(User* source, const char* token)
68 // checks to see if the oper's type has <type:override>
69 override_t::iterator j = overrides.find(source->oper);
71 if (j != overrides.end())
73 // its defined or * is set, return its value as a boolean for if the token is set
74 return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
77 // its not defined at all, count as false
82 ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
84 if (IS_LOCAL(source) && IS_OPER(source) && CanOverride(source, "TOPIC"))
86 if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE))
88 ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name));
95 return MOD_RES_PASSTHRU;
98 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
100 if (IS_OPER(source) && CanOverride(source,"KICK"))
102 // If the kicker's status is less than the target's, or the kicker's status is less than or equal to voice
103 if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE))
105 ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to kick "+std::string(memb->user->nick)+" on "+std::string(memb->chan->name)+" ("+reason+")");
106 return MOD_RES_ALLOW;
109 return MOD_RES_PASSTHRU;
112 ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
114 if (!IS_OPER(source))
115 return MOD_RES_PASSTHRU;
116 if (!source || !channel)
117 return MOD_RES_PASSTHRU;
119 unsigned int mode = 0;
120 if (channel->HasUser(source))
121 mode = channel->GetPrefixValue(source);
123 if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
125 std::string msg = std::string(source->nick)+" overriding modes:";
126 for(unsigned int i=0; i < parameters.size(); i++)
127 msg += " " + parameters[i];
128 ServerInstance->SNO->WriteGlobalSno('G',msg);
129 return MOD_RES_ALLOW;
131 return MOD_RES_PASSTHRU;
134 ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
136 if (IS_LOCAL(user) && IS_OPER(user))
140 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
142 irc::string x(chan->name.c_str());
143 if (!user->IsInvited(x))
145 if (RequireKey && keygiven != "override")
147 // Can't join normally -- must use a special key to bypass restrictions
148 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
149 return MOD_RES_PASSTHRU;
153 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
154 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +i on "+std::string(cname));
156 return MOD_RES_ALLOW;
159 if ((chan->modes[CM_KEY]) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
161 if (RequireKey && keygiven != "override")
163 // Can't join normally -- must use a special key to bypass restrictions
164 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
165 return MOD_RES_PASSTHRU;
169 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
170 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +k on "+std::string(cname));
171 return MOD_RES_ALLOW;
174 if ((chan->modes[CM_LIMIT]) && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
176 if (RequireKey && keygiven != "override")
178 // Can't join normally -- must use a special key to bypass restrictions
179 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
180 return MOD_RES_PASSTHRU;
184 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
185 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +l on "+std::string(cname));
186 return MOD_RES_ALLOW;
189 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
191 if (RequireKey && keygiven != "override")
193 // Can't join normally -- must use a special key to bypass restrictions
194 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
195 return MOD_RES_PASSTHRU;
199 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
200 ServerInstance->SNO->WriteGlobalSno('G',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
201 return MOD_RES_ALLOW;
205 return MOD_RES_PASSTHRU;
208 const char* OnRequest(Request* request)
210 if(strcmp(OVRREQID, request->GetId()) == 0)
212 OVRrequest* req = static_cast<OVRrequest*>(request);
213 return this->CanOverride(req->requser,req->reqtoken.c_str()) ? "yes":"";
220 ServerInstance->Modules->UnpublishFeature("Override");
221 ServerInstance->SNO->DisableSnomask('G');
226 return Version("Provides support for unreal-style oper-override",VF_VENDOR,API_VERSION);
230 MODULE_INIT(ModuleOverride)