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: 7329
Committed: Thu Feb 18 21:07:50 2016 UTC (10 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 10711 byte(s)
Log Message:
- Now that we got time_t to work nicely on openbsd with snprintf's conversion specifiers,
  we ran into a similiar issue on Raspbian/ARMv7's time_t which is of signed 32 bit and
  doesn't cope at all with %j. Instead of doing tricks, get rid of time_t everywhere and
  forever and use uintmax_t instead which has at least a 'standardized' conversion specifier
  associated with it.

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 7007 * Copyright (c) 1997-2016 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 4564 * 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 7208 #include "conf_cluster.h"
33     #include "conf_shared.h"
34 michael 1058 #include "ircd.h"
35     #include "hostmask.h"
36     #include "numeric.h"
37 michael 1309 #include "log.h"
38 michael 3347 #include "misc.h"
39 michael 1058 #include "send.h"
40 michael 3347 #include "server.h"
41 michael 1058 #include "parse.h"
42     #include "modules.h"
43 michael 1666 #include "memory.h"
44 michael 1058
45    
46 michael 3930 static void
47 michael 5831 dline_check(struct AddressRec *arec)
48 michael 3930 {
49 michael 4816 dlink_node *node = NULL, *node_next = NULL;
50 michael 3930
51 michael 4816 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
52 michael 3930 {
53 michael 4816 struct Client *client_p = node->data;
54 michael 3930
55     if (IsDead(client_p))
56     continue;
57    
58     switch (arec->masktype)
59     {
60     case HM_IPV4:
61 michael 4589 if (client_p->connection->aftype == AF_INET)
62     if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
63 michael 7303 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
64 michael 3930 break;
65     case HM_IPV6:
66 michael 4589 if (client_p->connection->aftype == AF_INET6)
67     if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
68 michael 7303 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
69 michael 3930 break;
70     default: break;
71     }
72     }
73    
74 michael 4816 DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
75 michael 3930 {
76 michael 4816 struct Client *client_p = node->data;
77 michael 3930
78     if (IsDead(client_p))
79     continue;
80    
81     switch (arec->masktype)
82     {
83     case HM_IPV4:
84 michael 4589 if (client_p->connection->aftype == AF_INET)
85     if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
86 michael 7303 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
87 michael 3930 break;
88     case HM_IPV6:
89 michael 4589 if (client_p->connection->aftype == AF_INET6)
90     if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
91 michael 7303 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
92 michael 3930 break;
93     default: break;
94     }
95     }
96     }
97    
98    
99 michael 5830 /* dline_add()
100 michael 1058 *
101     * inputs -
102     * output - NONE
103 michael 5830 * side effects - dline as given is placed
104 michael 1058 */
105     static void
106 michael 5874 dline_add(struct Client *source_p, const char *addr, const char *reason,
107 michael 7329 uintmax_t duration)
108 michael 1058 {
109 michael 5830 char buf[IRCD_BUFSIZE];
110    
111 michael 6457 if (duration)
112 michael 6781 snprintf(buf, sizeof(buf), "Temporary D-line %ju min. - %.*s (%s)",
113     duration / 60, REASONLEN, reason, date_iso8601(0));
114 michael 5830 else
115 michael 6421 snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, date_iso8601(0));
116 michael 5830
117 michael 7075 struct MaskItem *conf = conf_make(CONF_DLINE);
118 michael 5830 conf->host = xstrdup(addr);
119     conf->reason = xstrdup(buf);
120     conf->setat = CurrentTime;
121     SetConfDatabase(conf);
122    
123 michael 6457 if (duration)
124 michael 1622 {
125 michael 6457 conf->until = CurrentTime + duration;
126 michael 4640
127     if (IsClient(source_p))
128 michael 6781 sendto_one_notice(source_p, &me, ":Added temporary %ju min. D-Line [%s]",
129     duration / 60, conf->host);
130 michael 4889
131 michael 6317 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
132 michael 6781 "%s added temporary %ju min. D-Line for [%s] [%s]",
133 michael 6938 get_oper_name(source_p), duration / 60,
134 michael 1632 conf->host, conf->reason);
135 michael 6781 ilog(LOG_TYPE_DLINE, "%s added temporary %ju min. D-Line for [%s] [%s]",
136     get_oper_name(source_p), duration / 60, conf->host, conf->reason);
137 michael 1622 }
138     else
139     {
140 michael 4640 if (IsClient(source_p))
141     sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
142    
143 michael 6317 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
144 michael 1622 "%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 5831 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 4889 struct MaskItem *conf = NULL;
171 michael 7329 uintmax_t duration = 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 5775 if (!parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
182 michael 6457 NULL, &duration, &target_server, &reason))
183 michael 2820 return 0;
184 michael 1058
185 michael 3368 if (target_server)
186 michael 1301 {
187 michael 6781 sendto_match_servs(source_p, target_server, CAPAB_DLN, "DLINE %s %ju %s :%s",
188     target_server, duration,
189 michael 2807 dlhost, reason);
190 michael 1301
191 michael 6431 /* Allow ON to apply local dline 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 michael 7208 cluster_distribute(source_p, "DLINE", CAPAB_DLN, CLUSTER_DLINE,
197     "%ju %s :%s", duration, dlhost, reason);
198 michael 1301
199 michael 5821 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 3736 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 michael 6314 if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
211 michael 1058 {
212 michael 4935 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
213 michael 2820 return 0;
214 michael 1058 }
215    
216 michael 5050 getnameinfo((const struct sockaddr *)&target_p->connection->ip,
217 michael 4589 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 5820 switch (parse_netmask(dlhost, &daddr, &bits))
223 michael 1058 {
224 michael 5810 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 5810 if ((conf = find_conf_by_address(NULL, &daddr, CONF_DLINE, aftype, NULL, NULL, 1)))
249 michael 1058 {
250 michael 5810 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 6457 dline_add(source_p, dlhost, reason, duration);
256 michael 2820 return 0;
257 michael 1058 }
258    
259 michael 7093 /*! \brief DLINE command handler
260     *
261     * \param source_p Pointer to allocated Client struct from which the message
262     * originally comes from. This can be a local or remote client.
263     * \param parc Integer holding the number of supplied arguments.
264     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
265     * pointers.
266     * \note Valid arguments for this command are:
267     * - parv[0] = command
268     * - parv[1] = target server mask
269     * - parv[2] = duration in seconds
270     * - parv[3] = IP address
271     * - parv[4] = reason
272     */
273 michael 2820 static int
274 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
275 michael 1301 {
276 michael 5830 const char *dlhost, *reason;
277 michael 1301 struct irc_ssaddr daddr;
278 michael 4889 struct MaskItem *conf = NULL;
279 michael 7329 uintmax_t duration = 0;
280 michael 5817 int bits = 0, aftype = 0;
281 michael 1301
282     if (parc != 5 || EmptyString(parv[4]))
283 michael 2820 return 0;
284 michael 1301
285 michael 6353 sendto_match_servs(source_p, parv[1], CAPAB_DLN, "DLINE %s %s %s :%s",
286 michael 1301 parv[1], parv[2], parv[3], parv[4]);
287    
288 michael 1652 if (match(parv[1], me.name))
289 michael 2820 return 0;
290 michael 1301
291 michael 6457 duration = valid_tkline(parv[2], TK_SECONDS);
292 michael 1301 dlhost = parv[3];
293     reason = parv[4];
294    
295 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
296 michael 7208 shared_find(SHARED_DLINE, source_p->servptr->name,
297     source_p->username, source_p->host))
298 michael 1301 {
299 michael 5817 switch (parse_netmask(dlhost, &daddr, &bits))
300 michael 1301 {
301 michael 5810 case HM_IPV4:
302     if ((unsigned int)bits < ConfigGeneral.dline_min_cidr)
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_cidr);
307     return 0;
308     }
309    
310     aftype = AF_INET;
311     break;
312     case HM_IPV6:
313     if ((unsigned int)bits < ConfigGeneral.dline_min_cidr6)
314     {
315     if (IsClient(source_p))
316     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
317     ConfigGeneral.dline_min_cidr6);
318     return 0;
319     }
320    
321     aftype = AF_INET6;
322     break;
323     default: /* HM_HOST */
324     return 0;
325 michael 1301 }
326    
327 michael 5810 if ((conf = find_conf_by_address(NULL, &daddr, CONF_DLINE, aftype, NULL, NULL, 1)))
328 michael 1301 {
329 michael 5810 if (IsClient(source_p))
330 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
331 michael 5810 dlhost, conf->host, conf->reason);
332 michael 2820 return 0;
333 michael 1301 }
334    
335 michael 6457 dline_add(source_p, dlhost, reason, duration);
336 michael 1301 }
337 michael 2820
338     return 0;
339 michael 1301 }
340    
341 michael 2810 static struct Message dline_msgtab =
342     {
343 michael 5880 .cmd = "DLINE",
344     .args_min = 2,
345     .args_max = MAXPARA,
346     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
347     .handlers[CLIENT_HANDLER] = m_not_oper,
348     .handlers[SERVER_HANDLER] = ms_dline,
349     .handlers[ENCAP_HANDLER] = m_ignore,
350     .handlers[OPER_HANDLER] = mo_dline
351 michael 1230 };
352    
353     static void
354     module_init(void)
355     {
356     mod_add_cmd(&dline_msgtab);
357 michael 6353 add_capability("DLN", CAPAB_DLN);
358 michael 1230 }
359    
360     static void
361     module_exit(void)
362     {
363     mod_del_cmd(&dline_msgtab);
364 michael 1301 delete_capability("DLN");
365 michael 1230 }
366    
367 michael 2810 struct module module_entry =
368     {
369 michael 1230 .version = "$Revision$",
370     .modinit = module_init,
371     .modexit = module_exit,
372     };

Properties

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