1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_dline.c: Bans a user. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.h" |
27 |
#include "channel.h" |
28 |
#include "client.h" |
29 |
#include "irc_string.h" |
30 |
#include "sprintf_irc.h" |
31 |
#include "conf.h" |
32 |
#include "ircd.h" |
33 |
#include "hostmask.h" |
34 |
#include "numeric.h" |
35 |
#include "fdlist.h" |
36 |
#include "s_bsd.h" |
37 |
#include "log.h" |
38 |
#include "s_misc.h" |
39 |
#include "send.h" |
40 |
#include "hash.h" |
41 |
#include "s_serv.h" |
42 |
#include "parse.h" |
43 |
#include "modules.h" |
44 |
#include "conf_db.h" |
45 |
#include "memory.h" |
46 |
|
47 |
|
48 |
/* apply_tdline() |
49 |
* |
50 |
* inputs - |
51 |
* output - NONE |
52 |
* side effects - tkline as given is placed |
53 |
*/ |
54 |
static void |
55 |
apply_dline(struct Client *source_p, struct MaskItem *conf, |
56 |
time_t tkline_time) |
57 |
{ |
58 |
if (tkline_time) |
59 |
{ |
60 |
conf->until = CurrentTime + tkline_time; |
61 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
62 |
"%s added temporary %d min. D-Line for [%s] [%s]", |
63 |
get_oper_name(source_p), tkline_time/60, |
64 |
conf->host, conf->reason); |
65 |
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]", |
66 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
67 |
source_p->name, tkline_time/60, conf->host); |
68 |
ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]", |
69 |
get_oper_name(source_p), tkline_time/60, conf->host, conf->reason); |
70 |
} |
71 |
else |
72 |
{ |
73 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
74 |
"%s added D-Line for [%s] [%s]", |
75 |
get_oper_name(source_p), conf->host, conf->reason); |
76 |
sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s]", |
77 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
78 |
source_p->name, conf->host); |
79 |
ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]", |
80 |
get_oper_name(source_p), conf->host, conf->reason); |
81 |
|
82 |
} |
83 |
|
84 |
SetConfDatabase(conf); |
85 |
conf->setat = CurrentTime; |
86 |
add_conf_by_address(CONF_DLINE, conf); |
87 |
rehashed_klines = 1; |
88 |
} |
89 |
|
90 |
/* static int remove_tdline_match(const char *host, const char *user) |
91 |
* Input: An ip to undline. |
92 |
* Output: returns YES on success, NO if no tdline removed. |
93 |
* Side effects: Any matching tdlines are removed. |
94 |
*/ |
95 |
static int |
96 |
remove_dline_match(const char *host) |
97 |
{ |
98 |
struct irc_ssaddr iphost, *piphost; |
99 |
struct MaskItem *conf; |
100 |
int t = 0; |
101 |
int aftype = 0; |
102 |
|
103 |
if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST) |
104 |
{ |
105 |
#ifdef IPV6 |
106 |
if (t == HM_IPV6) |
107 |
aftype = AF_INET6; |
108 |
else |
109 |
#endif |
110 |
aftype = AF_INET; |
111 |
piphost = &iphost; |
112 |
} |
113 |
else |
114 |
piphost = NULL; |
115 |
|
116 |
if ((conf = find_conf_by_address(host, piphost, CONF_DLINE, aftype, NULL, NULL, 0))) |
117 |
{ |
118 |
if (IsConfDatabase(conf)) |
119 |
{ |
120 |
delete_one_address_conf(host, conf); |
121 |
return 1; |
122 |
} |
123 |
} |
124 |
|
125 |
return 0; |
126 |
} |
127 |
|
128 |
/* mo_dline() |
129 |
* |
130 |
* inputs - pointer to server |
131 |
* - pointer to client |
132 |
* - parameter count |
133 |
* - parameter list |
134 |
* output - |
135 |
* side effects - D line is added |
136 |
* |
137 |
*/ |
138 |
static void |
139 |
mo_dline(struct Client *client_p, struct Client *source_p, |
140 |
int parc, char *parv[]) |
141 |
{ |
142 |
char def_reason[] = "<No reason specified>"; |
143 |
char *dlhost = NULL, *reason = NULL; |
144 |
char *target_server = NULL; |
145 |
const char *creason; |
146 |
const struct Client *target_p = NULL; |
147 |
struct irc_ssaddr daddr; |
148 |
struct MaskItem *conf=NULL; |
149 |
time_t tkline_time=0; |
150 |
int bits = 0, aftype = 0, t = 0; |
151 |
const char *current_date = NULL; |
152 |
time_t cur_time; |
153 |
char hostip[HOSTIPLEN + 1]; |
154 |
char buffer[IRCD_BUFSIZE]; |
155 |
|
156 |
if (!HasOFlag(source_p, OPER_FLAG_DLINE)) |
157 |
{ |
158 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
159 |
me.name, source_p->name, "dline"); |
160 |
return; |
161 |
} |
162 |
|
163 |
if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost, |
164 |
NULL, &tkline_time, &target_server, &reason) < 0) |
165 |
return; |
166 |
|
167 |
if (target_server != NULL) |
168 |
{ |
169 |
if (HasID(source_p)) |
170 |
{ |
171 |
sendto_server(NULL, CAP_DLN|CAP_TS6, NOCAPS, |
172 |
":%s DLINE %s %lu %s :%s", |
173 |
source_p->id, target_server, (unsigned long)tkline_time, |
174 |
dlhost, reason); |
175 |
sendto_server(NULL, CAP_DLN, CAP_TS6, |
176 |
":%s DLINE %s %lu %s :%s", |
177 |
source_p->name, target_server, (unsigned long)tkline_time, |
178 |
dlhost, reason); |
179 |
} |
180 |
else |
181 |
sendto_server(NULL, CAP_DLN, NOCAPS, |
182 |
":%s DLINE %s %lu %s :%s", |
183 |
source_p->name, target_server, (unsigned long)tkline_time, |
184 |
dlhost, reason); |
185 |
|
186 |
/* Allow ON to apply local kline as well if it matches */ |
187 |
if (match(target_server, me.name)) |
188 |
return; |
189 |
} |
190 |
else |
191 |
cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE, |
192 |
"%d %s :%s", tkline_time, dlhost, reason); |
193 |
|
194 |
if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST) |
195 |
{ |
196 |
if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL) |
197 |
return; |
198 |
|
199 |
if (!MyConnect(target_p)) |
200 |
{ |
201 |
sendto_one(source_p, |
202 |
":%s NOTICE %s :Can't DLINE nick on another server", |
203 |
me.name, source_p->name); |
204 |
return; |
205 |
} |
206 |
|
207 |
if (IsExemptKline(target_p)) |
208 |
{ |
209 |
sendto_one(source_p, |
210 |
":%s NOTICE %s :%s is E-lined", me.name, |
211 |
source_p->name, target_p->name); |
212 |
return; |
213 |
} |
214 |
|
215 |
getnameinfo((struct sockaddr *)&target_p->localClient->ip, |
216 |
target_p->localClient->ip.ss_len, hostip, |
217 |
sizeof(hostip), NULL, 0, NI_NUMERICHOST); |
218 |
dlhost = hostip; |
219 |
t = parse_netmask(dlhost, NULL, &bits); |
220 |
assert(t == HM_IPV4 || t == HM_IPV6); |
221 |
} |
222 |
|
223 |
if (bits < 8) |
224 |
{ |
225 |
sendto_one(source_p, |
226 |
":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.", |
227 |
me.name, source_p->name); |
228 |
return; |
229 |
} |
230 |
|
231 |
#ifdef IPV6 |
232 |
if (t == HM_IPV6) |
233 |
aftype = AF_INET6; |
234 |
else |
235 |
#endif |
236 |
aftype = AF_INET; |
237 |
|
238 |
parse_netmask(dlhost, &daddr, NULL); |
239 |
|
240 |
if ((conf = find_dline_conf(&daddr, aftype)) != NULL) |
241 |
{ |
242 |
creason = conf->reason ? conf->reason : def_reason; |
243 |
if (IsConfExemptKline(conf)) |
244 |
sendto_one(source_p, |
245 |
":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", |
246 |
me.name, source_p->name, dlhost, conf->host, creason); |
247 |
else |
248 |
sendto_one(source_p, |
249 |
":%s NOTICE %s :[%s] already D-lined by [%s] - %s", |
250 |
me.name, source_p->name, dlhost, conf->host, creason); |
251 |
return; |
252 |
} |
253 |
|
254 |
cur_time = CurrentTime; |
255 |
current_date = smalldate(cur_time); |
256 |
|
257 |
if (!valid_comment(source_p, reason, 1)) |
258 |
return; |
259 |
|
260 |
conf = conf_make(CONF_DLINE); |
261 |
conf->host = xstrdup(dlhost); |
262 |
|
263 |
if (tkline_time != 0) |
264 |
snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)", |
265 |
(int)(tkline_time/60), reason, current_date); |
266 |
else |
267 |
snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); |
268 |
|
269 |
conf->reason = xstrdup(buffer); |
270 |
apply_dline(source_p, conf, tkline_time); |
271 |
rehashed_klines = 1; |
272 |
} |
273 |
|
274 |
static void |
275 |
ms_dline(struct Client *client_p, struct Client *source_p, |
276 |
int parc, char *parv[]) |
277 |
{ |
278 |
char def_reason[] = "<No reason specified>"; |
279 |
char *dlhost, *reason; |
280 |
const char *creason; |
281 |
const struct Client *target_p = NULL; |
282 |
struct irc_ssaddr daddr; |
283 |
struct MaskItem *conf=NULL; |
284 |
time_t tkline_time=0; |
285 |
int bits = 0, aftype = 0, t = 0; |
286 |
const char *current_date = NULL; |
287 |
time_t cur_time; |
288 |
char hostip[HOSTIPLEN + 1]; |
289 |
char buffer[IRCD_BUFSIZE]; |
290 |
|
291 |
if (parc != 5 || EmptyString(parv[4])) |
292 |
return; |
293 |
|
294 |
/* parv[0] parv[1] parv[2] parv[3] parv[4] */ |
295 |
/* oper target_server tkline_time host reason */ |
296 |
sendto_match_servs(source_p, parv[1], CAP_DLN, |
297 |
"DLINE %s %s %s :%s", |
298 |
parv[1], parv[2], parv[3], parv[4]); |
299 |
|
300 |
if (match(parv[1], me.name)) |
301 |
return; |
302 |
|
303 |
tkline_time = valid_tkline(parv[2], TK_SECONDS); |
304 |
dlhost = parv[3]; |
305 |
reason = parv[4]; |
306 |
|
307 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
308 |
source_p->username, source_p->host, |
309 |
SHARED_DLINE)) |
310 |
{ |
311 |
if (!IsClient(source_p)) |
312 |
return; |
313 |
if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST) |
314 |
{ |
315 |
if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL) |
316 |
return; |
317 |
|
318 |
if (!MyConnect(target_p)) |
319 |
{ |
320 |
sendto_one(source_p, |
321 |
":%s NOTICE %s :Can't DLINE nick on another server", |
322 |
me.name, source_p->name); |
323 |
return; |
324 |
} |
325 |
|
326 |
if (IsExemptKline(target_p)) |
327 |
{ |
328 |
sendto_one(source_p, |
329 |
":%s NOTICE %s :%s is E-lined", me.name, |
330 |
source_p->name, target_p->name); |
331 |
return; |
332 |
} |
333 |
|
334 |
getnameinfo((struct sockaddr *)&target_p->localClient->ip, |
335 |
target_p->localClient->ip.ss_len, hostip, |
336 |
sizeof(hostip), NULL, 0, NI_NUMERICHOST); |
337 |
dlhost = hostip; |
338 |
t = parse_netmask(dlhost, NULL, &bits); |
339 |
assert(t == HM_IPV4 || t == HM_IPV6); |
340 |
} |
341 |
|
342 |
if (bits < 8) |
343 |
{ |
344 |
sendto_one(source_p, |
345 |
":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.", |
346 |
me.name, source_p->name); |
347 |
return; |
348 |
} |
349 |
|
350 |
#ifdef IPV6 |
351 |
if (t == HM_IPV6) |
352 |
aftype= AF_INET6; |
353 |
else |
354 |
#endif |
355 |
aftype = AF_INET; |
356 |
|
357 |
parse_netmask(dlhost, &daddr, NULL); |
358 |
|
359 |
if ((conf = find_dline_conf(&daddr, aftype)) != NULL) |
360 |
{ |
361 |
creason = conf->reason ? conf->reason : def_reason; |
362 |
if (IsConfExemptKline(conf)) |
363 |
sendto_one(source_p, |
364 |
":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", |
365 |
me.name, source_p->name, dlhost, conf->host, creason); |
366 |
else |
367 |
sendto_one(source_p, |
368 |
":%s NOTICE %s :[%s] already D-lined by [%s] - %s", |
369 |
me.name, source_p->name, dlhost, conf->host, creason); |
370 |
return; |
371 |
} |
372 |
|
373 |
cur_time = CurrentTime; |
374 |
current_date = smalldate(cur_time); |
375 |
|
376 |
if (!valid_comment(source_p, reason, 1)) |
377 |
return; |
378 |
|
379 |
conf = conf_make(CONF_DLINE); |
380 |
conf->host = xstrdup(dlhost); |
381 |
|
382 |
if (tkline_time != 0) |
383 |
snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)", |
384 |
(int)(tkline_time/60), reason, current_date); |
385 |
else |
386 |
snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); |
387 |
|
388 |
conf->reason = xstrdup(buffer); |
389 |
apply_dline(source_p, conf, tkline_time); |
390 |
rehashed_klines = 1; |
391 |
} |
392 |
} |
393 |
|
394 |
/* |
395 |
** m_undline |
396 |
** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk> |
397 |
** based totally on m_unkline |
398 |
** added to hybrid-7 7/11/2000 --is |
399 |
** |
400 |
** parv[0] = sender nick |
401 |
** parv[1] = dline to remove |
402 |
*/ |
403 |
static void |
404 |
mo_undline(struct Client *client_p, struct Client *source_p, |
405 |
int parc, char *parv[]) |
406 |
{ |
407 |
char *addr = NULL, *user = NULL; |
408 |
char *target_server = NULL; |
409 |
|
410 |
if (!HasOFlag(source_p, OPER_FLAG_UNDLINE)) |
411 |
{ |
412 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
413 |
me.name, source_p->name, "undline"); |
414 |
return; |
415 |
} |
416 |
|
417 |
if (parc < 2 || EmptyString(parv[1])) |
418 |
{ |
419 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
420 |
me.name, source_p->name, "UNDLINE"); |
421 |
return; |
422 |
} |
423 |
|
424 |
if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user, |
425 |
&addr, NULL, &target_server, NULL) < 0) |
426 |
return; |
427 |
|
428 |
if (target_server != NULL) |
429 |
{ |
430 |
sendto_match_servs(source_p, target_server, CAP_UNDLN, |
431 |
"UNDLINE %s %s", target_server, addr); |
432 |
|
433 |
/* Allow ON to apply local unkline as well if it matches */ |
434 |
if (match(target_server, me.name)) |
435 |
return; |
436 |
} |
437 |
else |
438 |
cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE, |
439 |
"%s", addr); |
440 |
|
441 |
if (remove_dline_match(addr)) |
442 |
{ |
443 |
sendto_one(source_p, |
444 |
":%s NOTICE %s :D-Line for [%s] is removed", |
445 |
me.name, source_p->name, addr); |
446 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
447 |
"%s has removed the D-Line for: [%s]", |
448 |
get_oper_name(source_p), addr); |
449 |
ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]", |
450 |
get_oper_name(source_p), addr); |
451 |
} |
452 |
else |
453 |
sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found", |
454 |
me.name, source_p->name, addr); |
455 |
} |
456 |
|
457 |
static void |
458 |
me_undline(struct Client *client_p, struct Client *source_p, |
459 |
int parc, char *parv[]) |
460 |
{ |
461 |
const char *addr = NULL; |
462 |
|
463 |
if (parc != 3 || EmptyString(parv[2])) |
464 |
return; |
465 |
|
466 |
addr = parv[2]; |
467 |
|
468 |
if (!IsClient(source_p) || match(parv[1], me.name)) |
469 |
return; |
470 |
|
471 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, |
472 |
source_p->servptr->name, |
473 |
source_p->username, source_p->host, |
474 |
SHARED_UNDLINE)) |
475 |
{ |
476 |
if (remove_dline_match(addr)) |
477 |
{ |
478 |
sendto_one(source_p, |
479 |
":%s NOTICE %s :D-Line for [%s] is removed", |
480 |
me.name, source_p->name, addr); |
481 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
482 |
"%s has removed the D-Line for: [%s]", |
483 |
get_oper_name(source_p), addr); |
484 |
ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]", |
485 |
get_oper_name(source_p), addr); |
486 |
} |
487 |
else |
488 |
sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found", |
489 |
me.name, source_p->name, addr); |
490 |
} |
491 |
} |
492 |
|
493 |
static void |
494 |
ms_undline(struct Client *client_p, struct Client *source_p, |
495 |
int parc, char *parv[]) |
496 |
{ |
497 |
if (parc != 3 || EmptyString(parv[2])) |
498 |
return; |
499 |
|
500 |
sendto_match_servs(source_p, parv[1], CAP_UNDLN, |
501 |
"UNDLINE %s %s %s", |
502 |
parv[1], parv[2]); |
503 |
|
504 |
me_undline(client_p, source_p, parc, parv); |
505 |
} |
506 |
|
507 |
static struct Message dline_msgtab = { |
508 |
"DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
509 |
{m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore} |
510 |
}; |
511 |
|
512 |
static struct Message undline_msgtab = { |
513 |
"UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
514 |
{m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore} |
515 |
}; |
516 |
|
517 |
static void |
518 |
module_init(void) |
519 |
{ |
520 |
mod_add_cmd(&dline_msgtab); |
521 |
mod_add_cmd(&undline_msgtab); |
522 |
add_capability("DLN", CAP_DLN, 1); |
523 |
add_capability("UNDLN", CAP_UNDLN, 1); |
524 |
} |
525 |
|
526 |
static void |
527 |
module_exit(void) |
528 |
{ |
529 |
mod_del_cmd(&dline_msgtab); |
530 |
mod_del_cmd(&undline_msgtab); |
531 |
delete_capability("UNDLN"); |
532 |
delete_capability("DLN"); |
533 |
} |
534 |
|
535 |
struct module module_entry = { |
536 |
.node = { NULL, NULL, NULL }, |
537 |
.name = NULL, |
538 |
.version = "$Revision$", |
539 |
.handle = NULL, |
540 |
.modinit = module_init, |
541 |
.modexit = module_exit, |
542 |
.flags = 0 |
543 |
}; |