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