ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 8279
Committed: Tue Feb 20 19:30:13 2018 UTC (7 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 9838 byte(s)
Log Message:
- Update copyright years

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 8279 * Copyright (c) 1997-2018 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 7209 #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 8166 #include "server_capab.h"
41 michael 1058 #include "parse.h"
42     #include "modules.h"
43 michael 1666 #include "memory.h"
44 michael 1058
45    
46 michael 3929 static void
47 michael 7435 dline_check(const struct AddressRec *arec)
48 michael 3929 {
49 michael 8059 dlink_node *node, *node_next;
50 michael 3929
51 michael 4815 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
52 michael 3929 {
53 michael 4815 struct Client *client_p = node->data;
54 michael 3929
55     if (IsDead(client_p))
56     continue;
57    
58     switch (arec->masktype)
59     {
60     case HM_IPV4:
61 michael 4588 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 7304 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
64 michael 3929 break;
65     case HM_IPV6:
66 michael 4588 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 7304 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
69 michael 3929 break;
70     default: break;
71     }
72     }
73    
74 michael 4815 DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
75 michael 3929 {
76 michael 4815 struct Client *client_p = node->data;
77 michael 3929
78     if (IsDead(client_p))
79     continue;
80    
81     switch (arec->masktype)
82     {
83     case HM_IPV4:
84 michael 4588 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 7304 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
87 michael 3929 break;
88     case HM_IPV6:
89 michael 4588 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 7304 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
92 michael 3929 break;
93     default: break;
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 7673 dline_handle(struct Client *source_p, const char *addr, const char *reason, uintmax_t duration)
106 michael 1058 {
107 michael 5829 char buf[IRCD_BUFSIZE];
108 michael 7419 struct irc_ssaddr daddr;
109     int bits = 0, aftype = 0;
110     struct MaskItem *conf = NULL;
111 michael 5829
112 michael 7429 if (!HasFlag(source_p, FLAGS_SERVICE) && !valid_wild_card(1, addr))
113     {
114     sendto_one_notice(source_p, &me,
115     ":Please include at least %u non-wildcard characters with the mask",
116     ConfigGeneral.min_nonwildcard);
117     return;
118     }
119    
120 michael 7419 switch (parse_netmask(addr, &daddr, &bits))
121     {
122     case HM_IPV4:
123     if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr)
124     {
125     if (IsClient(source_p))
126     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
127     ConfigGeneral.dline_min_cidr);
128     return;
129     }
130    
131     aftype = AF_INET;
132     break;
133     case HM_IPV6:
134     if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr6)
135     {
136     if (IsClient(source_p))
137     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
138     ConfigGeneral.dline_min_cidr6);
139     return;
140     }
141    
142     aftype = AF_INET6;
143     break;
144     default: /* HM_HOST */
145     return;
146     }
147    
148     if ((conf = find_conf_by_address(NULL, &daddr, CONF_DLINE, aftype, NULL, NULL, 1)))
149     {
150     if (IsClient(source_p))
151     sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
152     addr, conf->host, conf->reason);
153     return;
154     }
155    
156 michael 6458 if (duration)
157 michael 6782 snprintf(buf, sizeof(buf), "Temporary D-line %ju min. - %.*s (%s)",
158     duration / 60, REASONLEN, reason, date_iso8601(0));
159 michael 5829 else
160 michael 6422 snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, date_iso8601(0));
161 michael 5829
162 michael 7419 conf = conf_make(CONF_DLINE);
163 michael 5829 conf->host = xstrdup(addr);
164     conf->reason = xstrdup(buf);
165     conf->setat = CurrentTime;
166     SetConfDatabase(conf);
167    
168 michael 6458 if (duration)
169 michael 1622 {
170 michael 6458 conf->until = CurrentTime + duration;
171 michael 4639
172     if (IsClient(source_p))
173 michael 6782 sendto_one_notice(source_p, &me, ":Added temporary %ju min. D-Line [%s]",
174     duration / 60, conf->host);
175 michael 4890
176 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
177 michael 6782 "%s added temporary %ju min. D-Line for [%s] [%s]",
178 michael 6937 get_oper_name(source_p), duration / 60,
179 michael 1632 conf->host, conf->reason);
180 michael 6782 ilog(LOG_TYPE_DLINE, "%s added temporary %ju min. D-Line for [%s] [%s]",
181     get_oper_name(source_p), duration / 60, conf->host, conf->reason);
182 michael 1622 }
183     else
184     {
185 michael 4639 if (IsClient(source_p))
186     sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
187    
188 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
189 michael 1622 "%s added D-Line for [%s] [%s]",
190 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
191 michael 1622 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
192 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
193 michael 1622 }
194    
195 michael 5832 dline_check(add_conf_by_address(CONF_DLINE, conf));
196 michael 1058 }
197    
198     /* mo_dline()
199     *
200     * inputs - pointer to server
201     * - pointer to client
202     * - parameter count
203     * - parameter list
204     * output -
205     * side effects - D line is added
206     *
207     */
208 michael 2820 static int
209 michael 3156 mo_dline(struct Client *source_p, int parc, char *parv[])
210 michael 1058 {
211 michael 1622 char *dlhost = NULL, *reason = NULL;
212 michael 1301 char *target_server = NULL;
213 michael 1058 const struct Client *target_p = NULL;
214 michael 7330 uintmax_t duration = 0;
215 michael 7419 int t = 0;
216 michael 1398 char hostip[HOSTIPLEN + 1];
217 michael 1058
218 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
219 michael 1058 {
220 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
221 michael 2820 return 0;
222 michael 1058 }
223    
224 michael 7429 if (!parse_aline("DLINE", source_p, parc, parv, &dlhost,
225 michael 6458 NULL, &duration, &target_server, &reason))
226 michael 2820 return 0;
227 michael 1058
228 michael 3368 if (target_server)
229 michael 1301 {
230 michael 6782 sendto_match_servs(source_p, target_server, CAPAB_DLN, "DLINE %s %ju %s :%s",
231     target_server, duration,
232 michael 2807 dlhost, reason);
233 michael 1301
234 michael 6432 /* Allow ON to apply local dline as well if it matches */
235 michael 1652 if (match(target_server, me.name))
236 michael 2820 return 0;
237 michael 1301 }
238     else
239 michael 7209 cluster_distribute(source_p, "DLINE", CAPAB_DLN, CLUSTER_DLINE,
240     "%ju %s :%s", duration, dlhost, reason);
241 michael 1301
242 michael 5822 if ((t = parse_netmask(dlhost, NULL, NULL)) == HM_HOST)
243 michael 1058 {
244 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
245 michael 3737 return 0; /* find_chasing sends ERR_NOSUCHNICK */
246 michael 1058
247     if (!MyConnect(target_p))
248     {
249 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
250 michael 2820 return 0;
251 michael 1058 }
252    
253 michael 6313 if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
254 michael 1058 {
255 michael 4934 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
256 michael 2820 return 0;
257 michael 1058 }
258    
259 michael 5051 getnameinfo((const struct sockaddr *)&target_p->connection->ip,
260 michael 4588 target_p->connection->ip.ss_len, hostip,
261 michael 1123 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
262 michael 1058 dlhost = hostip;
263     }
264    
265 michael 7419 dline_handle(source_p, dlhost, reason, duration);
266 michael 2820 return 0;
267 michael 1058 }
268    
269 michael 7094 /*! \brief DLINE command handler
270     *
271     * \param source_p Pointer to allocated Client struct from which the message
272     * originally comes from. This can be a local or remote client.
273     * \param parc Integer holding the number of supplied arguments.
274     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
275     * pointers.
276     * \note Valid arguments for this command are:
277     * - parv[0] = command
278     * - parv[1] = target server mask
279     * - parv[2] = duration in seconds
280     * - parv[3] = IP address
281     * - parv[4] = reason
282     */
283 michael 2820 static int
284 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
285 michael 1301 {
286 michael 5829 const char *dlhost, *reason;
287 michael 1301
288     if (parc != 5 || EmptyString(parv[4]))
289 michael 2820 return 0;
290 michael 1301
291 michael 6354 sendto_match_servs(source_p, parv[1], CAPAB_DLN, "DLINE %s %s %s :%s",
292 michael 1301 parv[1], parv[2], parv[3], parv[4]);
293    
294 michael 1652 if (match(parv[1], me.name))
295 michael 2820 return 0;
296 michael 1301
297     dlhost = parv[3];
298     reason = parv[4];
299    
300 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
301 michael 7209 shared_find(SHARED_DLINE, source_p->servptr->name,
302     source_p->username, source_p->host))
303 michael 7423 dline_handle(source_p, dlhost, reason, strtoumax(parv[2], NULL, 10));
304 michael 5805
305 michael 2820 return 0;
306 michael 1301 }
307    
308 michael 2810 static struct Message dline_msgtab =
309     {
310 michael 5881 .cmd = "DLINE",
311     .args_min = 2,
312     .args_max = MAXPARA,
313     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
314     .handlers[CLIENT_HANDLER] = m_not_oper,
315     .handlers[SERVER_HANDLER] = ms_dline,
316     .handlers[ENCAP_HANDLER] = m_ignore,
317     .handlers[OPER_HANDLER] = mo_dline
318 michael 1230 };
319    
320     static void
321     module_init(void)
322     {
323     mod_add_cmd(&dline_msgtab);
324 michael 8166 capab_add("DLN", CAPAB_DLN);
325 michael 1230 }
326    
327     static void
328     module_exit(void)
329     {
330     mod_del_cmd(&dline_msgtab);
331 michael 8166 capab_del("DLN");
332 michael 1230 }
333    
334 michael 2810 struct module module_entry =
335     {
336 michael 1230 .version = "$Revision$",
337     .modinit = module_init,
338     .modexit = module_exit,
339     };

Properties

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