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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1625 - (hide annotations)
Thu Nov 1 13:49:25 2012 UTC (7 years, 10 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 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 1058 rehashed_klines = 1;
87     }
88    
89 michael 1298 /* 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 michael 1622 remove_dline_match(const char *host)
96 michael 1298 {
97 michael 1369 struct irc_ssaddr iphost, *piphost;
98     struct AccessItem *aconf;
99     int t;
100 michael 1298
101 michael 1369 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
102 michael 1298 {
103     #ifdef IPV6
104 michael 1369 if (t == HM_IPV6)
105     t = AF_INET6;
106     else
107 michael 1298 #endif
108 michael 1369 t = AF_INET;
109     piphost = &iphost;
110     }
111     else
112     {
113     t = 0;
114     piphost = NULL;
115     }
116    
117 michael 1371 if ((aconf = find_conf_by_address(host, piphost, CONF_DLINE, t, NULL, NULL, 0)))
118 michael 1369 {
119 michael 1622 if (!IsConfMain(aconf))
120 michael 1298 {
121 michael 1369 delete_one_address_conf(host, aconf);
122 michael 1298 return 1;
123     }
124     }
125    
126     return 0;
127     }
128    
129 michael 1058 /* 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 michael 1301 char def_reason[] = "<No reason specified>";
144 michael 1622 char *dlhost = NULL, *reason = NULL;
145 michael 1301 char *target_server = NULL;
146 michael 1058 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 michael 1398 char hostip[HOSTIPLEN + 1];
156 michael 1230 char buffer[IRCD_BUFSIZE];
157 michael 1058
158 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
159 michael 1058 {
160     sendto_one(source_p, form_str(ERR_NOPRIVS),
161 michael 1515 me.name, source_p->name, "dline");
162 michael 1058 return;
163     }
164    
165     if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
166 michael 1301 NULL, &tkline_time, &target_server, &reason) < 0)
167 michael 1058 return;
168    
169 michael 1301 if (target_server != NULL)
170     {
171     if (HasID(source_p))
172     {
173 michael 1474 sendto_server(NULL, CAP_DLN|CAP_TS6, NOCAPS,
174 michael 1301 ":%s DLINE %s %lu %s :%s",
175     source_p->id, target_server, (unsigned long)tkline_time,
176     dlhost, reason);
177 michael 1474 sendto_server(NULL, CAP_DLN, CAP_TS6,
178 michael 1301 ":%s DLINE %s %lu %s :%s",
179     source_p->name, target_server, (unsigned long)tkline_time,
180     dlhost, reason);
181     }
182     else
183 michael 1474 sendto_server(NULL, CAP_DLN, NOCAPS,
184 michael 1301 ":%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 michael 1058 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 michael 1123 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
218     target_p->localClient->ip.ss_len, hostip,
219     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
220 michael 1058 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 michael 1243 if (!valid_comment(source_p, reason, 1))
260 michael 1058 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 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
269     (int)(tkline_time/60), reason, current_date);
270 michael 1058 DupString(aconf->reason, buffer);
271 michael 1622 apply_dline(source_p, aconf, tkline_time);
272 michael 1058 }
273     else
274     {
275 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
276 michael 1058 DupString(aconf->reason, buffer);
277 michael 1622 apply_dline(source_p, aconf, 0);
278 michael 1058 }
279    
280     rehashed_klines = 1;
281     }
282    
283 michael 1301 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 michael 1622 char *dlhost, *reason;
289 michael 1301 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 michael 1398 char hostip[HOSTIPLEN + 1];
299 michael 1301 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 michael 1622 apply_dline(source_p, aconf, tkline_time);
399 michael 1301 }
400     else
401     {
402     snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
403     DupString(aconf->reason, buffer);
404 michael 1622 apply_dline(source_p, aconf, 0);
405 michael 1301 }
406    
407     rehashed_klines = 1;
408     }
409     }
410    
411 michael 1058 /*
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 michael 1301 char *addr = NULL, *user = NULL;
425     char *target_server = NULL;
426 michael 1058
427 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
428 michael 1058 {
429     sendto_one(source_p, form_str(ERR_NOPRIVS),
430     me.name, source_p->name, "undline");
431     return;
432     }
433    
434 michael 1301 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 michael 1058
441 michael 1301 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 michael 1622 if (remove_dline_match(addr))
459 michael 1058 {
460     sendto_one(source_p,
461 michael 1622 ":%s NOTICE %s :D-Line for [%s] is removed",
462 michael 1301 me.name, source_p->name, addr);
463 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
464 michael 1622 "%s has removed the D-Line for: [%s]",
465 michael 1298 get_oper_name(source_p), addr);
466 michael 1247 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
467 michael 1298 get_oper_name(source_p), addr);
468 michael 1058 }
469     else
470     sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
471 michael 1298 me.name, source_p->name, addr);
472 michael 1058 }
473 michael 1230
474 michael 1301 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 michael 1622 if (remove_dline_match(addr))
494 michael 1301 {
495     sendto_one(source_p,
496 michael 1622 ":%s NOTICE %s :D-Line for [%s] is removed",
497 michael 1301 me.name, source_p->name, addr);
498 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
499 michael 1622 "%s has removed the D-Line for: [%s]",
500 michael 1301 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 michael 1230 static struct Message dline_msgtab = {
525     "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
526 michael 1301 {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
527 michael 1230 };
528    
529     static struct Message undline_msgtab = {
530     "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
531 michael 1301 {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
532 michael 1230 };
533    
534     static void
535     module_init(void)
536     {
537     mod_add_cmd(&dline_msgtab);
538     mod_add_cmd(&undline_msgtab);
539 michael 1301 add_capability("DLN", CAP_DLN, 1);
540     add_capability("UNDLN", CAP_UNDLN, 1);
541 michael 1230 }
542    
543     static void
544     module_exit(void)
545     {
546     mod_del_cmd(&dline_msgtab);
547     mod_del_cmd(&undline_msgtab);
548 michael 1301 delete_capability("UNDLN");
549     delete_capability("DLN");
550 michael 1230 }
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