]>
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 | 77 | static void apply_kline(struct Client *source_p, struct ConfItem *aconf, |
b52c2949 | 78 | const char *reason, const char *oper_reason); |
212380e3 | 79 | static void apply_tkline(struct Client *source_p, struct ConfItem *aconf, |
b52c2949 | 80 | const char *, const char *, int); |
212380e3 AC |
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]; | |
8bbeb278 | 101 | char *reason = def; |
212380e3 | 102 | char *oper_reason; |
212380e3 AC |
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 | { | |
8bbeb278 | 110 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline"); |
212380e3 AC |
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 | ||
8bbeb278 | 125 | if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) |
212380e3 AC |
126 | { |
127 | if(!IsOperRemoteBan(source_p)) | |
128 | { | |
129 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
8bbeb278 | 130 | me.name, source_p->name, "remoteban"); |
212380e3 AC |
131 | return 0; |
132 | } | |
133 | ||
8bbeb278 | 134 | target_server = parv[loc + 1]; |
212380e3 AC |
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, | |
8bbeb278 | 150 | "%d %s %s :%s", tkline_time, user, host, reason); |
212380e3 AC |
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.. */ | |
5b96d9a6 | 157 | else if(rb_dlink_list_length(&cluster_conf_list) > 0) |
8bbeb278 | 158 | cluster_generic(source_p, "KLINE", |
212380e3 | 159 | (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE, CAP_KLN, |
8bbeb278 | 160 | "%lu %s %s :%s", tkline_time, user, host, reason); |
212380e3 | 161 | |
8bbeb278 AC |
162 | if(!valid_user_host(source_p, user, host) || |
163 | !valid_wild_card(source_p, user, host) || !valid_comment(source_p, reason)) | |
212380e3 AC |
164 | return 0; |
165 | ||
166 | if(already_placed_kline(source_p, user, host, tkline_time)) | |
167 | return 0; | |
168 | ||
7df5fcfb | 169 | rb_set_time(); |
212380e3 AC |
170 | aconf = make_conf(); |
171 | aconf->status = CONF_KILL; | |
b52c2949 | 172 | aconf->created = rb_current_time(); |
47a03750 VY |
173 | aconf->host = rb_strdup(host); |
174 | aconf->user = rb_strdup(user); | |
212380e3 | 175 | aconf->port = 0; |
a12ad044 | 176 | aconf->passwd = rb_strdup(reason); |
212380e3 AC |
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)) | |
47a03750 | 185 | aconf->spasswd = rb_strdup(oper_reason); |
212380e3 AC |
186 | } |
187 | ||
188 | if(tkline_time > 0) | |
b52c2949 | 189 | apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); |
212380e3 | 190 | else |
b52c2949 | 191 | apply_kline(source_p, aconf, reason, oper_reason); |
212380e3 AC |
192 | |
193 | if(ConfigFileEntry.kline_delay) | |
194 | { | |
195 | if(kline_queued == 0) | |
196 | { | |
0e7cb7e6 | 197 | rb_event_addonce("check_klines", check_klines_event, NULL, |
8bbeb278 | 198 | ConfigFileEntry.kline_delay); |
212380e3 AC |
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, | |
8bbeb278 | 229 | "%d %s %s :%s", tkline_time, parv[3], parv[4], parv[5]); |
212380e3 AC |
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, | |
8bbeb278 | 254 | const char *user, const char *host, const char *kreason) |
212380e3 | 255 | { |
212380e3 AC |
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, | |
8bbeb278 AC |
261 | source_p->servptr->name, |
262 | (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE)) | |
212380e3 AC |
263 | return; |
264 | ||
265 | if(!valid_user_host(source_p, user, host) || | |
8bbeb278 | 266 | !valid_wild_card(source_p, user, host) || !valid_comment(source_p, reason)) |
212380e3 AC |
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; | |
b52c2949 | 275 | aconf->created = rb_current_time(); |
47a03750 VY |
276 | aconf->user = rb_strdup(user); |
277 | aconf->host = rb_strdup(host); | |
a12ad044 | 278 | aconf->passwd = rb_strdup(reason); |
212380e3 AC |
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)) | |
47a03750 | 287 | aconf->spasswd = rb_strdup(oper_reason); |
212380e3 AC |
288 | } |
289 | ||
212380e3 | 290 | if(tkline_time > 0) |
b52c2949 | 291 | apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); |
212380e3 | 292 | else |
b52c2949 | 293 | apply_kline(source_p, aconf, reason, oper_reason); |
212380e3 AC |
294 | |
295 | if(ConfigFileEntry.kline_delay) | |
296 | { | |
297 | if(kline_queued == 0) | |
298 | { | |
0e7cb7e6 | 299 | rb_event_addonce("check_klines", check_klines_event, NULL, |
8bbeb278 | 300 | ConfigFileEntry.kline_delay); |
212380e3 AC |
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 AC |
324 | |
325 | if(!IsOperUnkline(source_p)) | |
326 | { | |
8bbeb278 | 327 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline"); |
212380e3 AC |
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 AC |
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), | |
8bbeb278 | 367 | me.name, source_p->name, "remoteban"); |
212380e3 AC |
368 | return 0; |
369 | } | |
370 | ||
8bbeb278 | 371 | propagate_generic(source_p, "UNKLINE", parv[3], CAP_UNKLN, "%s %s", user, host); |
212380e3 AC |
372 | |
373 | if(match(parv[3], me.name) == 0) | |
374 | return 0; | |
375 | } | |
5b96d9a6 | 376 | else if(rb_dlink_list_length(&cluster_conf_list) > 0) |
212380e3 AC |
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 | ||
d922dded | 387 | if(remove_temp_kline(source_p, aconf)) |
212380e3 | 388 | return 0; |
212380e3 | 389 | |
40a1d446 | 390 | remove_permkline_match(source_p, aconf); |
212380e3 AC |
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 | { | |
8bbeb278 AC |
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 AC |
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, |
8bbeb278 | 435 | source_p->servptr->name, SHARED_UNKLINE)) |
212380e3 AC |
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 | ||
d922dded | 445 | if(remove_temp_kline(source_p, aconf)) |
212380e3 | 446 | return; |
212380e3 | 447 | |
40a1d446 | 448 | remove_permkline_match(source_p, aconf); |
212380e3 AC |
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, | |
b52c2949 | 460 | const char *reason, const char *oper_reason) |
212380e3 | 461 | { |
40c1fd47 | 462 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); |
8bbeb278 AC |
463 | bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host, |
464 | reason, EmptyString(oper_reason) ? NULL : oper_reason, 0); | |
9964e935 AC |
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 AC |
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, | |
b52c2949 | 497 | const char *reason, const char *oper_reason, int tkline_time) |
212380e3 | 498 | { |
e3354945 | 499 | aconf->hold = rb_current_time() + tkline_time; |
212380e3 AC |
500 | add_temp_kline(aconf); |
501 | ||
502 | /* no oper reason.. */ | |
503 | if(EmptyString(oper_reason)) | |
504 | { | |
505 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
8bbeb278 AC |
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", |
8bbeb278 | 510 | get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); |
212380e3 AC |
511 | } |
512 | else | |
513 | { | |
514 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
8bbeb278 AC |
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", |
8bbeb278 AC |
519 | get_oper_name(source_p), tkline_time / 60, |
520 | aconf->user, aconf->host, reason, oper_reason); | |
212380e3 AC |
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, '@'); | |
8bbeb278 | 539 | |
212380e3 AC |
540 | if(hostp != NULL) /* I'm a little user@host */ |
541 | { | |
542 | *(hostp++) = '\0'; /* short and squat */ | |
543 | if(*userhost) | |
f427c8b0 | 544 | rb_strlcpy(luser, userhost, USERLEN + 1); /* here is my user */ |
212380e3 AC |
545 | else |
546 | strcpy(luser, "*"); | |
547 | if(*hostp) | |
f427c8b0 | 548 | rb_strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ |
212380e3 AC |
549 | else |
550 | strcpy(lhost, "*"); | |
8bbeb278 | 551 | } |
212380e3 AC |
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) | |
af0ba24b JT |
558 | { |
559 | sendto_one_notice(source_p, ":K-Line must be a user@host or host"); | |
212380e3 | 560 | return 0; |
af0ba24b | 561 | } |
212380e3 AC |
562 | |
563 | luser[0] = '*'; /* no @ found, assume its *@somehost */ | |
564 | luser[1] = '\0'; | |
f427c8b0 | 565 | rb_strlcpy(lhost, userhost, HOSTLEN + 1); |
212380e3 AC |
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 | { | |
8bbeb278 AC |
580 | /* # is invalid, as are '!' (n!u@h kline) and '@' (u@@h kline) */ |
581 | if(strchr(lhost, '#') || strchr(luser, '#') || strchr(luser, '!') || strchr(lhost, '@')) | |
212380e3 AC |
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 */ |
8bbeb278 | 605 | if(!strchr(luser, '?') && !strchr(luser, '*')) |
598ebb42 JT |
606 | return 1; |
607 | ||
212380e3 AC |
608 | /* check there are enough non wildcard chars */ |
609 | p = luser; | |
8bbeb278 | 610 | while((tmpch = *p++)) |
212380e3 AC |
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 */ |
8bbeb278 | 622 | if((p = strrchr(lhost, '/')) != NULL && IsDigit(p[1])) |
212380e3 | 623 | { |
88a2a148 JT |
624 | bitlen = atoi(p + 1); |
625 | /* much like non-cidr for ipv6, rather arbitrary for ipv4 */ | |
8bbeb278 AC |
626 | if(bitlen > 0 |
627 | && bitlen >= | |
628 | (strchr(lhost, ':') ? 4 * (ConfigFileEntry.min_nonwildcard - nonwild) : 6 - | |
629 | 2 * nonwild)) | |
88a2a148 JT |
630 | return 1; |
631 | } | |
632 | else | |
633 | { | |
634 | p = lhost; | |
8bbeb278 | 635 | while((tmpch = *p++)) |
88a2a148 JT |
636 | { |
637 | if(!IsKWildChar(tmpch)) | |
638 | if(++nonwild >= ConfigFileEntry.min_nonwildcard) | |
639 | return 1; | |
640 | } | |
212380e3 AC |
641 | } |
642 | ||
643 | sendto_one_notice(source_p, | |
8bbeb278 AC |
644 | ":Please include at least %d non-wildcard " |
645 | "characters with the user@host", ConfigFileEntry.min_nonwildcard); | |
212380e3 AC |
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 JT |
665 | if(strlen(comment) > BANREASONLEN) |
666 | comment[BANREASONLEN] = '\0'; | |
212380e3 AC |
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 | { | |
7f27e316 | 685 | const char *reason, *p; |
e7046ee5 | 686 | struct rb_sockaddr_storage iphost, *piphost; |
212380e3 | 687 | struct ConfItem *aconf; |
8bbeb278 | 688 | int t, bits; |
7f27e316 JT |
689 | |
690 | aconf = find_exact_conf_by_address(lhost, CONF_KILL, luser); | |
8bbeb278 | 691 | if(aconf == NULL && ConfigFileEntry.non_redundant_klines) |
212380e3 | 692 | { |
7f27e316 | 693 | bits = 0; |
8bbeb278 | 694 | if((t = parse_netmask(lhost, (struct sockaddr *) &iphost, &bits)) != HM_HOST) |
212380e3 | 695 | { |
ccda6e3f | 696 | #ifdef RB_IPV6 |
212380e3 AC |
697 | if(t == HM_IPV6) |
698 | t = AF_INET6; | |
699 | else | |
700 | #endif | |
701 | t = AF_INET; | |
8bbeb278 | 702 | |
212380e3 AC |
703 | piphost = &iphost; |
704 | } | |
705 | else | |
706 | piphost = NULL; | |
707 | ||
8bbeb278 AC |
708 | aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *) piphost, |
709 | CONF_KILL, t, luser, NULL); | |
710 | if(aconf != NULL) | |
212380e3 | 711 | { |
7f27e316 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, '/'); | |
8bbeb278 | 718 | if(bits > 0 && (p == NULL || bits < atoi(p + 1))) |
7f27e316 JT |
719 | aconf = NULL; |
720 | } | |
721 | } | |
8bbeb278 | 722 | if(aconf != NULL) |
7f27e316 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", | |
8bbeb278 | 731 | luser, lhost, aconf->user, aconf->host, reason); |
7f27e316 | 732 | return 1; |
212380e3 AC |
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 | { |
8bbeb278 | 746 | sendto_one_notice(source_p, ":K-Line for [%s@%s] is removed", aconf->user, aconf->host); |
212380e3 AC |
747 | |
748 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
8bbeb278 AC |
749 | "%s has removed the K-Line for: [%s@%s]", |
750 | get_oper_name(source_p), aconf->user, aconf->host); | |
212380e3 | 751 | |
8bbeb278 | 752 | ilog(L_KLINE, "UK %s %s %s", get_oper_name(source_p), aconf->user, aconf->host); |
40a1d446 | 753 | |
54ac8b60 | 754 | remove_reject_mask(aconf->user, aconf->host); |
8bbeb278 | 755 | bandb_del(BANDB_KLINE, aconf->user, aconf->host); |
40a1d446 JT |
756 | delete_one_address_conf(aconf->host, aconf); |
757 | ||
212380e3 AC |
758 | return; |
759 | } | |
760 | ||
212380e3 AC |
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 | |
d922dded | 768 | remove_temp_kline(struct Client *source_p, struct ConfItem *aconf) |
212380e3 | 769 | { |
5b96d9a6 | 770 | rb_dlink_node *ptr; |
212380e3 AC |
771 | int i; |
772 | ||
8bbeb278 | 773 | for(i = 0; i < LAST_TEMP_TYPE; i++) |
212380e3 | 774 | { |
5b96d9a6 | 775 | RB_DLINK_FOREACH(ptr, temp_klines[i].head) |
212380e3 | 776 | { |
8bbeb278 | 777 | if(aconf == ptr->data) |
212380e3 | 778 | { |
d922dded | 779 | sendto_one_notice(source_p, |
8bbeb278 AC |
780 | ":Un-klined [%s@%s] from temporary k-lines", |
781 | aconf->user, aconf->host); | |
d922dded | 782 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
8bbeb278 AC |
783 | "%s has removed the temporary K-Line for: [%s@%s]", |
784 | get_oper_name(source_p), aconf->user, | |
785 | aconf->host); | |
d922dded JT |
786 | |
787 | ilog(L_KLINE, "UK %s %s %s", | |
8bbeb278 | 788 | get_oper_name(source_p), aconf->user, aconf->host); |
555ac41f | 789 | rb_dlinkDestroy(ptr, &temp_klines[i]); |
54ac8b60 | 790 | remove_reject_mask(aconf->user, aconf->host); |
40a1d446 JT |
791 | delete_one_address_conf(aconf->host, aconf); |
792 | return YES; | |
212380e3 | 793 | } |
212380e3 AC |
794 | } |
795 | } | |
796 | ||
797 | return NO; | |
798 | } |