]>
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 | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
212380e3 AC |
26 | #include "channel.h" |
27 | #include "class.h" | |
28 | #include "client.h" | |
4562c604 | 29 | #include "match.h" |
212380e3 AC |
30 | #include "ircd.h" |
31 | #include "hostmask.h" | |
32 | #include "numeric.h" | |
212380e3 AC |
33 | #include "s_conf.h" |
34 | #include "s_newconf.h" | |
4016731b | 35 | #include "logger.h" |
212380e3 AC |
36 | #include "send.h" |
37 | #include "hash.h" | |
38 | #include "s_serv.h" | |
39 | #include "msg.h" | |
40 | #include "parse.h" | |
41 | #include "modules.h" | |
35f6f850 | 42 | #include "reject.h" |
8bbeb278 | 43 | #include "bandbi.h" |
27f616dd | 44 | #include "operhash.h" |
212380e3 | 45 | |
eeabf33a EM |
46 | static const char kline_desc[] = "Provides the KLINE facility to ban users via hostmask"; |
47 | ||
3c7d6fcc EM |
48 | static void mo_kline(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
49 | static void ms_kline(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
50 | static void me_kline(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
51 | static void mo_unkline(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
52 | static void ms_unkline(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
53 | static void me_unkline(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
54 | |
55 | struct Message kline_msgtab = { | |
7baa37a9 | 56 | "KLINE", 0, 0, 0, 0, |
212380e3 AC |
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 = { | |
7baa37a9 | 61 | "UNKLINE", 0, 0, 0, 0, |
212380e3 AC |
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 | 66 | |
f1156bf0 | 67 | DECLARE_MODULE_AV2(kline, NULL, NULL, kline_clist, NULL, NULL, NULL, NULL, kline_desc); |
212380e3 AC |
68 | |
69 | /* Local function prototypes */ | |
3c7d6fcc EM |
70 | static bool find_user_host(struct Client *source_p, const char *userhost, char *user, char *host); |
71 | static bool valid_user_host(struct Client *source_p, const char *user, const char *host); | |
212380e3 AC |
72 | |
73 | static void handle_remote_kline(struct Client *source_p, int tkline_time, | |
8bbeb278 | 74 | const char *user, const char *host, const char *reason); |
212380e3 | 75 | static void apply_kline(struct Client *source_p, struct ConfItem *aconf, |
b52c2949 | 76 | const char *reason, const char *oper_reason); |
212380e3 | 77 | static void apply_tkline(struct Client *source_p, struct ConfItem *aconf, |
b52c2949 | 78 | const char *, const char *, int); |
431a1a27 JT |
79 | static void apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, |
80 | const char *, const char *, int); | |
3c7d6fcc | 81 | static bool already_placed_kline(struct Client *, const char *, const char *, int); |
212380e3 | 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 *); |
3c7d6fcc | 85 | static bool remove_temp_kline(struct Client *, struct ConfItem *); |
431a1a27 | 86 | static void remove_prop_kline(struct Client *, struct ConfItem *); |
212380e3 AC |
87 | |
88 | /* mo_kline() | |
89 | * | |
90 | * parv[1] - temp time or user@host | |
91 | * parv[2] - user@host, "ON", or reason | |
92 | * parv[3] - "ON", reason, or server to target | |
93 | * parv[4] - server to target, or reason | |
94 | * parv[5] - reason | |
95 | */ | |
3c7d6fcc | 96 | static void |
428ca87b | 97 | mo_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv) |
212380e3 | 98 | { |
8bbeb278 | 99 | char def[] = "No Reason"; |
212380e3 AC |
100 | char user[USERLEN + 2]; |
101 | char host[HOSTLEN + 2]; | |
8bbeb278 | 102 | char *reason = def; |
212380e3 | 103 | char *oper_reason; |
212380e3 AC |
104 | const char *target_server = NULL; |
105 | struct ConfItem *aconf; | |
106 | int tkline_time = 0; | |
107 | int loc = 1; | |
f66f0baa | 108 | bool propagated = ConfigFileEntry.use_propagated_bans; |
212380e3 AC |
109 | |
110 | if(!IsOperK(source_p)) | |
111 | { | |
8bbeb278 | 112 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline"); |
3c7d6fcc | 113 | return; |
212380e3 AC |
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) | |
3c7d6fcc | 123 | return; |
212380e3 AC |
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"); |
3c7d6fcc | 133 | return; |
212380e3 AC |
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"); | |
3c7d6fcc | 144 | return; |
212380e3 AC |
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)) | |
3c7d6fcc | 156 | return; |
431a1a27 JT |
157 | |
158 | /* Set as local-only. */ | |
f66f0baa | 159 | propagated = false; |
212380e3 AC |
160 | } |
161 | /* if we have cluster servers, send it to them.. */ | |
431a1a27 | 162 | else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0) |
8bbeb278 | 163 | cluster_generic(source_p, "KLINE", |
212380e3 | 164 | (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE, CAP_KLN, |
8bbeb278 | 165 | "%lu %s %s :%s", tkline_time, user, host, reason); |
212380e3 | 166 | |
9319a2e2 | 167 | if(!valid_user_host(source_p, user, host)) |
3c7d6fcc | 168 | return; |
212380e3 | 169 | |
5c2b9eaf JT |
170 | if(!valid_wild_card(user, host)) |
171 | { | |
172 | sendto_one_notice(source_p, | |
173 | ":Please include at least %d non-wildcard " | |
174 | "characters with the user@host", | |
175 | ConfigFileEntry.min_nonwildcard); | |
3c7d6fcc | 176 | return; |
5c2b9eaf JT |
177 | } |
178 | ||
431a1a27 JT |
179 | if(propagated && tkline_time == 0) |
180 | { | |
181 | sendto_one_notice(source_p, ":Cannot set a permanent global ban"); | |
3c7d6fcc | 182 | return; |
431a1a27 JT |
183 | } |
184 | ||
212380e3 | 185 | if(already_placed_kline(source_p, user, host, tkline_time)) |
3c7d6fcc | 186 | return; |
212380e3 | 187 | |
7df5fcfb | 188 | rb_set_time(); |
212380e3 AC |
189 | aconf = make_conf(); |
190 | aconf->status = CONF_KILL; | |
b52c2949 | 191 | aconf->created = rb_current_time(); |
47a03750 VY |
192 | aconf->host = rb_strdup(host); |
193 | aconf->user = rb_strdup(user); | |
212380e3 | 194 | aconf->port = 0; |
27f616dd | 195 | aconf->info.oper = operhash_add(get_oper_name(source_p)); |
212380e3 | 196 | |
9319a2e2 KB |
197 | if(strlen(reason) > BANREASONLEN) |
198 | reason[BANREASONLEN] = '\0'; | |
199 | ||
212380e3 AC |
200 | /* Look for an oper reason */ |
201 | if((oper_reason = strchr(reason, '|')) != NULL) | |
202 | { | |
203 | *oper_reason = '\0'; | |
204 | oper_reason++; | |
205 | ||
206 | if(!EmptyString(oper_reason)) | |
47a03750 | 207 | aconf->spasswd = rb_strdup(oper_reason); |
212380e3 | 208 | } |
c935336b | 209 | aconf->passwd = rb_strdup(reason); |
212380e3 | 210 | |
431a1a27 JT |
211 | if(propagated) |
212 | apply_prop_kline(source_p, aconf, reason, oper_reason, tkline_time); | |
213 | else if(tkline_time > 0) | |
b52c2949 | 214 | apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); |
212380e3 | 215 | else |
b52c2949 | 216 | apply_kline(source_p, aconf, reason, oper_reason); |
212380e3 AC |
217 | |
218 | if(ConfigFileEntry.kline_delay) | |
219 | { | |
f66f0baa | 220 | if(!kline_queued) |
212380e3 | 221 | { |
0e7cb7e6 | 222 | rb_event_addonce("check_klines", check_klines_event, NULL, |
8bbeb278 | 223 | ConfigFileEntry.kline_delay); |
f66f0baa | 224 | kline_queued = true; |
212380e3 AC |
225 | } |
226 | } | |
227 | else | |
228 | check_klines(); | |
212380e3 AC |
229 | } |
230 | ||
231 | /* ms_kline() | |
232 | * | |
233 | * parv[1] - server targeted at | |
234 | * parv[2] - tkline time (0 if perm) | |
235 | * parv[3] - user | |
236 | * parv[4] - host | |
237 | * parv[5] - reason | |
238 | */ | |
3c7d6fcc | 239 | static void |
428ca87b | 240 | ms_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
241 | { |
242 | int tkline_time = atoi(parv[2]); | |
243 | ||
244 | /* 1.5-3 and earlier contains a bug that allows remote klines to be | |
245 | * sent with an empty reason field. This is a protocol violation, | |
246 | * but its not worth dropping the link over.. --anfl | |
247 | */ | |
248 | if(parc < 6 || EmptyString(parv[5])) | |
3c7d6fcc | 249 | return; |
212380e3 AC |
250 | |
251 | propagate_generic(source_p, "KLINE", parv[1], CAP_KLN, | |
8bbeb278 | 252 | "%d %s %s :%s", tkline_time, parv[3], parv[4], parv[5]); |
212380e3 AC |
253 | |
254 | if(!match(parv[1], me.name)) | |
3c7d6fcc | 255 | return; |
212380e3 AC |
256 | |
257 | if(!IsPerson(source_p)) | |
3c7d6fcc | 258 | return; |
212380e3 AC |
259 | |
260 | handle_remote_kline(source_p, tkline_time, parv[3], parv[4], parv[5]); | |
212380e3 AC |
261 | } |
262 | ||
3c7d6fcc | 263 | static void |
428ca87b | 264 | me_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
265 | { |
266 | /* <tkline_time> <user> <host> :<reason> */ | |
267 | if(!IsPerson(source_p)) | |
3c7d6fcc | 268 | return; |
212380e3 AC |
269 | |
270 | handle_remote_kline(source_p, atoi(parv[1]), parv[2], parv[3], parv[4]); | |
212380e3 AC |
271 | } |
272 | ||
273 | static void | |
274 | handle_remote_kline(struct Client *source_p, int tkline_time, | |
8bbeb278 | 275 | const char *user, const char *host, const char *kreason) |
212380e3 | 276 | { |
212380e3 AC |
277 | char *reason = LOCAL_COPY(kreason); |
278 | struct ConfItem *aconf = NULL; | |
279 | char *oper_reason; | |
280 | ||
281 | if(!find_shared_conf(source_p->username, source_p->host, | |
8bbeb278 AC |
282 | source_p->servptr->name, |
283 | (tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE)) | |
212380e3 AC |
284 | return; |
285 | ||
9319a2e2 | 286 | if(!valid_user_host(source_p, user, host)) |
212380e3 AC |
287 | return; |
288 | ||
5c2b9eaf JT |
289 | if(!valid_wild_card(user, host)) |
290 | { | |
291 | sendto_one_notice(source_p, | |
292 | ":Please include at least %d non-wildcard " | |
293 | "characters with the user@host", | |
294 | ConfigFileEntry.min_nonwildcard); | |
803ce385 | 295 | return; |
5c2b9eaf JT |
296 | } |
297 | ||
212380e3 AC |
298 | if(already_placed_kline(source_p, user, host, tkline_time)) |
299 | return; | |
300 | ||
301 | aconf = make_conf(); | |
302 | ||
303 | aconf->status = CONF_KILL; | |
b52c2949 | 304 | aconf->created = rb_current_time(); |
47a03750 VY |
305 | aconf->user = rb_strdup(user); |
306 | aconf->host = rb_strdup(host); | |
27f616dd | 307 | aconf->info.oper = operhash_add(get_oper_name(source_p)); |
212380e3 | 308 | |
9319a2e2 KB |
309 | if(strlen(reason) > BANREASONLEN) |
310 | reason[BANREASONLEN] = '\0'; | |
311 | ||
212380e3 AC |
312 | /* Look for an oper reason */ |
313 | if((oper_reason = strchr(reason, '|')) != NULL) | |
314 | { | |
315 | *oper_reason = '\0'; | |
316 | oper_reason++; | |
317 | ||
318 | if(!EmptyString(oper_reason)) | |
47a03750 | 319 | aconf->spasswd = rb_strdup(oper_reason); |
212380e3 | 320 | } |
c935336b | 321 | aconf->passwd = rb_strdup(reason); |
212380e3 | 322 | |
212380e3 | 323 | if(tkline_time > 0) |
b52c2949 | 324 | apply_tkline(source_p, aconf, reason, oper_reason, tkline_time); |
212380e3 | 325 | else |
b52c2949 | 326 | apply_kline(source_p, aconf, reason, oper_reason); |
212380e3 AC |
327 | |
328 | if(ConfigFileEntry.kline_delay) | |
329 | { | |
f66f0baa | 330 | if(!kline_queued) |
212380e3 | 331 | { |
0e7cb7e6 | 332 | rb_event_addonce("check_klines", check_klines_event, NULL, |
8bbeb278 | 333 | ConfigFileEntry.kline_delay); |
f66f0baa | 334 | kline_queued = true; |
212380e3 AC |
335 | } |
336 | } | |
337 | else | |
338 | check_klines(); | |
212380e3 AC |
339 | } |
340 | ||
341 | /* mo_unkline() | |
342 | * | |
343 | * parv[1] - kline to remove | |
344 | * parv[2] - optional "ON" | |
345 | * parv[3] - optional target server | |
346 | */ | |
3c7d6fcc | 347 | static void |
428ca87b | 348 | mo_unkline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
349 | { |
350 | const char *user; | |
351 | char *host; | |
352 | char splat[] = "*"; | |
353 | char *h = LOCAL_COPY(parv[1]); | |
40a1d446 | 354 | struct ConfItem *aconf; |
f66f0baa | 355 | bool propagated = true; |
212380e3 AC |
356 | |
357 | if(!IsOperUnkline(source_p)) | |
358 | { | |
8bbeb278 | 359 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline"); |
3c7d6fcc | 360 | return; |
212380e3 AC |
361 | } |
362 | ||
363 | if((host = strchr(h, '@')) || *h == '*' || strchr(h, '.') || strchr(h, ':')) | |
364 | { | |
365 | /* Explicit user@host mask given */ | |
366 | ||
367 | if(host) /* Found user@host */ | |
368 | { | |
369 | *host++ = '\0'; | |
370 | ||
371 | /* check for @host */ | |
372 | if(*h) | |
373 | user = h; | |
374 | else | |
375 | user = splat; | |
376 | ||
377 | /* check for user@ */ | |
378 | if(!*host) | |
379 | host = splat; | |
380 | } | |
381 | else | |
382 | { | |
383 | user = splat; /* no @ found, assume its *@somehost */ | |
384 | host = h; | |
385 | } | |
386 | } | |
387 | else | |
388 | { | |
5366977b | 389 | sendto_one_notice(source_p, ":Invalid parameters"); |
3c7d6fcc | 390 | return; |
212380e3 AC |
391 | } |
392 | ||
393 | /* possible remote kline.. */ | |
394 | if((parc > 3) && (irccmp(parv[2], "ON") == 0)) | |
395 | { | |
396 | if(!IsOperRemoteBan(source_p)) | |
397 | { | |
398 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
8bbeb278 | 399 | me.name, source_p->name, "remoteban"); |
3c7d6fcc | 400 | return; |
212380e3 AC |
401 | } |
402 | ||
8bbeb278 | 403 | propagate_generic(source_p, "UNKLINE", parv[3], CAP_UNKLN, "%s %s", user, host); |
212380e3 AC |
404 | |
405 | if(match(parv[3], me.name) == 0) | |
3c7d6fcc | 406 | return; |
431a1a27 | 407 | |
f66f0baa | 408 | propagated = false; |
212380e3 | 409 | } |
431a1a27 JT |
410 | |
411 | aconf = find_exact_conf_by_address(host, CONF_KILL, user); | |
412 | ||
413 | /* No clustering for removing a propagated kline */ | |
414 | if(propagated && (aconf == NULL || !aconf->lifetime) && | |
415 | rb_dlink_list_length(&cluster_conf_list) > 0) | |
212380e3 AC |
416 | cluster_generic(source_p, "UNKLINE", SHARED_UNKLINE, CAP_UNKLN, |
417 | "%s %s", user, host); | |
418 | ||
40a1d446 JT |
419 | if(aconf == NULL) |
420 | { | |
421 | sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); | |
3c7d6fcc | 422 | return; |
40a1d446 | 423 | } |
55abcbb2 | 424 | |
431a1a27 JT |
425 | if(aconf->lifetime) |
426 | { | |
427 | if(propagated) | |
428 | remove_prop_kline(source_p, aconf); | |
429 | else | |
430 | sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); | |
3c7d6fcc | 431 | return; |
431a1a27 | 432 | } |
40a1d446 | 433 | |
d922dded | 434 | if(remove_temp_kline(source_p, aconf)) |
3c7d6fcc | 435 | return; |
212380e3 | 436 | |
40a1d446 | 437 | remove_permkline_match(source_p, aconf); |
212380e3 AC |
438 | } |
439 | ||
440 | /* ms_unkline() | |
441 | * | |
442 | * parv[1] - target server | |
443 | * parv[2] - user to unkline | |
444 | * parv[3] - host to unkline | |
445 | */ | |
3c7d6fcc | 446 | static void |
428ca87b | 447 | ms_unkline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 448 | { |
8bbeb278 AC |
449 | /* parv[0] parv[1] parv[2] parv[3] |
450 | * oper target server user host */ | |
451 | propagate_generic(source_p, "UNKLINE", parv[1], CAP_UNKLN, "%s %s", parv[2], parv[3]); | |
212380e3 AC |
452 | |
453 | if(!match(parv[1], me.name)) | |
3c7d6fcc | 454 | return; |
212380e3 AC |
455 | |
456 | if(!IsPerson(source_p)) | |
3c7d6fcc | 457 | return; |
212380e3 AC |
458 | |
459 | handle_remote_unkline(source_p, parv[2], parv[3]); | |
212380e3 AC |
460 | } |
461 | ||
3c7d6fcc | 462 | static void |
428ca87b | 463 | me_unkline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
464 | { |
465 | /* user host */ | |
466 | if(!IsPerson(source_p)) | |
3c7d6fcc | 467 | return; |
212380e3 AC |
468 | |
469 | handle_remote_unkline(source_p, parv[1], parv[2]); | |
212380e3 AC |
470 | } |
471 | ||
472 | static void | |
473 | handle_remote_unkline(struct Client *source_p, const char *user, const char *host) | |
474 | { | |
40a1d446 JT |
475 | struct ConfItem *aconf; |
476 | ||
212380e3 | 477 | if(!find_shared_conf(source_p->username, source_p->host, |
8bbeb278 | 478 | source_p->servptr->name, SHARED_UNKLINE)) |
212380e3 AC |
479 | return; |
480 | ||
40a1d446 JT |
481 | aconf = find_exact_conf_by_address(host, CONF_KILL, user); |
482 | if(aconf == NULL) | |
483 | { | |
484 | sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); | |
485 | return; | |
486 | } | |
431a1a27 JT |
487 | if(aconf->lifetime) |
488 | { | |
489 | sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); | |
490 | return; | |
491 | } | |
40a1d446 | 492 | |
d922dded | 493 | if(remove_temp_kline(source_p, aconf)) |
212380e3 | 494 | return; |
212380e3 | 495 | |
40a1d446 | 496 | remove_permkline_match(source_p, aconf); |
212380e3 AC |
497 | } |
498 | ||
499 | /* apply_kline() | |
500 | * | |
55abcbb2 | 501 | * inputs - |
212380e3 AC |
502 | * output - NONE |
503 | * side effects - kline as given, is added to the hashtable | |
504 | * and conf file | |
505 | */ | |
506 | static void | |
507 | apply_kline(struct Client *source_p, struct ConfItem *aconf, | |
b52c2949 | 508 | const char *reason, const char *oper_reason) |
212380e3 | 509 | { |
40c1fd47 | 510 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); |
8bbeb278 AC |
511 | bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host, |
512 | reason, EmptyString(oper_reason) ? NULL : oper_reason, 0); | |
9964e935 AC |
513 | |
514 | /* no oper reason.. */ | |
515 | if(EmptyString(oper_reason)) | |
516 | { | |
517 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
518 | "%s added K-Line for [%s@%s] [%s]", | |
519 | get_oper_name(source_p), aconf->user, aconf->host, reason); | |
520 | ilog(L_KLINE, "K %s 0 %s %s %s", | |
521 | get_oper_name(source_p), aconf->user, aconf->host, reason); | |
522 | } | |
523 | else | |
524 | { | |
525 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
526 | "%s added K-Line for [%s@%s] [%s|%s]", | |
527 | get_oper_name(source_p), aconf->user, aconf->host, | |
528 | reason, oper_reason); | |
529 | ilog(L_KLINE, "K %s 0 %s %s %s|%s", | |
530 | get_oper_name(source_p), aconf->user, aconf->host, reason, oper_reason); | |
531 | } | |
532 | ||
533 | sendto_one_notice(source_p, ":Added K-Line [%s@%s]", | |
534 | aconf->user, aconf->host); | |
212380e3 AC |
535 | } |
536 | ||
537 | /* apply_tkline() | |
538 | * | |
539 | * inputs - | |
540 | * output - NONE | |
541 | * side effects - tkline as given is placed | |
542 | */ | |
543 | static void | |
544 | apply_tkline(struct Client *source_p, struct ConfItem *aconf, | |
b52c2949 | 545 | const char *reason, const char *oper_reason, int tkline_time) |
212380e3 | 546 | { |
e3354945 | 547 | aconf->hold = rb_current_time() + tkline_time; |
212380e3 AC |
548 | add_temp_kline(aconf); |
549 | ||
550 | /* no oper reason.. */ | |
551 | if(EmptyString(oper_reason)) | |
552 | { | |
553 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
8bbeb278 AC |
554 | "%s added temporary %d min. K-Line for [%s@%s] [%s]", |
555 | get_oper_name(source_p), tkline_time / 60, | |
556 | aconf->user, aconf->host, reason); | |
212380e3 | 557 | ilog(L_KLINE, "K %s %d %s %s %s", |
8bbeb278 | 558 | get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); |
212380e3 AC |
559 | } |
560 | else | |
561 | { | |
562 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
8bbeb278 AC |
563 | "%s added temporary %d min. K-Line for [%s@%s] [%s|%s]", |
564 | get_oper_name(source_p), tkline_time / 60, | |
565 | aconf->user, aconf->host, reason, oper_reason); | |
212380e3 | 566 | ilog(L_KLINE, "K %s %d %s %s %s|%s", |
8bbeb278 AC |
567 | get_oper_name(source_p), tkline_time / 60, |
568 | aconf->user, aconf->host, reason, oper_reason); | |
212380e3 AC |
569 | } |
570 | ||
571 | sendto_one_notice(source_p, ":Added temporary %d min. K-Line [%s@%s]", | |
572 | tkline_time / 60, aconf->user, aconf->host); | |
573 | } | |
574 | ||
431a1a27 JT |
575 | static void |
576 | apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, | |
577 | const char *reason, const char *oper_reason, int tkline_time) | |
578 | { | |
431a1a27 JT |
579 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; |
580 | aconf->hold = rb_current_time() + tkline_time; | |
581 | aconf->lifetime = aconf->hold; | |
582 | ||
3cbbfb25 | 583 | replace_old_ban(aconf); |
431a1a27 JT |
584 | |
585 | rb_dlinkAddAlloc(aconf, &prop_bans); | |
586 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); | |
587 | ||
588 | /* no oper reason.. */ | |
589 | if(EmptyString(oper_reason)) | |
590 | { | |
591 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
592 | "%s added global %d min. K-Line for [%s@%s] [%s]", | |
593 | get_oper_name(source_p), tkline_time / 60, | |
594 | aconf->user, aconf->host, reason); | |
595 | ilog(L_KLINE, "K %s %d %s %s %s", | |
596 | get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason); | |
597 | } | |
598 | else | |
599 | { | |
600 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
601 | "%s added global %d min. K-Line for [%s@%s] [%s|%s]", | |
602 | get_oper_name(source_p), tkline_time / 60, | |
603 | aconf->user, aconf->host, reason, oper_reason); | |
604 | ilog(L_KLINE, "K %s %d %s %s %s|%s", | |
605 | get_oper_name(source_p), tkline_time / 60, | |
606 | aconf->user, aconf->host, reason, oper_reason); | |
607 | } | |
608 | ||
609 | sendto_one_notice(source_p, ":Added global %d min. K-Line [%s@%s]", | |
610 | tkline_time / 60, aconf->user, aconf->host); | |
611 | ||
612 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
cedb7d05 | 613 | ":%s BAN K %s %s %lu %d %d * :%s%s%s", |
431a1a27 JT |
614 | source_p->id, aconf->user, aconf->host, |
615 | (unsigned long)aconf->created, | |
616 | (int)(aconf->hold - aconf->created), | |
617 | (int)(aconf->lifetime - aconf->created), | |
618 | reason, | |
619 | oper_reason ? "|" : "", | |
620 | oper_reason ? oper_reason : ""); | |
621 | } | |
622 | ||
212380e3 | 623 | /* find_user_host() |
55abcbb2 | 624 | * |
212380e3 | 625 | * inputs - client placing kline, user@host, user buffer, host buffer |
3c7d6fcc | 626 | * output - false if not ok to kline, true to kline i.e. if valid user host |
212380e3 AC |
627 | * side effects - |
628 | */ | |
3c7d6fcc | 629 | static bool |
212380e3 AC |
630 | find_user_host(struct Client *source_p, const char *userhost, char *luser, char *lhost) |
631 | { | |
632 | char *hostp; | |
633 | ||
634 | hostp = strchr(userhost, '@'); | |
8bbeb278 | 635 | |
212380e3 AC |
636 | if(hostp != NULL) /* I'm a little user@host */ |
637 | { | |
638 | *(hostp++) = '\0'; /* short and squat */ | |
639 | if(*userhost) | |
f427c8b0 | 640 | rb_strlcpy(luser, userhost, USERLEN + 1); /* here is my user */ |
212380e3 AC |
641 | else |
642 | strcpy(luser, "*"); | |
643 | if(*hostp) | |
f427c8b0 | 644 | rb_strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ |
212380e3 AC |
645 | else |
646 | strcpy(lhost, "*"); | |
8bbeb278 | 647 | } |
212380e3 AC |
648 | else |
649 | { | |
650 | /* no '@', no '.', so its not a user@host or host, therefore | |
651 | * its a nick, which support was removed for. | |
652 | */ | |
653 | if(strchr(userhost, '.') == NULL && strchr(userhost, ':') == NULL) | |
af0ba24b JT |
654 | { |
655 | sendto_one_notice(source_p, ":K-Line must be a user@host or host"); | |
3c7d6fcc | 656 | return false; |
af0ba24b | 657 | } |
212380e3 AC |
658 | |
659 | luser[0] = '*'; /* no @ found, assume its *@somehost */ | |
660 | luser[1] = '\0'; | |
f427c8b0 | 661 | rb_strlcpy(lhost, userhost, HOSTLEN + 1); |
212380e3 AC |
662 | } |
663 | ||
2b843a5b JT |
664 | /* would break the protocol */ |
665 | if (*luser == ':' || *lhost == ':') | |
666 | { | |
667 | sendto_one_notice(source_p, ":Invalid K-Line"); | |
3c7d6fcc | 668 | return false; |
2b843a5b JT |
669 | } |
670 | ||
3c7d6fcc | 671 | return true; |
212380e3 AC |
672 | } |
673 | ||
674 | /* valid_user_host() | |
675 | * | |
676 | * inputs - user buffer, host buffer | |
3c7d6fcc | 677 | * output - false if invalid, true if valid |
212380e3 AC |
678 | * side effects - |
679 | */ | |
3c7d6fcc | 680 | static bool |
212380e3 AC |
681 | valid_user_host(struct Client *source_p, const char *luser, const char *lhost) |
682 | { | |
8bbeb278 AC |
683 | /* # is invalid, as are '!' (n!u@h kline) and '@' (u@@h kline) */ |
684 | if(strchr(lhost, '#') || strchr(luser, '#') || strchr(luser, '!') || strchr(lhost, '@')) | |
212380e3 AC |
685 | { |
686 | sendto_one_notice(source_p, ":Invalid K-Line"); | |
3c7d6fcc | 687 | return false; |
212380e3 AC |
688 | } |
689 | ||
3c7d6fcc | 690 | return true; |
212380e3 AC |
691 | } |
692 | ||
212380e3 AC |
693 | /* already_placed_kline() |
694 | * | |
695 | * inputs - source to notify, user@host to check, tkline time | |
3c7d6fcc EM |
696 | * outputs - true if a perm kline or a tkline when a tkline is being |
697 | * set exists, else false | |
212380e3 AC |
698 | * side effects - notifies source_p kline exists |
699 | */ | |
700 | /* Note: This currently works if the new K-line is a special case of an | |
701 | * existing K-line, but not the other way round. To do that we would | |
702 | * have to walk the hash and check every existing K-line. -A1kmm. | |
703 | */ | |
3c7d6fcc | 704 | static bool |
212380e3 AC |
705 | already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int tkline) |
706 | { | |
7f27e316 | 707 | const char *reason, *p; |
e7046ee5 | 708 | struct rb_sockaddr_storage iphost, *piphost; |
212380e3 | 709 | struct ConfItem *aconf; |
8bbeb278 | 710 | int t, bits; |
7f27e316 JT |
711 | |
712 | aconf = find_exact_conf_by_address(lhost, CONF_KILL, luser); | |
8bbeb278 | 713 | if(aconf == NULL && ConfigFileEntry.non_redundant_klines) |
212380e3 | 714 | { |
7f27e316 | 715 | bits = 0; |
29c92cf9 | 716 | if((t = parse_netmask(lhost, &iphost, &bits)) != HM_HOST) |
212380e3 | 717 | { |
ccda6e3f | 718 | #ifdef RB_IPV6 |
212380e3 AC |
719 | if(t == HM_IPV6) |
720 | t = AF_INET6; | |
721 | else | |
722 | #endif | |
723 | t = AF_INET; | |
8bbeb278 | 724 | |
212380e3 AC |
725 | piphost = &iphost; |
726 | } | |
727 | else | |
728 | piphost = NULL; | |
729 | ||
8bbeb278 AC |
730 | aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *) piphost, |
731 | CONF_KILL, t, luser, NULL); | |
732 | if(aconf != NULL) | |
212380e3 | 733 | { |
7f27e316 JT |
734 | /* The above was really a lookup of a single IP, |
735 | * so check if the new kline is wider than the | |
736 | * existing one. | |
737 | * -- jilles | |
738 | */ | |
739 | p = strchr(aconf->host, '/'); | |
8bbeb278 | 740 | if(bits > 0 && (p == NULL || bits < atoi(p + 1))) |
7f27e316 JT |
741 | aconf = NULL; |
742 | } | |
743 | } | |
8bbeb278 | 744 | if(aconf != NULL) |
7f27e316 JT |
745 | { |
746 | /* setting a tkline, or existing one is perm */ | |
747 | if(tkline || ((aconf->flags & CONF_FLAGS_TEMPORARY) == 0)) | |
748 | { | |
749 | reason = aconf->passwd ? aconf->passwd : "<No Reason>"; | |
750 | ||
751 | sendto_one_notice(source_p, | |
752 | ":[%s@%s] already K-Lined by [%s@%s] - %s", | |
8bbeb278 | 753 | luser, lhost, aconf->user, aconf->host, reason); |
3c7d6fcc | 754 | return true; |
212380e3 AC |
755 | } |
756 | } | |
757 | ||
3c7d6fcc | 758 | return false; |
212380e3 AC |
759 | } |
760 | ||
761 | /* remove_permkline_match() | |
762 | * | |
763 | * hunts for a permanent kline, and removes it. | |
764 | */ | |
765 | static void | |
40a1d446 | 766 | remove_permkline_match(struct Client *source_p, struct ConfItem *aconf) |
212380e3 | 767 | { |
8bbeb278 | 768 | sendto_one_notice(source_p, ":K-Line for [%s@%s] is removed", aconf->user, aconf->host); |
212380e3 AC |
769 | |
770 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
8bbeb278 AC |
771 | "%s has removed the K-Line for: [%s@%s]", |
772 | get_oper_name(source_p), aconf->user, aconf->host); | |
212380e3 | 773 | |
8bbeb278 | 774 | ilog(L_KLINE, "UK %s %s %s", get_oper_name(source_p), aconf->user, aconf->host); |
40a1d446 | 775 | |
54ac8b60 | 776 | remove_reject_mask(aconf->user, aconf->host); |
8bbeb278 | 777 | bandb_del(BANDB_KLINE, aconf->user, aconf->host); |
40a1d446 | 778 | delete_one_address_conf(aconf->host, aconf); |
212380e3 AC |
779 | } |
780 | ||
212380e3 AC |
781 | /* remove_temp_kline() |
782 | * | |
783 | * inputs - username, hostname to unkline | |
784 | * outputs - | |
785 | * side effects - tries to unkline anything that matches | |
786 | */ | |
3c7d6fcc | 787 | static bool |
d922dded | 788 | remove_temp_kline(struct Client *source_p, struct ConfItem *aconf) |
212380e3 | 789 | { |
5b96d9a6 | 790 | rb_dlink_node *ptr; |
212380e3 AC |
791 | int i; |
792 | ||
8bbeb278 | 793 | for(i = 0; i < LAST_TEMP_TYPE; i++) |
212380e3 | 794 | { |
5b96d9a6 | 795 | RB_DLINK_FOREACH(ptr, temp_klines[i].head) |
212380e3 | 796 | { |
8bbeb278 | 797 | if(aconf == ptr->data) |
212380e3 | 798 | { |
d922dded | 799 | sendto_one_notice(source_p, |
8bbeb278 AC |
800 | ":Un-klined [%s@%s] from temporary k-lines", |
801 | aconf->user, aconf->host); | |
d922dded | 802 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
8bbeb278 AC |
803 | "%s has removed the temporary K-Line for: [%s@%s]", |
804 | get_oper_name(source_p), aconf->user, | |
805 | aconf->host); | |
d922dded JT |
806 | |
807 | ilog(L_KLINE, "UK %s %s %s", | |
8bbeb278 | 808 | get_oper_name(source_p), aconf->user, aconf->host); |
555ac41f | 809 | rb_dlinkDestroy(ptr, &temp_klines[i]); |
54ac8b60 | 810 | remove_reject_mask(aconf->user, aconf->host); |
40a1d446 | 811 | delete_one_address_conf(aconf->host, aconf); |
3c7d6fcc | 812 | return true; |
212380e3 | 813 | } |
212380e3 AC |
814 | } |
815 | } | |
816 | ||
3c7d6fcc | 817 | return false; |
212380e3 | 818 | } |
431a1a27 JT |
819 | |
820 | static void | |
821 | remove_prop_kline(struct Client *source_p, struct ConfItem *aconf) | |
822 | { | |
823 | rb_dlink_node *ptr; | |
483987a4 | 824 | time_t now; |
431a1a27 JT |
825 | |
826 | ptr = rb_dlinkFind(aconf, &prop_bans); | |
827 | if (!ptr) | |
828 | return; | |
829 | sendto_one_notice(source_p, | |
830 | ":Un-klined [%s@%s] from global k-lines", | |
831 | aconf->user, aconf->host); | |
832 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
833 | "%s has removed the global K-Line for: [%s@%s]", | |
834 | get_oper_name(source_p), aconf->user, | |
835 | aconf->host); | |
836 | ||
837 | ilog(L_KLINE, "UK %s %s %s", | |
838 | get_oper_name(source_p), aconf->user, aconf->host); | |
483987a4 JT |
839 | now = rb_current_time(); |
840 | if(aconf->created < now) | |
841 | aconf->created = now; | |
431a1a27 JT |
842 | else |
843 | aconf->created++; | |
cedb7d05 | 844 | aconf->hold = aconf->created; |
431a1a27 JT |
845 | operhash_delete(aconf->info.oper); |
846 | aconf->info.oper = operhash_add(get_oper_name(source_p)); | |
847 | aconf->flags |= CONF_FLAGS_MYOPER | CONF_FLAGS_TEMPORARY; | |
848 | sendto_server(NULL, NULL, CAP_BAN|CAP_TS6, NOCAPS, | |
cedb7d05 | 849 | ":%s BAN K %s %s %lu %d %d * :*", |
431a1a27 JT |
850 | source_p->id, aconf->user, aconf->host, |
851 | (unsigned long)aconf->created, | |
852 | 0, | |
853 | (int)(aconf->lifetime - aconf->created)); | |
854 | remove_reject_mask(aconf->user, aconf->host); | |
483987a4 | 855 | deactivate_conf(aconf, ptr, now); |
431a1a27 | 856 | } |