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