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