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