]>
Commit | Line | Data |
---|---|---|
1 | /* modules/m_xline.c | |
2 | * | |
3 | * Copyright (C) 2002-2003 Lee Hardy <lee@leeh.co.uk> | |
4 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are | |
8 | * met: | |
9 | * | |
10 | * 1.Redistributions of source code must retain the above copyright notice, | |
11 | * this list of conditions and the following disclaimer. | |
12 | * 2.Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3.The name of the author may not be used to endorse or promote products | |
16 | * derived from this software without specific prior written permission. | |
17 | * | |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
27 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
28 | * POSSIBILITY OF SUCH DAMAGE. | |
29 | */ | |
30 | ||
31 | #include "stdinc.h" | |
32 | #include "send.h" | |
33 | #include "channel.h" | |
34 | #include "client.h" | |
35 | #include "defaults.h" | |
36 | #include "class.h" | |
37 | #include "ircd.h" | |
38 | #include "numeric.h" | |
39 | #include "logger.h" | |
40 | #include "s_serv.h" | |
41 | #include "whowas.h" | |
42 | #include "match.h" | |
43 | #include "hash.h" | |
44 | #include "msg.h" | |
45 | #include "parse.h" | |
46 | #include "modules.h" | |
47 | #include "s_conf.h" | |
48 | #include "s_newconf.h" | |
49 | #include "reject.h" | |
50 | #include "bandbi.h" | |
51 | #include "operhash.h" | |
52 | ||
53 | static const char xline_desc[] = | |
54 | "Provides management of GECOS bans via (UN)XLINE command"; | |
55 | ||
56 | static void mo_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
57 | static void ms_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
58 | static void me_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
59 | static void mo_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, | |
60 | const char *parv[]); | |
61 | static void ms_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, | |
62 | const char *parv[]); | |
63 | static void me_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, | |
64 | const char *parv[]); | |
65 | ||
66 | static bool valid_xline(struct Client *, const char *, const char *); | |
67 | static void apply_xline(struct Client *client_p, const char *name, | |
68 | const char *reason, int temp_time, bool propagated); | |
69 | static void propagate_xline(struct Client *source_p, const char *target, | |
70 | int temp_time, const char *name, const char *type, const char *reason); | |
71 | static void cluster_xline(struct Client *source_p, int temp_time, | |
72 | const char *name, const char *reason); | |
73 | ||
74 | static void handle_remote_xline(struct Client *source_p, int temp_time, | |
75 | const char *name, const char *reason); | |
76 | static void handle_remote_unxline(struct Client *source_p, const char *name); | |
77 | static void remove_xline(struct Client *source_p, const char *name, | |
78 | bool propagated); | |
79 | ||
80 | struct Message xline_msgtab = { | |
81 | "XLINE", 0, 0, 0, 0, | |
82 | {mg_unreg, mg_not_oper, {ms_xline, 5}, {ms_xline, 5}, {me_xline, 5}, {mo_xline, 3}} | |
83 | }; | |
84 | ||
85 | struct Message unxline_msgtab = { | |
86 | "UNXLINE", 0, 0, 0, 0, | |
87 | {mg_unreg, mg_not_oper, {ms_unxline, 3}, {ms_unxline, 3}, {me_unxline, 2}, {mo_unxline, 2}} | |
88 | }; | |
89 | ||
90 | mapi_clist_av1 xline_clist[] = { &xline_msgtab, &unxline_msgtab, NULL }; | |
91 | ||
92 | DECLARE_MODULE_AV2(xline, NULL, NULL, xline_clist, NULL, NULL, NULL, NULL, xline_desc); | |
93 | ||
94 | /* m_xline() | |
95 | * | |
96 | * parv[1] - thing to xline | |
97 | * parv[2] - optional type/reason | |
98 | * parv[3] - reason | |
99 | */ | |
100 | static void | |
101 | mo_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
102 | { | |
103 | struct ConfItem *aconf; | |
104 | const char *name; | |
105 | const char *reason; | |
106 | const char *target_server = NULL; | |
107 | int temp_time; | |
108 | int loc = 1; | |
109 | bool propagated = ConfigFileEntry.use_propagated_bans; | |
110 | ||
111 | if(!IsOperXline(source_p)) | |
112 | { | |
113 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline"); | |
114 | return; | |
115 | } | |
116 | ||
117 | if((temp_time = valid_temp_time(parv[loc])) >= 0) | |
118 | loc++; | |
119 | /* we just set temp_time to -1! */ | |
120 | else | |
121 | temp_time = 0; | |
122 | ||
123 | name = parv[loc]; | |
124 | loc++; | |
125 | ||
126 | /* XLINE <gecos> ON <server> :<reason> */ | |
127 | if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) | |
128 | { | |
129 | if(!IsOperRemoteBan(source_p)) | |
130 | { | |
131 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
132 | me.name, source_p->name, "remoteban"); | |
133 | return; | |
134 | } | |
135 | ||
136 | target_server = parv[loc + 1]; | |
137 | loc += 2; | |
138 | } | |
139 | ||
140 | if(parc <= loc || EmptyString(parv[loc])) | |
141 | { | |
142 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
143 | me.name, source_p->name, "XLINE"); | |
144 | return; | |
145 | } | |
146 | ||
147 | reason = parv[loc]; | |
148 | ||
149 | if(target_server != NULL) | |
150 | { | |
151 | propagate_xline(source_p, target_server, temp_time, name, "2", reason); | |
152 | ||
153 | if(!match(target_server, me.name)) | |
154 | return; | |
155 | ||
156 | /* Set as local-only. */ | |
157 | propagated = false; | |
158 | } | |
159 | else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) | |
160 | cluster_xline(source_p, temp_time, name, reason); | |
161 | ||
162 | if((aconf = find_xline_mask(name)) != NULL) | |
163 | { | |
164 | sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s", | |
165 | me.name, source_p->name, name, aconf->host, aconf->passwd); | |
166 | return; | |
167 | } | |
168 | ||
169 | if(!valid_xline(source_p, name, reason)) | |
170 | return; | |
171 | ||
172 | if(propagated && temp_time == 0) | |
173 | { | |
174 | sendto_one_notice(source_p, ":Cannot set a permanent global ban"); | |
175 | return; | |
176 | } | |
177 | ||
178 | apply_xline(source_p, name, reason, temp_time, propagated); | |
179 | } | |
180 | ||
181 | /* ms_xline() | |
182 | * | |
183 | * handles a remote xline | |
184 | */ | |
185 | static void | |
186 | ms_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
187 | { | |
188 | /* parv[0] parv[1] parv[2] parv[3] parv[4] | |
189 | * oper target serv xline type reason | |
190 | */ | |
191 | propagate_xline(source_p, parv[1], 0, parv[2], parv[3], parv[4]); | |
192 | ||
193 | if(!IsPerson(source_p)) | |
194 | return; | |
195 | ||
196 | /* destined for me? */ | |
197 | if(!match(parv[1], me.name)) | |
198 | return; | |
199 | ||
200 | handle_remote_xline(source_p, 0, parv[2], parv[4]); | |
201 | } | |
202 | ||
203 | static void | |
204 | me_xline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
205 | { | |
206 | /* time name type :reason */ | |
207 | if(!IsPerson(source_p)) | |
208 | return; | |
209 | ||
210 | handle_remote_xline(source_p, atoi(parv[1]), parv[2], parv[4]); | |
211 | } | |
212 | ||
213 | static void | |
214 | handle_remote_xline(struct Client *source_p, int temp_time, const char *name, const char *reason) | |
215 | { | |
216 | struct ConfItem *aconf; | |
217 | ||
218 | if(!valid_xline(source_p, name, reason)) | |
219 | return; | |
220 | ||
221 | /* already xlined */ | |
222 | if((aconf = find_xline_mask(name)) != NULL) | |
223 | { | |
224 | sendto_one_notice(source_p, ":[%s] already X-Lined by [%s] - %s", name, aconf->host, | |
225 | aconf->passwd); | |
226 | return; | |
227 | } | |
228 | ||
229 | apply_xline(source_p, name, reason, temp_time, false); | |
230 | } | |
231 | ||
232 | /* valid_xline() | |
233 | * | |
234 | * inputs - client xlining, gecos, reason and whether to warn | |
235 | * outputs - | |
236 | * side effects - checks the xline for validity, erroring if needed | |
237 | */ | |
238 | static bool | |
239 | valid_xline(struct Client *source_p, const char *gecos, const char *reason) | |
240 | { | |
241 | if(EmptyString(reason)) | |
242 | { | |
243 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
244 | get_id(&me, source_p), get_id(source_p, source_p), "XLINE"); | |
245 | return false; | |
246 | } | |
247 | ||
248 | if(!valid_wild_card_simple(gecos)) | |
249 | { | |
250 | sendto_one_notice(source_p, | |
251 | ":Please include at least %d non-wildcard " | |
252 | "characters with the xline", | |
253 | ConfigFileEntry.min_nonwildcard_simple); | |
254 | return false; | |
255 | } | |
256 | ||
257 | return true; | |
258 | } | |
259 | ||
260 | void | |
261 | apply_xline(struct Client *source_p, const char *name, const char *reason, int temp_time, bool propagated) | |
262 | { | |
263 | struct ConfItem *aconf; | |
264 | ||
265 | aconf = make_conf(); | |
266 | aconf->status = CONF_XLINE; | |
267 | aconf->created = rb_current_time(); | |
268 | aconf->host = rb_strdup(name); | |
269 | aconf->passwd = rb_strdup(reason); | |
270 | collapse(aconf->host); | |
271 | ||
272 | aconf->info.oper = operhash_add(get_oper_name(source_p)); | |
273 | ||
274 | if(propagated) | |
275 | { | |
276 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; | |
277 | aconf->hold = rb_current_time() + temp_time; | |
278 | aconf->lifetime = aconf->hold; | |
279 | ||
280 | replace_old_ban(aconf); | |
281 | rb_dlinkAddAlloc(aconf, &prop_bans); | |
282 | ||
283 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
284 | "%s added global %d min. X-Line for [%s] [%s]", | |
285 | get_oper_name(source_p), temp_time / 60, | |
286 | aconf->host, reason); | |
287 | ilog(L_KLINE, "X %s %d %s %s", | |
288 | get_oper_name(source_p), temp_time / 60, name, reason); | |
289 | sendto_one_notice(source_p, ":Added global %d min. X-Line [%s]", | |
290 | temp_time / 60, aconf->host); | |
291 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
292 | ":%s BAN X * %s %lu %d %d * :%s", | |
293 | source_p->id, aconf->host, | |
294 | (unsigned long)aconf->created, | |
295 | (int)(aconf->hold - aconf->created), | |
296 | (int)(aconf->lifetime - aconf->created), | |
297 | reason); | |
298 | } | |
299 | else if(temp_time > 0) | |
300 | { | |
301 | aconf->hold = rb_current_time() + temp_time; | |
302 | ||
303 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
304 | "%s added temporary %d min. X-Line for [%s] [%s]", | |
305 | get_oper_name(source_p), temp_time / 60, | |
306 | aconf->host, reason); | |
307 | ilog(L_KLINE, "X %s %d %s %s", | |
308 | get_oper_name(source_p), temp_time / 60, name, reason); | |
309 | sendto_one_notice(source_p, ":Added temporary %d min. X-Line [%s]", | |
310 | temp_time / 60, aconf->host); | |
311 | } | |
312 | else | |
313 | { | |
314 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s added X-Line for [%s] [%s]", | |
315 | get_oper_name(source_p), aconf->host, aconf->passwd); | |
316 | sendto_one_notice(source_p, ":Added X-Line for [%s] [%s]", | |
317 | aconf->host, aconf->passwd); | |
318 | ||
319 | bandb_add(BANDB_XLINE, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); | |
320 | ilog(L_KLINE, "X %s 0 %s %s", get_oper_name(source_p), name, aconf->passwd); | |
321 | } | |
322 | ||
323 | rb_dlinkAddAlloc(aconf, &xline_conf_list); | |
324 | check_xlines(); | |
325 | } | |
326 | ||
327 | static void | |
328 | propagate_xline(struct Client *source_p, const char *target, | |
329 | int temp_time, const char *name, const char *type, const char *reason) | |
330 | { | |
331 | if(!temp_time) | |
332 | { | |
333 | sendto_match_servs(source_p, target, CAP_CLUSTER, NOCAPS, | |
334 | "XLINE %s %s %s :%s", target, name, type, reason); | |
335 | sendto_match_servs(source_p, target, CAP_ENCAP, CAP_CLUSTER, | |
336 | "ENCAP %s XLINE %d %s 2 :%s", target, temp_time, name, reason); | |
337 | } | |
338 | else | |
339 | sendto_match_servs(source_p, target, CAP_ENCAP, NOCAPS, | |
340 | "ENCAP %s XLINE %d %s %s :%s", | |
341 | target, temp_time, name, type, reason); | |
342 | } | |
343 | ||
344 | static void | |
345 | cluster_xline(struct Client *source_p, int temp_time, const char *name, const char *reason) | |
346 | { | |
347 | struct remote_conf *shared_p; | |
348 | rb_dlink_node *ptr; | |
349 | ||
350 | RB_DLINK_FOREACH(ptr, cluster_conf_list.head) | |
351 | { | |
352 | shared_p = ptr->data; | |
353 | ||
354 | /* old protocol cant handle temps, and we dont really want | |
355 | * to convert them to perm.. --fl | |
356 | */ | |
357 | if(!temp_time) | |
358 | { | |
359 | if(!(shared_p->flags & SHARED_PXLINE)) | |
360 | continue; | |
361 | ||
362 | sendto_match_servs(source_p, shared_p->server, CAP_CLUSTER, NOCAPS, | |
363 | "XLINE %s %s 2 :%s", shared_p->server, name, reason); | |
364 | sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, CAP_CLUSTER, | |
365 | "ENCAP %s XLINE 0 %s 2 :%s", | |
366 | shared_p->server, name, reason); | |
367 | } | |
368 | else if(shared_p->flags & SHARED_TXLINE) | |
369 | sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, NOCAPS, | |
370 | "ENCAP %s XLINE %d %s 2 :%s", | |
371 | shared_p->server, temp_time, name, reason); | |
372 | } | |
373 | } | |
374 | ||
375 | /* mo_unxline() | |
376 | * | |
377 | * parv[1] - thing to unxline | |
378 | */ | |
379 | static void | |
380 | mo_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
381 | { | |
382 | bool propagated = true; | |
383 | ||
384 | if(!IsOperXline(source_p)) | |
385 | { | |
386 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline"); | |
387 | return; | |
388 | } | |
389 | ||
390 | if(parc == 4 && !(irccmp(parv[2], "ON"))) | |
391 | { | |
392 | if(!IsOperRemoteBan(source_p)) | |
393 | { | |
394 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
395 | me.name, source_p->name, "remoteban"); | |
396 | return; | |
397 | } | |
398 | ||
399 | propagate_generic(source_p, "UNXLINE", parv[3], CAP_CLUSTER, "%s", parv[1]); | |
400 | ||
401 | if(match(parv[3], me.name) == 0) | |
402 | return; | |
403 | ||
404 | propagated = false; | |
405 | } | |
406 | /* cluster{} moved to remove_xline */ | |
407 | ||
408 | remove_xline(source_p, parv[1], propagated); | |
409 | } | |
410 | ||
411 | /* ms_unxline() | |
412 | * | |
413 | * handles a remote unxline | |
414 | */ | |
415 | static void | |
416 | ms_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
417 | { | |
418 | /* parv[0] parv[1] parv[2] | |
419 | * oper target server gecos | |
420 | */ | |
421 | propagate_generic(source_p, "UNXLINE", parv[1], CAP_CLUSTER, "%s", parv[2]); | |
422 | ||
423 | if(!match(parv[1], me.name)) | |
424 | return; | |
425 | ||
426 | if(!IsPerson(source_p)) | |
427 | return; | |
428 | ||
429 | handle_remote_unxline(source_p, parv[2]); | |
430 | } | |
431 | ||
432 | static void | |
433 | me_unxline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
434 | { | |
435 | /* name */ | |
436 | if(!IsPerson(source_p)) | |
437 | return; | |
438 | ||
439 | handle_remote_unxline(source_p, parv[1]); | |
440 | } | |
441 | ||
442 | static void | |
443 | handle_remote_unxline(struct Client *source_p, const char *name) | |
444 | { | |
445 | remove_xline(source_p, name, false); | |
446 | } | |
447 | ||
448 | static void | |
449 | remove_xline(struct Client *source_p, const char *name, bool propagated) | |
450 | { | |
451 | struct ConfItem *aconf; | |
452 | rb_dlink_node *ptr; | |
453 | time_t now; | |
454 | ||
455 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) | |
456 | { | |
457 | aconf = ptr->data; | |
458 | ||
459 | if(!irccmp(aconf->host, name)) | |
460 | { | |
461 | if(aconf->lifetime) | |
462 | { | |
463 | if(!propagated) | |
464 | { | |
465 | sendto_one_notice(source_p, ":Cannot remove global X-Line %s on specific servers", name); | |
466 | return; | |
467 | } | |
468 | ptr = rb_dlinkFind(aconf, &prop_bans); | |
469 | if(ptr == NULL) | |
470 | return; | |
471 | sendto_one_notice(source_p, ":X-Line for [%s] is removed", name); | |
472 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
473 | "%s has removed the global X-Line for: [%s]", | |
474 | get_oper_name(source_p), name); | |
475 | ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name); | |
476 | now = rb_current_time(); | |
477 | if(aconf->created < now) | |
478 | aconf->created = now; | |
479 | else | |
480 | aconf->created++; | |
481 | aconf->hold = aconf->created; | |
482 | operhash_delete(aconf->info.oper); | |
483 | aconf->info.oper = operhash_add(get_oper_name(source_p)); | |
484 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; | |
485 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
486 | ":%s BAN X * %s %lu %d %d * :*", | |
487 | source_p->id, aconf->host, | |
488 | (unsigned long)aconf->created, | |
489 | 0, | |
490 | (int)(aconf->lifetime - aconf->created)); | |
491 | remove_reject_mask(aconf->host, NULL); | |
492 | deactivate_conf(aconf, ptr, now); | |
493 | return; | |
494 | } | |
495 | else if(propagated && rb_dlink_list_length(&cluster_conf_list)) | |
496 | cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); | |
497 | if(!aconf->hold) | |
498 | { | |
499 | bandb_del(BANDB_XLINE, aconf->host, NULL); | |
500 | ||
501 | sendto_one_notice(source_p, ":X-Line for [%s] is removed", aconf->host); | |
502 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
503 | "%s has removed the X-Line for: [%s]", | |
504 | get_oper_name(source_p), aconf->host); | |
505 | ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), aconf->host); | |
506 | } | |
507 | else | |
508 | { | |
509 | sendto_one_notice(source_p, ":X-Line for [%s] is removed", name); | |
510 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
511 | "%s has removed the temporary X-Line for: [%s]", | |
512 | get_oper_name(source_p), name); | |
513 | ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name); | |
514 | } | |
515 | ||
516 | remove_reject_mask(aconf->host, NULL); | |
517 | free_conf(aconf); | |
518 | rb_dlinkDestroy(ptr, &xline_conf_list); | |
519 | return; | |
520 | } | |
521 | } | |
522 | ||
523 | if(propagated && rb_dlink_list_length(&cluster_conf_list)) | |
524 | cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", name); | |
525 | ||
526 | sendto_one_notice(source_p, ":No X-Line for %s", name); | |
527 | } |