ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 2997
Committed: Tue Feb 18 21:19:28 2014 UTC (12 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 14744 byte(s)
Log Message:
- m_dline.c: get rid of this (type & ~0x1) hack

File Contents

# User Rev Content
1 michael 1058 /*
2 michael 2810 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 michael 1058 *
4 michael 2818 * Copyright (c) 1997-2014 ircd-hybrid development team
5 michael 1058 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22 michael 2810 /*! \file m_dline.c
23     * \brief Includes required functions for processing the DLINE/UNDLINE command.
24     * \version $Id$
25     */
26    
27 michael 1058 #include "stdinc.h"
28     #include "list.h"
29     #include "channel.h"
30     #include "client.h"
31     #include "irc_string.h"
32 michael 1632 #include "conf.h"
33 michael 1058 #include "ircd.h"
34     #include "hostmask.h"
35     #include "numeric.h"
36     #include "fdlist.h"
37     #include "s_bsd.h"
38 michael 1309 #include "log.h"
39 michael 1058 #include "s_misc.h"
40     #include "send.h"
41     #include "hash.h"
42     #include "s_serv.h"
43     #include "parse.h"
44     #include "modules.h"
45 michael 1622 #include "conf_db.h"
46 michael 1666 #include "memory.h"
47 michael 1058
48    
49     /* apply_tdline()
50     *
51     * inputs -
52     * output - NONE
53     * side effects - tkline as given is placed
54     */
55     static void
56 michael 1632 apply_dline(struct Client *source_p, struct MaskItem *conf,
57 michael 1622 time_t tkline_time)
58 michael 1058 {
59 michael 1622 if (tkline_time)
60     {
61 michael 1649 conf->until = CurrentTime + tkline_time;
62 michael 1622 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
63     "%s added temporary %d min. D-Line for [%s] [%s]",
64     get_oper_name(source_p), tkline_time/60,
65 michael 1632 conf->host, conf->reason);
66 michael 1622 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
67 michael 2888 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p),
68 michael 1632 source_p->name, tkline_time/60, conf->host);
69 michael 1622 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
70 michael 1632 get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
71 michael 1622 }
72     else
73     {
74     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
75     "%s added D-Line for [%s] [%s]",
76 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
77 michael 1622 sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s]",
78 michael 2888 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p),
79 michael 1632 source_p->name, conf->host);
80 michael 1622 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
81 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
82 michael 1058
83 michael 1622 }
84    
85 michael 1632 SetConfDatabase(conf);
86     conf->setat = CurrentTime;
87     add_conf_by_address(CONF_DLINE, conf);
88 michael 1058 rehashed_klines = 1;
89     }
90    
91 michael 1298 /* static int remove_tdline_match(const char *host, const char *user)
92     * Input: An ip to undline.
93     * Output: returns YES on success, NO if no tdline removed.
94     * Side effects: Any matching tdlines are removed.
95     */
96     static int
97 michael 1622 remove_dline_match(const char *host)
98 michael 1298 {
99 michael 1369 struct irc_ssaddr iphost, *piphost;
100 michael 1632 struct MaskItem *conf;
101 michael 1644 int t = 0;
102     int aftype = 0;
103 michael 1298
104 michael 1369 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
105 michael 1298 {
106     #ifdef IPV6
107 michael 1369 if (t == HM_IPV6)
108 michael 1644 aftype = AF_INET6;
109 michael 1369 else
110 michael 1298 #endif
111 michael 1644 aftype = AF_INET;
112 michael 1369 piphost = &iphost;
113     }
114     else
115     piphost = NULL;
116    
117 michael 2997 if ((conf = find_conf_by_address(host, piphost, CONF_DLINE, aftype, 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 michael 2820 static int
140 michael 1058 mo_dline(struct Client *client_p, struct Client *source_p,
141     int parc, char *parv[])
142     {
143 michael 1794 char def_reason[] = CONF_NOREASON;
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 michael 1644 int bits = 0, aftype = 0, t = 0;
152 michael 1058 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 michael 2810 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
160     source_p->name, "dline");
161 michael 2820 return 0;
162 michael 1058 }
163    
164     if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
165 michael 1301 NULL, &tkline_time, &target_server, &reason) < 0)
166 michael 2820 return 0;
167 michael 1058
168 michael 1301 if (target_server != NULL)
169     {
170 michael 2807 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
171     target_server, (unsigned long)tkline_time,
172     dlhost, reason);
173 michael 1301
174     /* Allow ON to apply local kline as well if it matches */
175 michael 1652 if (match(target_server, me.name))
176 michael 2820 return 0;
177 michael 1301 }
178     else
179     cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
180     "%d %s :%s", tkline_time, dlhost, reason);
181    
182 michael 1058 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
183     {
184 michael 2475 if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
185 michael 2820 return 0;
186 michael 1058
187     if (!MyConnect(target_p))
188     {
189     sendto_one(source_p,
190     ":%s NOTICE %s :Can't DLINE nick on another server",
191     me.name, source_p->name);
192 michael 2820 return 0;
193 michael 1058 }
194    
195     if (IsExemptKline(target_p))
196     {
197 michael 2810 sendto_one(source_p, ":%s NOTICE %s :%s is E-lined",
198     me.name, source_p->name, target_p->name);
199 michael 2820 return 0;
200 michael 1058 }
201    
202 michael 1123 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
203     target_p->localClient->ip.ss_len, hostip,
204     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
205 michael 1058 dlhost = hostip;
206     t = parse_netmask(dlhost, NULL, &bits);
207     assert(t == HM_IPV4 || t == HM_IPV6);
208     }
209    
210     if (bits < 8)
211     {
212     sendto_one(source_p,
213     ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
214     me.name, source_p->name);
215 michael 2820 return 0;
216 michael 1058 }
217    
218     #ifdef IPV6
219     if (t == HM_IPV6)
220 michael 1644 aftype = AF_INET6;
221 michael 1058 else
222     #endif
223 michael 1644 aftype = AF_INET;
224 michael 1058
225     parse_netmask(dlhost, &daddr, NULL);
226    
227 michael 1644 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
228 michael 1058 {
229 michael 1632 creason = conf->reason ? conf->reason : def_reason;
230 michael 2810
231 michael 1632 if (IsConfExemptKline(conf))
232 michael 2810 sendto_one(source_p, ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
233     me.name, source_p->name, dlhost, conf->host, creason);
234 michael 1058 else
235 michael 2810 sendto_one(source_p, ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
236     me.name, source_p->name, dlhost, conf->host, creason);
237 michael 2820 return 0;
238 michael 1058 }
239    
240     cur_time = CurrentTime;
241     current_date = smalldate(cur_time);
242    
243 michael 1243 if (!valid_comment(source_p, reason, 1))
244 michael 2820 return 0;
245 michael 1058
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 michael 2820 return 0;
259 michael 1058 }
260    
261 michael 2820 static int
262 michael 1301 ms_dline(struct Client *client_p, struct Client *source_p,
263     int parc, char *parv[])
264     {
265 michael 1794 char def_reason[] = CONF_NOREASON;
266 michael 1622 char *dlhost, *reason;
267 michael 1301 const char *creason;
268     const struct Client *target_p = NULL;
269     struct irc_ssaddr daddr;
270 michael 1632 struct MaskItem *conf=NULL;
271 michael 1301 time_t tkline_time=0;
272 michael 1644 int bits = 0, aftype = 0, t = 0;
273 michael 1301 const char *current_date = NULL;
274     time_t cur_time;
275 michael 1398 char hostip[HOSTIPLEN + 1];
276 michael 1301 char buffer[IRCD_BUFSIZE];
277    
278     if (parc != 5 || EmptyString(parv[4]))
279 michael 2820 return 0;
280 michael 1301
281     /* parv[0] parv[1] parv[2] parv[3] parv[4] */
282     /* oper target_server tkline_time host reason */
283     sendto_match_servs(source_p, parv[1], CAP_DLN,
284     "DLINE %s %s %s :%s",
285     parv[1], parv[2], parv[3], parv[4]);
286    
287 michael 1652 if (match(parv[1], me.name))
288 michael 2820 return 0;
289 michael 1301
290     tkline_time = valid_tkline(parv[2], TK_SECONDS);
291     dlhost = parv[3];
292     reason = parv[4];
293    
294 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
295     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
296 michael 1301 source_p->username, source_p->host,
297     SHARED_DLINE))
298     {
299     if (!IsClient(source_p))
300 michael 2820 return 0;
301    
302 michael 1301 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
303     {
304 michael 2475 if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
305 michael 2820 return 0;
306 michael 1301
307     if (!MyConnect(target_p))
308     {
309     sendto_one(source_p,
310     ":%s NOTICE %s :Can't DLINE nick on another server",
311     me.name, source_p->name);
312 michael 2820 return 0;
313 michael 1301 }
314    
315     if (IsExemptKline(target_p))
316     {
317     sendto_one(source_p,
318     ":%s NOTICE %s :%s is E-lined", me.name,
319     source_p->name, target_p->name);
320 michael 2820 return 0;
321 michael 1301 }
322    
323     getnameinfo((struct sockaddr *)&target_p->localClient->ip,
324     target_p->localClient->ip.ss_len, hostip,
325     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
326     dlhost = hostip;
327     t = parse_netmask(dlhost, NULL, &bits);
328     assert(t == HM_IPV4 || t == HM_IPV6);
329     }
330    
331     if (bits < 8)
332     {
333     sendto_one(source_p,
334     ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
335     me.name, source_p->name);
336 michael 2820 return 0;
337 michael 1301 }
338    
339     #ifdef IPV6
340     if (t == HM_IPV6)
341 michael 1644 aftype= AF_INET6;
342 michael 1301 else
343     #endif
344 michael 1644 aftype = AF_INET;
345 michael 1301
346     parse_netmask(dlhost, &daddr, NULL);
347    
348 michael 1644 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
349 michael 1301 {
350 michael 1632 creason = conf->reason ? conf->reason : def_reason;
351     if (IsConfExemptKline(conf))
352 michael 1301 sendto_one(source_p,
353     ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
354 michael 1632 me.name, source_p->name, dlhost, conf->host, creason);
355 michael 1301 else
356     sendto_one(source_p,
357     ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
358 michael 1632 me.name, source_p->name, dlhost, conf->host, creason);
359 michael 2820 return 0;
360 michael 1301 }
361    
362     cur_time = CurrentTime;
363     current_date = smalldate(cur_time);
364    
365     if (!valid_comment(source_p, reason, 1))
366 michael 2820 return 0;
367 michael 1301
368 michael 1632 conf = conf_make(CONF_DLINE);
369 michael 1646 conf->host = xstrdup(dlhost);
370 michael 1301
371     if (tkline_time != 0)
372     snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
373     (int)(tkline_time/60), reason, current_date);
374     else
375     snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
376    
377 michael 1646 conf->reason = xstrdup(buffer);
378 michael 1632 apply_dline(source_p, conf, tkline_time);
379 michael 1301 rehashed_klines = 1;
380     }
381 michael 2820
382     return 0;
383 michael 1301 }
384    
385 michael 1058 /*
386     ** m_undline
387     ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
388     ** based totally on m_unkline
389     ** added to hybrid-7 7/11/2000 --is
390     **
391     ** parv[0] = sender nick
392     ** parv[1] = dline to remove
393     */
394 michael 2820 static int
395 michael 1058 mo_undline(struct Client *client_p, struct Client *source_p,
396     int parc, char *parv[])
397     {
398 michael 1301 char *addr = NULL, *user = NULL;
399     char *target_server = NULL;
400 michael 1058
401 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
402 michael 1058 {
403 michael 2810 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
404     source_p->name, "undline");
405 michael 2820 return 0;
406 michael 1058 }
407    
408 michael 1301 if (parc < 2 || EmptyString(parv[1]))
409     {
410 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
411 michael 1301 me.name, source_p->name, "UNDLINE");
412 michael 2820 return 0;
413 michael 1301 }
414 michael 1058
415 michael 1301 if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
416     &addr, NULL, &target_server, NULL) < 0)
417 michael 2820 return 0;
418 michael 1301
419     if (target_server != NULL)
420     {
421     sendto_match_servs(source_p, target_server, CAP_UNDLN,
422     "UNDLINE %s %s", target_server, addr);
423    
424     /* Allow ON to apply local unkline as well if it matches */
425 michael 1652 if (match(target_server, me.name))
426 michael 2820 return 0;
427 michael 1301 }
428     else
429     cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
430     "%s", addr);
431    
432 michael 1622 if (remove_dline_match(addr))
433 michael 1058 {
434 michael 2810 sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
435 michael 1301 me.name, source_p->name, addr);
436 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
437 michael 1622 "%s has removed the D-Line for: [%s]",
438 michael 1298 get_oper_name(source_p), addr);
439 michael 1247 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
440 michael 1298 get_oper_name(source_p), addr);
441 michael 1058 }
442     else
443     sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
444 michael 1298 me.name, source_p->name, addr);
445 michael 2820 return 0;
446 michael 1058 }
447 michael 1230
448 michael 2820 static int
449 michael 2857 ms_undline(struct Client *client_p, struct Client *source_p,
450 michael 1301 int parc, char *parv[])
451     {
452 michael 2857 const char *addr = parv[1];
453 michael 1301
454     if (parc != 3 || EmptyString(parv[2]))
455 michael 2820 return 0;
456 michael 1301
457 michael 2857 sendto_match_servs(source_p, parv[1], CAP_UNDLN,
458     "UNDLINE %s %s",
459     parv[1], parv[2]);
460 michael 1301
461 michael 1652 if (!IsClient(source_p) || match(parv[1], me.name))
462 michael 2820 return 0;
463 michael 1301
464 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
465     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
466     source_p->username, source_p->host,
467     SHARED_UNDLINE))
468 michael 1301 {
469 michael 1622 if (remove_dline_match(addr))
470 michael 1301 {
471 michael 2810 sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
472 michael 1301 me.name, source_p->name, addr);
473 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
474 michael 1622 "%s has removed the D-Line for: [%s]",
475 michael 1301 get_oper_name(source_p), addr);
476 michael 2340 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
477 michael 1301 get_oper_name(source_p), addr);
478     }
479     else
480     sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
481     me.name, source_p->name, addr);
482     }
483 michael 2820
484     return 0;
485 michael 1301 }
486    
487 michael 2810 static struct Message dline_msgtab =
488     {
489 michael 1230 "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
490 michael 2810 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
491 michael 1230 };
492    
493 michael 2810 static struct Message undline_msgtab =
494     {
495 michael 1230 "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
496 michael 2810 { m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore }
497 michael 1230 };
498    
499     static void
500     module_init(void)
501     {
502     mod_add_cmd(&dline_msgtab);
503     mod_add_cmd(&undline_msgtab);
504 michael 1301 add_capability("DLN", CAP_DLN, 1);
505     add_capability("UNDLN", CAP_UNDLN, 1);
506 michael 1230 }
507    
508     static void
509     module_exit(void)
510     {
511     mod_del_cmd(&dline_msgtab);
512     mod_del_cmd(&undline_msgtab);
513 michael 1301 delete_capability("UNDLN");
514     delete_capability("DLN");
515 michael 1230 }
516    
517 michael 2810 struct module module_entry =
518     {
519 michael 1230 .node = { NULL, NULL, NULL },
520     .name = NULL,
521     .version = "$Revision$",
522     .handle = NULL,
523     .modinit = module_init,
524     .modexit = module_exit,
525     .flags = 0
526     };

Properties

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