ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_dline.c
Revision: 4414
Committed: Thu Aug 7 14:06:08 2014 UTC (11 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 11111 byte(s)
Log Message:
- Removed ipv6 detection. We now assume all systems that run hybrid have
  ipv6 availability and sockaddr_storage.

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 michael 3348 * \brief Includes required functions for processing the DLINE command.
24 michael 2810 * \version $Id$
25     */
26    
27 michael 1058 #include "stdinc.h"
28     #include "list.h"
29     #include "client.h"
30     #include "irc_string.h"
31 michael 1632 #include "conf.h"
32 michael 1058 #include "ircd.h"
33     #include "hostmask.h"
34     #include "numeric.h"
35 michael 1309 #include "log.h"
36 michael 3347 #include "misc.h"
37 michael 1058 #include "send.h"
38     #include "hash.h"
39 michael 3347 #include "server.h"
40 michael 1058 #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 michael 3930 static void
47     check_dline(struct AddressRec *arec)
48     {
49     dlink_node *ptr = NULL, *ptr_next = NULL;
50    
51     DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head)
52     {
53     struct Client *client_p = ptr->data;
54    
55     if (IsDead(client_p))
56     continue;
57    
58     switch (arec->masktype)
59     {
60     case HM_IPV4:
61     if (client_p->localClient->aftype == AF_INET)
62     if (match_ipv4(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
63     conf_try_ban(client_p, arec->conf);
64     break;
65     case HM_IPV6:
66     if (client_p->localClient->aftype == AF_INET6)
67     if (match_ipv6(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
68     conf_try_ban(client_p, arec->conf);
69     break;
70     default: break;
71     }
72     }
73    
74     DLINK_FOREACH_SAFE(ptr, ptr_next, unknown_list.head)
75     {
76     struct Client *client_p = ptr->data;
77    
78     if (IsDead(client_p))
79     continue;
80    
81     switch (arec->masktype)
82     {
83     case HM_IPV4:
84     if (client_p->localClient->aftype == AF_INET)
85     if (match_ipv4(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
86     conf_try_ban(client_p, arec->conf);
87     break;
88     case HM_IPV6:
89     if (client_p->localClient->aftype == AF_INET6)
90     if (match_ipv6(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
91     conf_try_ban(client_p, arec->conf);
92     break;
93     default: break;
94     }
95     }
96     }
97    
98    
99 michael 1058 /* apply_tdline()
100     *
101     * inputs -
102     * output - NONE
103     * side effects - tkline as given is placed
104     */
105     static void
106 michael 1632 apply_dline(struct Client *source_p, struct MaskItem *conf,
107 michael 1622 time_t tkline_time)
108 michael 1058 {
109 michael 1622 if (tkline_time)
110     {
111 michael 1649 conf->until = CurrentTime + tkline_time;
112 michael 1622 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
113     "%s added temporary %d min. D-Line for [%s] [%s]",
114     get_oper_name(source_p), tkline_time/60,
115 michael 1632 conf->host, conf->reason);
116 michael 3110 sendto_one_notice(source_p, &me, ":Added temporary %d min. D-Line [%s]",
117     tkline_time/60, conf->host);
118 michael 1622 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
119 michael 1632 get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
120 michael 1622 }
121     else
122     {
123     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
124     "%s added D-Line for [%s] [%s]",
125 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
126 michael 3110 sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
127 michael 1622 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
128 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
129 michael 1058
130 michael 1622 }
131    
132 michael 1632 SetConfDatabase(conf);
133     conf->setat = CurrentTime;
134 michael 3930 check_dline(add_conf_by_address(CONF_DLINE, conf));
135 michael 1058 }
136    
137     /* mo_dline()
138     *
139     * inputs - pointer to server
140     * - pointer to client
141     * - parameter count
142     * - parameter list
143     * output -
144     * side effects - D line is added
145     *
146     */
147 michael 2820 static int
148 michael 3156 mo_dline(struct Client *source_p, int parc, char *parv[])
149 michael 1058 {
150 michael 1794 char def_reason[] = CONF_NOREASON;
151 michael 1622 char *dlhost = NULL, *reason = NULL;
152 michael 1301 char *target_server = NULL;
153 michael 1058 const char *creason;
154     const struct Client *target_p = NULL;
155     struct irc_ssaddr daddr;
156 michael 1632 struct MaskItem *conf=NULL;
157 michael 1058 time_t tkline_time=0;
158 michael 1644 int bits = 0, aftype = 0, t = 0;
159 michael 1058 const char *current_date = NULL;
160 michael 1398 char hostip[HOSTIPLEN + 1];
161 michael 1230 char buffer[IRCD_BUFSIZE];
162 michael 1058
163 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
164 michael 1058 {
165 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
166 michael 2820 return 0;
167 michael 1058 }
168    
169     if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
170 michael 1301 NULL, &tkline_time, &target_server, &reason) < 0)
171 michael 2820 return 0;
172 michael 1058
173 michael 3368 if (target_server)
174 michael 1301 {
175 michael 2807 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
176     target_server, (unsigned long)tkline_time,
177     dlhost, reason);
178 michael 1301
179     /* Allow ON to apply local kline as well if it matches */
180 michael 1652 if (match(target_server, me.name))
181 michael 2820 return 0;
182 michael 1301 }
183     else
184     cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
185     "%d %s :%s", tkline_time, dlhost, reason);
186    
187 michael 1058 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
188     {
189 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
190 michael 3736 return 0; /* find_chasing sends ERR_NOSUCHNICK */
191 michael 1058
192     if (!MyConnect(target_p))
193     {
194 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
195 michael 2820 return 0;
196 michael 1058 }
197    
198     if (IsExemptKline(target_p))
199     {
200 michael 3110 sendto_one_notice(source_p, &me, ":%s is E-lined",
201     target_p->name);
202 michael 2820 return 0;
203 michael 1058 }
204    
205 michael 1123 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
206     target_p->localClient->ip.ss_len, hostip,
207     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
208 michael 1058 dlhost = hostip;
209     t = parse_netmask(dlhost, NULL, &bits);
210     assert(t == HM_IPV4 || t == HM_IPV6);
211     }
212    
213     if (bits < 8)
214     {
215 michael 3110 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
216 michael 2820 return 0;
217 michael 1058 }
218    
219     if (t == HM_IPV6)
220 michael 1644 aftype = AF_INET6;
221 michael 1058 else
222 michael 1644 aftype = AF_INET;
223 michael 1058
224     parse_netmask(dlhost, &daddr, NULL);
225    
226 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
227 michael 1058 {
228 michael 1632 creason = conf->reason ? conf->reason : def_reason;
229 michael 2810
230 michael 1632 if (IsConfExemptKline(conf))
231 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
232     dlhost, conf->host, creason);
233 michael 1058 else
234 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
235     dlhost, conf->host, creason);
236 michael 2820 return 0;
237 michael 1058 }
238    
239 michael 3208 current_date = smalldate(0);
240 michael 1058
241 michael 1243 if (!valid_comment(source_p, reason, 1))
242 michael 2820 return 0;
243 michael 1058
244 michael 1632 conf = conf_make(CONF_DLINE);
245 michael 1646 conf->host = xstrdup(dlhost);
246 michael 1058
247 michael 3368 if (tkline_time)
248 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
249     (int)(tkline_time/60), reason, current_date);
250 michael 1058 else
251 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
252 michael 1058
253 michael 1646 conf->reason = xstrdup(buffer);
254 michael 1632 apply_dline(source_p, conf, tkline_time);
255 michael 2820 return 0;
256 michael 1058 }
257    
258 michael 2820 static int
259 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
260 michael 1301 {
261 michael 1794 char def_reason[] = CONF_NOREASON;
262 michael 1622 char *dlhost, *reason;
263 michael 1301 const char *creason;
264     const struct Client *target_p = NULL;
265     struct irc_ssaddr daddr;
266 michael 1632 struct MaskItem *conf=NULL;
267 michael 1301 time_t tkline_time=0;
268 michael 1644 int bits = 0, aftype = 0, t = 0;
269 michael 1301 const char *current_date = NULL;
270 michael 1398 char hostip[HOSTIPLEN + 1];
271 michael 1301 char buffer[IRCD_BUFSIZE];
272    
273     if (parc != 5 || EmptyString(parv[4]))
274 michael 2820 return 0;
275 michael 1301
276     /* parv[0] parv[1] parv[2] parv[3] parv[4] */
277     /* oper target_server tkline_time host reason */
278     sendto_match_servs(source_p, parv[1], CAP_DLN,
279     "DLINE %s %s %s :%s",
280     parv[1], parv[2], parv[3], parv[4]);
281    
282 michael 1652 if (match(parv[1], me.name))
283 michael 2820 return 0;
284 michael 1301
285     tkline_time = valid_tkline(parv[2], TK_SECONDS);
286     dlhost = parv[3];
287     reason = parv[4];
288    
289 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
290     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
291 michael 1301 source_p->username, source_p->host,
292     SHARED_DLINE))
293     {
294     if (!IsClient(source_p))
295 michael 2820 return 0;
296    
297 michael 1301 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
298     {
299 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
300 michael 3736 return 0; /* find_chasing sends ERR_NOSUCHNICK */
301 michael 1301
302     if (!MyConnect(target_p))
303     {
304 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
305 michael 2820 return 0;
306 michael 1301 }
307    
308     if (IsExemptKline(target_p))
309     {
310 michael 3110 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
311 michael 2820 return 0;
312 michael 1301 }
313    
314     getnameinfo((struct sockaddr *)&target_p->localClient->ip,
315     target_p->localClient->ip.ss_len, hostip,
316     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
317     dlhost = hostip;
318     t = parse_netmask(dlhost, NULL, &bits);
319     assert(t == HM_IPV4 || t == HM_IPV6);
320     }
321    
322     if (bits < 8)
323     {
324 michael 3110 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
325 michael 2820 return 0;
326 michael 1301 }
327    
328     if (t == HM_IPV6)
329 michael 1644 aftype= AF_INET6;
330 michael 1301 else
331 michael 1644 aftype = AF_INET;
332 michael 1301
333     parse_netmask(dlhost, &daddr, NULL);
334    
335 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
336 michael 1301 {
337 michael 1632 creason = conf->reason ? conf->reason : def_reason;
338     if (IsConfExemptKline(conf))
339 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
340     dlhost, conf->host, creason);
341 michael 1301 else
342 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
343     dlhost, conf->host, creason);
344 michael 2820 return 0;
345 michael 1301 }
346    
347 michael 3208 current_date = smalldate(0);
348 michael 1301
349     if (!valid_comment(source_p, reason, 1))
350 michael 2820 return 0;
351 michael 1301
352 michael 1632 conf = conf_make(CONF_DLINE);
353 michael 1646 conf->host = xstrdup(dlhost);
354 michael 1301
355 michael 3368 if (tkline_time)
356 michael 1301 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
357     (int)(tkline_time/60), reason, current_date);
358     else
359     snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
360    
361 michael 1646 conf->reason = xstrdup(buffer);
362 michael 1632 apply_dline(source_p, conf, tkline_time);
363 michael 1301 }
364 michael 2820
365     return 0;
366 michael 1301 }
367    
368 michael 2810 static struct Message dline_msgtab =
369     {
370 michael 1230 "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
371 michael 2810 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
372 michael 1230 };
373    
374     static void
375     module_init(void)
376     {
377     mod_add_cmd(&dline_msgtab);
378 michael 1301 add_capability("DLN", CAP_DLN, 1);
379 michael 1230 }
380    
381     static void
382     module_exit(void)
383     {
384     mod_del_cmd(&dline_msgtab);
385 michael 1301 delete_capability("DLN");
386 michael 1230 }
387    
388 michael 2810 struct module module_entry =
389     {
390 michael 1230 .node = { NULL, NULL, NULL },
391     .name = NULL,
392     .version = "$Revision$",
393     .handle = NULL,
394     .modinit = module_init,
395     .modexit = module_exit,
396     .flags = 0
397     };

Properties

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