]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_override.cpp
8a3fcdd62faa6509fa411edf8df949abcacee717
[user/henk/code/inspircd.git] / src / modules / m_override.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides support for unreal-style oper-override */
17
18 typedef std::map<std::string,std::string> override_t;
19
20 class ModuleOverride : public Module
21 {
22         override_t overrides;
23         bool RequireKey;
24         bool NoisyOverride;
25
26  public:
27
28         ModuleOverride()
29                         {
30                 // read our config options (main config file)
31                 OnRehash(NULL);
32                 ServerInstance->SNO->EnableSnomask('G', "GODMODE");
33                 Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange };
34                 ServerInstance->Modules->Attach(eventlist, this, 6);
35         }
36
37         void OnRehash(User* user)
38         {
39                 // on a rehash we delete our classes for good measure and create them again.
40                 ConfigReader Conf;
41
42                 // re-read our config options on a rehash
43                 NoisyOverride = Conf.ReadFlag("override", "noisy", 0);
44                 RequireKey = Conf.ReadFlag("override", "requirekey", 0);
45
46                 overrides.clear();
47
48                 for (int j =0; j < Conf.Enumerate("type"); j++)
49                 {
50                         std::string typen = Conf.ReadValue("type","name",j);
51                         std::string tokenlist = Conf.ReadValue("type","override",j);
52                         overrides[typen] = tokenlist;
53                 }
54         }
55
56         void On005Numeric(std::string &output)
57         {
58                 output.append(" OVERRIDE");
59         }
60
61         bool CanOverride(User* source, const char* token)
62         {
63                 // checks to see if the oper's type has <type:override>
64                 override_t::iterator j = overrides.find(source->oper);
65
66                 if (j != overrides.end())
67                 {
68                         // its defined or * is set, return its value as a boolean for if the token is set
69                         return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
70                 }
71
72                 // its not defined at all, count as false
73                 return false;
74         }
75
76
77         ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
78         {
79                 if (IS_LOCAL(source) && IS_OPER(source) && CanOverride(source, "TOPIC"))
80                 {
81                         if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE))
82                         {
83                                 ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name));
84                         }
85
86                         // Explicit allow
87                         return MOD_RES_ALLOW;
88                 }
89
90                 return MOD_RES_PASSTHRU;
91         }
92
93         ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
94         {
95                 if (IS_OPER(source) && CanOverride(source,"KICK"))
96                 {
97                         // If the kicker's status is less than the target's,                    or      the kicker's status is less than or equal to voice
98                         if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE))
99                         {
100                                 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+")");
101                                 return MOD_RES_ALLOW;
102                         }
103                 }
104                 return MOD_RES_PASSTHRU;
105         }
106
107         ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
108         {
109                 if (!IS_OPER(source))
110                         return MOD_RES_PASSTHRU;
111                 if (!source || !channel)
112                         return MOD_RES_PASSTHRU;
113
114                 unsigned int mode = 0;
115                 if (channel->HasUser(source))
116                         mode = channel->GetPrefixValue(source);
117
118                 if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
119                 {
120                         std::string msg = std::string(source->nick)+" overriding modes:";
121                         for(unsigned int i=0; i < parameters.size(); i++)
122                                 msg += " " + parameters[i];
123                         ServerInstance->SNO->WriteGlobalSno('G',msg);
124                         return MOD_RES_ALLOW;
125                 }
126                 return MOD_RES_PASSTHRU;
127         }
128
129         ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
130         {
131                 if (IS_LOCAL(user) && IS_OPER(user))
132                 {
133                         if (chan)
134                         {
135                                 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
136                                 {
137                                         irc::string x(chan->name.c_str());
138                                         if (!IS_LOCAL(user)->IsInvited(x))
139                                         {
140                                                 if (RequireKey && keygiven != "override")
141                                                 {
142                                                         // Can't join normally -- must use a special key to bypass restrictions
143                                                         user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
144                                                         return MOD_RES_PASSTHRU;
145                                                 }
146
147                                                 if (NoisyOverride)
148                                                         chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
149                                                 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +i on "+std::string(cname));
150                                         }
151                                         return MOD_RES_ALLOW;
152                                 }
153
154                                 if ((chan->modes[CM_KEY]) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
155                                 {
156                                         if (RequireKey && keygiven != "override")
157                                         {
158                                                 // Can't join normally -- must use a special key to bypass restrictions
159                                                 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
160                                                 return MOD_RES_PASSTHRU;
161                                         }
162
163                                         if (NoisyOverride)
164                                                 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
165                                         ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +k on "+std::string(cname));
166                                         return MOD_RES_ALLOW;
167                                 }
168
169                                 if ((chan->modes[CM_LIMIT]) && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
170                                 {
171                                         if (RequireKey && keygiven != "override")
172                                         {
173                                                 // Can't join normally -- must use a special key to bypass restrictions
174                                                 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
175                                                 return MOD_RES_PASSTHRU;
176                                         }
177
178                                         if (NoisyOverride)
179                                                 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
180                                         ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +l on "+std::string(cname));
181                                         return MOD_RES_ALLOW;
182                                 }
183
184                                 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
185                                 {
186                                         if (RequireKey && keygiven != "override")
187                                         {
188                                                 // Can't join normally -- must use a special key to bypass restrictions
189                                                 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
190                                                 return MOD_RES_PASSTHRU;
191                                         }
192
193                                         if (NoisyOverride)
194                                                 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
195                                         ServerInstance->SNO->WriteGlobalSno('G',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
196                                         return MOD_RES_ALLOW;
197                                 }
198                         }
199                 }
200                 return MOD_RES_PASSTHRU;
201         }
202
203         ~ModuleOverride()
204         {
205                 ServerInstance->SNO->DisableSnomask('G');
206         }
207
208         Version GetVersion()
209         {
210                 return Version("Provides support for unreal-style oper-override",VF_VENDOR);
211         }
212 };
213
214 MODULE_INIT(ModuleOverride)