ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 6313
Committed: Sat Aug 1 18:03:39 2015 UTC (10 years ago) by michael
Content type: text/x-csrc
File size: 10179 byte(s)
Log Message:
- Make use of the *Flag() macros in some more places

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

Properties

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