ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 2807
Committed: Sun Jan 12 17:19:01 2014 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 14871 byte(s)
Log Message:
- m_dline.c:mo_dline(). if a target server exists, use sendto_match_servs()
  instead of sendto_server()

File Contents

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

Properties

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