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