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