/[svn]/ircd-hybrid-8/modules/m_dline.c
ViewVC logotype

Contents of /ircd-hybrid-8/modules/m_dline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1398 - (show annotations)
Sun May 6 10:57:06 2012 UTC (8 years, 2 months ago) by michael
File MIME type: text/x-chdr
File size: 16805 byte(s)
- decrease HOSTIPLEN to 45
- fix some buffers that should use HOSTIPLEN+1

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 "ircd.h"
32 #include "hostmask.h"
33 #include "numeric.h"
34 #include "fdlist.h"
35 #include "s_bsd.h"
36 #include "conf.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 "s_gline.h"
43 #include "parse.h"
44 #include "modules.h"
45
46
47 /* apply_tdline()
48 *
49 * inputs -
50 * output - NONE
51 * side effects - tkline as given is placed
52 */
53 static void
54 apply_tdline(struct Client *source_p, struct ConfItem *conf,
55 const char *current_date, int tkline_time)
56 {
57 struct AccessItem *aconf;
58
59 aconf = map_to_conf(conf);
60 aconf->hold = CurrentTime + tkline_time;
61 SetConfTemporary(aconf);
62 add_conf_by_address(CONF_DLINE, aconf);
63
64
65 sendto_realops_flags(UMODE_ALL, L_ALL,
66 "%s added temporary %d min. D-Line for [%s] [%s]",
67 get_oper_name(source_p), tkline_time/60,
68 aconf->host, aconf->reason);
69
70 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
71 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
72 source_p->name, tkline_time/60, aconf->host);
73 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
74 source_p->name, tkline_time/60, aconf->host, aconf->reason);
75
76 rehashed_klines = 1;
77 }
78
79 /* static int remove_tdline_match(const char *host, const char *user)
80 * Input: An ip to undline.
81 * Output: returns YES on success, NO if no tdline removed.
82 * Side effects: Any matching tdlines are removed.
83 */
84 static int
85 remove_tdline_match(const char *host)
86 {
87 struct irc_ssaddr iphost, *piphost;
88 struct AccessItem *aconf;
89 int t;
90
91 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
92 {
93 #ifdef IPV6
94 if (t == HM_IPV6)
95 t = AF_INET6;
96 else
97 #endif
98 t = AF_INET;
99 piphost = &iphost;
100 }
101 else
102 {
103 t = 0;
104 piphost = NULL;
105 }
106
107 if ((aconf = find_conf_by_address(host, piphost, CONF_DLINE, t, NULL, NULL, 0)))
108 {
109 if (IsConfTemporary(aconf))
110 {
111 delete_one_address_conf(host, aconf);
112 return 1;
113 }
114 }
115
116 return 0;
117 }
118
119 /* mo_dline()
120 *
121 * inputs - pointer to server
122 * - pointer to client
123 * - parameter count
124 * - parameter list
125 * output -
126 * side effects - D line is added
127 *
128 */
129 static void
130 mo_dline(struct Client *client_p, struct Client *source_p,
131 int parc, char *parv[])
132 {
133 char def_reason[] = "<No reason specified>";
134 char *dlhost = NULL, *oper_reason = NULL, *reason = NULL;
135 char *target_server = NULL;
136 const char *creason;
137 const struct Client *target_p = NULL;
138 struct irc_ssaddr daddr;
139 struct ConfItem *conf=NULL;
140 struct AccessItem *aconf=NULL;
141 time_t tkline_time=0;
142 int bits, t;
143 const char *current_date = NULL;
144 time_t cur_time;
145 char hostip[HOSTIPLEN + 1];
146 char buffer[IRCD_BUFSIZE];
147
148 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
149 {
150 sendto_one(source_p, form_str(ERR_NOPRIVS),
151 me.name, source_p->name, "kline");
152 return;
153 }
154
155 if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
156 NULL, &tkline_time, &target_server, &reason) < 0)
157 return;
158
159 if (target_server != NULL)
160 {
161 if (HasID(source_p))
162 {
163 sendto_server(NULL, NULL, CAP_DLN|CAP_TS6, NOCAPS,
164 ":%s DLINE %s %lu %s :%s",
165 source_p->id, target_server, (unsigned long)tkline_time,
166 dlhost, reason);
167 sendto_server(NULL, NULL, CAP_DLN, CAP_TS6,
168 ":%s DLINE %s %lu %s :%s",
169 source_p->name, target_server, (unsigned long)tkline_time,
170 dlhost, reason);
171 }
172 else
173 sendto_server(NULL, NULL, CAP_DLN, NOCAPS,
174 ":%s DLINE %s %lu %s :%s",
175 source_p->name, target_server, (unsigned long)tkline_time,
176 dlhost, reason);
177
178 /* Allow ON to apply local kline as well if it matches */
179 if (!match(target_server, me.name))
180 return;
181 }
182 else
183 cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
184 "%d %s :%s", tkline_time, dlhost, reason);
185
186 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
187 {
188 if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
189 return;
190
191 if (!MyConnect(target_p))
192 {
193 sendto_one(source_p,
194 ":%s NOTICE %s :Can't DLINE nick on another server",
195 me.name, source_p->name);
196 return;
197 }
198
199 if (IsExemptKline(target_p))
200 {
201 sendto_one(source_p,
202 ":%s NOTICE %s :%s is E-lined", me.name,
203 source_p->name, target_p->name);
204 return;
205 }
206
207 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
208 target_p->localClient->ip.ss_len, hostip,
209 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
210 dlhost = hostip;
211 t = parse_netmask(dlhost, NULL, &bits);
212 assert(t == HM_IPV4 || t == HM_IPV6);
213 }
214
215 if (bits < 8)
216 {
217 sendto_one(source_p,
218 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
219 me.name, source_p->name);
220 return;
221 }
222
223 #ifdef IPV6
224 if (t == HM_IPV6)
225 t = AF_INET6;
226 else
227 #endif
228 t = AF_INET;
229
230 parse_netmask(dlhost, &daddr, NULL);
231
232 if ((aconf = find_dline_conf(&daddr, t)) != NULL)
233 {
234 creason = aconf->reason ? aconf->reason : def_reason;
235 if (IsConfExemptKline(aconf))
236 sendto_one(source_p,
237 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
238 me.name, source_p->name, dlhost, aconf->host, creason);
239 else
240 sendto_one(source_p,
241 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
242 me.name, source_p->name, dlhost, aconf->host, creason);
243 return;
244 }
245
246 cur_time = CurrentTime;
247 current_date = smalldate(cur_time);
248
249 /* Look for an oper reason */
250 if ((oper_reason = strchr(reason, '|')) != NULL)
251 *oper_reason++ = '\0';
252
253 if (!valid_comment(source_p, reason, 1))
254 return;
255
256 conf = make_conf_item(DLINE_TYPE);
257 aconf = map_to_conf(conf);
258 DupString(aconf->host, dlhost);
259
260 if (tkline_time != 0)
261 {
262 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
263 (int)(tkline_time/60), reason, current_date);
264 DupString(aconf->reason, buffer);
265 if (oper_reason != NULL)
266 DupString(aconf->oper_reason, oper_reason);
267 apply_tdline(source_p, conf, current_date, tkline_time);
268 }
269 else
270 {
271 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
272 DupString(aconf->reason, buffer);
273 if (oper_reason != NULL)
274 DupString(aconf->oper_reason, oper_reason);
275 add_conf_by_address(CONF_DLINE, aconf);
276 write_conf_line(source_p, conf, current_date, cur_time);
277 }
278
279 rehashed_klines = 1;
280 }
281
282 static void
283 ms_dline(struct Client *client_p, struct Client *source_p,
284 int parc, char *parv[])
285 {
286 char def_reason[] = "<No reason specified>";
287 char *dlhost, *oper_reason, *reason;
288 const char *creason;
289 const struct Client *target_p = NULL;
290 struct irc_ssaddr daddr;
291 struct ConfItem *conf=NULL;
292 struct AccessItem *aconf=NULL;
293 time_t tkline_time=0;
294 int bits, t;
295 const char *current_date = NULL;
296 time_t cur_time;
297 char hostip[HOSTIPLEN + 1];
298 char buffer[IRCD_BUFSIZE];
299
300 if (parc != 5 || EmptyString(parv[4]))
301 return;
302
303 /* parv[0] parv[1] parv[2] parv[3] parv[4] */
304 /* oper target_server tkline_time host reason */
305 sendto_match_servs(source_p, parv[1], CAP_DLN,
306 "DLINE %s %s %s :%s",
307 parv[1], parv[2], parv[3], parv[4]);
308
309 if (!match(parv[1], me.name))
310 return;
311
312 tkline_time = valid_tkline(parv[2], TK_SECONDS);
313 dlhost = parv[3];
314 reason = parv[4];
315
316 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
317 source_p->username, source_p->host,
318 SHARED_DLINE))
319 {
320 if (!IsClient(source_p))
321 return;
322 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
323 {
324 if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
325 return;
326
327 if (!MyConnect(target_p))
328 {
329 sendto_one(source_p,
330 ":%s NOTICE %s :Can't DLINE nick on another server",
331 me.name, source_p->name);
332 return;
333 }
334
335 if (IsExemptKline(target_p))
336 {
337 sendto_one(source_p,
338 ":%s NOTICE %s :%s is E-lined", me.name,
339 source_p->name, target_p->name);
340 return;
341 }
342
343 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
344 target_p->localClient->ip.ss_len, hostip,
345 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
346 dlhost = hostip;
347 t = parse_netmask(dlhost, NULL, &bits);
348 assert(t == HM_IPV4 || t == HM_IPV6);
349 }
350
351 if (bits < 8)
352 {
353 sendto_one(source_p,
354 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
355 me.name, source_p->name);
356 return;
357 }
358
359 #ifdef IPV6
360 if (t == HM_IPV6)
361 t = AF_INET6;
362 else
363 #endif
364 t = AF_INET;
365
366 parse_netmask(dlhost, &daddr, NULL);
367
368 if ((aconf = find_dline_conf(&daddr, t)) != NULL)
369 {
370 creason = aconf->reason ? aconf->reason : def_reason;
371 if (IsConfExemptKline(aconf))
372 sendto_one(source_p,
373 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
374 me.name, source_p->name, dlhost, aconf->host, creason);
375 else
376 sendto_one(source_p,
377 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
378 me.name, source_p->name, dlhost, aconf->host, creason);
379 return;
380 }
381
382 cur_time = CurrentTime;
383 current_date = smalldate(cur_time);
384
385 /* Look for an oper reason */
386 if ((oper_reason = strchr(reason, '|')) != NULL)
387 *oper_reason++ = '\0';
388
389 if (!valid_comment(source_p, reason, 1))
390 return;
391
392 conf = make_conf_item(DLINE_TYPE);
393 aconf = map_to_conf(conf);
394 DupString(aconf->host, dlhost);
395
396 if (tkline_time != 0)
397 {
398 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
399 (int)(tkline_time/60), reason, current_date);
400 DupString(aconf->reason, buffer);
401 if (oper_reason != NULL)
402 DupString(aconf->oper_reason, oper_reason);
403 apply_tdline(source_p, conf, current_date, tkline_time);
404 }
405 else
406 {
407 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
408 DupString(aconf->reason, buffer);
409 if (oper_reason != NULL)
410 DupString(aconf->oper_reason, oper_reason);
411 add_conf_by_address(CONF_DLINE, aconf);
412 write_conf_line(source_p, conf, current_date, cur_time);
413 }
414
415 rehashed_klines = 1;
416 }
417 }
418
419 /*
420 ** m_undline
421 ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
422 ** based totally on m_unkline
423 ** added to hybrid-7 7/11/2000 --is
424 **
425 ** parv[0] = sender nick
426 ** parv[1] = dline to remove
427 */
428 static void
429 mo_undline(struct Client *client_p, struct Client *source_p,
430 int parc, char *parv[])
431 {
432 char *addr = NULL, *user = NULL;
433 char *target_server = NULL;
434
435 if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
436 {
437 sendto_one(source_p, form_str(ERR_NOPRIVS),
438 me.name, source_p->name, "undline");
439 return;
440 }
441
442 if (parc < 2 || EmptyString(parv[1]))
443 {
444 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
445 me.name, source_p->name, "UNDLINE");
446 return;
447 }
448
449 if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
450 &addr, NULL, &target_server, NULL) < 0)
451 return;
452
453 if (target_server != NULL)
454 {
455 sendto_match_servs(source_p, target_server, CAP_UNDLN,
456 "UNDLINE %s %s", target_server, addr);
457
458 /* Allow ON to apply local unkline as well if it matches */
459 if (!match(target_server, me.name))
460 return;
461 }
462 else
463 cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
464 "%s", addr);
465
466 if (remove_tdline_match(addr))
467 {
468 sendto_one(source_p,
469 ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
470 me.name, source_p->name, addr);
471 sendto_realops_flags(UMODE_ALL, L_ALL,
472 "%s has removed the temporary D-Line for: [%s]",
473 get_oper_name(source_p), addr);
474 ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]",
475 source_p->name, addr);
476 return;
477 }
478
479 if (remove_conf_line(DLINE_TYPE, source_p, addr, NULL) > 0)
480 {
481 sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
482 me.name, source_p->name, addr);
483 sendto_realops_flags(UMODE_ALL, L_ALL,
484 "%s has removed the D-Line for: [%s]",
485 get_oper_name(source_p), addr);
486 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
487 get_oper_name(source_p), addr);
488 }
489 else
490 sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
491 me.name, source_p->name, addr);
492 }
493
494 static void
495 me_undline(struct Client *client_p, struct Client *source_p,
496 int parc, char *parv[])
497 {
498 const char *addr = NULL;
499
500 if (parc != 3 || EmptyString(parv[2]))
501 return;
502
503 addr = parv[2];
504
505 if (!IsClient(source_p) || !match(parv[1], me.name))
506 return;
507
508 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE,
509 source_p->servptr->name,
510 source_p->username, source_p->host,
511 SHARED_UNDLINE))
512 {
513 if (remove_tdline_match(addr))
514 {
515 sendto_one(source_p,
516 ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
517 me.name, source_p->name, addr);
518 sendto_realops_flags(UMODE_ALL, L_ALL,
519 "%s has removed the temporary D-Line for: [%s]",
520 get_oper_name(source_p), addr);
521 ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]",
522 source_p->name, addr);
523 return;
524 }
525
526 if (remove_conf_line(DLINE_TYPE, source_p, addr, NULL) > 0)
527 {
528 sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
529 me.name, source_p->name, addr);
530 sendto_realops_flags(UMODE_ALL, L_ALL,
531 "%s has removed the D-Line for: [%s]",
532 get_oper_name(source_p), addr);
533 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
534 get_oper_name(source_p), addr);
535 }
536 else
537 sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
538 me.name, source_p->name, addr);
539 }
540 }
541
542 static void
543 ms_undline(struct Client *client_p, struct Client *source_p,
544 int parc, char *parv[])
545 {
546 if (parc != 3 || EmptyString(parv[2]))
547 return;
548
549 sendto_match_servs(source_p, parv[1], CAP_UNDLN,
550 "UNDLINE %s %s %s",
551 parv[1], parv[2]);
552
553 me_undline(client_p, source_p, parc, parv);
554 }
555
556 static struct Message dline_msgtab = {
557 "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
558 {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
559 };
560
561 static struct Message undline_msgtab = {
562 "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
563 {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
564 };
565
566 static void
567 module_init(void)
568 {
569 mod_add_cmd(&dline_msgtab);
570 mod_add_cmd(&undline_msgtab);
571 add_capability("DLN", CAP_DLN, 1);
572 add_capability("UNDLN", CAP_UNDLN, 1);
573 }
574
575 static void
576 module_exit(void)
577 {
578 mod_del_cmd(&dline_msgtab);
579 mod_del_cmd(&undline_msgtab);
580 delete_capability("UNDLN");
581 delete_capability("DLN");
582 }
583
584 struct module module_entry = {
585 .node = { NULL, NULL, NULL },
586 .name = NULL,
587 .version = "$Revision$",
588 .handle = NULL,
589 .modinit = module_init,
590 .modexit = module_exit,
591 .flags = 0
592 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28