/[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 1622 - (show annotations)
Thu Nov 1 13:16:37 2012 UTC (7 years, 10 months ago) by michael
File MIME type: text/x-chdr
File size: 15763 byte(s)
- klines, dlines, xlines, glines and resv now make use of the new database;
  also, temporary *lines are now stored, so they're not lost after
  restarting the ircd. This also applies to G-lines.

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

Properties

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

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