]> jfr.im git - solanum.git/blame - modules/m_kline.c
msg: remove last vestiges of the fakelag system. charybdis has never supported fakelag.
[solanum.git] / modules / m_kline.c
CommitLineData
212380e3
AC
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 *
8bbeb278 24 * $Id$
212380e3
AC
25 */
26
27#include "stdinc.h"
212380e3
AC
28#include "channel.h"
29#include "class.h"
30#include "client.h"
31#include "common.h"
4562c604 32#include "match.h"
212380e3
AC
33#include "ircd.h"
34#include "hostmask.h"
35#include "numeric.h"
212380e3
AC
36#include "s_conf.h"
37#include "s_newconf.h"
4016731b 38#include "logger.h"
212380e3
AC
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"
35f6f850 45#include "reject.h"
8bbeb278 46#include "bandbi.h"
27f616dd 47#include "operhash.h"
212380e3 48
428ca87b
AC
49static int mo_kline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
50static int ms_kline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
51static int me_kline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
52static int mo_unkline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
53static int ms_unkline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
54static int me_unkline(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
55
56struct Message kline_msgtab = {
7baa37a9 57 "KLINE", 0, 0, 0, 0,
212380e3
AC
58 {mg_unreg, mg_not_oper, {ms_kline, 5}, {ms_kline, 5}, {me_kline, 5}, {mo_kline, 3}}
59};
60
61struct Message unkline_msgtab = {
7baa37a9 62 "UNKLINE", 0, 0, 0, 0,
212380e3
AC
63 {mg_unreg, mg_not_oper, {ms_unkline, 4}, {ms_unkline, 4}, {me_unkline, 3}, {mo_unkline, 2}}
64};
65
66mapi_clist_av1 kline_clist[] = { &kline_msgtab, &unkline_msgtab, NULL };
8bbeb278
AC
67
68DECLARE_MODULE_AV1(kline, NULL, NULL, kline_clist, NULL, NULL, "$Revision$");
212380e3
AC
69
70/* Local function prototypes */
71static int find_user_host(struct Client *source_p, const char *userhost, char *user, char *host);
212380e3 72static int valid_user_host(struct Client *source_p, const char *user, const char *host);
212380e3
AC
73
74static void handle_remote_kline(struct Client *source_p, int tkline_time,
8bbeb278 75 const char *user, const char *host, const char *reason);
212380e3 76static void apply_kline(struct Client *source_p, struct ConfItem *aconf,
b52c2949 77 const char *reason, const char *oper_reason);
212380e3 78static void apply_tkline(struct Client *source_p, struct ConfItem *aconf,
b52c2949 79 const char *, const char *, int);
431a1a27
JT
80static void apply_prop_kline(struct Client *source_p, struct ConfItem *aconf,
81 const char *, const char *, int);
212380e3
AC
82static int already_placed_kline(struct Client *, const char *, const char *, int);
83
8bbeb278 84static void handle_remote_unkline(struct Client *source_p, const char *user, const char *host);
40a1d446 85static void remove_permkline_match(struct Client *, struct ConfItem *);
d922dded 86static int remove_temp_kline(struct Client *, struct ConfItem *);
431a1a27 87static void remove_prop_kline(struct Client *, struct ConfItem *);
212380e3
AC
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 */
97static int
428ca87b 98mo_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
212380e3 99{
8bbeb278 100 char def[] = "No Reason";
212380e3
AC
101 char user[USERLEN + 2];
102 char host[HOSTLEN + 2];
8bbeb278 103 char *reason = def;
212380e3 104 char *oper_reason;
212380e3
AC
105 const char *target_server = NULL;
106 struct ConfItem *aconf;
107 int tkline_time = 0;
108 int loc = 1;
1702b694 109 int propagated = ConfigFileEntry.use_propagated_bans;
212380e3
AC
110
111 if(!IsOperK(source_p))
112 {
8bbeb278 113 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline");
212380e3
AC
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
8bbeb278 128 if(parc >= loc + 2 && !irccmp(parv[loc], "ON"))
212380e3
AC
129 {
130 if(!IsOperRemoteBan(source_p))
131 {
132 sendto_one(source_p, form_str(ERR_NOPRIVS),
8bbeb278 133 me.name, source_p->name, "remoteban");
212380e3
AC
134 return 0;
135 }
136
8bbeb278 137 target_server = parv[loc + 1];
212380e3
AC
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,
8bbeb278 153 "%d %s %s :%s", tkline_time, user, host, reason);
212380e3
AC
154
155 /* If we are sending it somewhere that doesnt include us, stop */
156 if(!match(target_server, me.name))
157 return 0;
431a1a27
JT
158
159 /* Set as local-only. */
160 propagated = 0;
212380e3
AC
161 }
162 /* if we have cluster servers, send it to them.. */
431a1a27 163 else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0)
8bbeb278 164 cluster_generic(source_p, "KLINE",
212380e3 165 (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE, CAP_KLN,
8bbeb278 166 "%lu %s %s :%s", tkline_time, user, host, reason);
212380e3 167
9319a2e2 168 if(!valid_user_host(source_p, user, host))
212380e3
AC
169 return 0;
170
5c2b9eaf
JT
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
431a1a27
JT
180 if(propagated && tkline_time == 0)
181 {
182 sendto_one_notice(source_p, ":Cannot set a permanent global ban");
183 return 0;
184 }
185
212380e3
AC
186 if(already_placed_kline(source_p, user, host, tkline_time))
187 return 0;
188
7df5fcfb 189 rb_set_time();
212380e3
AC
190 aconf = make_conf();
191 aconf->status = CONF_KILL;
b52c2949 192 aconf->created = rb_current_time();
47a03750
VY
193 aconf->host = rb_strdup(host);
194 aconf->user = rb_strdup(user);
212380e3 195 aconf->port = 0;
27f616dd 196 aconf->info.oper = operhash_add(get_oper_name(source_p));
212380e3 197
9319a2e2
KB
198 if(strlen(reason) > BANREASONLEN)
199 reason[BANREASONLEN] = '\0';
200
212380e3
AC
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))
47a03750 208 aconf->spasswd = rb_strdup(oper_reason);
212380e3 209 }
c935336b 210 aconf->passwd = rb_strdup(reason);
212380e3 211
431a1a27
JT
212 if(propagated)
213 apply_prop_kline(source_p, aconf, reason, oper_reason, tkline_time);
214 else if(tkline_time > 0)
b52c2949 215 apply_tkline(source_p, aconf, reason, oper_reason, tkline_time);
212380e3 216 else
b52c2949 217 apply_kline(source_p, aconf, reason, oper_reason);
212380e3
AC
218
219 if(ConfigFileEntry.kline_delay)
220 {
221 if(kline_queued == 0)
222 {
0e7cb7e6 223 rb_event_addonce("check_klines", check_klines_event, NULL,
8bbeb278 224 ConfigFileEntry.kline_delay);
212380e3
AC
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 */
242static int
428ca87b 243ms_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
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,
8bbeb278 255 "%d %s %s :%s", tkline_time, parv[3], parv[4], parv[5]);
212380e3
AC
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
267static int
428ca87b 268me_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
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
278static void
279handle_remote_kline(struct Client *source_p, int tkline_time,
8bbeb278 280 const char *user, const char *host, const char *kreason)
212380e3 281{
212380e3
AC
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,
8bbeb278
AC
287 source_p->servptr->name,
288 (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE))
212380e3
AC
289 return;
290
9319a2e2 291 if(!valid_user_host(source_p, user, host))
212380e3
AC
292 return;
293
5c2b9eaf
JT
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);
803ce385 300 return;
5c2b9eaf
JT
301 }
302
212380e3
AC
303 if(already_placed_kline(source_p, user, host, tkline_time))
304 return;
305
306 aconf = make_conf();
307
308 aconf->status = CONF_KILL;
b52c2949 309 aconf->created = rb_current_time();
47a03750
VY
310 aconf->user = rb_strdup(user);
311 aconf->host = rb_strdup(host);
27f616dd 312 aconf->info.oper = operhash_add(get_oper_name(source_p));
212380e3 313
9319a2e2
KB
314 if(strlen(reason) > BANREASONLEN)
315 reason[BANREASONLEN] = '\0';
316
212380e3
AC
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))
47a03750 324 aconf->spasswd = rb_strdup(oper_reason);
212380e3 325 }
c935336b 326 aconf->passwd = rb_strdup(reason);
212380e3 327
212380e3 328 if(tkline_time > 0)
b52c2949 329 apply_tkline(source_p, aconf, reason, oper_reason, tkline_time);
212380e3 330 else
b52c2949 331 apply_kline(source_p, aconf, reason, oper_reason);
212380e3
AC
332
333 if(ConfigFileEntry.kline_delay)
334 {
335 if(kline_queued == 0)
336 {
0e7cb7e6 337 rb_event_addonce("check_klines", check_klines_event, NULL,
8bbeb278 338 ConfigFileEntry.kline_delay);
212380e3
AC
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 */
354static int
428ca87b 355mo_unkline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
356{
357 const char *user;
358 char *host;
359 char splat[] = "*";
360 char *h = LOCAL_COPY(parv[1]);
40a1d446 361 struct ConfItem *aconf;
431a1a27 362 int propagated = 1;
212380e3
AC
363
364 if(!IsOperUnkline(source_p))
365 {
8bbeb278 366 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline");
212380e3
AC
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 {
5366977b 396 sendto_one_notice(source_p, ":Invalid parameters");
212380e3
AC
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),
8bbeb278 406 me.name, source_p->name, "remoteban");
212380e3
AC
407 return 0;
408 }
409
8bbeb278 410 propagate_generic(source_p, "UNKLINE", parv[3], CAP_UNKLN, "%s %s", user, host);
212380e3
AC
411
412 if(match(parv[3], me.name) == 0)
413 return 0;
431a1a27
JT
414
415 propagated = 0;
212380e3 416 }
431a1a27
JT
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)
212380e3
AC
423 cluster_generic(source_p, "UNKLINE", SHARED_UNKLINE, CAP_UNKLN,
424 "%s %s", user, host);
425
40a1d446
JT
426 if(aconf == NULL)
427 {
428 sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host);
429 return 0;
430 }
55abcbb2 431
431a1a27
JT
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 }
40a1d446 440
d922dded 441 if(remove_temp_kline(source_p, aconf))
212380e3 442 return 0;
212380e3 443
40a1d446 444 remove_permkline_match(source_p, aconf);
212380e3
AC
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 */
455static int
428ca87b 456ms_unkline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3 457{
8bbeb278
AC
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]);
212380e3
AC
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
472static int
428ca87b 473me_unkline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
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
483static void
484handle_remote_unkline(struct Client *source_p, const char *user, const char *host)
485{
40a1d446
JT
486 struct ConfItem *aconf;
487
212380e3 488 if(!find_shared_conf(source_p->username, source_p->host,
8bbeb278 489 source_p->servptr->name, SHARED_UNKLINE))
212380e3
AC
490 return;
491
40a1d446
JT
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 }
431a1a27
JT
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 }
40a1d446 503
d922dded 504 if(remove_temp_kline(source_p, aconf))
212380e3 505 return;
212380e3 506
40a1d446 507 remove_permkline_match(source_p, aconf);
212380e3
AC
508}
509
510/* apply_kline()
511 *
55abcbb2 512 * inputs -
212380e3
AC
513 * output - NONE
514 * side effects - kline as given, is added to the hashtable
515 * and conf file
516 */
517static void
518apply_kline(struct Client *source_p, struct ConfItem *aconf,
b52c2949 519 const char *reason, const char *oper_reason)
212380e3 520{
40c1fd47 521 add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
8bbeb278
AC
522 bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host,
523 reason, EmptyString(oper_reason) ? NULL : oper_reason, 0);
9964e935
AC
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);
212380e3
AC
546}
547
548/* apply_tkline()
549 *
550 * inputs -
551 * output - NONE
552 * side effects - tkline as given is placed
553 */
554static void
555apply_tkline(struct Client *source_p, struct ConfItem *aconf,
b52c2949 556 const char *reason, const char *oper_reason, int tkline_time)
212380e3 557{
e3354945 558 aconf->hold = rb_current_time() + tkline_time;
212380e3
AC
559 add_temp_kline(aconf);
560
561 /* no oper reason.. */
562 if(EmptyString(oper_reason))
563 {
564 sendto_realops_snomask(SNO_GENERAL, L_ALL,
8bbeb278
AC
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);
212380e3 568 ilog(L_KLINE, "K %s %d %s %s %s",
8bbeb278 569 get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason);
212380e3
AC
570 }
571 else
572 {
573 sendto_realops_snomask(SNO_GENERAL, L_ALL,
8bbeb278
AC
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);
212380e3 577 ilog(L_KLINE, "K %s %d %s %s %s|%s",
8bbeb278
AC
578 get_oper_name(source_p), tkline_time / 60,
579 aconf->user, aconf->host, reason, oper_reason);
212380e3
AC
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
431a1a27
JT
586static void
587apply_prop_kline(struct Client *source_p, struct ConfItem *aconf,
588 const char *reason, const char *oper_reason, int tkline_time)
589{
431a1a27
JT
590 aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY;
591 aconf->hold = rb_current_time() + tkline_time;
592 aconf->lifetime = aconf->hold;
593
3cbbfb25 594 replace_old_ban(aconf);
431a1a27
JT
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,
cedb7d05 624 ":%s BAN K %s %s %lu %d %d * :%s%s%s",
431a1a27
JT
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
212380e3 634/* find_user_host()
55abcbb2 635 *
212380e3
AC
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 */
640static int
641find_user_host(struct Client *source_p, const char *userhost, char *luser, char *lhost)
642{
643 char *hostp;
644
645 hostp = strchr(userhost, '@');
8bbeb278 646
212380e3
AC
647 if(hostp != NULL) /* I'm a little user@host */
648 {
649 *(hostp++) = '\0'; /* short and squat */
650 if(*userhost)
f427c8b0 651 rb_strlcpy(luser, userhost, USERLEN + 1); /* here is my user */
212380e3
AC
652 else
653 strcpy(luser, "*");
654 if(*hostp)
f427c8b0 655 rb_strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
212380e3
AC
656 else
657 strcpy(lhost, "*");
8bbeb278 658 }
212380e3
AC
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)
af0ba24b
JT
665 {
666 sendto_one_notice(source_p, ":K-Line must be a user@host or host");
212380e3 667 return 0;
af0ba24b 668 }
212380e3
AC
669
670 luser[0] = '*'; /* no @ found, assume its *@somehost */
671 luser[1] = '\0';
f427c8b0 672 rb_strlcpy(lhost, userhost, HOSTLEN + 1);
212380e3
AC
673 }
674
2b843a5b
JT
675 /* would break the protocol */
676 if (*luser == ':' || *lhost == ':')
677 {
678 sendto_one_notice(source_p, ":Invalid K-Line");
679 return 0;
680 }
681
212380e3
AC
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 */
691static int
692valid_user_host(struct Client *source_p, const char *luser, const char *lhost)
693{
8bbeb278
AC
694 /* # is invalid, as are '!' (n!u@h kline) and '@' (u@@h kline) */
695 if(strchr(lhost, '#') || strchr(luser, '#') || strchr(luser, '!') || strchr(lhost, '@'))
212380e3
AC
696 {
697 sendto_one_notice(source_p, ":Invalid K-Line");
698 return 0;
699 }
700
701 return 1;
702}
703
212380e3
AC
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 */
715static int
716already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int tkline)
717{
7f27e316 718 const char *reason, *p;
e7046ee5 719 struct rb_sockaddr_storage iphost, *piphost;
212380e3 720 struct ConfItem *aconf;
8bbeb278 721 int t, bits;
7f27e316
JT
722
723 aconf = find_exact_conf_by_address(lhost, CONF_KILL, luser);
8bbeb278 724 if(aconf == NULL && ConfigFileEntry.non_redundant_klines)
212380e3 725 {
7f27e316 726 bits = 0;
29c92cf9 727 if((t = parse_netmask(lhost, &iphost, &bits)) != HM_HOST)
212380e3 728 {
ccda6e3f 729#ifdef RB_IPV6
212380e3
AC
730 if(t == HM_IPV6)
731 t = AF_INET6;
732 else
733#endif
734 t = AF_INET;
8bbeb278 735
212380e3
AC
736 piphost = &iphost;
737 }
738 else
739 piphost = NULL;
740
8bbeb278
AC
741 aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *) piphost,
742 CONF_KILL, t, luser, NULL);
743 if(aconf != NULL)
212380e3 744 {
7f27e316
JT
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, '/');
8bbeb278 751 if(bits > 0 && (p == NULL || bits < atoi(p + 1)))
7f27e316
JT
752 aconf = NULL;
753 }
754 }
8bbeb278 755 if(aconf != NULL)
7f27e316
JT
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",
8bbeb278 764 luser, lhost, aconf->user, aconf->host, reason);
7f27e316 765 return 1;
212380e3
AC
766 }
767 }
768
769 return 0;
770}
771
772/* remove_permkline_match()
773 *
774 * hunts for a permanent kline, and removes it.
775 */
776static void
40a1d446 777remove_permkline_match(struct Client *source_p, struct ConfItem *aconf)
212380e3 778{
8bbeb278 779 sendto_one_notice(source_p, ":K-Line for [%s@%s] is removed", aconf->user, aconf->host);
212380e3
AC
780
781 sendto_realops_snomask(SNO_GENERAL, L_ALL,
8bbeb278
AC
782 "%s has removed the K-Line for: [%s@%s]",
783 get_oper_name(source_p), aconf->user, aconf->host);
212380e3 784
8bbeb278 785 ilog(L_KLINE, "UK %s %s %s", get_oper_name(source_p), aconf->user, aconf->host);
40a1d446 786
54ac8b60 787 remove_reject_mask(aconf->user, aconf->host);
8bbeb278 788 bandb_del(BANDB_KLINE, aconf->user, aconf->host);
40a1d446
JT
789 delete_one_address_conf(aconf->host, aconf);
790
212380e3
AC
791 return;
792}
793
212380e3
AC
794/* remove_temp_kline()
795 *
796 * inputs - username, hostname to unkline
797 * outputs -
798 * side effects - tries to unkline anything that matches
799 */
800static int
d922dded 801remove_temp_kline(struct Client *source_p, struct ConfItem *aconf)
212380e3 802{
5b96d9a6 803 rb_dlink_node *ptr;
212380e3
AC
804 int i;
805
8bbeb278 806 for(i = 0; i < LAST_TEMP_TYPE; i++)
212380e3 807 {
5b96d9a6 808 RB_DLINK_FOREACH(ptr, temp_klines[i].head)
212380e3 809 {
8bbeb278 810 if(aconf == ptr->data)
212380e3 811 {
d922dded 812 sendto_one_notice(source_p,
8bbeb278
AC
813 ":Un-klined [%s@%s] from temporary k-lines",
814 aconf->user, aconf->host);
d922dded 815 sendto_realops_snomask(SNO_GENERAL, L_ALL,
8bbeb278
AC
816 "%s has removed the temporary K-Line for: [%s@%s]",
817 get_oper_name(source_p), aconf->user,
818 aconf->host);
d922dded
JT
819
820 ilog(L_KLINE, "UK %s %s %s",
8bbeb278 821 get_oper_name(source_p), aconf->user, aconf->host);
555ac41f 822 rb_dlinkDestroy(ptr, &temp_klines[i]);
54ac8b60 823 remove_reject_mask(aconf->user, aconf->host);
40a1d446
JT
824 delete_one_address_conf(aconf->host, aconf);
825 return YES;
212380e3 826 }
212380e3
AC
827 }
828 }
829
830 return NO;
831}
431a1a27
JT
832
833static void
834remove_prop_kline(struct Client *source_p, struct ConfItem *aconf)
835{
836 rb_dlink_node *ptr;
483987a4 837 time_t now;
431a1a27
JT
838
839 ptr = rb_dlinkFind(aconf, &prop_bans);
840 if (!ptr)
841 return;
842 sendto_one_notice(source_p,
843 ":Un-klined [%s@%s] from global k-lines",
844 aconf->user, aconf->host);
845 sendto_realops_snomask(SNO_GENERAL, L_ALL,
846 "%s has removed the global K-Line for: [%s@%s]",
847 get_oper_name(source_p), aconf->user,
848 aconf->host);
849
850 ilog(L_KLINE, "UK %s %s %s",
851 get_oper_name(source_p), aconf->user, aconf->host);
483987a4
JT
852 now = rb_current_time();
853 if(aconf->created < now)
854 aconf->created = now;
431a1a27
JT
855 else
856 aconf->created++;
cedb7d05 857 aconf->hold = aconf->created;
431a1a27
JT
858 operhash_delete(aconf->info.oper);
859 aconf->info.oper = operhash_add(get_oper_name(source_p));
860 aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY;
861 sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS,
cedb7d05 862 ":%s BAN K %s %s %lu %d %d * :*",
431a1a27
JT
863 source_p->id, aconf->user, aconf->host,
864 (unsigned long)aconf->created,
865 0,
866 (int)(aconf->lifetime - aconf->created));
867 remove_reject_mask(aconf->user, aconf->host);
483987a4 868 deactivate_conf(aconf, ptr, now);
431a1a27 869}