]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_kline.c: Bans/unbans a user. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
24 | * $Id$ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "channel.h" | |
29 | #include "class.h" | |
30 | #include "client.h" | |
31 | #include "common.h" | |
32 | #include "match.h" | |
33 | #include "ircd.h" | |
34 | #include "hostmask.h" | |
35 | #include "numeric.h" | |
36 | #include "s_conf.h" | |
37 | #include "s_newconf.h" | |
38 | #include "logger.h" | |
39 | #include "send.h" | |
40 | #include "hash.h" | |
41 | #include "s_serv.h" | |
42 | #include "msg.h" | |
43 | #include "parse.h" | |
44 | #include "modules.h" | |
45 | #include "reject.h" | |
46 | #include "bandbi.h" | |
47 | #include "operhash.h" | |
48 | ||
49 | static int mo_kline(struct Client *, struct Client *, int, const char **); | |
50 | static int ms_kline(struct Client *, struct Client *, int, const char **); | |
51 | static int me_kline(struct Client *, struct Client *, int, const char **); | |
52 | static int mo_unkline(struct Client *, struct Client *, int, const char **); | |
53 | static int ms_unkline(struct Client *, struct Client *, int, const char **); | |
54 | static int me_unkline(struct Client *, struct Client *, int, const char **); | |
55 | ||
56 | struct Message kline_msgtab = { | |
57 | "KLINE", 0, 0, 0, MFLG_SLOW, | |
58 | {mg_unreg, mg_not_oper, {ms_kline, 5}, {ms_kline, 5}, {me_kline, 5}, {mo_kline, 3}} | |
59 | }; | |
60 | ||
61 | struct Message unkline_msgtab = { | |
62 | "UNKLINE", 0, 0, 0, MFLG_SLOW, | |
63 | {mg_unreg, mg_not_oper, {ms_unkline, 4}, {ms_unkline, 4}, {me_unkline, 3}, {mo_unkline, 2}} | |
64 | }; | |
65 | ||
66 | mapi_clist_av1 kline_clist[] = { &kline_msgtab, &unkline_msgtab, NULL }; | |
67 | ||
68 | DECLARE_MODULE_AV1(kline, NULL, NULL, kline_clist, NULL, NULL, "$Revision$"); | |
69 | ||
70 | /* Local function prototypes */ | |
71 | static int find_user_host(struct Client *source_p, const char *userhost, char *user, char *host); | |
72 | static int valid_comment(struct Client *source_p, char *comment); | |
73 | static int valid_user_host(struct Client *source_p, const char *user, const char *host); | |
74 | ||
75 | static void handle_remote_kline(struct Client *source_p, int tkline_time, | |
76 | const char *user, const char *host, const char *reason); | |
77 | static void apply_kline(struct Client *source_p, struct ConfItem *aconf, | |
78 | const char *reason, const char *oper_reason); | |
79 | static void apply_tkline(struct Client *source_p, struct ConfItem *aconf, | |
80 | const char *, const char *, int); | |
81 | static void apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, | |
82 | const char *, const char *, int); | |
83 | static int already_placed_kline(struct Client *, const char *, const char *, int); | |
84 | ||
85 | static void handle_remote_unkline(struct Client *source_p, const char *user, const char *host); | |
86 | static void remove_permkline_match(struct Client *, struct ConfItem *); | |
87 | static int remove_temp_kline(struct Client *, struct ConfItem *); | |
88 | static void remove_prop_kline(struct Client *, struct ConfItem *); | |
89 | ||
90 | /* mo_kline() | |
91 | * | |
92 | * parv[1] - temp time or user@host | |
93 | * parv[2] - user@host, "ON", or reason | |
94 | * parv[3] - "ON", reason, or server to target | |
95 | * parv[4] - server to target, or reason | |
96 | * parv[5] - reason | |
97 | */ | |
98 | static int | |
99 | mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char **parv) | |
100 | { | |
101 | char def[] = "No Reason"; | |
102 | char user[USERLEN + 2]; | |
103 | char host[HOSTLEN + 2]; | |
104 | char *reason = def; | |
105 | char *oper_reason; | |
106 | const char *target_server = NULL; | |
107 | struct ConfItem *aconf; | |
108 | int tkline_time = 0; | |
109 | int loc = 1; | |
110 | int propagated = ConfigFileEntry.use_propagated_bans; | |
111 | ||
112 | if(!IsOperK(source_p)) | |
113 | { | |
114 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline"); | |
115 | return 0; | |
116 | } | |
117 | ||
118 | if((tkline_time = valid_temp_time(parv[loc])) >= 0) | |
119 | loc++; | |
120 | /* we just set tkline_time to -1! */ | |
121 | else | |
122 | tkline_time = 0; | |
123 | ||
124 | if(find_user_host(source_p, parv[loc], user, host) == 0) | |
125 | return 0; | |
126 | ||
127 | loc++; | |
128 | ||
129 | if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) | |
130 | { | |
131 | if(!IsOperRemoteBan(source_p)) | |
132 | { | |
133 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
134 | me.name, source_p->name, "remoteban"); | |
135 | return 0; | |
136 | } | |
137 | ||
138 | target_server = parv[loc + 1]; | |
139 | loc += 2; | |
140 | } | |
141 | ||
142 | if(parc <= loc || EmptyString(parv[loc])) | |
143 | { | |
144 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
145 | me.name, source_p->name, "KLINE"); | |
146 | return 0; | |
147 | } | |
148 | ||
149 | reason = LOCAL_COPY(parv[loc]); | |
150 | ||
151 | if(target_server != NULL) | |
152 | { | |
153 | propagate_generic(source_p, "KLINE", target_server, CAP_KLN, | |
154 | "%d %s %s :%s", tkline_time, user, host, reason); | |
155 | ||
156 | /* If we are sending it somewhere that doesnt include us, stop */ | |
157 | if(!match(target_server, me.name)) | |
158 | return 0; | |
159 | ||
160 | /* Set as local-only. */ | |
161 | propagated = 0; | |
162 | } | |
163 | /* if we have cluster servers, send it to them.. */ | |
164 | else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) | |
165 | cluster_generic(source_p, "KLINE", | |
166 | (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE, CAP_KLN, | |
167 | "%lu %s %s :%s", tkline_time, user, host, reason); | |
168 | ||
169 | if(!valid_user_host(source_p, user, host) || | |
170 | !valid_comment(source_p, reason)) | |
171 | return 0; | |
172 | ||
173 | if(!valid_wild_card(user, host)) | |
174 | { | |
175 | sendto_one_notice(source_p, | |
176 | ":Please include at least %d non-wildcard " | |
177 | "characters with the user@host", | |
178 | ConfigFileEntry.min_nonwildcard); | |
179 | return 0; | |
180 | } | |
181 | ||
182 | if(propagated && tkline_time == 0) | |
183 | { | |
184 | sendto_one_notice(source_p, ":Cannot set a permanent global ban"); | |
185 | return 0; | |
186 | } | |
187 | ||
188 | if(already_placed_kline(source_p, user, host, tkline_time)) | |
189 | return 0; | |
190 | ||
191 | rb_set_time(); | |
192 | aconf = make_conf(); | |
193 | aconf->status = CONF_KILL; | |
194 | aconf->created = rb_current_time(); | |
195 | aconf->host = rb_strdup(host); | |
196 | aconf->user = rb_strdup(user); | |
197 | aconf->port = 0; | |
198 | aconf->info.oper = operhash_add(get_oper_name(source_p)); | |
199 | ||
200 | /* Look for an oper reason */ | |
201 | if((oper_reason = strchr(reason, '|')) != NULL) | |
202 | { | |
203 | *oper_reason = '\0'; | |
204 | oper_reason++; | |
205 | ||
206 | if(!EmptyString(oper_reason)) | |
207 | aconf->spasswd = rb_strdup(oper_reason); | |
208 | } | |
209 | aconf->passwd = rb_strdup(reason); | |
210 | ||
211 | if(propagated) | |
212 | apply_prop_kline(source_p, aconf, reason, oper_reason, tkline_time); | |
213 | else if(tkline_time > 0) | |
214 | apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); | |
215 | else | |
216 | apply_kline(source_p, aconf, reason, oper_reason); | |
217 | ||
218 | if(ConfigFileEntry.kline_delay) | |
219 | { | |
220 | if(kline_queued == 0) | |
221 | { | |
222 | rb_event_addonce("check_klines", check_klines_event, NULL, | |
223 | ConfigFileEntry.kline_delay); | |
224 | kline_queued = 1; | |
225 | } | |
226 | } | |
227 | else | |
228 | check_klines(); | |
229 | ||
230 | return 0; | |
231 | } | |
232 | ||
233 | /* ms_kline() | |
234 | * | |
235 | * parv[1] - server targeted at | |
236 | * parv[2] - tkline time (0 if perm) | |
237 | * parv[3] - user | |
238 | * parv[4] - host | |
239 | * parv[5] - reason | |
240 | */ | |
241 | static int | |
242 | ms_kline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
243 | { | |
244 | int tkline_time = atoi(parv[2]); | |
245 | ||
246 | /* 1.5-3 and earlier contains a bug that allows remote klines to be | |
247 | * sent with an empty reason field. This is a protocol violation, | |
248 | * but its not worth dropping the link over.. --anfl | |
249 | */ | |
250 | if(parc < 6 || EmptyString(parv[5])) | |
251 | return 0; | |
252 | ||
253 | propagate_generic(source_p, "KLINE", parv[1], CAP_KLN, | |
254 | "%d %s %s :%s", tkline_time, parv[3], parv[4], parv[5]); | |
255 | ||
256 | if(!match(parv[1], me.name)) | |
257 | return 0; | |
258 | ||
259 | if(!IsPerson(source_p)) | |
260 | return 0; | |
261 | ||
262 | handle_remote_kline(source_p, tkline_time, parv[3], parv[4], parv[5]); | |
263 | return 0; | |
264 | } | |
265 | ||
266 | static int | |
267 | me_kline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
268 | { | |
269 | /* <tkline_time> <user> <host> :<reason> */ | |
270 | if(!IsPerson(source_p)) | |
271 | return 0; | |
272 | ||
273 | handle_remote_kline(source_p, atoi(parv[1]), parv[2], parv[3], parv[4]); | |
274 | return 0; | |
275 | } | |
276 | ||
277 | static void | |
278 | handle_remote_kline(struct Client *source_p, int tkline_time, | |
279 | const char *user, const char *host, const char *kreason) | |
280 | { | |
281 | char *reason = LOCAL_COPY(kreason); | |
282 | struct ConfItem *aconf = NULL; | |
283 | char *oper_reason; | |
284 | ||
285 | if(!find_shared_conf(source_p->username, source_p->host, | |
286 | source_p->servptr->name, | |
287 | (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE)) | |
288 | return; | |
289 | ||
290 | if(!valid_user_host(source_p, user, host) || | |
291 | !valid_comment(source_p, reason)) | |
292 | return; | |
293 | ||
294 | if(!valid_wild_card(user, host)) | |
295 | { | |
296 | sendto_one_notice(source_p, | |
297 | ":Please include at least %d non-wildcard " | |
298 | "characters with the user@host", | |
299 | ConfigFileEntry.min_nonwildcard); | |
300 | return; | |
301 | } | |
302 | ||
303 | if(already_placed_kline(source_p, user, host, tkline_time)) | |
304 | return; | |
305 | ||
306 | aconf = make_conf(); | |
307 | ||
308 | aconf->status = CONF_KILL; | |
309 | aconf->created = rb_current_time(); | |
310 | aconf->user = rb_strdup(user); | |
311 | aconf->host = rb_strdup(host); | |
312 | aconf->info.oper = operhash_add(get_oper_name(source_p)); | |
313 | ||
314 | /* Look for an oper reason */ | |
315 | if((oper_reason = strchr(reason, '|')) != NULL) | |
316 | { | |
317 | *oper_reason = '\0'; | |
318 | oper_reason++; | |
319 | ||
320 | if(!EmptyString(oper_reason)) | |
321 | aconf->spasswd = rb_strdup(oper_reason); | |
322 | } | |
323 | aconf->passwd = rb_strdup(reason); | |
324 | ||
325 | if(tkline_time > 0) | |
326 | apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); | |
327 | else | |
328 | apply_kline(source_p, aconf, reason, oper_reason); | |
329 | ||
330 | if(ConfigFileEntry.kline_delay) | |
331 | { | |
332 | if(kline_queued == 0) | |
333 | { | |
334 | rb_event_addonce("check_klines", check_klines_event, NULL, | |
335 | ConfigFileEntry.kline_delay); | |
336 | kline_queued = 1; | |
337 | } | |
338 | } | |
339 | else | |
340 | check_klines(); | |
341 | ||
342 | return; | |
343 | } | |
344 | ||
345 | /* mo_unkline() | |
346 | * | |
347 | * parv[1] - kline to remove | |
348 | * parv[2] - optional "ON" | |
349 | * parv[3] - optional target server | |
350 | */ | |
351 | static int | |
352 | mo_unkline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
353 | { | |
354 | const char *user; | |
355 | char *host; | |
356 | char splat[] = "*"; | |
357 | char *h = LOCAL_COPY(parv[1]); | |
358 | struct ConfItem *aconf; | |
359 | int propagated = 1; | |
360 | ||
361 | if(!IsOperUnkline(source_p)) | |
362 | { | |
363 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline"); | |
364 | return 0; | |
365 | } | |
366 | ||
367 | if((host = strchr(h, '@')) || *h == '*' || strchr(h, '.') || strchr(h, ':')) | |
368 | { | |
369 | /* Explicit user@host mask given */ | |
370 | ||
371 | if(host) /* Found user@host */ | |
372 | { | |
373 | *host++ = '\0'; | |
374 | ||
375 | /* check for @host */ | |
376 | if(*h) | |
377 | user = h; | |
378 | else | |
379 | user = splat; | |
380 | ||
381 | /* check for user@ */ | |
382 | if(!*host) | |
383 | host = splat; | |
384 | } | |
385 | else | |
386 | { | |
387 | user = splat; /* no @ found, assume its *@somehost */ | |
388 | host = h; | |
389 | } | |
390 | } | |
391 | else | |
392 | { | |
393 | sendto_one_notice(source_p, ":Invalid parameters"); | |
394 | return 0; | |
395 | } | |
396 | ||
397 | /* possible remote kline.. */ | |
398 | if((parc > 3) && (irccmp(parv[2], "ON") == 0)) | |
399 | { | |
400 | if(!IsOperRemoteBan(source_p)) | |
401 | { | |
402 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
403 | me.name, source_p->name, "remoteban"); | |
404 | return 0; | |
405 | } | |
406 | ||
407 | propagate_generic(source_p, "UNKLINE", parv[3], CAP_UNKLN, "%s %s", user, host); | |
408 | ||
409 | if(match(parv[3], me.name) == 0) | |
410 | return 0; | |
411 | ||
412 | propagated = 0; | |
413 | } | |
414 | ||
415 | aconf = find_exact_conf_by_address(host, CONF_KILL, user); | |
416 | ||
417 | /* No clustering for removing a propagated kline */ | |
418 | if(propagated && (aconf == NULL || !aconf->lifetime) && | |
419 | rb_dlink_list_length(&cluster_conf_list) > 0) | |
420 | cluster_generic(source_p, "UNKLINE", SHARED_UNKLINE, CAP_UNKLN, | |
421 | "%s %s", user, host); | |
422 | ||
423 | if(aconf == NULL) | |
424 | { | |
425 | sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); | |
426 | return 0; | |
427 | } | |
428 | ||
429 | if(aconf->lifetime) | |
430 | { | |
431 | if(propagated) | |
432 | remove_prop_kline(source_p, aconf); | |
433 | else | |
434 | sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); | |
435 | return 0; | |
436 | } | |
437 | ||
438 | if(remove_temp_kline(source_p, aconf)) | |
439 | return 0; | |
440 | ||
441 | remove_permkline_match(source_p, aconf); | |
442 | ||
443 | return 0; | |
444 | } | |
445 | ||
446 | /* ms_unkline() | |
447 | * | |
448 | * parv[1] - target server | |
449 | * parv[2] - user to unkline | |
450 | * parv[3] - host to unkline | |
451 | */ | |
452 | static int | |
453 | ms_unkline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
454 | { | |
455 | /* parv[0] parv[1] parv[2] parv[3] | |
456 | * oper target server user host */ | |
457 | propagate_generic(source_p, "UNKLINE", parv[1], CAP_UNKLN, "%s %s", parv[2], parv[3]); | |
458 | ||
459 | if(!match(parv[1], me.name)) | |
460 | return 0; | |
461 | ||
462 | if(!IsPerson(source_p)) | |
463 | return 0; | |
464 | ||
465 | handle_remote_unkline(source_p, parv[2], parv[3]); | |
466 | return 0; | |
467 | } | |
468 | ||
469 | static int | |
470 | me_unkline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
471 | { | |
472 | /* user host */ | |
473 | if(!IsPerson(source_p)) | |
474 | return 0; | |
475 | ||
476 | handle_remote_unkline(source_p, parv[1], parv[2]); | |
477 | return 0; | |
478 | } | |
479 | ||
480 | static void | |
481 | handle_remote_unkline(struct Client *source_p, const char *user, const char *host) | |
482 | { | |
483 | struct ConfItem *aconf; | |
484 | ||
485 | if(!find_shared_conf(source_p->username, source_p->host, | |
486 | source_p->servptr->name, SHARED_UNKLINE)) | |
487 | return; | |
488 | ||
489 | aconf = find_exact_conf_by_address(host, CONF_KILL, user); | |
490 | if(aconf == NULL) | |
491 | { | |
492 | sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); | |
493 | return; | |
494 | } | |
495 | if(aconf->lifetime) | |
496 | { | |
497 | sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); | |
498 | return; | |
499 | } | |
500 | ||
501 | if(remove_temp_kline(source_p, aconf)) | |
502 | return; | |
503 | ||
504 | remove_permkline_match(source_p, aconf); | |
505 | } | |
506 | ||
507 | /* apply_kline() | |
508 | * | |
509 | * inputs - | |
510 | * output - NONE | |
511 | * side effects - kline as given, is added to the hashtable | |
512 | * and conf file | |
513 | */ | |
514 | static void | |
515 | apply_kline(struct Client *source_p, struct ConfItem *aconf, | |
516 | const char *reason, const char *oper_reason) | |
517 | { | |
518 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); | |
519 | bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host, | |
520 | reason, EmptyString(oper_reason) ? NULL : oper_reason, 0); | |
521 | ||
522 | /* no oper reason.. */ | |
523 | if(EmptyString(oper_reason)) | |
524 | { | |
525 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
526 | "%s added K-Line for [%s@%s] [%s]", | |
527 | get_oper_name(source_p), aconf->user, aconf->host, reason); | |
528 | ilog(L_KLINE, "K %s 0 %s %s %s", | |
529 | get_oper_name(source_p), aconf->user, aconf->host, reason); | |
530 | } | |
531 | else | |
532 | { | |
533 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
534 | "%s added K-Line for [%s@%s] [%s|%s]", | |
535 | get_oper_name(source_p), aconf->user, aconf->host, | |
536 | reason, oper_reason); | |
537 | ilog(L_KLINE, "K %s 0 %s %s %s|%s", | |
538 | get_oper_name(source_p), aconf->user, aconf->host, reason, oper_reason); | |
539 | } | |
540 | ||
541 | sendto_one_notice(source_p, ":Added K-Line [%s@%s]", | |
542 | aconf->user, aconf->host); | |
543 | } | |
544 | ||
545 | /* apply_tkline() | |
546 | * | |
547 | * inputs - | |
548 | * output - NONE | |
549 | * side effects - tkline as given is placed | |
550 | */ | |
551 | static void | |
552 | apply_tkline(struct Client *source_p, struct ConfItem *aconf, | |
553 | const char *reason, const char *oper_reason, int tkline_time) | |
554 | { | |
555 | aconf->hold = rb_current_time() + tkline_time; | |
556 | add_temp_kline(aconf); | |
557 | ||
558 | /* no oper reason.. */ | |
559 | if(EmptyString(oper_reason)) | |
560 | { | |
561 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
562 | "%s added temporary %d min. K-Line for [%s@%s] [%s]", | |
563 | get_oper_name(source_p), tkline_time / 60, | |
564 | aconf->user, aconf->host, reason); | |
565 | ilog(L_KLINE, "K %s %d %s %s %s", | |
566 | get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); | |
567 | } | |
568 | else | |
569 | { | |
570 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
571 | "%s added temporary %d min. K-Line for [%s@%s] [%s|%s]", | |
572 | get_oper_name(source_p), tkline_time / 60, | |
573 | aconf->user, aconf->host, reason, oper_reason); | |
574 | ilog(L_KLINE, "K %s %d %s %s %s|%s", | |
575 | get_oper_name(source_p), tkline_time / 60, | |
576 | aconf->user, aconf->host, reason, oper_reason); | |
577 | } | |
578 | ||
579 | sendto_one_notice(source_p, ":Added temporary %d min. K-Line [%s@%s]", | |
580 | tkline_time / 60, aconf->user, aconf->host); | |
581 | } | |
582 | ||
583 | static void | |
584 | apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, | |
585 | const char *reason, const char *oper_reason, int tkline_time) | |
586 | { | |
587 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; | |
588 | aconf->hold = rb_current_time() + tkline_time; | |
589 | aconf->lifetime = aconf->hold; | |
590 | ||
591 | replace_old_ban(aconf); | |
592 | ||
593 | rb_dlinkAddAlloc(aconf, &prop_bans); | |
594 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); | |
595 | ||
596 | /* no oper reason.. */ | |
597 | if(EmptyString(oper_reason)) | |
598 | { | |
599 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
600 | "%s added global %d min. K-Line for [%s@%s] [%s]", | |
601 | get_oper_name(source_p), tkline_time / 60, | |
602 | aconf->user, aconf->host, reason); | |
603 | ilog(L_KLINE, "K %s %d %s %s %s", | |
604 | get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); | |
605 | } | |
606 | else | |
607 | { | |
608 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
609 | "%s added global %d min. K-Line for [%s@%s] [%s|%s]", | |
610 | get_oper_name(source_p), tkline_time / 60, | |
611 | aconf->user, aconf->host, reason, oper_reason); | |
612 | ilog(L_KLINE, "K %s %d %s %s %s|%s", | |
613 | get_oper_name(source_p), tkline_time / 60, | |
614 | aconf->user, aconf->host, reason, oper_reason); | |
615 | } | |
616 | ||
617 | sendto_one_notice(source_p, ":Added global %d min. K-Line [%s@%s]", | |
618 | tkline_time / 60, aconf->user, aconf->host); | |
619 | ||
620 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
621 | ":%s BAN K %s %s %lu %d %d * :%s%s%s", | |
622 | source_p->id, aconf->user, aconf->host, | |
623 | (unsigned long)aconf->created, | |
624 | (int)(aconf->hold - aconf->created), | |
625 | (int)(aconf->lifetime - aconf->created), | |
626 | reason, | |
627 | oper_reason ? "|" : "", | |
628 | oper_reason ? oper_reason : ""); | |
629 | } | |
630 | ||
631 | /* find_user_host() | |
632 | * | |
633 | * inputs - client placing kline, user@host, user buffer, host buffer | |
634 | * output - 0 if not ok to kline, 1 to kline i.e. if valid user host | |
635 | * side effects - | |
636 | */ | |
637 | static int | |
638 | find_user_host(struct Client *source_p, const char *userhost, char *luser, char *lhost) | |
639 | { | |
640 | char *hostp; | |
641 | ||
642 | hostp = strchr(userhost, '@'); | |
643 | ||
644 | if(hostp != NULL) /* I'm a little user@host */ | |
645 | { | |
646 | *(hostp++) = '\0'; /* short and squat */ | |
647 | if(*userhost) | |
648 | rb_strlcpy(luser, userhost, USERLEN + 1); /* here is my user */ | |
649 | else | |
650 | strcpy(luser, "*"); | |
651 | if(*hostp) | |
652 | rb_strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ | |
653 | else | |
654 | strcpy(lhost, "*"); | |
655 | } | |
656 | else | |
657 | { | |
658 | /* no '@', no '.', so its not a user@host or host, therefore | |
659 | * its a nick, which support was removed for. | |
660 | */ | |
661 | if(strchr(userhost, '.') == NULL && strchr(userhost, ':') == NULL) | |
662 | { | |
663 | sendto_one_notice(source_p, ":K-Line must be a user@host or host"); | |
664 | return 0; | |
665 | } | |
666 | ||
667 | luser[0] = '*'; /* no @ found, assume its *@somehost */ | |
668 | luser[1] = '\0'; | |
669 | rb_strlcpy(lhost, userhost, HOSTLEN + 1); | |
670 | } | |
671 | ||
672 | /* would break the protocol */ | |
673 | if (*luser == ':' || *lhost == ':') | |
674 | { | |
675 | sendto_one_notice(source_p, ":Invalid K-Line"); | |
676 | return 0; | |
677 | } | |
678 | ||
679 | return 1; | |
680 | } | |
681 | ||
682 | /* valid_user_host() | |
683 | * | |
684 | * inputs - user buffer, host buffer | |
685 | * output - 0 if invalid, 1 if valid | |
686 | * side effects - | |
687 | */ | |
688 | static int | |
689 | valid_user_host(struct Client *source_p, const char *luser, const char *lhost) | |
690 | { | |
691 | /* # is invalid, as are '!' (n!u@h kline) and '@' (u@@h kline) */ | |
692 | if(strchr(lhost, '#') || strchr(luser, '#') || strchr(luser, '!') || strchr(lhost, '@')) | |
693 | { | |
694 | sendto_one_notice(source_p, ":Invalid K-Line"); | |
695 | return 0; | |
696 | } | |
697 | ||
698 | return 1; | |
699 | } | |
700 | ||
701 | /* | |
702 | * valid_comment | |
703 | * inputs - pointer to client | |
704 | * - pointer to comment | |
705 | * output - 0 if no valid comment, 1 if valid | |
706 | * side effects - NONE | |
707 | */ | |
708 | static int | |
709 | valid_comment(struct Client *source_p, char *comment) | |
710 | { | |
711 | if(strchr(comment, '"')) | |
712 | { | |
713 | sendto_one_notice(source_p, ":Invalid character '\"' in comment"); | |
714 | return 0; | |
715 | } | |
716 | ||
717 | if(strlen(comment) > BANREASONLEN) | |
718 | comment[BANREASONLEN] = '\0'; | |
719 | ||
720 | return 1; | |
721 | } | |
722 | ||
723 | /* already_placed_kline() | |
724 | * | |
725 | * inputs - source to notify, user@host to check, tkline time | |
726 | * outputs - 1 if a perm kline or a tkline when a tkline is being | |
727 | * set exists, else 0 | |
728 | * side effects - notifies source_p kline exists | |
729 | */ | |
730 | /* Note: This currently works if the new K-line is a special case of an | |
731 | * existing K-line, but not the other way round. To do that we would | |
732 | * have to walk the hash and check every existing K-line. -A1kmm. | |
733 | */ | |
734 | static int | |
735 | already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int tkline) | |
736 | { | |
737 | const char *reason, *p; | |
738 | struct rb_sockaddr_storage iphost, *piphost; | |
739 | struct ConfItem *aconf; | |
740 | int t, bits; | |
741 | ||
742 | aconf = find_exact_conf_by_address(lhost, CONF_KILL, luser); | |
743 | if(aconf == NULL && ConfigFileEntry.non_redundant_klines) | |
744 | { | |
745 | bits = 0; | |
746 | if((t = parse_netmask(lhost, (struct sockaddr *) &iphost, &bits)) != HM_HOST) | |
747 | { | |
748 | #ifdef RB_IPV6 | |
749 | if(t == HM_IPV6) | |
750 | t = AF_INET6; | |
751 | else | |
752 | #endif | |
753 | t = AF_INET; | |
754 | ||
755 | piphost = &iphost; | |
756 | } | |
757 | else | |
758 | piphost = NULL; | |
759 | ||
760 | aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *) piphost, | |
761 | CONF_KILL, t, luser, NULL); | |
762 | if(aconf != NULL) | |
763 | { | |
764 | /* The above was really a lookup of a single IP, | |
765 | * so check if the new kline is wider than the | |
766 | * existing one. | |
767 | * -- jilles | |
768 | */ | |
769 | p = strchr(aconf->host, '/'); | |
770 | if(bits > 0 && (p == NULL || bits < atoi(p + 1))) | |
771 | aconf = NULL; | |
772 | } | |
773 | } | |
774 | if(aconf != NULL) | |
775 | { | |
776 | /* setting a tkline, or existing one is perm */ | |
777 | if(tkline || ((aconf->flags & CONF_FLAGS_TEMPORARY) == 0)) | |
778 | { | |
779 | reason = aconf->passwd ? aconf->passwd : "<No Reason>"; | |
780 | ||
781 | sendto_one_notice(source_p, | |
782 | ":[%s@%s] already K-Lined by [%s@%s] - %s", | |
783 | luser, lhost, aconf->user, aconf->host, reason); | |
784 | return 1; | |
785 | } | |
786 | } | |
787 | ||
788 | return 0; | |
789 | } | |
790 | ||
791 | /* remove_permkline_match() | |
792 | * | |
793 | * hunts for a permanent kline, and removes it. | |
794 | */ | |
795 | static void | |
796 | remove_permkline_match(struct Client *source_p, struct ConfItem *aconf) | |
797 | { | |
798 | sendto_one_notice(source_p, ":K-Line for [%s@%s] is removed", aconf->user, aconf->host); | |
799 | ||
800 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
801 | "%s has removed the K-Line for: [%s@%s]", | |
802 | get_oper_name(source_p), aconf->user, aconf->host); | |
803 | ||
804 | ilog(L_KLINE, "UK %s %s %s", get_oper_name(source_p), aconf->user, aconf->host); | |
805 | ||
806 | remove_reject_mask(aconf->user, aconf->host); | |
807 | bandb_del(BANDB_KLINE, aconf->user, aconf->host); | |
808 | delete_one_address_conf(aconf->host, aconf); | |
809 | ||
810 | return; | |
811 | } | |
812 | ||
813 | /* remove_temp_kline() | |
814 | * | |
815 | * inputs - username, hostname to unkline | |
816 | * outputs - | |
817 | * side effects - tries to unkline anything that matches | |
818 | */ | |
819 | static int | |
820 | remove_temp_kline(struct Client *source_p, struct ConfItem *aconf) | |
821 | { | |
822 | rb_dlink_node *ptr; | |
823 | int i; | |
824 | ||
825 | for(i = 0; i < LAST_TEMP_TYPE; i++) | |
826 | { | |
827 | RB_DLINK_FOREACH(ptr, temp_klines[i].head) | |
828 | { | |
829 | if(aconf == ptr->data) | |
830 | { | |
831 | sendto_one_notice(source_p, | |
832 | ":Un-klined [%s@%s] from temporary k-lines", | |
833 | aconf->user, aconf->host); | |
834 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
835 | "%s has removed the temporary K-Line for: [%s@%s]", | |
836 | get_oper_name(source_p), aconf->user, | |
837 | aconf->host); | |
838 | ||
839 | ilog(L_KLINE, "UK %s %s %s", | |
840 | get_oper_name(source_p), aconf->user, aconf->host); | |
841 | rb_dlinkDestroy(ptr, &temp_klines[i]); | |
842 | remove_reject_mask(aconf->user, aconf->host); | |
843 | delete_one_address_conf(aconf->host, aconf); | |
844 | return YES; | |
845 | } | |
846 | } | |
847 | } | |
848 | ||
849 | return NO; | |
850 | } | |
851 | ||
852 | static void | |
853 | remove_prop_kline(struct Client *source_p, struct ConfItem *aconf) | |
854 | { | |
855 | rb_dlink_node *ptr; | |
856 | ||
857 | ptr = rb_dlinkFind(aconf, &prop_bans); | |
858 | if (!ptr) | |
859 | return; | |
860 | sendto_one_notice(source_p, | |
861 | ":Un-klined [%s@%s] from global k-lines", | |
862 | aconf->user, aconf->host); | |
863 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
864 | "%s has removed the global K-Line for: [%s@%s]", | |
865 | get_oper_name(source_p), aconf->user, | |
866 | aconf->host); | |
867 | ||
868 | ilog(L_KLINE, "UK %s %s %s", | |
869 | get_oper_name(source_p), aconf->user, aconf->host); | |
870 | if(aconf->created < rb_current_time()) | |
871 | aconf->created = rb_current_time(); | |
872 | else | |
873 | aconf->created++; | |
874 | aconf->hold = aconf->created; | |
875 | operhash_delete(aconf->info.oper); | |
876 | aconf->info.oper = operhash_add(get_oper_name(source_p)); | |
877 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; | |
878 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
879 | ":%s BAN K %s %s %lu %d %d * :*", | |
880 | source_p->id, aconf->user, aconf->host, | |
881 | (unsigned long)aconf->created, | |
882 | 0, | |
883 | (int)(aconf->lifetime - aconf->created)); | |
884 | remove_reject_mask(aconf->user, aconf->host); | |
885 | deactivate_conf(aconf, ptr); | |
886 | } |