]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
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 | * | |
8bbeb278 | 30 | * $Id$ |
212380e3 AC |
31 | */ |
32 | ||
33 | #include "stdinc.h" | |
212380e3 AC |
34 | #include "send.h" |
35 | #include "channel.h" | |
36 | #include "client.h" | |
37 | #include "common.h" | |
38 | #include "config.h" | |
39 | #include "class.h" | |
40 | #include "ircd.h" | |
41 | #include "numeric.h" | |
4016731b | 42 | #include "logger.h" |
212380e3 AC |
43 | #include "s_serv.h" |
44 | #include "whowas.h" | |
4562c604 | 45 | #include "match.h" |
212380e3 AC |
46 | #include "hash.h" |
47 | #include "msg.h" | |
48 | #include "parse.h" | |
49 | #include "modules.h" | |
50 | #include "s_conf.h" | |
51 | #include "s_newconf.h" | |
35f6f850 | 52 | #include "reject.h" |
8bbeb278 | 53 | #include "bandbi.h" |
212380e3 AC |
54 | |
55 | static int mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
56 | static int ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
57 | static int me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
8bbeb278 AC |
58 | static int mo_unxline(struct Client *client_p, struct Client *source_p, int parc, |
59 | const char *parv[]); | |
60 | static int ms_unxline(struct Client *client_p, struct Client *source_p, int parc, | |
61 | const char *parv[]); | |
62 | static int me_unxline(struct Client *client_p, struct Client *source_p, int parc, | |
63 | const char *parv[]); | |
212380e3 AC |
64 | |
65 | struct Message xline_msgtab = { | |
66 | "XLINE", 0, 0, 0, MFLG_SLOW, | |
67 | {mg_unreg, mg_not_oper, {ms_xline, 5}, {ms_xline, 5}, {me_xline, 5}, {mo_xline, 3}} | |
68 | }; | |
8bbeb278 | 69 | |
212380e3 AC |
70 | struct Message unxline_msgtab = { |
71 | "UNXLINE", 0, 0, 0, MFLG_SLOW, | |
72 | {mg_unreg, mg_not_oper, {ms_unxline, 3}, {ms_unxline, 3}, {me_unxline, 2}, {mo_unxline, 2}} | |
73 | }; | |
74 | ||
8bbeb278 AC |
75 | mapi_clist_av1 xline_clist[] = { &xline_msgtab, &unxline_msgtab, NULL }; |
76 | ||
77 | DECLARE_MODULE_AV1(xline, NULL, NULL, xline_clist, NULL, NULL, "$Revision$"); | |
212380e3 | 78 | |
8bbeb278 AC |
79 | static int valid_xline(struct Client *, const char *, const char *); |
80 | static void apply_xline(struct Client *client_p, const char *name, | |
212380e3 | 81 | const char *reason, int temp_time); |
212380e3 | 82 | static void propagate_xline(struct Client *source_p, const char *target, |
8bbeb278 | 83 | int temp_time, const char *name, const char *type, const char *reason); |
212380e3 | 84 | static void cluster_xline(struct Client *source_p, int temp_time, |
8bbeb278 | 85 | const char *name, const char *reason); |
212380e3 AC |
86 | |
87 | static void handle_remote_xline(struct Client *source_p, int temp_time, | |
88 | const char *name, const char *reason); | |
89 | static void handle_remote_unxline(struct Client *source_p, const char *name); | |
90 | ||
60c96e64 | 91 | static void remove_xline(struct Client *source_p, const char *name); |
212380e3 AC |
92 | |
93 | ||
94 | /* m_xline() | |
95 | * | |
96 | * parv[1] - thing to xline | |
97 | * parv[2] - optional type/reason | |
98 | * parv[3] - reason | |
99 | */ | |
100 | static int | |
101 | mo_xline(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 | ||
110 | if(!IsOperXline(source_p)) | |
111 | { | |
8bbeb278 | 112 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline"); |
212380e3 AC |
113 | return 0; |
114 | } | |
115 | ||
116 | if((temp_time = valid_temp_time(parv[loc])) >= 0) | |
117 | loc++; | |
118 | /* we just set temp_time to -1! */ | |
119 | else | |
120 | temp_time = 0; | |
121 | ||
122 | name = parv[loc]; | |
123 | loc++; | |
124 | ||
125 | /* XLINE <gecos> ON <server> :<reason> */ | |
8bbeb278 | 126 | if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) |
212380e3 AC |
127 | { |
128 | if(!IsOperRemoteBan(source_p)) | |
129 | { | |
130 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
8bbeb278 | 131 | me.name, source_p->name, "remoteban"); |
212380e3 AC |
132 | return 0; |
133 | } | |
134 | ||
8bbeb278 | 135 | target_server = parv[loc + 1]; |
212380e3 AC |
136 | loc += 2; |
137 | } | |
138 | ||
139 | if(parc <= loc || EmptyString(parv[loc])) | |
140 | { | |
141 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
8bbeb278 | 142 | me.name, source_p->name, "XLINE"); |
212380e3 AC |
143 | return 0; |
144 | } | |
145 | ||
146 | reason = parv[loc]; | |
147 | ||
148 | if(target_server != NULL) | |
149 | { | |
8bbeb278 | 150 | propagate_xline(source_p, target_server, temp_time, name, "2", reason); |
212380e3 AC |
151 | |
152 | if(!match(target_server, me.name)) | |
153 | return 0; | |
154 | } | |
5b96d9a6 | 155 | else if(rb_dlink_list_length(&cluster_conf_list) > 0) |
8bbeb278 | 156 | cluster_xline(source_p, temp_time, name, reason); |
212380e3 | 157 | |
8bbeb278 | 158 | if((aconf = find_xline_mask(name)) != NULL) |
212380e3 AC |
159 | { |
160 | sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s", | |
23959371 | 161 | me.name, source_p->name, name, aconf->host, aconf->passwd); |
212380e3 AC |
162 | return 0; |
163 | } | |
164 | ||
8bbeb278 | 165 | if(!valid_xline(source_p, name, reason)) |
212380e3 AC |
166 | return 0; |
167 | ||
8bbeb278 | 168 | apply_xline(source_p, name, reason, temp_time); |
212380e3 AC |
169 | |
170 | return 0; | |
171 | } | |
172 | ||
173 | /* ms_xline() | |
174 | * | |
175 | * handles a remote xline | |
176 | */ | |
177 | static int | |
178 | ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
179 | { | |
8bbeb278 AC |
180 | /* parv[0] parv[1] parv[2] parv[3] parv[4] |
181 | * oper target serv xline type reason | |
212380e3 AC |
182 | */ |
183 | propagate_xline(source_p, parv[1], 0, parv[2], parv[3], parv[4]); | |
184 | ||
185 | if(!IsPerson(source_p)) | |
186 | return 0; | |
187 | ||
188 | /* destined for me? */ | |
189 | if(!match(parv[1], me.name)) | |
190 | return 0; | |
191 | ||
192 | handle_remote_xline(source_p, 0, parv[2], parv[4]); | |
193 | return 0; | |
194 | } | |
195 | ||
196 | static int | |
197 | me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
198 | { | |
199 | /* time name type :reason */ | |
200 | if(!IsPerson(source_p)) | |
201 | return 0; | |
202 | ||
203 | handle_remote_xline(source_p, atoi(parv[1]), parv[2], parv[4]); | |
204 | return 0; | |
205 | } | |
206 | ||
207 | static void | |
8bbeb278 | 208 | handle_remote_xline(struct Client *source_p, int temp_time, const char *name, const char *reason) |
212380e3 AC |
209 | { |
210 | struct ConfItem *aconf; | |
211 | ||
212 | if(!find_shared_conf(source_p->username, source_p->host, | |
8bbeb278 AC |
213 | source_p->servptr->name, |
214 | (temp_time > 0) ? SHARED_TXLINE : SHARED_PXLINE)) | |
212380e3 AC |
215 | return; |
216 | ||
8bbeb278 | 217 | if(!valid_xline(source_p, name, reason)) |
212380e3 AC |
218 | return; |
219 | ||
220 | /* already xlined */ | |
0fdb2570 | 221 | if((aconf = find_xline_mask(name)) != NULL) |
212380e3 | 222 | { |
23959371 | 223 | sendto_one_notice(source_p, ":[%s] already X-Lined by [%s] - %s", name, aconf->host, |
8bbeb278 | 224 | aconf->passwd); |
212380e3 AC |
225 | return; |
226 | } | |
227 | ||
228 | apply_xline(source_p, name, reason, temp_time); | |
229 | } | |
230 | ||
231 | /* valid_xline() | |
232 | * | |
8bbeb278 | 233 | * inputs - client xlining, gecos, reason and whether to warn |
212380e3 AC |
234 | * outputs - |
235 | * side effects - checks the xline for validity, erroring if needed | |
236 | */ | |
237 | static int | |
8bbeb278 | 238 | valid_xline(struct Client *source_p, const char *gecos, const char *reason) |
212380e3 AC |
239 | { |
240 | if(EmptyString(reason)) | |
241 | { | |
242 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
8bbeb278 | 243 | get_id(&me, source_p), get_id(source_p, source_p), "XLINE"); |
cc169c94 JT |
244 | return 0; |
245 | } | |
246 | ||
212380e3 AC |
247 | if(strchr(reason, ':') != NULL) |
248 | { | |
8bbeb278 | 249 | sendto_one_notice(source_p, ":Invalid character ':' in comment"); |
212380e3 AC |
250 | return 0; |
251 | } | |
252 | ||
253 | if(strchr(reason, '"')) | |
254 | { | |
8bbeb278 | 255 | sendto_one_notice(source_p, ":Invalid character '\"' in comment"); |
212380e3 AC |
256 | return 0; |
257 | } | |
258 | ||
259 | if(!valid_wild_card_simple(gecos)) | |
260 | { | |
261 | sendto_one_notice(source_p, | |
262 | ":Please include at least %d non-wildcard " | |
263 | "characters with the xline", | |
264 | ConfigFileEntry.min_nonwildcard_simple); | |
265 | return 0; | |
266 | } | |
267 | ||
268 | return 1; | |
269 | } | |
270 | ||
271 | void | |
8bbeb278 | 272 | apply_xline(struct Client *source_p, const char *name, const char *reason, int temp_time) |
212380e3 AC |
273 | { |
274 | struct ConfItem *aconf; | |
275 | ||
276 | aconf = make_conf(); | |
277 | aconf->status = CONF_XLINE; | |
4418166c | 278 | aconf->host = rb_strdup(name); |
8bbeb278 | 279 | aconf->passwd = rb_strdup(reason); |
23959371 | 280 | collapse(aconf->host); |
212380e3 | 281 | |
8bbeb278 | 282 | if(temp_time > 0) |
212380e3 | 283 | { |
8bbeb278 | 284 | aconf->hold = rb_current_time() + temp_time; |
212380e3 | 285 | |
8bbeb278 AC |
286 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
287 | "%s added temporary %d min. X-Line for [%s] [%s]", | |
288 | get_oper_name(source_p), temp_time / 60, | |
23959371 | 289 | aconf->host, reason); |
8bbeb278 AC |
290 | ilog(L_KLINE, "X %s %d %s %s", |
291 | get_oper_name(source_p), temp_time / 60, name, reason); | |
292 | sendto_one_notice(source_p, ":Added temporary %d min. X-Line [%s]", | |
23959371 | 293 | temp_time / 60, aconf->host); |
8bbeb278 AC |
294 | } |
295 | else | |
212380e3 | 296 | { |
8bbeb278 | 297 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s added X-Line for [%s] [%s]", |
23959371 | 298 | get_oper_name(source_p), aconf->host, aconf->passwd); |
8bbeb278 | 299 | sendto_one_notice(source_p, ":Added X-Line for [%s] [%s]", |
23959371 | 300 | aconf->host, aconf->passwd); |
8bbeb278 | 301 | |
23959371 | 302 | bandb_add(BANDB_XLINE, source_p, aconf->host, NULL, aconf->passwd, NULL, 0); |
f36d4fdd | 303 | ilog(L_KLINE, "X %s 0 %s %s", get_oper_name(source_p), name, aconf->passwd); |
212380e3 | 304 | } |
8bbeb278 AC |
305 | |
306 | rb_dlinkAddAlloc(aconf, &xline_conf_list); | |
307 | check_xlines(); | |
212380e3 AC |
308 | } |
309 | ||
8bbeb278 | 310 | static void |
212380e3 | 311 | propagate_xline(struct Client *source_p, const char *target, |
8bbeb278 | 312 | int temp_time, const char *name, const char *type, const char *reason) |
212380e3 AC |
313 | { |
314 | if(!temp_time) | |
315 | { | |
316 | sendto_match_servs(source_p, target, CAP_CLUSTER, NOCAPS, | |
8bbeb278 | 317 | "XLINE %s %s %s :%s", target, name, type, reason); |
212380e3 | 318 | sendto_match_servs(source_p, target, CAP_ENCAP, CAP_CLUSTER, |
8bbeb278 | 319 | "ENCAP %s XLINE %d %s 2 :%s", target, temp_time, name, reason); |
212380e3 AC |
320 | } |
321 | else | |
322 | sendto_match_servs(source_p, target, CAP_ENCAP, NOCAPS, | |
8bbeb278 AC |
323 | "ENCAP %s XLINE %d %s %s :%s", |
324 | target, temp_time, name, type, reason); | |
212380e3 | 325 | } |
8bbeb278 | 326 | |
212380e3 | 327 | static void |
8bbeb278 | 328 | cluster_xline(struct Client *source_p, int temp_time, const char *name, const char *reason) |
212380e3 AC |
329 | { |
330 | struct remote_conf *shared_p; | |
5b96d9a6 | 331 | rb_dlink_node *ptr; |
212380e3 | 332 | |
5b96d9a6 | 333 | RB_DLINK_FOREACH(ptr, cluster_conf_list.head) |
212380e3 AC |
334 | { |
335 | shared_p = ptr->data; | |
336 | ||
337 | /* old protocol cant handle temps, and we dont really want | |
338 | * to convert them to perm.. --fl | |
339 | */ | |
340 | if(!temp_time) | |
341 | { | |
342 | if(!(shared_p->flags & SHARED_PXLINE)) | |
343 | continue; | |
344 | ||
345 | sendto_match_servs(source_p, shared_p->server, CAP_CLUSTER, NOCAPS, | |
8bbeb278 | 346 | "XLINE %s %s 2 :%s", shared_p->server, name, reason); |
212380e3 | 347 | sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, CAP_CLUSTER, |
8bbeb278 AC |
348 | "ENCAP %s XLINE 0 %s 2 :%s", |
349 | shared_p->server, name, reason); | |
212380e3 AC |
350 | } |
351 | else if(shared_p->flags & SHARED_TXLINE) | |
352 | sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, NOCAPS, | |
8bbeb278 AC |
353 | "ENCAP %s XLINE %d %s 2 :%s", |
354 | shared_p->server, temp_time, name, reason); | |
212380e3 AC |
355 | } |
356 | } | |
357 | ||
358 | /* mo_unxline() | |
359 | * | |
360 | * parv[1] - thing to unxline | |
361 | */ | |
362 | static int | |
363 | mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
364 | { | |
365 | if(!IsOperXline(source_p)) | |
366 | { | |
8bbeb278 | 367 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline"); |
212380e3 AC |
368 | return 0; |
369 | } | |
370 | ||
371 | if(parc == 4 && !(irccmp(parv[2], "ON"))) | |
372 | { | |
373 | if(!IsOperRemoteBan(source_p)) | |
374 | { | |
375 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
8bbeb278 | 376 | me.name, source_p->name, "remoteban"); |
212380e3 AC |
377 | return 0; |
378 | } | |
379 | ||
8bbeb278 | 380 | propagate_generic(source_p, "UNXLINE", parv[3], CAP_CLUSTER, "%s", parv[1]); |
212380e3 AC |
381 | |
382 | if(match(parv[3], me.name) == 0) | |
383 | return 0; | |
384 | } | |
5b96d9a6 | 385 | else if(rb_dlink_list_length(&cluster_conf_list)) |
8bbeb278 | 386 | cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", parv[1]); |
212380e3 | 387 | |
212380e3 AC |
388 | remove_xline(source_p, parv[1]); |
389 | ||
390 | return 0; | |
391 | } | |
392 | ||
393 | /* ms_unxline() | |
394 | * | |
395 | * handles a remote unxline | |
396 | */ | |
397 | static int | |
398 | ms_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
399 | { | |
8bbeb278 AC |
400 | /* parv[0] parv[1] parv[2] |
401 | * oper target server gecos | |
212380e3 | 402 | */ |
8bbeb278 | 403 | propagate_generic(source_p, "UNXLINE", parv[1], CAP_CLUSTER, "%s", parv[2]); |
212380e3 AC |
404 | |
405 | if(!match(parv[1], me.name)) | |
406 | return 0; | |
407 | ||
408 | if(!IsPerson(source_p)) | |
409 | return 0; | |
410 | ||
411 | handle_remote_unxline(source_p, parv[2]); | |
412 | return 0; | |
413 | } | |
414 | ||
415 | static int | |
416 | me_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
417 | { | |
418 | /* name */ | |
419 | if(!IsPerson(source_p)) | |
420 | return 0; | |
421 | ||
422 | handle_remote_unxline(source_p, parv[1]); | |
423 | return 0; | |
424 | } | |
425 | ||
426 | static void | |
427 | handle_remote_unxline(struct Client *source_p, const char *name) | |
428 | { | |
429 | if(!find_shared_conf(source_p->username, source_p->host, | |
8bbeb278 | 430 | source_p->servptr->name, SHARED_UNXLINE)) |
212380e3 AC |
431 | return; |
432 | ||
212380e3 AC |
433 | remove_xline(source_p, name); |
434 | ||
435 | return; | |
436 | } | |
437 | ||
60c96e64 | 438 | static void |
5408b484 | 439 | remove_xline(struct Client *source_p, const char *name) |
212380e3 AC |
440 | { |
441 | struct ConfItem *aconf; | |
5b96d9a6 | 442 | rb_dlink_node *ptr; |
212380e3 | 443 | |
5b96d9a6 | 444 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) |
212380e3 AC |
445 | { |
446 | aconf = ptr->data; | |
447 | ||
23959371 | 448 | if(!irccmp(aconf->host, name)) |
212380e3 | 449 | { |
8bbeb278 | 450 | if(!aconf->hold) |
5408b484 | 451 | { |
8bbeb278 AC |
452 | bandb_del(BANDB_XLINE, aconf->host, NULL); |
453 | ||
454 | sendto_one_notice(source_p, ":X-Line for [%s] is removed", aconf->host); | |
455 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
456 | "%s has removed the X-Line for: [%s]", | |
457 | get_oper_name(source_p), aconf->host); | |
458 | ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), aconf->host); | |
5408b484 JT |
459 | } |
460 | else | |
461 | { | |
8bbeb278 | 462 | sendto_one_notice(source_p, ":X-Line for [%s] is removed", name); |
5408b484 | 463 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
8bbeb278 AC |
464 | "%s has removed the temporary X-Line for: [%s]", |
465 | get_oper_name(source_p), name); | |
466 | ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name); | |
5408b484 | 467 | } |
8bbeb278 | 468 | |
23959371 | 469 | remove_reject_mask(aconf->host, NULL); |
212380e3 | 470 | free_conf(aconf); |
555ac41f | 471 | rb_dlinkDestroy(ptr, &xline_conf_list); |
60c96e64 | 472 | return; |
212380e3 AC |
473 | } |
474 | } | |
475 | ||
8bbeb278 | 476 | sendto_one_notice(source_p, ":No X-Line for %s", name); |
5408b484 | 477 | |
60c96e64 | 478 | return; |
212380e3 | 479 | } |