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