]>
Commit | Line | Data |
---|---|---|
212380e3 | 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 | * | |
d8a4c5f6 | 24 | * $Id$ |
212380e3 | 25 | */ |
26 | ||
27 | #include "stdinc.h" | |
212380e3 | 28 | #include "channel.h" |
29 | #include "class.h" | |
30 | #include "client.h" | |
31 | #include "common.h" | |
13ae2f4b | 32 | #include "match.h" |
212380e3 | 33 | #include "ircd.h" |
34 | #include "hostmask.h" | |
35 | #include "numeric.h" | |
212380e3 | 36 | #include "s_conf.h" |
37 | #include "s_newconf.h" | |
d3455e2c | 38 | #include "logger.h" |
212380e3 | 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" |
d8a4c5f6 | 46 | #include "bandbi.h" |
a0f4c418 | 47 | #include "operhash.h" |
212380e3 | 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 }; | |
d8a4c5f6 WP |
67 | |
68 | DECLARE_MODULE_AV1(kline, NULL, NULL, kline_clist, NULL, NULL, "$Revision$"); | |
212380e3 | 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 | 74 | |
75 | static void handle_remote_kline(struct Client *source_p, int tkline_time, | |
d8a4c5f6 | 76 | const char *user, const char *host, const char *reason); |
212380e3 | 77 | static void apply_kline(struct Client *source_p, struct ConfItem *aconf, |
ce60772d | 78 | const char *reason, const char *oper_reason); |
212380e3 | 79 | static void apply_tkline(struct Client *source_p, struct ConfItem *aconf, |
ce60772d | 80 | const char *, const char *, int); |
65b8e002 JT |
81 | static void apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, |
82 | const char *, const char *, int); | |
212380e3 | 83 | static int already_placed_kline(struct Client *, const char *, const char *, int); |
84 | ||
d8a4c5f6 | 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 *); |
4c171a9c | 87 | static int remove_temp_kline(struct Client *, struct ConfItem *); |
65b8e002 | 88 | static void remove_prop_kline(struct Client *, struct ConfItem *); |
212380e3 | 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 | |
d8a4c5f6 | 99 | mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char **parv) |
212380e3 | 100 | { |
d8a4c5f6 | 101 | char def[] = "No Reason"; |
212380e3 | 102 | char user[USERLEN + 2]; |
103 | char host[HOSTLEN + 2]; | |
d8a4c5f6 | 104 | char *reason = def; |
212380e3 | 105 | char *oper_reason; |
212380e3 | 106 | const char *target_server = NULL; |
107 | struct ConfItem *aconf; | |
108 | int tkline_time = 0; | |
109 | int loc = 1; | |
504f309e | 110 | int propagated = ConfigFileEntry.use_propagated_bans; |
212380e3 | 111 | |
112 | if(!IsOperK(source_p)) | |
113 | { | |
d8a4c5f6 | 114 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline"); |
212380e3 | 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 | ||
d8a4c5f6 | 129 | if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) |
212380e3 | 130 | { |
131 | if(!IsOperRemoteBan(source_p)) | |
132 | { | |
133 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
d8a4c5f6 | 134 | me.name, source_p->name, "remoteban"); |
212380e3 | 135 | return 0; |
136 | } | |
137 | ||
d8a4c5f6 | 138 | target_server = parv[loc + 1]; |
212380e3 | 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, | |
d8a4c5f6 | 154 | "%d %s %s :%s", tkline_time, user, host, reason); |
212380e3 | 155 | |
156 | /* If we are sending it somewhere that doesnt include us, stop */ | |
157 | if(!match(target_server, me.name)) | |
158 | return 0; | |
65b8e002 JT |
159 | |
160 | /* Set as local-only. */ | |
161 | propagated = 0; | |
212380e3 | 162 | } |
163 | /* if we have cluster servers, send it to them.. */ | |
65b8e002 | 164 | else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) |
d8a4c5f6 | 165 | cluster_generic(source_p, "KLINE", |
212380e3 | 166 | (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE, CAP_KLN, |
d8a4c5f6 | 167 | "%lu %s %s :%s", tkline_time, user, host, reason); |
212380e3 | 168 | |
d8a4c5f6 | 169 | if(!valid_user_host(source_p, user, host) || |
70fd7fc9 | 170 | !valid_comment(source_p, reason)) |
212380e3 | 171 | return 0; |
172 | ||
70fd7fc9 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 | ||
65b8e002 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 | 188 | if(already_placed_kline(source_p, user, host, tkline_time)) |
189 | return 0; | |
190 | ||
4362b282 | 191 | rb_set_time(); |
212380e3 | 192 | aconf = make_conf(); |
193 | aconf->status = CONF_KILL; | |
ce60772d | 194 | aconf->created = rb_current_time(); |
62d28946 VY |
195 | aconf->host = rb_strdup(host); |
196 | aconf->user = rb_strdup(user); | |
212380e3 | 197 | aconf->port = 0; |
a0f4c418 | 198 | aconf->info.oper = operhash_add(get_oper_name(source_p)); |
212380e3 | 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)) | |
62d28946 | 207 | aconf->spasswd = rb_strdup(oper_reason); |
212380e3 | 208 | } |
90072e8b | 209 | aconf->passwd = rb_strdup(reason); |
212380e3 | 210 | |
65b8e002 JT |
211 | if(propagated) |
212 | apply_prop_kline(source_p, aconf, reason, oper_reason, tkline_time); | |
213 | else if(tkline_time > 0) | |
ce60772d | 214 | apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); |
212380e3 | 215 | else |
ce60772d | 216 | apply_kline(source_p, aconf, reason, oper_reason); |
212380e3 | 217 | |
218 | if(ConfigFileEntry.kline_delay) | |
219 | { | |
220 | if(kline_queued == 0) | |
221 | { | |
bfccb2c0 | 222 | rb_event_addonce("check_klines", check_klines_event, NULL, |
d8a4c5f6 | 223 | ConfigFileEntry.kline_delay); |
212380e3 | 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, | |
d8a4c5f6 | 254 | "%d %s %s :%s", tkline_time, parv[3], parv[4], parv[5]); |
212380e3 | 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, | |
d8a4c5f6 | 279 | const char *user, const char *host, const char *kreason) |
212380e3 | 280 | { |
212380e3 | 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, | |
d8a4c5f6 WP |
286 | source_p->servptr->name, |
287 | (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE)) | |
212380e3 | 288 | return; |
289 | ||
290 | if(!valid_user_host(source_p, user, host) || | |
70fd7fc9 | 291 | !valid_comment(source_p, reason)) |
212380e3 | 292 | return; |
293 | ||
70fd7fc9 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); | |
7c880acb | 300 | return; |
70fd7fc9 JT |
301 | } |
302 | ||
212380e3 | 303 | if(already_placed_kline(source_p, user, host, tkline_time)) |
304 | return; | |
305 | ||
306 | aconf = make_conf(); | |
307 | ||
308 | aconf->status = CONF_KILL; | |
ce60772d | 309 | aconf->created = rb_current_time(); |
62d28946 VY |
310 | aconf->user = rb_strdup(user); |
311 | aconf->host = rb_strdup(host); | |
a0f4c418 | 312 | aconf->info.oper = operhash_add(get_oper_name(source_p)); |
212380e3 | 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)) | |
62d28946 | 321 | aconf->spasswd = rb_strdup(oper_reason); |
212380e3 | 322 | } |
90072e8b | 323 | aconf->passwd = rb_strdup(reason); |
212380e3 | 324 | |
212380e3 | 325 | if(tkline_time > 0) |
ce60772d | 326 | apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); |
212380e3 | 327 | else |
ce60772d | 328 | apply_kline(source_p, aconf, reason, oper_reason); |
212380e3 | 329 | |
330 | if(ConfigFileEntry.kline_delay) | |
331 | { | |
332 | if(kline_queued == 0) | |
333 | { | |
bfccb2c0 | 334 | rb_event_addonce("check_klines", check_klines_event, NULL, |
d8a4c5f6 | 335 | ConfigFileEntry.kline_delay); |
212380e3 | 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; |
65b8e002 | 359 | int propagated = 1; |
212380e3 | 360 | |
361 | if(!IsOperUnkline(source_p)) | |
362 | { | |
d8a4c5f6 | 363 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline"); |
212380e3 | 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 | 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), | |
d8a4c5f6 | 403 | me.name, source_p->name, "remoteban"); |
212380e3 | 404 | return 0; |
405 | } | |
406 | ||
d8a4c5f6 | 407 | propagate_generic(source_p, "UNKLINE", parv[3], CAP_UNKLN, "%s %s", user, host); |
212380e3 | 408 | |
409 | if(match(parv[3], me.name) == 0) | |
410 | return 0; | |
65b8e002 JT |
411 | |
412 | propagated = 0; | |
212380e3 | 413 | } |
65b8e002 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 | 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 | } | |
65b8e002 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 | |
4c171a9c | 438 | if(remove_temp_kline(source_p, aconf)) |
212380e3 | 439 | return 0; |
212380e3 | 440 | |
40a1d446 | 441 | remove_permkline_match(source_p, aconf); |
212380e3 | 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 | { | |
d8a4c5f6 WP |
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 | 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, |
d8a4c5f6 | 486 | source_p->servptr->name, SHARED_UNKLINE)) |
212380e3 | 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 | } | |
65b8e002 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 | |
4c171a9c | 501 | if(remove_temp_kline(source_p, aconf)) |
212380e3 | 502 | return; |
212380e3 | 503 | |
40a1d446 | 504 | remove_permkline_match(source_p, aconf); |
212380e3 | 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, | |
ce60772d | 516 | const char *reason, const char *oper_reason) |
212380e3 | 517 | { |
969a1ae6 | 518 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); |
d8a4c5f6 WP |
519 | bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host, |
520 | reason, EmptyString(oper_reason) ? NULL : oper_reason, 0); | |
d63447bf WP |
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 | 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, | |
ce60772d | 553 | const char *reason, const char *oper_reason, int tkline_time) |
212380e3 | 554 | { |
9f6bbe3c | 555 | aconf->hold = rb_current_time() + tkline_time; |
212380e3 | 556 | add_temp_kline(aconf); |
557 | ||
558 | /* no oper reason.. */ | |
559 | if(EmptyString(oper_reason)) | |
560 | { | |
561 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
d8a4c5f6 WP |
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", |
d8a4c5f6 | 566 | get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); |
212380e3 | 567 | } |
568 | else | |
569 | { | |
570 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
d8a4c5f6 WP |
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", |
d8a4c5f6 WP |
575 | get_oper_name(source_p), tkline_time / 60, |
576 | aconf->user, aconf->host, reason, oper_reason); | |
212380e3 | 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 | ||
65b8e002 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 | { | |
65b8e002 JT |
587 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; |
588 | aconf->hold = rb_current_time() + tkline_time; | |
589 | aconf->lifetime = aconf->hold; | |
590 | ||
112e8a66 | 591 | replace_old_ban(aconf); |
65b8e002 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, | |
e49d8185 | 621 | ":%s BAN K %s %s %lu %d %d * :%s%s%s", |
65b8e002 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 | 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, '@'); | |
d8a4c5f6 | 643 | |
212380e3 | 644 | if(hostp != NULL) /* I'm a little user@host */ |
645 | { | |
646 | *(hostp++) = '\0'; /* short and squat */ | |
647 | if(*userhost) | |
907468c4 | 648 | rb_strlcpy(luser, userhost, USERLEN + 1); /* here is my user */ |
212380e3 | 649 | else |
650 | strcpy(luser, "*"); | |
651 | if(*hostp) | |
907468c4 | 652 | rb_strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ |
212380e3 | 653 | else |
654 | strcpy(lhost, "*"); | |
d8a4c5f6 | 655 | } |
212380e3 | 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) | |
1dc9ac1d JT |
662 | { |
663 | sendto_one_notice(source_p, ":K-Line must be a user@host or host"); | |
212380e3 | 664 | return 0; |
1dc9ac1d | 665 | } |
212380e3 | 666 | |
667 | luser[0] = '*'; /* no @ found, assume its *@somehost */ | |
668 | luser[1] = '\0'; | |
907468c4 | 669 | rb_strlcpy(lhost, userhost, HOSTLEN + 1); |
212380e3 | 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 | { | |
d8a4c5f6 WP |
684 | /* # is invalid, as are '!' (n!u@h kline) and '@' (u@@h kline) */ |
685 | if(strchr(lhost, '#') || strchr(luser, '#') || strchr(luser, '!') || strchr(lhost, '@')) | |
212380e3 | 686 | { |
687 | sendto_one_notice(source_p, ":Invalid K-Line"); | |
688 | return 0; | |
689 | } | |
690 | ||
691 | return 1; | |
692 | } | |
693 | ||
212380e3 | 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 | 710 | if(strlen(comment) > BANREASONLEN) |
711 | comment[BANREASONLEN] = '\0'; | |
212380e3 | 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 | { | |
df7a3250 | 730 | const char *reason, *p; |
3ea5fee7 | 731 | struct rb_sockaddr_storage iphost, *piphost; |
212380e3 | 732 | struct ConfItem *aconf; |
d8a4c5f6 | 733 | int t, bits; |
df7a3250 JT |
734 | |
735 | aconf = find_exact_conf_by_address(lhost, CONF_KILL, luser); | |
d8a4c5f6 | 736 | if(aconf == NULL && ConfigFileEntry.non_redundant_klines) |
212380e3 | 737 | { |
df7a3250 | 738 | bits = 0; |
d8a4c5f6 | 739 | if((t = parse_netmask(lhost, (struct sockaddr *) &iphost, &bits)) != HM_HOST) |
212380e3 | 740 | { |
2c2e0aa9 | 741 | #ifdef RB_IPV6 |
212380e3 | 742 | if(t == HM_IPV6) |
743 | t = AF_INET6; | |
744 | else | |
745 | #endif | |
746 | t = AF_INET; | |
d8a4c5f6 | 747 | |
212380e3 | 748 | piphost = &iphost; |
749 | } | |
750 | else | |
751 | piphost = NULL; | |
752 | ||
d8a4c5f6 WP |
753 | aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *) piphost, |
754 | CONF_KILL, t, luser, NULL); | |
755 | if(aconf != NULL) | |
212380e3 | 756 | { |
df7a3250 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, '/'); | |
d8a4c5f6 | 763 | if(bits > 0 && (p == NULL || bits < atoi(p + 1))) |
df7a3250 JT |
764 | aconf = NULL; |
765 | } | |
766 | } | |
d8a4c5f6 | 767 | if(aconf != NULL) |
df7a3250 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", | |
d8a4c5f6 | 776 | luser, lhost, aconf->user, aconf->host, reason); |
df7a3250 | 777 | return 1; |
212380e3 | 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 | { |
d8a4c5f6 | 791 | sendto_one_notice(source_p, ":K-Line for [%s@%s] is removed", aconf->user, aconf->host); |
212380e3 | 792 | |
793 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
d8a4c5f6 WP |
794 | "%s has removed the K-Line for: [%s@%s]", |
795 | get_oper_name(source_p), aconf->user, aconf->host); | |
212380e3 | 796 | |
d8a4c5f6 | 797 | ilog(L_KLINE, "UK %s %s %s", get_oper_name(source_p), aconf->user, aconf->host); |
40a1d446 | 798 | |
21c9d815 | 799 | remove_reject_mask(aconf->user, aconf->host); |
d8a4c5f6 | 800 | bandb_del(BANDB_KLINE, aconf->user, aconf->host); |
40a1d446 JT |
801 | delete_one_address_conf(aconf->host, aconf); |
802 | ||
212380e3 | 803 | return; |
804 | } | |
805 | ||
212380e3 | 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 | |
4c171a9c | 813 | remove_temp_kline(struct Client *source_p, struct ConfItem *aconf) |
212380e3 | 814 | { |
08d11e34 | 815 | rb_dlink_node *ptr; |
212380e3 | 816 | int i; |
817 | ||
d8a4c5f6 | 818 | for(i = 0; i < LAST_TEMP_TYPE; i++) |
212380e3 | 819 | { |
08d11e34 | 820 | RB_DLINK_FOREACH(ptr, temp_klines[i].head) |
212380e3 | 821 | { |
d8a4c5f6 | 822 | if(aconf == ptr->data) |
212380e3 | 823 | { |
4c171a9c | 824 | sendto_one_notice(source_p, |
d8a4c5f6 WP |
825 | ":Un-klined [%s@%s] from temporary k-lines", |
826 | aconf->user, aconf->host); | |
4c171a9c | 827 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
d8a4c5f6 WP |
828 | "%s has removed the temporary K-Line for: [%s@%s]", |
829 | get_oper_name(source_p), aconf->user, | |
830 | aconf->host); | |
4c171a9c JT |
831 | |
832 | ilog(L_KLINE, "UK %s %s %s", | |
d8a4c5f6 | 833 | get_oper_name(source_p), aconf->user, aconf->host); |
9f6c3353 | 834 | rb_dlinkDestroy(ptr, &temp_klines[i]); |
21c9d815 | 835 | remove_reject_mask(aconf->user, aconf->host); |
40a1d446 JT |
836 | delete_one_address_conf(aconf->host, aconf); |
837 | return YES; | |
212380e3 | 838 | } |
212380e3 | 839 | } |
840 | } | |
841 | ||
842 | return NO; | |
843 | } | |
65b8e002 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++; | |
e49d8185 | 867 | aconf->hold = aconf->created; |
65b8e002 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, | |
e49d8185 | 872 | ":%s BAN K %s %s %lu %d %d * :*", |
65b8e002 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 | } |