ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 5875
Committed: Wed Apr 29 11:09:28 2015 UTC (10 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 10041 byte(s)
Log Message:
- Style corrections; removed trailing whitespaces

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 5347 * Copyright (c) 1997-2015 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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 michael 1058 * 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 michael 3347 #include "server.h"
39 michael 1058 #include "parse.h"
40     #include "modules.h"
41 michael 1622 #include "conf_db.h"
42 michael 1666 #include "memory.h"
43 michael 1058
44    
45 michael 3929 static void
46 michael 5832 dline_check(struct AddressRec *arec)
47 michael 3929 {
48 michael 4815 dlink_node *node = NULL, *node_next = NULL;
49 michael 3929
50 michael 4815 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
51 michael 3929 {
52 michael 4815 struct Client *client_p = node->data;
53 michael 3929
54     if (IsDead(client_p))
55     continue;
56    
57     switch (arec->masktype)
58     {
59     case HM_IPV4:
60 michael 4588 if (client_p->connection->aftype == AF_INET)
61     if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
62 michael 3929 conf_try_ban(client_p, arec->conf);
63     break;
64     case HM_IPV6:
65 michael 4588 if (client_p->connection->aftype == AF_INET6)
66     if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
67 michael 3929 conf_try_ban(client_p, arec->conf);
68     break;
69     default: break;
70     }
71     }
72    
73 michael 4815 DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
74 michael 3929 {
75 michael 4815 struct Client *client_p = node->data;
76 michael 3929
77     if (IsDead(client_p))
78     continue;
79    
80     switch (arec->masktype)
81     {
82     case HM_IPV4:
83 michael 4588 if (client_p->connection->aftype == AF_INET)
84     if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
85 michael 3929 conf_try_ban(client_p, arec->conf);
86     break;
87     case HM_IPV6:
88 michael 4588 if (client_p->connection->aftype == AF_INET6)
89     if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
90 michael 3929 conf_try_ban(client_p, arec->conf);
91     break;
92     default: break;
93     }
94     }
95     }
96    
97    
98 michael 5829 /* dline_add()
99 michael 1058 *
100     * inputs -
101     * output - NONE
102 michael 5829 * side effects - dline as given is placed
103 michael 1058 */
104     static void
105 michael 5875 dline_add(struct Client *source_p, const char *addr, const char *reason,
106     time_t tdline_time)
107 michael 1058 {
108 michael 5829 char buf[IRCD_BUFSIZE];
109     struct MaskItem *conf;
110    
111     if (tdline_time)
112     snprintf(buf, sizeof(buf), "Temporary D-line %d min. - %.*s (%s)",
113     (int)(tdline_time/60), REASONLEN, reason, smalldate(0));
114     else
115     snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, smalldate(0));
116    
117     conf = conf_make(CONF_DLINE);
118     conf->host = xstrdup(addr);
119     conf->reason = xstrdup(buf);
120     conf->setat = CurrentTime;
121     SetConfDatabase(conf);
122    
123     if (tdline_time)
124 michael 1622 {
125 michael 5829 conf->until = CurrentTime + tdline_time;
126 michael 4639
127     if (IsClient(source_p))
128     sendto_one_notice(source_p, &me, ":Added temporary %d min. D-Line [%s]",
129 michael 5829 tdline_time/60, conf->host);
130 michael 4890
131 michael 1622 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
132     "%s added temporary %d min. D-Line for [%s] [%s]",
133 michael 5829 get_oper_name(source_p), tdline_time/60,
134 michael 1632 conf->host, conf->reason);
135 michael 1622 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
136 michael 5829 get_oper_name(source_p), tdline_time/60, conf->host, conf->reason);
137 michael 1622 }
138     else
139     {
140 michael 4639 if (IsClient(source_p))
141     sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
142    
143 michael 1622 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
144     "%s added D-Line for [%s] [%s]",
145 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
146 michael 1622 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
147 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
148 michael 1622 }
149    
150 michael 5832 dline_check(add_conf_by_address(CONF_DLINE, conf));
151 michael 1058 }
152    
153     /* mo_dline()
154     *
155     * inputs - pointer to server
156     * - pointer to client
157     * - parameter count
158     * - parameter list
159     * output -
160     * side effects - D line is added
161     *
162     */
163 michael 2820 static int
164 michael 3156 mo_dline(struct Client *source_p, int parc, char *parv[])
165 michael 1058 {
166 michael 1622 char *dlhost = NULL, *reason = NULL;
167 michael 1301 char *target_server = NULL;
168 michael 1058 const struct Client *target_p = NULL;
169     struct irc_ssaddr daddr;
170 michael 4890 struct MaskItem *conf = NULL;
171 michael 5829 time_t tdline_time = 0;
172 michael 1644 int bits = 0, aftype = 0, t = 0;
173 michael 1398 char hostip[HOSTIPLEN + 1];
174 michael 1058
175 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
176 michael 1058 {
177 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
178 michael 2820 return 0;
179 michael 1058 }
180    
181 michael 5776 if (!parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
182 michael 5829 NULL, &tdline_time, &target_server, &reason))
183 michael 2820 return 0;
184 michael 1058
185 michael 3368 if (target_server)
186 michael 1301 {
187 michael 2807 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
188 michael 5829 target_server, (unsigned long)tdline_time,
189 michael 2807 dlhost, reason);
190 michael 1301
191     /* Allow ON to apply local kline as well if it matches */
192 michael 1652 if (match(target_server, me.name))
193 michael 2820 return 0;
194 michael 1301 }
195     else
196     cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
197 michael 5829 "%d %s :%s", tdline_time, dlhost, reason);
198 michael 1301
199 michael 5822 if ((t = parse_netmask(dlhost, NULL, NULL)) == HM_HOST)
200 michael 1058 {
201 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
202 michael 3737 return 0; /* find_chasing sends ERR_NOSUCHNICK */
203 michael 1058
204     if (!MyConnect(target_p))
205     {
206 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
207 michael 2820 return 0;
208 michael 1058 }
209    
210     if (IsExemptKline(target_p))
211     {
212 michael 4934 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
213 michael 2820 return 0;
214 michael 1058 }
215    
216 michael 5051 getnameinfo((const struct sockaddr *)&target_p->connection->ip,
217 michael 4588 target_p->connection->ip.ss_len, hostip,
218 michael 1123 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
219 michael 1058 dlhost = hostip;
220     }
221    
222 michael 5819 switch (parse_netmask(dlhost, &daddr, &bits))
223 michael 1058 {
224 michael 5805 case HM_IPV4:
225     if ((unsigned int)bits < ConfigGeneral.dline_min_cidr)
226     {
227     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
228     ConfigGeneral.dline_min_cidr);
229     return 0;
230     }
231    
232     aftype = AF_INET;
233     break;
234     case HM_IPV6:
235     if ((unsigned int)bits < ConfigGeneral.dline_min_cidr6)
236     {
237     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
238     ConfigGeneral.dline_min_cidr6);
239     return 0;
240     }
241    
242     aftype = AF_INET6;
243     break;
244     default: /* HM_HOST */
245     return 0;
246 michael 1058 }
247    
248 michael 5807 if ((conf = find_conf_by_address(NULL, &daddr, CONF_DLINE, aftype, NULL, NULL, 1)))
249 michael 1058 {
250 michael 5807 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
251     dlhost, conf->host, conf->reason);
252 michael 2820 return 0;
253 michael 1058 }
254    
255 michael 5829 dline_add(source_p, dlhost, reason, tdline_time);
256 michael 2820 return 0;
257 michael 1058 }
258    
259 michael 2820 static int
260 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
261 michael 1301 {
262 michael 5829 const char *dlhost, *reason;
263 michael 1301 struct irc_ssaddr daddr;
264 michael 4890 struct MaskItem *conf = NULL;
265 michael 5875 time_t tdline_time = 0;
266 michael 5818 int bits = 0, aftype = 0;
267 michael 1301
268     if (parc != 5 || EmptyString(parv[4]))
269 michael 2820 return 0;
270 michael 1301
271     /* parv[0] parv[1] parv[2] parv[3] parv[4] */
272 michael 5829 /* command target_server tdline_time host reason */
273 michael 4890 sendto_match_servs(source_p, parv[1], CAP_DLN, "DLINE %s %s %s :%s",
274 michael 1301 parv[1], parv[2], parv[3], parv[4]);
275    
276 michael 1652 if (match(parv[1], me.name))
277 michael 2820 return 0;
278 michael 1301
279 michael 5829 tdline_time = valid_tkline(parv[2], TK_SECONDS);
280 michael 1301 dlhost = parv[3];
281     reason = parv[4];
282    
283 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
284     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
285 michael 1301 source_p->username, source_p->host,
286     SHARED_DLINE))
287     {
288 michael 5818 switch (parse_netmask(dlhost, &daddr, &bits))
289 michael 1301 {
290 michael 5805 case HM_IPV4:
291     if ((unsigned int)bits < ConfigGeneral.dline_min_cidr)
292     {
293     if (IsClient(source_p))
294     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
295     ConfigGeneral.dline_min_cidr);
296     return 0;
297     }
298    
299     aftype = AF_INET;
300     break;
301     case HM_IPV6:
302     if ((unsigned int)bits < ConfigGeneral.dline_min_cidr6)
303     {
304     if (IsClient(source_p))
305     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
306     ConfigGeneral.dline_min_cidr6);
307     return 0;
308     }
309    
310     aftype = AF_INET6;
311     break;
312     default: /* HM_HOST */
313     return 0;
314 michael 1301 }
315    
316 michael 5807 if ((conf = find_conf_by_address(NULL, &daddr, CONF_DLINE, aftype, NULL, NULL, 1)))
317 michael 1301 {
318 michael 5807 if (IsClient(source_p))
319 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
320 michael 5807 dlhost, conf->host, conf->reason);
321 michael 2820 return 0;
322 michael 1301 }
323    
324 michael 5829 dline_add(source_p, dlhost, reason, tdline_time);
325 michael 1301 }
326 michael 2820
327     return 0;
328 michael 1301 }
329    
330 michael 2810 static struct Message dline_msgtab =
331     {
332 michael 4545 "DLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
333 michael 2810 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
334 michael 1230 };
335    
336     static void
337     module_init(void)
338     {
339     mod_add_cmd(&dline_msgtab);
340 michael 5796 add_capability("DLN", CAP_DLN);
341 michael 1230 }
342    
343     static void
344     module_exit(void)
345     {
346     mod_del_cmd(&dline_msgtab);
347 michael 1301 delete_capability("DLN");
348 michael 1230 }
349    
350 michael 2810 struct module module_entry =
351     {
352 michael 1230 .version = "$Revision$",
353     .modinit = module_init,
354     .modexit = module_exit,
355     };

Properties

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