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
29 ModuleOverride(InspIRCd* Me)
32 // read our config options (main config file)
34 ServerInstance->SNO->EnableSnomask('G', "GODMODE");
35 if (!ServerInstance->Modules->PublishFeature("Override", this))
37 throw ModuleException("m_override: Unable to publish feature 'Override'");
39 Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange, I_OnRequest };
40 ServerInstance->Modules->Attach(eventlist, this, 7);
43 void OnRehash(User* user)
45 // on a rehash we delete our classes for good measure and create them again.
46 ConfigReader Conf(ServerInstance);
48 // re-read our config options on a rehash
49 NoisyOverride = Conf.ReadFlag("override", "noisy", 0);
50 RequireKey = Conf.ReadFlag("override", "requirekey", 0);
54 for (int j =0; j < Conf.Enumerate("type"); j++)
56 std::string typen = Conf.ReadValue("type","name",j);
57 std::string tokenlist = Conf.ReadValue("type","override",j);
58 overrides[typen] = tokenlist;
62 void On005Numeric(std::string &output)
64 output.append(" OVERRIDE");
67 bool CanOverride(User* source, const char* token)
69 // checks to see if the oper's type has <type:override>
70 override_t::iterator j = overrides.find(source->oper);
72 if (j != overrides.end())
74 // its defined or * is set, return its value as a boolean for if the token is set
75 return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
78 // its not defined at all, count as false
83 ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
85 if (IS_LOCAL(source) && IS_OPER(source) && CanOverride(source, "TOPIC"))
87 if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE))
89 ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name));
96 return MOD_RES_PASSTHRU;
99 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
101 if (IS_OPER(source) && CanOverride(source,"KICK"))
103 // If the kicker's status is less than the target's, or the kicker's status is less than or equal to voice
104 if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE))
106 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+")");
107 return MOD_RES_ALLOW;
110 return MOD_RES_PASSTHRU;
113 ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
115 if (!IS_OPER(source))
116 return MOD_RES_PASSTHRU;
117 if (!source || !channel)
118 return MOD_RES_PASSTHRU;
120 unsigned int mode = 0;
121 if (channel->HasUser(source))
122 mode = channel->GetPrefixValue(source);
124 if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
126 std::string msg = std::string(source->nick)+" overriding modes:";
127 for(unsigned int i=0; i < parameters.size(); i++)
128 msg += " " + parameters[i];
129 ServerInstance->SNO->WriteGlobalSno('G',msg);
130 return MOD_RES_ALLOW;
132 return MOD_RES_PASSTHRU;
135 ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
137 if (IS_LOCAL(user) && IS_OPER(user))
141 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
143 irc::string x(chan->name.c_str());
144 if (!user->IsInvited(x))
146 if (RequireKey && keygiven != "override")
148 // Can't join normally -- must use a special key to bypass restrictions
149 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
150 return MOD_RES_PASSTHRU;
154 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
155 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +i on "+std::string(cname));
157 return MOD_RES_ALLOW;
160 if ((chan->modes[CM_KEY]) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
162 if (RequireKey && keygiven != "override")
164 // Can't join normally -- must use a special key to bypass restrictions
165 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
166 return MOD_RES_PASSTHRU;
170 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
171 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +k on "+std::string(cname));
172 return MOD_RES_ALLOW;
175 if ((chan->modes[CM_LIMIT]) && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
177 if (RequireKey && keygiven != "override")
179 // Can't join normally -- must use a special key to bypass restrictions
180 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
181 return MOD_RES_PASSTHRU;
185 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
186 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +l on "+std::string(cname));
187 return MOD_RES_ALLOW;
190 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
192 if (RequireKey && keygiven != "override")
194 // Can't join normally -- must use a special key to bypass restrictions
195 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
196 return MOD_RES_PASSTHRU;
200 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
201 ServerInstance->SNO->WriteGlobalSno('G',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
202 return MOD_RES_ALLOW;
206 return MOD_RES_PASSTHRU;
209 const char* OnRequest(Request* request)
211 if(strcmp(OVRREQID, request->GetId()) == 0)
213 OVRrequest* req = static_cast<OVRrequest*>(request);
214 return this->CanOverride(req->requser,req->reqtoken.c_str()) ? "yes":"";
221 ServerInstance->Modules->UnpublishFeature("Override");
222 ServerInstance->SNO->DisableSnomask('G');
227 return Version("$Id$",VF_VENDOR,API_VERSION);
231 MODULE_INIT(ModuleOverride)