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