]> jfr.im git - solanum.git/blame - extensions/override.c
add separate priv (oper:message) for walking over CALLERID (umode +g) (#152)
[solanum.git] / extensions / override.c
CommitLineData
429cf1b7 1/*
a6f63a82 2 * oper-override for solanum.
429cf1b7
AC
3 *
4 * adds usermode +p and has a timer event that is iterated over to disable
5 * usermode +p after a while...
6 *
7 * you need to have oper:override permission on the opers you want to be
8 * able to use this extension.
9 */
10
11#include "stdinc.h"
12#include "modules.h"
13#include "hook.h"
14#include "client.h"
15#include "ircd.h"
16#include "send.h"
17#include "hash.h"
18#include "s_conf.h"
19#include "s_user.h"
20#include "s_serv.h"
21#include "numeric.h"
22#include "privilege.h"
23#include "s_newconf.h"
24
3fd3d7e1
EM
25static const char override_desc[] =
26 "Adds user mode +p, an operator-only user mode that grants temporary privileges to override anything";
27
429cf1b7
AC
28static void check_umode_change(void *data);
29static void hack_channel_access(void *data);
d3076881 30static void hack_can_join(void *data);
f69d7feb 31static void hack_can_kick(void *data);
9101dbcd 32static void hack_can_send(void *data);
5c3014d0 33static void handle_client_exit(void *data);
429cf1b7
AC
34
35mapi_hfn_list_av1 override_hfnlist[] = {
36 { "umode_changed", (hookfn) check_umode_change },
c500b0bd
EK
37 { "get_channel_access", (hookfn) hack_channel_access, HOOK_HIGHEST },
38 { "can_join", (hookfn) hack_can_join, HOOK_HIGHEST },
39 { "can_kick", (hookfn) hack_can_kick, HOOK_HIGHEST },
40 { "can_send", (hookfn) hack_can_send, HOOK_HIGHEST },
5c3014d0 41 { "client_exit", (hookfn) handle_client_exit },
429cf1b7
AC
42 { NULL, NULL }
43};
44
f69d7feb 45#define CHFL_OVERRIDE 0x0004
429cf1b7
AC
46#define IsOperOverride(x) (HasPrivilege((x), "oper:override"))
47
48struct OverrideSession {
49 rb_dlink_node node;
50
51 struct Client *client;
52 time_t deadline;
53};
54
55rb_dlink_list overriding_opers = { NULL, NULL, 0 };
56
57static void
58update_session_deadline(struct Client *source_p, struct OverrideSession *session_p)
59{
60 if (session_p == NULL)
61 {
62 rb_dlink_node *n;
63
64 RB_DLINK_FOREACH(n, overriding_opers.head)
65 {
66 struct OverrideSession *s = n->data;
67
68 if (s->client == source_p)
69 {
70 session_p = s;
71 break;
72 }
73 }
74 }
75
76 if (session_p == NULL)
77 {
78 session_p = rb_malloc(sizeof(struct OverrideSession));
79 session_p->client = source_p;
80 }
81
82 session_p->deadline = rb_current_time() + 1800;
83
84 rb_dlinkDelete(&session_p->node, &overriding_opers);
85 rb_dlinkAdd(session_p, &session_p->node, &overriding_opers);
86}
87
88static void
89expire_override_deadlines(void *unused)
90{
91 rb_dlink_node *n, *tn;
92
93 RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
94 {
95 struct OverrideSession *session_p = n->data;
96
97 if (session_p->deadline > rb_current_time())
98 break;
99 else if (session_p->deadline < rb_current_time())
100 {
bd2c29f7 101 const char *parv[4] = {session_p->client->name, session_p->client->name, "-p", NULL};
429cf1b7
AC
102 user_mode(session_p->client, session_p->client, 3, parv);
103 }
104 }
105}
106
107static void
108check_umode_change(void *vdata)
109{
110 hook_data_umode_changed *data = (hook_data_umode_changed *)vdata;
dbeda234 111 bool changed = false;
429cf1b7
AC
112 struct Client *source_p = data->client;
113
114 if (!MyClient(source_p))
115 return;
116
e5c254d7
JT
117 if (data->oldumodes & UMODE_OPER && !IsOper(source_p))
118 source_p->umodes &= ~user_modes['p'];
119
dbeda234 120 changed = ((data->oldumodes ^ source_p->umodes) & user_modes['p']);
429cf1b7 121
429cf1b7
AC
122 if (source_p->umodes & user_modes['p'])
123 {
e5c254d7
JT
124 if (!IsOperOverride(source_p))
125 {
126 sendto_one_notice(source_p, ":*** You need oper:override privilege for +p");
127 source_p->umodes &= ~user_modes['p'];
128 return;
129 }
130
dbeda234
EK
131 if (changed)
132 {
133 update_session_deadline(source_p, NULL);
dbeda234 134 }
429cf1b7 135 }
dbeda234 136 else if (changed && !(source_p->umodes & user_modes['p']))
429cf1b7
AC
137 {
138 rb_dlink_node *n, *tn;
139
140 RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
141 {
142 struct OverrideSession *session_p = n->data;
143
144 if (session_p->client != source_p)
145 continue;
146
429cf1b7
AC
147 rb_dlinkDelete(n, &overriding_opers);
148 rb_free(session_p);
149 }
150 }
151}
152
153static void
154hack_channel_access(void *vdata)
155{
156 hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
157
202d4966
AC
158 if (data->dir == MODE_QUERY)
159 return;
160
429cf1b7
AC
161 if (data->approved == CHFL_CHANOP)
162 return;
163
164 if (data->client->umodes & user_modes['p'])
165 {
166 update_session_deadline(data->client, NULL);
f69d7feb 167 data->approved = CHFL_OVERRIDE;
429cf1b7 168
b870a5f8
AC
169 /* we only want to report modehacks, which are always non-NULL */
170 if (data->modestr)
171 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (modehacking: %s)",
172 get_oper_name(data->client), data->chptr->chname, data->modestr);
429cf1b7
AC
173 }
174}
175
d3076881
AC
176static void
177hack_can_join(void *vdata)
178{
179 hook_data_channel *data = (hook_data_channel *) vdata;
180
181 if (data->approved == 0)
182 return;
183
184 if (data->client->umodes & user_modes['p'])
185 {
186 update_session_deadline(data->client, NULL);
187 data->approved = 0;
188
189 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (banwalking)",
190 get_oper_name(data->client), data->chptr->chname);
191 }
192}
193
f69d7feb
AC
194static void
195hack_can_kick(void *vdata)
196{
197 hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
198 int alevel;
199
103a1bfd 200 alevel = get_channel_access(data->client, data->chptr, data->msptr, data->dir, NULL);
f69d7feb
AC
201 if (alevel != CHFL_OVERRIDE)
202 return;
203
204 if (data->client->umodes & user_modes['p'])
205 {
206 update_session_deadline(data->client, NULL);
207 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (KICK %s)",
208 get_oper_name(data->client), data->chptr->chname, data->target->name);
209 }
210}
211
9101dbcd
AC
212static void
213hack_can_send(void *vdata)
214{
215 hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
216
202d4966
AC
217 if (data->dir == MODE_QUERY)
218 return;
219
9101dbcd
AC
220 if (data->approved == CAN_SEND_NONOP || data->approved == CAN_SEND_OPV)
221 return;
222
223 if (data->client->umodes & user_modes['p'])
224 {
0d165b52 225 data->approved = CAN_SEND_NONOP;
9101dbcd 226
b4cdedaa
JT
227 if (MyClient(data->client))
228 {
229 update_session_deadline(data->client, NULL);
230 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (forcing message)",
231 get_oper_name(data->client), data->chptr->chname);
232 }
9101dbcd
AC
233 }
234}
235
5c3014d0
AC
236static void
237handle_client_exit(void *vdata)
238{
239 hook_data_client_exit *data = (hook_data_client_exit *) vdata;
240 rb_dlink_node *n, *tn;
241 struct Client *source_p = data->target;
242
243 RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
244 {
245 struct OverrideSession *session_p = n->data;
246
247 if (session_p->client != source_p)
248 continue;
249
250 rb_dlinkDelete(n, &overriding_opers);
251 rb_free(session_p);
55abcbb2 252 }
5c3014d0
AC
253}
254
429cf1b7
AC
255struct ev_entry *expire_override_deadlines_ev = NULL;
256
257static int
258_modinit(void)
259{
cc75db3f
EK
260 rb_dlink_node *ptr;
261
429cf1b7
AC
262 /* add the usermode to the available slot */
263 user_modes['p'] = find_umode_slot();
264 construct_umodebuf();
265
cc75db3f
EK
266 RB_DLINK_FOREACH(ptr, lclient_list.head)
267 {
268 struct Client *client_p = ptr->data;
269 if (IsPerson(client_p) && (client_p->umodes & user_modes['p']))
270 update_session_deadline(client_p, NULL);
271 }
272
bd2c29f7 273 expire_override_deadlines_ev = rb_event_add("expire_override_deadlines", expire_override_deadlines, NULL, 60);
429cf1b7
AC
274
275 return 0;
276}
277
278static void
279_moddeinit(void)
280{
6637a547
EK
281 rb_dlink_node *n, *tn;
282
429cf1b7
AC
283 /* disable the umode and remove it from the available list */
284 user_modes['p'] = 0;
285 construct_umodebuf();
286
6637a547
EK
287 RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
288 {
289 rb_dlinkDelete(n, &overriding_opers);
290 rb_free(n->data);
291 }
292
429cf1b7
AC
293 rb_event_delete(expire_override_deadlines_ev);
294}
295
3fd3d7e1
EM
296DECLARE_MODULE_AV2(override, _modinit, _moddeinit, NULL, NULL,
297 override_hfnlist, NULL, NULL, override_desc);