ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_dline.c
Revision: 1622
Committed: Thu Nov 1 13:16:37 2012 UTC (13 years, 8 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_dline.c
File size: 15763 byte(s)
Log Message:
- 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.

File Contents

# User Rev Content
1 michael 1058 /*
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 michael 1309 #include "conf.h"
37     #include "log.h"
38 michael 1058 #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 michael 1622 #include "conf_db.h"
45 michael 1058
46    
47     /* apply_tdline()
48     *
49     * inputs -
50     * output - NONE
51     * side effects - tkline as given is placed
52     */
53     static void
54 michael 1622 apply_dline(struct Client *source_p, struct AccessItem *aconf,
55     time_t tkline_time)
56 michael 1058 {
57 michael 1622 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 michael 1058
82 michael 1622 }
83    
84     aconf->setat = CurrentTime;
85 michael 1369 add_conf_by_address(CONF_DLINE, aconf);
86 michael 1622 save_dline_database();
87 michael 1058 rehashed_klines = 1;
88     }
89    
90 michael 1298 /* 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 michael 1622 remove_dline_match(const char *host)
97 michael 1298 {
98 michael 1369 struct irc_ssaddr iphost, *piphost;
99     struct AccessItem *aconf;
100     int t;
101 michael 1298
102 michael 1369 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
103 michael 1298 {
104     #ifdef IPV6
105 michael 1369 if (t == HM_IPV6)
106     t = AF_INET6;
107     else
108 michael 1298 #endif
109 michael 1369 t = AF_INET;
110     piphost = &iphost;
111     }
112     else
113     {
114     t = 0;
115     piphost = NULL;
116     }
117    
118 michael 1371 if ((aconf = find_conf_by_address(host, piphost, CONF_DLINE, t, NULL, NULL, 0)))
119 michael 1369 {
120 michael 1622 if (!IsConfMain(aconf))
121 michael 1298 {
122 michael 1369 delete_one_address_conf(host, aconf);
123 michael 1622 save_dline_database();
124 michael 1298 return 1;
125     }
126     }
127    
128     return 0;
129     }
130    
131 michael 1058 /* 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 michael 1301 char def_reason[] = "<No reason specified>";
146 michael 1622 char *dlhost = NULL, *reason = NULL;
147 michael 1301 char *target_server = NULL;
148 michael 1058 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 michael 1398 char hostip[HOSTIPLEN + 1];
158 michael 1230 char buffer[IRCD_BUFSIZE];
159 michael 1058
160 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
161 michael 1058 {
162     sendto_one(source_p, form_str(ERR_NOPRIVS),
163 michael 1515 me.name, source_p->name, "dline");
164 michael 1058 return;
165     }
166    
167     if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
168 michael 1301 NULL, &tkline_time, &target_server, &reason) < 0)
169 michael 1058 return;
170    
171 michael 1301 if (target_server != NULL)
172     {
173     if (HasID(source_p))
174     {
175 michael 1474 sendto_server(NULL, CAP_DLN|CAP_TS6, NOCAPS,
176 michael 1301 ":%s DLINE %s %lu %s :%s",
177     source_p->id, target_server, (unsigned long)tkline_time,
178     dlhost, reason);
179 michael 1474 sendto_server(NULL, CAP_DLN, CAP_TS6,
180 michael 1301 ":%s DLINE %s %lu %s :%s",
181     source_p->name, target_server, (unsigned long)tkline_time,
182     dlhost, reason);
183     }
184     else
185 michael 1474 sendto_server(NULL, CAP_DLN, NOCAPS,
186 michael 1301 ":%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 michael 1058 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 michael 1123 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
220     target_p->localClient->ip.ss_len, hostip,
221     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
222 michael 1058 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 michael 1243 if (!valid_comment(source_p, reason, 1))
262 michael 1058 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 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
271     (int)(tkline_time/60), reason, current_date);
272 michael 1058 DupString(aconf->reason, buffer);
273 michael 1622 apply_dline(source_p, aconf, tkline_time);
274 michael 1058 }
275     else
276     {
277 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
278 michael 1058 DupString(aconf->reason, buffer);
279 michael 1622 apply_dline(source_p, aconf, 0);
280 michael 1058 }
281    
282     rehashed_klines = 1;
283     }
284    
285 michael 1301 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 michael 1622 char *dlhost, *reason;
291 michael 1301 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 michael 1398 char hostip[HOSTIPLEN + 1];
301 michael 1301 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 michael 1622 apply_dline(source_p, aconf, tkline_time);
401 michael 1301 }
402     else
403     {
404     snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
405     DupString(aconf->reason, buffer);
406 michael 1622 apply_dline(source_p, aconf, 0);
407 michael 1301 }
408    
409     rehashed_klines = 1;
410     }
411     }
412    
413 michael 1058 /*
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 michael 1301 char *addr = NULL, *user = NULL;
427     char *target_server = NULL;
428 michael 1058
429 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
430 michael 1058 {
431     sendto_one(source_p, form_str(ERR_NOPRIVS),
432     me.name, source_p->name, "undline");
433     return;
434     }
435    
436 michael 1301 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 michael 1058
443 michael 1301 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 michael 1622 if (remove_dline_match(addr))
461 michael 1058 {
462     sendto_one(source_p,
463 michael 1622 ":%s NOTICE %s :D-Line for [%s] is removed",
464 michael 1301 me.name, source_p->name, addr);
465 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
466 michael 1622 "%s has removed the D-Line for: [%s]",
467 michael 1298 get_oper_name(source_p), addr);
468 michael 1247 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
469 michael 1298 get_oper_name(source_p), addr);
470 michael 1058 }
471     else
472     sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
473 michael 1298 me.name, source_p->name, addr);
474 michael 1058 }
475 michael 1230
476 michael 1301 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 michael 1622 if (remove_dline_match(addr))
496 michael 1301 {
497     sendto_one(source_p,
498 michael 1622 ":%s NOTICE %s :D-Line for [%s] is removed",
499 michael 1301 me.name, source_p->name, addr);
500 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
501 michael 1622 "%s has removed the D-Line for: [%s]",
502 michael 1301 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 michael 1230 static struct Message dline_msgtab = {
527     "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
528 michael 1301 {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
529 michael 1230 };
530    
531     static struct Message undline_msgtab = {
532     "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
533 michael 1301 {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
534 michael 1230 };
535    
536     static void
537     module_init(void)
538     {
539     mod_add_cmd(&dline_msgtab);
540     mod_add_cmd(&undline_msgtab);
541 michael 1301 add_capability("DLN", CAP_DLN, 1);
542     add_capability("UNDLN", CAP_UNDLN, 1);
543 michael 1230 }
544    
545     static void
546     module_exit(void)
547     {
548     mod_del_cmd(&dline_msgtab);
549     mod_del_cmd(&undline_msgtab);
550 michael 1301 delete_capability("UNDLN");
551     delete_capability("DLN");
552 michael 1230 }
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