/[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 1703 - (hide annotations)
Sun Dec 23 14:26:36 2012 UTC (7 years, 8 months ago) by michael
File MIME type: text/x-chdr
File size: 15434 byte(s)
- Fixed core on UNDLINE

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

Properties

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

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