ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 5818
Committed: Sun Apr 26 11:57:53 2015 UTC (10 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 10584 byte(s)
Log Message:
- m_dline.c:ms_dline(): minor cleanup

File Contents

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

Properties

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