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