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: 8499
Committed: Thu Apr 5 12:59:25 2018 UTC (6 years ago) by michael
Content type: text/x-csrc
File size: 9731 byte(s)
Log Message:
- Killed Connection::aftype. Use Client::ip.ss.ss_family instead.

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2018 ircd-hybrid development team
5 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_dline.c
23 * \brief Includes required functions for processing the DLINE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "irc_string.h"
31 #include "conf.h"
32 #include "conf_cluster.h"
33 #include "conf_shared.h"
34 #include "ircd.h"
35 #include "hostmask.h"
36 #include "numeric.h"
37 #include "log.h"
38 #include "misc.h"
39 #include "send.h"
40 #include "server_capab.h"
41 #include "parse.h"
42 #include "modules.h"
43 #include "memory.h"
44
45
46 static void
47 dline_check(const struct AddressRec *arec)
48 {
49 dlink_node *node, *node_next;
50
51 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
52 {
53 struct Client *client_p = node->data;
54
55 if (IsDead(client_p))
56 continue;
57
58 switch (arec->masktype)
59 {
60 case HM_IPV4:
61 if (client_p->ip.ss.ss_family == AF_INET)
62 if (match_ipv4(&client_p->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
63 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
64 break;
65 case HM_IPV6:
66 if (client_p->ip.ss.ss_family == AF_INET6)
67 if (match_ipv6(&client_p->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
68 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
69 break;
70 default: break;
71 }
72 }
73
74 DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
75 {
76 struct Client *client_p = node->data;
77
78 if (IsDead(client_p))
79 continue;
80
81 switch (arec->masktype)
82 {
83 case HM_IPV4:
84 if (client_p->ip.ss.ss_family == AF_INET)
85 if (match_ipv4(&client_p->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
86 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
87 break;
88 case HM_IPV6:
89 if (client_p->ip.ss.ss_family == AF_INET6)
90 if (match_ipv6(&client_p->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
91 conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason);
92 break;
93 default: break;
94 }
95 }
96 }
97
98 /* dline_add()
99 *
100 * inputs -
101 * output - NONE
102 * side effects - dline as given is placed
103 */
104 static void
105 dline_handle(struct Client *source_p, const char *addr, const char *reason, uintmax_t duration)
106 {
107 char buf[IRCD_BUFSIZE];
108 struct irc_ssaddr daddr;
109 int bits = 0, aftype = 0;
110
111 if (!HasFlag(source_p, FLAGS_SERVICE) && !valid_wild_card(1, addr))
112 {
113 sendto_one_notice(source_p, &me,
114 ":Please include at least %u non-wildcard characters with the mask",
115 ConfigGeneral.min_nonwildcard);
116 return;
117 }
118
119 switch (parse_netmask(addr, &daddr, &bits))
120 {
121 case HM_IPV4:
122 if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr)
123 {
124 if (IsClient(source_p))
125 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
126 ConfigGeneral.dline_min_cidr);
127 return;
128 }
129
130 aftype = AF_INET;
131 break;
132 case HM_IPV6:
133 if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr6)
134 {
135 if (IsClient(source_p))
136 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
137 ConfigGeneral.dline_min_cidr6);
138 return;
139 }
140
141 aftype = AF_INET6;
142 break;
143 default: /* HM_HOST */
144 return;
145 }
146
147 struct MaskItem *conf;
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 if (duration)
157 snprintf(buf, sizeof(buf), "Temporary D-line %ju min. - %.*s (%s)",
158 duration / 60, REASONLEN, reason, date_iso8601(0));
159 else
160 snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, date_iso8601(0));
161
162 conf = conf_make(CONF_DLINE);
163 conf->host = xstrdup(addr);
164 conf->reason = xstrdup(buf);
165 conf->setat = CurrentTime;
166 SetConfDatabase(conf);
167
168 if (duration)
169 {
170 conf->until = CurrentTime + duration;
171
172 if (IsClient(source_p))
173 sendto_one_notice(source_p, &me, ":Added temporary %ju min. D-Line [%s]",
174 duration / 60, conf->host);
175
176 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
177 "%s added temporary %ju min. D-Line for [%s] [%s]",
178 get_oper_name(source_p), duration / 60,
179 conf->host, conf->reason);
180 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 }
183 else
184 {
185 if (IsClient(source_p))
186 sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
187
188 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
189 "%s added D-Line for [%s] [%s]",
190 get_oper_name(source_p), conf->host, conf->reason);
191 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
192 get_oper_name(source_p), conf->host, conf->reason);
193 }
194
195 dline_check(add_conf_by_address(CONF_DLINE, conf));
196 }
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 static int
209 mo_dline(struct Client *source_p, int parc, char *parv[])
210 {
211 char *dlhost = NULL, *reason = NULL;
212 char *target_server = NULL;
213 const struct Client *target_p = NULL;
214 uintmax_t duration = 0;
215 int t = 0;
216 char hostip[HOSTIPLEN + 1];
217
218 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
219 {
220 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
221 return 0;
222 }
223
224 if (!parse_aline("DLINE", source_p, parc, parv, &dlhost,
225 NULL, &duration, &target_server, &reason))
226 return 0;
227
228 if (target_server)
229 {
230 sendto_match_servs(source_p, target_server, CAPAB_DLN, "DLINE %s %ju %s :%s",
231 target_server, duration,
232 dlhost, reason);
233
234 /* Allow ON to apply local dline as well if it matches */
235 if (match(target_server, me.name))
236 return 0;
237 }
238 else
239 cluster_distribute(source_p, "DLINE", CAPAB_DLN, CLUSTER_DLINE,
240 "%ju %s :%s", duration, dlhost, reason);
241
242 if ((t = parse_netmask(dlhost, NULL, NULL)) == HM_HOST)
243 {
244 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
245 return 0; /* find_chasing sends ERR_NOSUCHNICK */
246
247 if (!MyConnect(target_p))
248 {
249 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
250 return 0;
251 }
252
253 if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
254 {
255 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
256 return 0;
257 }
258
259 getnameinfo((const struct sockaddr *)&target_p->ip, target_p->ip.ss_len,
260 hostip, sizeof(hostip), NULL, 0, NI_NUMERICHOST);
261 dlhost = hostip;
262 }
263
264 dline_handle(source_p, dlhost, reason, duration);
265 return 0;
266 }
267
268 /*! \brief DLINE command handler
269 *
270 * \param source_p Pointer to allocated Client struct from which the message
271 * originally comes from. This can be a local or remote client.
272 * \param parc Integer holding the number of supplied arguments.
273 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
274 * pointers.
275 * \note Valid arguments for this command are:
276 * - parv[0] = command
277 * - parv[1] = target server mask
278 * - parv[2] = duration in seconds
279 * - parv[3] = IP address
280 * - parv[4] = reason
281 */
282 static int
283 ms_dline(struct Client *source_p, int parc, char *parv[])
284 {
285 const char *dlhost, *reason;
286
287 if (parc != 5 || EmptyString(parv[4]))
288 return 0;
289
290 sendto_match_servs(source_p, parv[1], CAPAB_DLN, "DLINE %s %s %s :%s",
291 parv[1], parv[2], parv[3], parv[4]);
292
293 if (match(parv[1], me.name))
294 return 0;
295
296 dlhost = parv[3];
297 reason = parv[4];
298
299 if (HasFlag(source_p, FLAGS_SERVICE) ||
300 shared_find(SHARED_DLINE, source_p->servptr->name,
301 source_p->username, source_p->host))
302 dline_handle(source_p, dlhost, reason, strtoumax(parv[2], NULL, 10));
303
304 return 0;
305 }
306
307 static struct Message dline_msgtab =
308 {
309 .cmd = "DLINE",
310 .args_min = 2,
311 .args_max = MAXPARA,
312 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
313 .handlers[CLIENT_HANDLER] = m_not_oper,
314 .handlers[SERVER_HANDLER] = ms_dline,
315 .handlers[ENCAP_HANDLER] = m_ignore,
316 .handlers[OPER_HANDLER] = mo_dline
317 };
318
319 static void
320 module_init(void)
321 {
322 mod_add_cmd(&dline_msgtab);
323 capab_add("DLN", CAPAB_DLN);
324 }
325
326 static void
327 module_exit(void)
328 {
329 mod_del_cmd(&dline_msgtab);
330 capab_del("DLN");
331 }
332
333 struct module module_entry =
334 {
335 .version = "$Revision$",
336 .modinit = module_init,
337 .modexit = module_exit,
338 };

Properties

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