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: 4640
Committed: Sun Sep 21 11:18:20 2014 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 11277 byte(s)
Log Message:
- m_dline.c, m_undline.c: allow servers to add/remove DLINEs

File Contents

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

Properties

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