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: 3109
Committed: Thu Mar 6 19:25:12 2014 UTC (12 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_dline.c
File size: 14633 byte(s)
Log Message:
- Applied Adam's sendto_one_numeric() changes

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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file m_dline.c
23 * \brief Includes required functions for processing the DLINE/UNDLINE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "channel.h"
30 #include "client.h"
31 #include "irc_string.h"
32 #include "conf.h"
33 #include "ircd.h"
34 #include "hostmask.h"
35 #include "numeric.h"
36 #include "fdlist.h"
37 #include "s_bsd.h"
38 #include "log.h"
39 #include "s_misc.h"
40 #include "send.h"
41 #include "hash.h"
42 #include "s_serv.h"
43 #include "parse.h"
44 #include "modules.h"
45 #include "conf_db.h"
46 #include "memory.h"
47
48
49 /* apply_tdline()
50 *
51 * inputs -
52 * output - NONE
53 * side effects - tkline as given is placed
54 */
55 static void
56 apply_dline(struct Client *source_p, struct MaskItem *conf,
57 time_t tkline_time)
58 {
59 if (tkline_time)
60 {
61 conf->until = CurrentTime + tkline_time;
62 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
63 "%s added temporary %d min. D-Line for [%s] [%s]",
64 get_oper_name(source_p), tkline_time/60,
65 conf->host, conf->reason);
66 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
67 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p),
68 source_p->name, tkline_time/60, conf->host);
69 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
70 get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
71 }
72 else
73 {
74 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
75 "%s added D-Line for [%s] [%s]",
76 get_oper_name(source_p), conf->host, conf->reason);
77 sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s]",
78 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p),
79 source_p->name, conf->host);
80 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
81 get_oper_name(source_p), conf->host, conf->reason);
82
83 }
84
85 SetConfDatabase(conf);
86 conf->setat = CurrentTime;
87 add_conf_by_address(CONF_DLINE, conf);
88 rehashed_klines = 1;
89 }
90
91 /* static int remove_tdline_match(const char *host, const char *user)
92 * Input: An ip to undline.
93 * Output: returns YES on success, NO if no tdline removed.
94 * Side effects: Any matching tdlines are removed.
95 */
96 static int
97 remove_dline_match(const char *host)
98 {
99 struct irc_ssaddr iphost, *piphost;
100 struct MaskItem *conf;
101 int t = 0;
102 int aftype = 0;
103
104 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
105 {
106 #ifdef IPV6
107 if (t == HM_IPV6)
108 aftype = AF_INET6;
109 else
110 #endif
111 aftype = AF_INET;
112 piphost = &iphost;
113 }
114 else
115 piphost = NULL;
116
117 if ((conf = find_conf_by_address(host, piphost, CONF_DLINE, aftype, NULL, NULL, 0)))
118 {
119 if (IsConfDatabase(conf))
120 {
121 delete_one_address_conf(host, conf);
122 return 1;
123 }
124 }
125
126 return 0;
127 }
128
129 /* mo_dline()
130 *
131 * inputs - pointer to server
132 * - pointer to client
133 * - parameter count
134 * - parameter list
135 * output -
136 * side effects - D line is added
137 *
138 */
139 static int
140 mo_dline(struct Client *client_p, struct Client *source_p,
141 int parc, char *parv[])
142 {
143 char def_reason[] = CONF_NOREASON;
144 char *dlhost = NULL, *reason = NULL;
145 char *target_server = NULL;
146 const char *creason;
147 const struct Client *target_p = NULL;
148 struct irc_ssaddr daddr;
149 struct MaskItem *conf=NULL;
150 time_t tkline_time=0;
151 int bits = 0, aftype = 0, t = 0;
152 const char *current_date = NULL;
153 time_t cur_time;
154 char hostip[HOSTIPLEN + 1];
155 char buffer[IRCD_BUFSIZE];
156
157 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
158 {
159 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
160 return 0;
161 }
162
163 if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
164 NULL, &tkline_time, &target_server, &reason) < 0)
165 return 0;
166
167 if (target_server != NULL)
168 {
169 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
170 target_server, (unsigned long)tkline_time,
171 dlhost, reason);
172
173 /* Allow ON to apply local kline as well if it matches */
174 if (match(target_server, me.name))
175 return 0;
176 }
177 else
178 cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
179 "%d %s :%s", tkline_time, dlhost, reason);
180
181 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
182 {
183 if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
184 return 0;
185
186 if (!MyConnect(target_p))
187 {
188 sendto_one(source_p,
189 ":%s NOTICE %s :Can't DLINE nick on another server",
190 me.name, source_p->name);
191 return 0;
192 }
193
194 if (IsExemptKline(target_p))
195 {
196 sendto_one(source_p, ":%s NOTICE %s :%s is E-lined",
197 me.name, source_p->name, target_p->name);
198 return 0;
199 }
200
201 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
202 target_p->localClient->ip.ss_len, hostip,
203 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
204 dlhost = hostip;
205 t = parse_netmask(dlhost, NULL, &bits);
206 assert(t == HM_IPV4 || t == HM_IPV6);
207 }
208
209 if (bits < 8)
210 {
211 sendto_one(source_p,
212 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
213 me.name, source_p->name);
214 return 0;
215 }
216
217 #ifdef IPV6
218 if (t == HM_IPV6)
219 aftype = AF_INET6;
220 else
221 #endif
222 aftype = AF_INET;
223
224 parse_netmask(dlhost, &daddr, NULL);
225
226 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
227 {
228 creason = conf->reason ? conf->reason : def_reason;
229
230 if (IsConfExemptKline(conf))
231 sendto_one(source_p, ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
232 me.name, source_p->name, dlhost, conf->host, creason);
233 else
234 sendto_one(source_p, ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
235 me.name, source_p->name, dlhost, conf->host, creason);
236 return 0;
237 }
238
239 cur_time = CurrentTime;
240 current_date = smalldate(cur_time);
241
242 if (!valid_comment(source_p, reason, 1))
243 return 0;
244
245 conf = conf_make(CONF_DLINE);
246 conf->host = xstrdup(dlhost);
247
248 if (tkline_time != 0)
249 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
250 (int)(tkline_time/60), reason, current_date);
251 else
252 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
253
254 conf->reason = xstrdup(buffer);
255 apply_dline(source_p, conf, tkline_time);
256 rehashed_klines = 1;
257 return 0;
258 }
259
260 static int
261 ms_dline(struct Client *client_p, struct Client *source_p,
262 int parc, char *parv[])
263 {
264 char def_reason[] = CONF_NOREASON;
265 char *dlhost, *reason;
266 const char *creason;
267 const struct Client *target_p = NULL;
268 struct irc_ssaddr daddr;
269 struct MaskItem *conf=NULL;
270 time_t tkline_time=0;
271 int bits = 0, aftype = 0, t = 0;
272 const char *current_date = NULL;
273 time_t cur_time;
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 /* oper 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 (!IsClient(source_p))
299 return 0;
300
301 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
302 {
303 if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
304 return 0;
305
306 if (!MyConnect(target_p))
307 {
308 sendto_one(source_p,
309 ":%s NOTICE %s :Can't DLINE nick on another server",
310 me.name, source_p->name);
311 return 0;
312 }
313
314 if (IsExemptKline(target_p))
315 {
316 sendto_one(source_p,
317 ":%s NOTICE %s :%s is E-lined", me.name,
318 source_p->name, target_p->name);
319 return 0;
320 }
321
322 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
323 target_p->localClient->ip.ss_len, hostip,
324 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
325 dlhost = hostip;
326 t = parse_netmask(dlhost, NULL, &bits);
327 assert(t == HM_IPV4 || t == HM_IPV6);
328 }
329
330 if (bits < 8)
331 {
332 sendto_one(source_p,
333 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
334 me.name, source_p->name);
335 return 0;
336 }
337
338 #ifdef IPV6
339 if (t == HM_IPV6)
340 aftype= AF_INET6;
341 else
342 #endif
343 aftype = AF_INET;
344
345 parse_netmask(dlhost, &daddr, NULL);
346
347 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
348 {
349 creason = conf->reason ? conf->reason : def_reason;
350 if (IsConfExemptKline(conf))
351 sendto_one(source_p,
352 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
353 me.name, source_p->name, dlhost, conf->host, creason);
354 else
355 sendto_one(source_p,
356 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
357 me.name, source_p->name, dlhost, conf->host, creason);
358 return 0;
359 }
360
361 cur_time = CurrentTime;
362 current_date = smalldate(cur_time);
363
364 if (!valid_comment(source_p, reason, 1))
365 return 0;
366
367 conf = conf_make(CONF_DLINE);
368 conf->host = xstrdup(dlhost);
369
370 if (tkline_time != 0)
371 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
372 (int)(tkline_time/60), reason, current_date);
373 else
374 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
375
376 conf->reason = xstrdup(buffer);
377 apply_dline(source_p, conf, tkline_time);
378 rehashed_klines = 1;
379 }
380
381 return 0;
382 }
383
384 /*
385 ** m_undline
386 ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
387 ** based totally on m_unkline
388 ** added to hybrid-7 7/11/2000 --is
389 **
390 ** parv[0] = sender nick
391 ** parv[1] = dline to remove
392 */
393 static int
394 mo_undline(struct Client *client_p, struct Client *source_p,
395 int parc, char *parv[])
396 {
397 char *addr = NULL, *user = NULL;
398 char *target_server = NULL;
399
400 if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
401 {
402 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "undline");
403 return 0;
404 }
405
406 if (parc < 2 || EmptyString(parv[1]))
407 {
408 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNDLINE");
409 return 0;
410 }
411
412 if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
413 &addr, NULL, &target_server, NULL) < 0)
414 return 0;
415
416 if (target_server != NULL)
417 {
418 sendto_match_servs(source_p, target_server, CAP_UNDLN,
419 "UNDLINE %s %s", target_server, addr);
420
421 /* Allow ON to apply local unkline as well if it matches */
422 if (match(target_server, me.name))
423 return 0;
424 }
425 else
426 cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
427 "%s", addr);
428
429 if (remove_dline_match(addr))
430 {
431 sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
432 me.name, source_p->name, addr);
433 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
434 "%s has removed the D-Line for: [%s]",
435 get_oper_name(source_p), addr);
436 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
437 get_oper_name(source_p), addr);
438 }
439 else
440 sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
441 me.name, source_p->name, addr);
442 return 0;
443 }
444
445 static int
446 ms_undline(struct Client *client_p, struct Client *source_p,
447 int parc, char *parv[])
448 {
449 const char *addr = parv[1];
450
451 if (parc != 3 || EmptyString(parv[2]))
452 return 0;
453
454 sendto_match_servs(source_p, parv[1], CAP_UNDLN,
455 "UNDLINE %s %s",
456 parv[1], parv[2]);
457
458 if (!IsClient(source_p) || match(parv[1], me.name))
459 return 0;
460
461 if (HasFlag(source_p, FLAGS_SERVICE) ||
462 find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
463 source_p->username, source_p->host,
464 SHARED_UNDLINE))
465 {
466 if (remove_dline_match(addr))
467 {
468 sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
469 me.name, source_p->name, addr);
470 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
471 "%s has removed the D-Line for: [%s]",
472 get_oper_name(source_p), addr);
473 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
474 get_oper_name(source_p), addr);
475 }
476 else
477 sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
478 me.name, source_p->name, addr);
479 }
480
481 return 0;
482 }
483
484 static struct Message dline_msgtab =
485 {
486 "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
487 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
488 };
489
490 static struct Message undline_msgtab =
491 {
492 "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
493 { m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore }
494 };
495
496 static void
497 module_init(void)
498 {
499 mod_add_cmd(&dline_msgtab);
500 mod_add_cmd(&undline_msgtab);
501 add_capability("DLN", CAP_DLN, 1);
502 add_capability("UNDLN", CAP_UNDLN, 1);
503 }
504
505 static void
506 module_exit(void)
507 {
508 mod_del_cmd(&dline_msgtab);
509 mod_del_cmd(&undline_msgtab);
510 delete_capability("UNDLN");
511 delete_capability("DLN");
512 }
513
514 struct module module_entry =
515 {
516 .node = { NULL, NULL, NULL },
517 .name = NULL,
518 .version = "$Revision$",
519 .handle = NULL,
520 .modinit = module_init,
521 .modexit = module_exit,
522 .flags = 0
523 };

Properties

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