]>
Commit | Line | Data |
---|---|---|
429cf1b7 AC |
1 | /* |
2 | * oper-override for charybdis. | |
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 | ||
25 | static void check_umode_change(void *data); | |
26 | static void hack_channel_access(void *data); | |
d3076881 | 27 | static void hack_can_join(void *data); |
9101dbcd | 28 | static void hack_can_send(void *data); |
5c3014d0 | 29 | static void handle_client_exit(void *data); |
429cf1b7 AC |
30 | |
31 | mapi_hfn_list_av1 override_hfnlist[] = { | |
32 | { "umode_changed", (hookfn) check_umode_change }, | |
33 | { "get_channel_access", (hookfn) hack_channel_access }, | |
d3076881 | 34 | { "can_join", (hookfn) hack_can_join }, |
9101dbcd | 35 | { "can_send", (hookfn) hack_can_send }, |
5c3014d0 | 36 | { "client_exit", (hookfn) handle_client_exit }, |
429cf1b7 AC |
37 | { NULL, NULL } |
38 | }; | |
39 | ||
40 | #define IsOperOverride(x) (HasPrivilege((x), "oper:override")) | |
41 | ||
42 | struct OverrideSession { | |
43 | rb_dlink_node node; | |
44 | ||
45 | struct Client *client; | |
46 | time_t deadline; | |
47 | }; | |
48 | ||
49 | rb_dlink_list overriding_opers = { NULL, NULL, 0 }; | |
50 | ||
51 | static void | |
52 | update_session_deadline(struct Client *source_p, struct OverrideSession *session_p) | |
53 | { | |
54 | if (session_p == NULL) | |
55 | { | |
56 | rb_dlink_node *n; | |
57 | ||
58 | RB_DLINK_FOREACH(n, overriding_opers.head) | |
59 | { | |
60 | struct OverrideSession *s = n->data; | |
61 | ||
62 | if (s->client == source_p) | |
63 | { | |
64 | session_p = s; | |
65 | break; | |
66 | } | |
67 | } | |
68 | } | |
69 | ||
70 | if (session_p == NULL) | |
71 | { | |
72 | session_p = rb_malloc(sizeof(struct OverrideSession)); | |
73 | session_p->client = source_p; | |
74 | } | |
75 | ||
76 | session_p->deadline = rb_current_time() + 1800; | |
77 | ||
78 | rb_dlinkDelete(&session_p->node, &overriding_opers); | |
79 | rb_dlinkAdd(session_p, &session_p->node, &overriding_opers); | |
80 | } | |
81 | ||
82 | static void | |
83 | expire_override_deadlines(void *unused) | |
84 | { | |
85 | rb_dlink_node *n, *tn; | |
86 | ||
87 | RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head) | |
88 | { | |
89 | struct OverrideSession *session_p = n->data; | |
90 | ||
91 | if (session_p->deadline > rb_current_time()) | |
92 | break; | |
93 | else if (session_p->deadline < rb_current_time()) | |
94 | { | |
95 | const char *parv[4] = {session_p->client->name, session_p->client->name, "-p", NULL}; | |
96 | user_mode(session_p->client, session_p->client, 3, parv); | |
97 | } | |
98 | } | |
99 | } | |
100 | ||
101 | static void | |
102 | check_umode_change(void *vdata) | |
103 | { | |
104 | hook_data_umode_changed *data = (hook_data_umode_changed *)vdata; | |
105 | struct Client *source_p = data->client; | |
106 | ||
107 | if (!MyClient(source_p)) | |
108 | return; | |
109 | ||
e5c254d7 JT |
110 | if (data->oldumodes & UMODE_OPER && !IsOper(source_p)) |
111 | source_p->umodes &= ~user_modes['p']; | |
112 | ||
429cf1b7 AC |
113 | /* didn't change +p umode, we don't need to do anything */ |
114 | if (!((data->oldumodes ^ source_p->umodes) & user_modes['p'])) | |
115 | return; | |
116 | ||
429cf1b7 AC |
117 | if (source_p->umodes & user_modes['p']) |
118 | { | |
e5c254d7 JT |
119 | if (!IsOperOverride(source_p)) |
120 | { | |
121 | sendto_one_notice(source_p, ":*** You need oper:override privilege for +p"); | |
122 | source_p->umodes &= ~user_modes['p']; | |
123 | return; | |
124 | } | |
125 | ||
429cf1b7 AC |
126 | update_session_deadline(source_p, NULL); |
127 | ||
128 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s has enabled oper-override (+p)", | |
129 | get_oper_name(source_p)); | |
130 | } | |
131 | else if (!(source_p->umodes & user_modes['p'])) | |
132 | { | |
133 | rb_dlink_node *n, *tn; | |
134 | ||
135 | RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head) | |
136 | { | |
137 | struct OverrideSession *session_p = n->data; | |
138 | ||
139 | if (session_p->client != source_p) | |
140 | continue; | |
141 | ||
142 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s has disabled oper-override (+p)", | |
143 | get_oper_name(session_p->client)); | |
144 | ||
145 | rb_dlinkDelete(n, &overriding_opers); | |
146 | rb_free(session_p); | |
147 | } | |
148 | } | |
149 | } | |
150 | ||
151 | static void | |
152 | hack_channel_access(void *vdata) | |
153 | { | |
154 | hook_data_channel_approval *data = (hook_data_channel_approval *) vdata; | |
155 | ||
156 | if (data->approved == CHFL_CHANOP) | |
157 | return; | |
158 | ||
159 | if (data->client->umodes & user_modes['p']) | |
160 | { | |
161 | update_session_deadline(data->client, NULL); | |
162 | data->approved = CHFL_CHANOP; | |
163 | ||
164 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (modehacking)", | |
165 | get_oper_name(data->client), data->chptr->chname); | |
166 | } | |
167 | } | |
168 | ||
d3076881 AC |
169 | static void |
170 | hack_can_join(void *vdata) | |
171 | { | |
172 | hook_data_channel *data = (hook_data_channel *) vdata; | |
173 | ||
174 | if (data->approved == 0) | |
175 | return; | |
176 | ||
177 | if (data->client->umodes & user_modes['p']) | |
178 | { | |
179 | update_session_deadline(data->client, NULL); | |
180 | data->approved = 0; | |
181 | ||
182 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (banwalking)", | |
183 | get_oper_name(data->client), data->chptr->chname); | |
184 | } | |
185 | } | |
186 | ||
9101dbcd AC |
187 | static void |
188 | hack_can_send(void *vdata) | |
189 | { | |
190 | hook_data_channel_approval *data = (hook_data_channel_approval *) vdata; | |
191 | ||
192 | if (data->approved == CAN_SEND_NONOP || data->approved == CAN_SEND_OPV) | |
193 | return; | |
194 | ||
195 | if (data->client->umodes & user_modes['p']) | |
196 | { | |
0d165b52 | 197 | data->approved = CAN_SEND_NONOP; |
9101dbcd | 198 | |
b4cdedaa JT |
199 | if (MyClient(data->client)) |
200 | { | |
201 | update_session_deadline(data->client, NULL); | |
202 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (forcing message)", | |
203 | get_oper_name(data->client), data->chptr->chname); | |
204 | } | |
9101dbcd AC |
205 | } |
206 | } | |
207 | ||
5c3014d0 AC |
208 | static void |
209 | handle_client_exit(void *vdata) | |
210 | { | |
211 | hook_data_client_exit *data = (hook_data_client_exit *) vdata; | |
212 | rb_dlink_node *n, *tn; | |
213 | struct Client *source_p = data->target; | |
214 | ||
215 | RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head) | |
216 | { | |
217 | struct OverrideSession *session_p = n->data; | |
218 | ||
219 | if (session_p->client != source_p) | |
220 | continue; | |
221 | ||
222 | rb_dlinkDelete(n, &overriding_opers); | |
223 | rb_free(session_p); | |
224 | } | |
225 | } | |
226 | ||
429cf1b7 AC |
227 | struct ev_entry *expire_override_deadlines_ev = NULL; |
228 | ||
229 | static int | |
230 | _modinit(void) | |
231 | { | |
232 | /* add the usermode to the available slot */ | |
233 | user_modes['p'] = find_umode_slot(); | |
234 | construct_umodebuf(); | |
235 | ||
236 | expire_override_deadlines_ev = rb_event_add("expire_override_deadlines", expire_override_deadlines, NULL, 60); | |
237 | ||
238 | return 0; | |
239 | } | |
240 | ||
241 | static void | |
242 | _moddeinit(void) | |
243 | { | |
244 | /* disable the umode and remove it from the available list */ | |
245 | user_modes['p'] = 0; | |
246 | construct_umodebuf(); | |
247 | ||
248 | rb_event_delete(expire_override_deadlines_ev); | |
249 | } | |
250 | ||
251 | DECLARE_MODULE_AV1(override, _modinit, _moddeinit, NULL, NULL, | |
252 | override_hfnlist, "$Revision: 3526 $"); |