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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1625 - (show annotations)
Thu Nov 1 13:49:25 2012 UTC (7 years, 9 months ago) by michael
File MIME type: text/x-chdr
File size: 15709 byte(s)
- dbs are now periodically flushed on disc every 5 minutes

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

Properties

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

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