]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_dline.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" | |
8bbeb278 | 45 | #include "bandbi.h" |
212380e3 AC |
46 | |
47 | static int mo_dline(struct Client *, struct Client *, int, const char **); | |
f5cb68d5 | 48 | static int me_dline(struct Client *, struct Client *, int, const char **); |
212380e3 | 49 | static int mo_undline(struct Client *, struct Client *, int, const char **); |
f5cb68d5 | 50 | static int me_undline(struct Client *, struct Client *, int, const char **); |
212380e3 AC |
51 | |
52 | struct Message dline_msgtab = { | |
53 | "DLINE", 0, 0, 0, MFLG_SLOW, | |
f5cb68d5 | 54 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_dline, 3}, {mo_dline, 2}} |
212380e3 | 55 | }; |
8bbeb278 | 56 | |
212380e3 AC |
57 | struct Message undline_msgtab = { |
58 | "UNDLINE", 0, 0, 0, MFLG_SLOW, | |
f5cb68d5 | 59 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_undline, 1}, {mo_undline, 2}} |
212380e3 AC |
60 | }; |
61 | ||
62 | mapi_clist_av1 dline_clist[] = { &dline_msgtab, &undline_msgtab, NULL }; | |
8bbeb278 AC |
63 | |
64 | DECLARE_MODULE_AV1(dline, NULL, NULL, dline_clist, NULL, NULL, "$Revision$"); | |
212380e3 AC |
65 | |
66 | static int valid_comment(char *comment); | |
6f3a09ff | 67 | static int remove_temp_dline(struct ConfItem *); |
5f7a6a3d | 68 | static int apply_dline(struct Client *, const char *, int, char *); |
f5cb68d5 | 69 | static int apply_undline(struct Client *, const char *); |
212380e3 AC |
70 | |
71 | /* mo_dline() | |
72 | * | |
73 | * parv[1] - dline to add | |
74 | * parv[2] - reason | |
75 | */ | |
76 | static int | |
8bbeb278 | 77 | mo_dline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
78 | { |
79 | char def[] = "No Reason"; | |
80 | const char *dlhost; | |
212380e3 | 81 | char *reason = def; |
212380e3 | 82 | char cidr_form_host[HOSTLEN + 1]; |
212380e3 | 83 | int tdline_time = 0; |
f5cb68d5 | 84 | const char *target_server = NULL; |
212380e3 AC |
85 | int loc = 1; |
86 | ||
87 | if(!IsOperK(source_p)) | |
88 | { | |
8bbeb278 | 89 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline"); |
212380e3 AC |
90 | return 0; |
91 | } | |
92 | ||
93 | if((tdline_time = valid_temp_time(parv[loc])) >= 0) | |
94 | loc++; | |
95 | ||
212380e3 | 96 | dlhost = parv[loc]; |
f427c8b0 | 97 | rb_strlcpy(cidr_form_host, dlhost, sizeof(cidr_form_host)); |
212380e3 | 98 | |
f5cb68d5 VY |
99 | loc++; |
100 | ||
8bbeb278 AC |
101 | if(parc >= loc + 2 && !irccmp(parv[loc], "ON")) |
102 | { | |
2cfb7214 JT |
103 | if(!IsOperRemoteBan(source_p)) |
104 | { | |
105 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
8bbeb278 | 106 | me.name, source_p->name, "remoteban"); |
2cfb7214 JT |
107 | return 0; |
108 | } | |
109 | ||
8bbeb278 | 110 | target_server = parv[loc + 1]; |
f5cb68d5 VY |
111 | loc += 2; |
112 | } | |
113 | ||
114 | if(parc >= loc + 1 && !EmptyString(parv[loc])) | |
115 | reason = LOCAL_COPY(parv[loc]); | |
116 | ||
117 | if(target_server != NULL) | |
212380e3 | 118 | { |
f5cb68d5 | 119 | sendto_match_servs(source_p, target_server, |
8bbeb278 AC |
120 | CAP_ENCAP, NOCAPS, |
121 | "ENCAP %s DLINE %d %s :%s", | |
122 | target_server, tdline_time, dlhost, reason); | |
f5cb68d5 VY |
123 | |
124 | if(!match(target_server, me.name)) | |
125 | return 0; | |
212380e3 AC |
126 | } |
127 | ||
f5cb68d5 VY |
128 | apply_dline(source_p, dlhost, tdline_time, reason); |
129 | ||
130 | check_dlines(); | |
131 | return 0; | |
132 | } | |
212380e3 | 133 | |
f5cb68d5 VY |
134 | /* mo_undline() |
135 | * | |
136 | * parv[1] = dline to remove | |
137 | */ | |
138 | static int | |
139 | mo_undline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
140 | { | |
141 | const char *cidr; | |
142 | const char *target_server = NULL; | |
143 | ||
144 | if(!IsOperK(source_p)) | |
145 | { | |
8bbeb278 AC |
146 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline"); |
147 | return 0; | |
148 | } | |
149 | ||
f5cb68d5 VY |
150 | cidr = parv[1]; |
151 | ||
152 | if(parc >= 4 && !irccmp(parv[2], "ON")) | |
212380e3 | 153 | { |
2cfb7214 JT |
154 | if(!IsOperRemoteBan(source_p)) |
155 | { | |
156 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
8bbeb278 | 157 | me.name, source_p->name, "remoteban"); |
2cfb7214 JT |
158 | return 0; |
159 | } | |
160 | ||
f5cb68d5 VY |
161 | target_server = parv[3]; |
162 | sendto_match_servs(source_p, target_server, | |
8bbeb278 | 163 | CAP_ENCAP, NOCAPS, "ENCAP %s UNDLINE %s", target_server, cidr); |
212380e3 | 164 | |
f5cb68d5 | 165 | if(!match(target_server, me.name)) |
212380e3 | 166 | return 0; |
212380e3 AC |
167 | } |
168 | ||
f5cb68d5 VY |
169 | apply_undline(source_p, cidr); |
170 | ||
171 | return 0; | |
172 | } | |
173 | ||
5f7a6a3d JT |
174 | static int |
175 | me_dline(struct Client *client_p, struct Client *source_p, int parc, const char **parv) | |
176 | { | |
177 | int tdline_time = atoi(parv[1]); | |
178 | /* Since this is coming over a server link, assume that the originating | |
179 | * server did the relevant permission/sanity checks... | |
180 | */ | |
181 | ||
182 | if(!IsPerson(source_p)) | |
183 | return 0; | |
184 | ||
185 | if(!find_shared_conf(source_p->username, source_p->host, | |
8bbeb278 AC |
186 | source_p->servptr->name, |
187 | tdline_time > 0 ? SHARED_TDLINE : SHARED_PDLINE)) | |
5f7a6a3d | 188 | return 0; |
5f7a6a3d JT |
189 | |
190 | apply_dline(source_p, parv[2], tdline_time, LOCAL_COPY(parv[3])); | |
191 | ||
192 | check_dlines(); | |
193 | return 0; | |
194 | } | |
195 | ||
196 | static int | |
197 | me_undline(struct Client *client_p, struct Client *source_p, int parc, const char **parv) | |
198 | { | |
199 | if(!IsPerson(source_p)) | |
200 | return 0; | |
201 | ||
202 | if(!find_shared_conf(source_p->username, source_p->host, | |
8bbeb278 | 203 | source_p->servptr->name, SHARED_UNDLINE)) |
5f7a6a3d JT |
204 | return 0; |
205 | ||
206 | apply_undline(source_p, parv[1]); | |
207 | ||
208 | return 0; | |
f5cb68d5 VY |
209 | } |
210 | ||
211 | static int | |
212 | apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *reason) | |
213 | { | |
214 | struct ConfItem *aconf; | |
215 | char *oper_reason; | |
216 | char dlbuffer[IRCD_BUFSIZE]; | |
217 | const char *current_date; | |
218 | struct rb_sockaddr_storage daddr; | |
219 | int t = AF_INET, ty, b; | |
220 | const char *creason; | |
221 | ||
8bbeb278 | 222 | ty = parse_netmask(dlhost, (struct sockaddr *) &daddr, &b); |
f5cb68d5 VY |
223 | if(ty == HM_HOST) |
224 | { | |
8bbeb278 | 225 | sendto_one(source_p, ":%s NOTICE %s :Invalid D-Line", me.name, source_p->name); |
f5cb68d5 VY |
226 | return 0; |
227 | } | |
228 | #ifdef RB_IPV6 | |
229 | if(ty == HM_IPV6) | |
230 | t = AF_INET6; | |
231 | else | |
232 | #endif | |
233 | t = AF_INET; | |
234 | ||
235 | /* This means dlines wider than /16 cannot be set remotely */ | |
212380e3 AC |
236 | if(IsOperAdmin(source_p)) |
237 | { | |
f5cb68d5 | 238 | if(b < 8) |
212380e3 | 239 | { |
f5cb68d5 | 240 | sendto_one_notice(source_p, |
8bbeb278 | 241 | ":For safety, bitmasks less than 8 require conf access."); |
212380e3 AC |
242 | return 0; |
243 | } | |
244 | } | |
245 | else | |
246 | { | |
f5cb68d5 | 247 | if(b < 16) |
212380e3 | 248 | { |
f5cb68d5 | 249 | sendto_one_notice(source_p, |
8bbeb278 | 250 | ":Dline bitmasks less than 16 are for admins only."); |
212380e3 AC |
251 | return 0; |
252 | } | |
253 | } | |
254 | ||
f5cb68d5 VY |
255 | if(!valid_comment(reason)) |
256 | { | |
257 | sendto_one(source_p, | |
258 | ":%s NOTICE %s :Invalid character '\"' in comment", | |
259 | me.name, source_p->name); | |
260 | return 0; | |
261 | } | |
262 | ||
54ac8b60 VY |
263 | if(ConfigFileEntry.non_redundant_klines) |
264 | { | |
8bbeb278 | 265 | if((aconf = find_dline((struct sockaddr *) &daddr, t)) != NULL) |
54ac8b60 VY |
266 | { |
267 | int bx; | |
268 | parse_netmask(aconf->host, NULL, &bx); | |
269 | if(b >= bx) | |
270 | { | |
271 | creason = aconf->passwd ? aconf->passwd : "<No Reason>"; | |
272 | if(IsConfExemptKline(aconf)) | |
273 | sendto_one(source_p, | |
274 | ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", | |
8bbeb278 AC |
275 | me.name, source_p->name, dlhost, aconf->host, |
276 | creason); | |
54ac8b60 VY |
277 | else |
278 | sendto_one(source_p, | |
279 | ":%s NOTICE %s :[%s] already D-lined by [%s] - %s", | |
8bbeb278 AC |
280 | me.name, source_p->name, dlhost, aconf->host, |
281 | creason); | |
54ac8b60 VY |
282 | return 0; |
283 | } | |
284 | } | |
212380e3 AC |
285 | } |
286 | ||
7df5fcfb | 287 | rb_set_time(); |
212380e3 AC |
288 | current_date = smalldate(); |
289 | ||
290 | aconf = make_conf(); | |
291 | aconf->status = CONF_DLINE; | |
47a03750 | 292 | aconf->host = rb_strdup(dlhost); |
212380e3 | 293 | |
08e8aa7a VY |
294 | /* Look for an oper reason */ |
295 | if((oper_reason = strchr(reason, '|')) != NULL) | |
296 | { | |
297 | *oper_reason = '\0'; | |
298 | oper_reason++; | |
299 | ||
300 | if(!EmptyString(oper_reason)) | |
301 | aconf->spasswd = rb_strdup(oper_reason); | |
302 | } | |
303 | ||
212380e3 AC |
304 | if(tdline_time > 0) |
305 | { | |
8bbeb278 AC |
306 | rb_snprintf(dlbuffer, sizeof(dlbuffer), |
307 | "Temporary D-line %d min. - %s (%s)", | |
308 | (int) (tdline_time / 60), reason, current_date); | |
47a03750 | 309 | aconf->passwd = rb_strdup(dlbuffer); |
e3354945 | 310 | aconf->hold = rb_current_time() + tdline_time; |
212380e3 AC |
311 | add_temp_dline(aconf); |
312 | ||
313 | if(EmptyString(oper_reason)) | |
314 | { | |
61c096aa | 315 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
8bbeb278 AC |
316 | "%s added temporary %d min. D-Line for [%s] [%s]", |
317 | get_oper_name(source_p), tdline_time / 60, | |
318 | aconf->host, reason); | |
212380e3 | 319 | ilog(L_KLINE, "D %s %d %s %s", |
8bbeb278 | 320 | get_oper_name(source_p), tdline_time / 60, aconf->host, reason); |
212380e3 AC |
321 | } |
322 | else | |
323 | { | |
61c096aa | 324 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
8bbeb278 AC |
325 | "%s added temporary %d min. D-Line for [%s] [%s|%s]", |
326 | get_oper_name(source_p), tdline_time / 60, | |
327 | aconf->host, reason, oper_reason); | |
212380e3 | 328 | ilog(L_KLINE, "D %s %d %s %s|%s", |
8bbeb278 AC |
329 | get_oper_name(source_p), tdline_time / 60, |
330 | aconf->host, reason, oper_reason); | |
212380e3 AC |
331 | } |
332 | ||
333 | sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line for [%s]", | |
334 | me.name, source_p->name, tdline_time / 60, aconf->host); | |
335 | } | |
336 | else | |
337 | { | |
7cdb0a09 | 338 | rb_snprintf(dlbuffer, sizeof(dlbuffer), "%s (%s)", reason, current_date); |
47a03750 | 339 | aconf->passwd = rb_strdup(dlbuffer); |
40c1fd47 | 340 | add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf); |
8bbeb278 AC |
341 | |
342 | bandb_add(BANDB_DLINE, source_p, aconf->host, NULL, | |
343 | reason, EmptyString(aconf->spasswd) ? NULL : aconf->spasswd, 0); | |
9964e935 AC |
344 | |
345 | if(EmptyString(oper_reason)) | |
346 | { | |
347 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
348 | "%s added D-Line for [%s] [%s]", | |
349 | get_oper_name(source_p), aconf->host, reason); | |
350 | ilog(L_KLINE, "D %s 0 %s %s", | |
351 | get_oper_name(source_p), aconf->host, reason); | |
352 | } | |
353 | else | |
354 | { | |
355 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
356 | "%s added D-Line for [%s] [%s|%s]", | |
357 | get_oper_name(source_p), aconf->host, reason, oper_reason); | |
358 | ilog(L_KLINE, "D %s 0 %s %s|%s", | |
359 | get_oper_name(source_p), | |
360 | aconf->host, reason, oper_reason); | |
361 | } | |
212380e3 AC |
362 | } |
363 | ||
212380e3 AC |
364 | return 0; |
365 | } | |
366 | ||
212380e3 | 367 | static int |
f5cb68d5 | 368 | apply_undline(struct Client *source_p, const char *cidr) |
212380e3 | 369 | { |
8bbeb278 | 370 | char buf[BUFSIZE]; |
f5cb68d5 | 371 | struct ConfItem *aconf; |
212380e3 AC |
372 | |
373 | if(parse_netmask(cidr, NULL, NULL) == HM_HOST) | |
374 | { | |
5366977b | 375 | sendto_one_notice(source_p, ":Invalid D-Line"); |
212380e3 AC |
376 | return 0; |
377 | } | |
378 | ||
6f3a09ff JT |
379 | aconf = find_exact_conf_by_address(cidr, CONF_DLINE, NULL); |
380 | if(aconf == NULL) | |
381 | { | |
382 | sendto_one_notice(source_p, ":No D-Line for %s", cidr); | |
383 | return 0; | |
384 | } | |
385 | ||
f427c8b0 | 386 | rb_strlcpy(buf, aconf->host, sizeof buf); |
6f3a09ff | 387 | if(remove_temp_dline(aconf)) |
212380e3 AC |
388 | { |
389 | sendto_one(source_p, | |
390 | ":%s NOTICE %s :Un-dlined [%s] from temporary D-lines", | |
f5cb68d5 | 391 | me.name, source_p->name, buf); |
212380e3 | 392 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
8bbeb278 AC |
393 | "%s has removed the temporary D-Line for: [%s]", |
394 | get_oper_name(source_p), buf); | |
6f3a09ff | 395 | ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), buf); |
212380e3 AC |
396 | return 0; |
397 | } | |
398 | ||
8bbeb278 | 399 | bandb_del(BANDB_DLINE, aconf->host, NULL); |
212380e3 | 400 | |
8bbeb278 AC |
401 | sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", me.name, source_p->name, |
402 | aconf->host); | |
403 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has removed the D-Line for: [%s]", | |
404 | get_oper_name(source_p), aconf->host); | |
37f6cc05 JT |
405 | ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), aconf->host); |
406 | delete_one_address_conf(aconf->host, aconf); | |
212380e3 AC |
407 | |
408 | return 0; | |
409 | } | |
410 | ||
411 | /* | |
412 | * valid_comment | |
413 | * inputs - pointer to client | |
414 | * - pointer to comment | |
415 | * output - 0 if no valid comment, 1 if valid | |
416 | * side effects - NONE | |
417 | */ | |
418 | static int | |
419 | valid_comment(char *comment) | |
420 | { | |
421 | if(strchr(comment, '"')) | |
422 | return 0; | |
423 | ||
61569b65 JT |
424 | if(strlen(comment) > BANREASONLEN) |
425 | comment[BANREASONLEN] = '\0'; | |
212380e3 AC |
426 | |
427 | return 1; | |
428 | } | |
429 | ||
212380e3 AC |
430 | /* remove_temp_dline() |
431 | * | |
6f3a09ff | 432 | * inputs - confitem to undline |
212380e3 AC |
433 | * outputs - |
434 | * side effects - tries to undline anything that matches | |
435 | */ | |
436 | static int | |
6f3a09ff | 437 | remove_temp_dline(struct ConfItem *aconf) |
212380e3 | 438 | { |
5b96d9a6 | 439 | rb_dlink_node *ptr; |
212380e3 AC |
440 | int i; |
441 | ||
8bbeb278 | 442 | for(i = 0; i < LAST_TEMP_TYPE; i++) |
212380e3 | 443 | { |
5b96d9a6 | 444 | RB_DLINK_FOREACH(ptr, temp_dlines[i].head) |
212380e3 | 445 | { |
8bbeb278 | 446 | if(aconf == ptr->data) |
212380e3 | 447 | { |
555ac41f | 448 | rb_dlinkDestroy(ptr, &temp_dlines[i]); |
212380e3 AC |
449 | delete_one_address_conf(aconf->host, aconf); |
450 | return YES; | |
451 | } | |
452 | } | |
453 | } | |
454 | ||
455 | return NO; | |
456 | } |