/[svn]/ircd-hybrid/branches/8.2.x/modules/m_dline.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/modules/m_dline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5830 - (show annotations)
Sun Apr 26 16:25:56 2015 UTC (5 years, 2 months ago) by michael
File MIME type: text/x-chdr
File size: 10127 byte(s)
- m_dline.c: deduplication

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 /* dline_add()
99 *
100 * inputs -
101 * output - NONE
102 * side effects - dline as given is placed
103 */
104 static void
105 dline_add(struct Client *source_p, const char *addr,
106 const char *reason, time_t tdline_time)
107 {
108 char buf[IRCD_BUFSIZE];
109 struct MaskItem *conf;
110
111 if (tdline_time)
112 snprintf(buf, sizeof(buf), "Temporary D-line %d min. - %.*s (%s)",
113 (int)(tdline_time/60), REASONLEN, reason, smalldate(0));
114 else
115 snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, smalldate(0));
116
117 conf = conf_make(CONF_DLINE);
118 conf->host = xstrdup(addr);
119 conf->reason = xstrdup(buf);
120 conf->setat = CurrentTime;
121 SetConfDatabase(conf);
122
123 if (tdline_time)
124 {
125 conf->until = CurrentTime + tdline_time;
126
127 if (IsClient(source_p))
128 sendto_one_notice(source_p, &me, ":Added temporary %d min. D-Line [%s]",
129 tdline_time/60, conf->host);
130
131 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
132 "%s added temporary %d min. D-Line for [%s] [%s]",
133 get_oper_name(source_p), tdline_time/60,
134 conf->host, conf->reason);
135 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
136 get_oper_name(source_p), tdline_time/60, conf->host, conf->reason);
137 }
138 else
139 {
140 if (IsClient(source_p))
141 sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
142
143 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
144 "%s added D-Line for [%s] [%s]",
145 get_oper_name(source_p), conf->host, conf->reason);
146 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
147 get_oper_name(source_p), conf->host, conf->reason);
148 }
149
150 check_dline(add_conf_by_address(CONF_DLINE, conf));
151 }
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 static int
164 mo_dline(struct Client *source_p, int parc, char *parv[])
165 {
166 char *dlhost = NULL, *reason = NULL;
167 char *target_server = NULL;
168 const struct Client *target_p = NULL;
169 struct irc_ssaddr daddr;
170 struct MaskItem *conf = NULL;
171 time_t tdline_time = 0;
172 int bits = 0, aftype = 0, t = 0;
173 char hostip[HOSTIPLEN + 1];
174
175 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
176 {
177 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
178 return 0;
179 }
180
181 if (!parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
182 NULL, &tdline_time, &target_server, &reason))
183 return 0;
184
185 if (target_server)
186 {
187 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
188 target_server, (unsigned long)tdline_time,
189 dlhost, reason);
190
191 /* Allow ON to apply local kline as well if it matches */
192 if (match(target_server, me.name))
193 return 0;
194 }
195 else
196 cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
197 "%d %s :%s", tdline_time, dlhost, reason);
198
199 if ((t = parse_netmask(dlhost, NULL, NULL)) == HM_HOST)
200 {
201 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
202 return 0; /* find_chasing sends ERR_NOSUCHNICK */
203
204 if (!MyConnect(target_p))
205 {
206 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
207 return 0;
208 }
209
210 if (IsExemptKline(target_p))
211 {
212 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
213 return 0;
214 }
215
216 getnameinfo((const struct sockaddr *)&target_p->connection->ip,
217 target_p->connection->ip.ss_len, hostip,
218 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
219 dlhost = hostip;
220 }
221
222 switch (parse_netmask(dlhost, &daddr, &bits))
223 {
224 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 }
247
248 if ((conf = find_conf_by_address(NULL, &daddr, CONF_DLINE, aftype, NULL, NULL, 1)))
249 {
250 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
251 dlhost, conf->host, conf->reason);
252 return 0;
253 }
254
255 dline_add(source_p, dlhost, reason, tdline_time);
256 return 0;
257 }
258
259 static int
260 ms_dline(struct Client *source_p, int parc, char *parv[])
261 {
262 const char *dlhost, *reason;
263 struct irc_ssaddr daddr;
264 struct MaskItem *conf = NULL;
265 time_t tdline_time=0;
266 int bits = 0, aftype = 0;
267
268 if (parc != 5 || EmptyString(parv[4]))
269 return 0;
270
271 /* parv[0] parv[1] parv[2] parv[3] parv[4] */
272 /* command target_server tdline_time host reason */
273 sendto_match_servs(source_p, parv[1], CAP_DLN, "DLINE %s %s %s :%s",
274 parv[1], parv[2], parv[3], parv[4]);
275
276 if (match(parv[1], me.name))
277 return 0;
278
279 tdline_time = valid_tkline(parv[2], TK_SECONDS);
280 dlhost = parv[3];
281 reason = parv[4];
282
283 if (HasFlag(source_p, FLAGS_SERVICE) ||
284 find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
285 source_p->username, source_p->host,
286 SHARED_DLINE))
287 {
288 switch (parse_netmask(dlhost, &daddr, &bits))
289 {
290 case HM_IPV4:
291 if ((unsigned int)bits < ConfigGeneral.dline_min_cidr)
292 {
293 if (IsClient(source_p))
294 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
295 ConfigGeneral.dline_min_cidr);
296 return 0;
297 }
298
299 aftype = AF_INET;
300 break;
301 case HM_IPV6:
302 if ((unsigned int)bits < ConfigGeneral.dline_min_cidr6)
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_cidr6);
307 return 0;
308 }
309
310 aftype = AF_INET6;
311 break;
312 default: /* HM_HOST */
313 return 0;
314 }
315
316 if ((conf = find_conf_by_address(NULL, &daddr, CONF_DLINE, aftype, NULL, NULL, 1)))
317 {
318 if (IsClient(source_p))
319 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
320 dlhost, conf->host, conf->reason);
321 return 0;
322 }
323
324 dline_add(source_p, dlhost, reason, tdline_time);
325 }
326
327 return 0;
328 }
329
330 static struct Message dline_msgtab =
331 {
332 "DLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
333 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
334 };
335
336 static void
337 module_init(void)
338 {
339 mod_add_cmd(&dline_msgtab);
340 add_capability("DLN", CAP_DLN);
341 }
342
343 static void
344 module_exit(void)
345 {
346 mod_del_cmd(&dline_msgtab);
347 delete_capability("DLN");
348 }
349
350 struct module module_entry =
351 {
352 .node = { NULL, NULL, NULL },
353 .name = NULL,
354 .version = "$Revision$",
355 .handle = NULL,
356 .modinit = module_init,
357 .modexit = module_exit,
358 .flags = 0
359 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28