ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/newio/modules/m_dline.c
Revision: 2392
Committed: Sat Jul 13 22:13:28 2013 UTC (10 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 15356 byte(s)
Log Message:
- ioengine changes as of 14JUL13

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

Properties

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