ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 2807
Committed: Sun Jan 12 17:19:01 2014 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 14871 byte(s)
Log Message:
- m_dline.c:mo_dline(). if a target server exists, use sendto_match_servs()
  instead of sendto_server()

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

Properties

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