ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 1632
Committed: Sun Nov 4 15:37:10 2012 UTC (12 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 15330 byte(s)
Log Message:
- Initial rewrite of the configuration subsystem

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

Properties

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