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