ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_kline.c
Revision: 350
Committed: Sun Jan 1 09:29:42 2006 UTC (20 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 25868 byte(s)
Log Message:
- documentings

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_kline.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 "channel.h"
27 #include "client.h"
28 #include "common.h"
29 #include "ircd.h"
30 #include "hostmask.h"
31 #include "numeric.h"
32 #include "s_conf.h"
33 #include "parse_aline.h"
34 #include "send.h"
35 #include "hash.h"
36 #include "handlers.h"
37 #include "s_serv.h"
38 #include "msg.h"
39 #include "s_gline.h"
40 #include "parse.h"
41 #include "modules.h"
42
43 static void me_kline(struct Client *, struct Client *, int, char **);
44 static void mo_kline(struct Client *, struct Client *, int, char **);
45 static void ms_kline(struct Client *, struct Client *, int, char **);
46 static void mo_dline(struct Client *, struct Client *, int, char **);
47 static void me_unkline(struct Client *, struct Client *, int, char **);
48 static void mo_unkline(struct Client *, struct Client *, int, char **);
49 static void ms_unkline(struct Client *, struct Client *, int, char **);
50 static void mo_undline(struct Client *, struct Client *, int, char **);
51
52 #ifndef IPV6
53 static char *make_cidr(char *dlhost, struct Client *);
54 #endif
55
56 static int remove_tkline_match(const char *, const char *);
57 static int remove_tdline_match(const char *);
58
59 struct Message kline_msgtab = {
60 "KLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
61 {m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore}
62 };
63
64 struct Message dline_msgtab = {
65 "DLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
66 {m_unregistered, m_not_oper, m_error, m_ignore, mo_dline, m_ignore}
67 };
68
69 struct Message unkline_msgtab = {
70 "UNKLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
71 {m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore}
72 };
73
74 struct Message undline_msgtab = {
75 "UNDLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
76 {m_unregistered, m_not_oper, m_error, m_ignore, mo_undline, m_ignore}
77 };
78
79 #ifndef STATIC_MODULES
80 void
81 _modinit(void)
82 {
83 mod_add_cmd(&kline_msgtab);
84 mod_add_cmd(&unkline_msgtab);
85 mod_add_cmd(&dline_msgtab);
86 mod_add_cmd(&undline_msgtab);
87 add_capability("KLN", CAP_KLN, 1);
88 add_capability("UNKLN", CAP_UNKLN, 1);
89 }
90
91 void
92 _moddeinit(void)
93 {
94 mod_del_cmd(&kline_msgtab);
95 mod_del_cmd(&unkline_msgtab);
96 mod_del_cmd(&dline_msgtab);
97 mod_del_cmd(&undline_msgtab);
98 delete_capability("UNKLN");
99 delete_capability("KLN");
100 }
101
102 const char *_version = "$Revision$";
103 #endif
104
105 /* Local function prototypes */
106 static int already_placed_kline(struct Client *, const char *, const char *, int);
107 static void apply_kline(struct Client *, struct ConfItem *, const char *, time_t);
108 static void apply_tkline(struct Client *, struct ConfItem *, int);
109
110 static char buffer[IRCD_BUFSIZE];
111
112
113 /*! \brief KLINE command handler (called for operators only)
114 *
115 * \param client_p Pointer to allocated Client struct with physical connection
116 * to this server, i.e. with an open socket connected.
117 * \param source_p Pointer to allocated Client struct from which the message
118 * originally comes from. This can be a local or remote client.
119 * \param parc Integer holding the number of supplied arguments.
120 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
121 * pointers.
122 * \note Valid arguments for this command are:
123 * - parv[0] = sender prefix
124 * - parv[1] = time in minutes
125 * - parv[2] = nick or user@host mask
126 * - parv[3] = reason (optional)
127 * or
128 * - parv[0] = sender prefix
129 * - parv[1] = nick or user@host mask
130 * - parv[2] = reason (optional)
131 */
132 static void
133 mo_kline(struct Client *client_p, struct Client *source_p,
134 int parc, char **parv)
135 {
136 char *reason = NULL;
137 char *oper_reason;
138 char *user = NULL;
139 char *host = NULL;
140 const char *current_date;
141 char *target_server = NULL;
142 struct ConfItem *conf;
143 struct AccessItem *aconf;
144 time_t tkline_time = 0;
145 time_t cur_time;
146
147 if (!IsOperK(source_p))
148 {
149 sendto_one(source_p, form_str(ERR_NOPRIVS),
150 me.name, source_p->name, "kline");
151 return;
152 }
153
154 if (parse_aline("KLINE", source_p, parc, parv,
155 AWILD, &user, &host, &tkline_time, &target_server, &reason) < 0)
156 return;
157
158 if (target_server != NULL)
159 {
160 if (HasID(source_p))
161 {
162 sendto_server(NULL, source_p, NULL, CAP_KLN|CAP_TS6, NOCAPS, LL_ICLIENT,
163 ":%s KLINE %s %lu %s %s :%s",
164 source_p->id, target_server, (unsigned long)tkline_time,
165 user, host, reason);
166 sendto_server(NULL, source_p, NULL, CAP_KLN, CAP_TS6, LL_ICLIENT,
167 ":%s KLINE %s %lu %s %s :%s",
168 source_p->name, target_server, (unsigned long)tkline_time,
169 user, host, reason);
170 }
171 else
172 sendto_server(NULL, source_p, NULL, CAP_KLN, NOCAPS, LL_ICLIENT,
173 ":%s KLINE %s %lu %s %s :%s",
174 source_p->name, target_server, (unsigned long)tkline_time,
175 user, host, reason);
176
177 /* Allow ON to apply local kline as well if it matches */
178 if (!match(target_server, me.name))
179 return;
180 }
181 else
182 cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
183 "%d %s %s :%s", tkline_time, user, host, reason);
184
185 if (already_placed_kline(source_p, user, host, YES))
186 return;
187
188 /* Look for an oper reason */
189 if ((oper_reason = strchr(reason, '|')) != NULL)
190 *oper_reason++ = '\0';
191
192 cur_time = CurrentTime;
193 current_date = smalldate(cur_time);
194 conf = make_conf_item(KLINE_TYPE);
195 aconf = &conf->conf.AccessItem;
196
197 DupString(aconf->host, host);
198 DupString(aconf->user, user);
199
200 if (tkline_time != 0)
201 {
202 ircsprintf(buffer, "Temporary K-line %d min. - %s (%s)",
203 (int)(tkline_time/60), reason, current_date);
204 DupString(aconf->reason, buffer);
205
206 if (oper_reason != NULL)
207 DupString(aconf->oper_reason, oper_reason);
208 apply_tkline(source_p, conf, tkline_time);
209 }
210 else
211 {
212 ircsprintf(buffer, "%s (%s)", reason, current_date);
213 DupString(aconf->reason, buffer);
214
215 if (oper_reason != NULL)
216 DupString(aconf->oper_reason, oper_reason);
217 apply_kline(source_p, conf, current_date, cur_time);
218 }
219 }
220
221 /* me_kline - handle remote kline. no propagation */
222 static void
223 me_kline(struct Client *client_p, struct Client *source_p,
224 int parc, char *parv[])
225 {
226 struct ConfItem *conf=NULL;
227 struct AccessItem *aconf=NULL;
228 int tkline_time;
229 const char* current_date;
230 time_t cur_time;
231 char *kuser, *khost, *kreason, *oper_reason;
232
233 if (parc != 6)
234 return;
235
236 if (!match(parv[1], me.name))
237 return;
238
239 tkline_time = valid_tkline(parv[2], TK_SECONDS);
240 kuser = parv[3];
241 khost = parv[4];
242 kreason = parv[5];
243
244 if ((oper_reason = strchr(kreason, '|')) != NULL)
245 *oper_reason++ = '\0';
246
247 cur_time = CurrentTime;
248 current_date = smalldate(cur_time);
249
250 if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
251 source_p->username, source_p->host,
252 SHARED_KLINE))
253 {
254 if (!IsClient(source_p) ||
255 already_placed_kline(source_p, kuser, khost, YES))
256 return;
257
258 conf = make_conf_item(KLINE_TYPE);
259 aconf = &conf->conf.AccessItem;
260 DupString(aconf->host, khost);
261 DupString(aconf->user, kuser);
262
263 if (tkline_time != 0)
264 {
265 ircsprintf(buffer, "Temporary K-line %d min. - %s (%s)",
266 (int)(tkline_time/60), kreason, current_date);
267 DupString(aconf->reason, buffer);
268
269 if (oper_reason != NULL)
270 DupString(aconf->oper_reason, oper_reason);
271 apply_tkline(source_p, conf, tkline_time);
272 }
273 else
274 {
275 ircsprintf(buffer, "%s (%s)", kreason, current_date);
276 DupString(aconf->reason, buffer);
277
278 if (oper_reason != NULL)
279 DupString(aconf->oper_reason, oper_reason);
280 apply_kline(source_p, conf, current_date, cur_time);
281 }
282 }
283 }
284
285 /*! \brief KLINE command handler (called for remote clients and servers only)
286 *
287 * Returns various information such as maxmimum entries, slots that
288 * are in use and collision count
289 *
290 * \param client_p Pointer to allocated Client struct with physical connection
291 * to this server, i.e. with an open socket connected.
292 * \param source_p Pointer to allocated Client struct from which the message
293 * originally comes from. This can be a local or remote client.
294 * \param parc Integer holding the number of supplied arguments.
295 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
296 * pointers.
297 * \note Valid arguments for this command are:
298 * - parv[0] = sender prefix
299 * - parv[1] = target server (string may include wildcards)
300 * - parv[2] = duration in minutes
301 * - parv[3] = username
302 * - parv[4] = hostname
303 * - parv[5] = reason
304 */
305 static void
306 ms_kline(struct Client *client_p, struct Client *source_p,
307 int parc, char *parv[])
308 {
309 if (parc != 6)
310 return;
311
312 sendto_match_servs(source_p, parv[1], CAP_KLN,
313 "KLINE %s %s %s %s :%s",
314 parv[1], parv[2], parv[3], parv[4], parv[5]);
315
316 me_kline(client_p, source_p, parc, parv);
317 }
318
319 /* apply_kline()
320 *
321 * inputs -
322 * output - NONE
323 * side effects - kline as given, is added to the hashtable
324 * and conf file
325 */
326 static void
327 apply_kline(struct Client *source_p, struct ConfItem *conf,
328 const char *current_date, time_t cur_time)
329 {
330 struct AccessItem *aconf = &conf->conf.AccessItem;
331
332 add_conf_by_address(CONF_KILL, aconf);
333 write_conf_line(source_p, conf, current_date, cur_time);
334 /* Now, activate kline against current online clients */
335 rehashed_klines = 1;
336 }
337
338 /* apply_tkline()
339 *
340 * inputs -
341 * output - NONE
342 * side effects - tkline as given is placed
343 */
344 static void
345 apply_tkline(struct Client *source_p, struct ConfItem *conf,
346 int tkline_time)
347 {
348 struct AccessItem *aconf;
349
350 aconf = &conf->conf.AccessItem;
351 aconf->hold = CurrentTime + tkline_time;
352 add_temp_line(conf);
353 sendto_realops_flags(UMODE_ALL, L_ALL,
354 "%s added temporary %d min. K-Line for [%s@%s] [%s]",
355 get_oper_name(source_p), tkline_time/60,
356 aconf->user, aconf->host,
357 aconf->reason);
358 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
359 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
360 source_p->name, tkline_time/60, aconf->user, aconf->host);
361 ilog(L_TRACE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
362 source_p->name, tkline_time/60,
363 aconf->user, aconf->host, aconf->reason);
364 log_oper_action(LOG_TEMP_KLINE_TYPE, source_p, "[%s@%s] [%s]\n",
365 aconf->user, aconf->host, aconf->reason);
366 rehashed_klines = 1;
367 }
368
369 /* apply_tdline()
370 *
371 * inputs -
372 * output - NONE
373 * side effects - tkline as given is placed
374 */
375 static void
376 apply_tdline(struct Client *source_p, struct ConfItem *conf,
377 const char *current_date, int tkline_time)
378 {
379 struct AccessItem *aconf;
380
381 aconf = &conf->conf.AccessItem;
382 aconf->hold = CurrentTime + tkline_time;
383
384 add_temp_line(conf);
385 sendto_realops_flags(UMODE_ALL, L_ALL,
386 "%s added temporary %d min. D-Line for [%s] [%s]",
387 get_oper_name(source_p), tkline_time/60,
388 aconf->host, aconf->reason);
389
390 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
391 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
392 source_p->name, tkline_time/60, aconf->host);
393 ilog(L_TRACE, "%s added temporary %d min. D-Line for [%s] [%s]",
394 source_p->name, tkline_time/60, aconf->host, aconf->reason);
395 log_oper_action(LOG_TEMP_DLINE_TYPE, source_p, "[%s@%s] [%s]\n",
396 aconf->user, aconf->host, aconf->reason);
397 rehashed_klines = 1;
398 }
399
400 /* mo_dline()
401 *
402 * inputs - pointer to server
403 * - pointer to client
404 * - parameter count
405 * - parameter list
406 * output -
407 * side effects - D line is added
408 *
409 */
410 static void
411 mo_dline(struct Client *client_p, struct Client *source_p,
412 int parc, char *parv[])
413 {
414 char def_reason[] = "No reason";
415 char *dlhost, *oper_reason, *reason;
416 const char *creason;
417 #ifndef IPV6
418 struct Client *target_p;
419 #endif
420 struct irc_ssaddr daddr;
421 struct ConfItem *conf=NULL;
422 struct AccessItem *aconf=NULL;
423 time_t tkline_time=0;
424 int bits, t;
425 const char* current_date;
426 time_t cur_time;
427
428 if (!IsOperK(source_p))
429 {
430 sendto_one(source_p, form_str(ERR_NOPRIVS),
431 me.name, source_p->name, "kline");
432 return;
433 }
434
435 if (parse_aline("DLINE", source_p, parc, parv,
436 AWILD, &dlhost, NULL, &tkline_time, NULL, &reason) < 0)
437 return;
438
439 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
440 {
441 #ifdef IPV6
442 sendto_one(source_p, ":%s NOTICE %s :Sorry, please supply an address.",
443 me.name, parv[0]);
444 return;
445 #else
446 if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
447 return;
448
449 t = HM_IPV4;
450 if (IsServer(target_p))
451 {
452 sendto_one(source_p,
453 ":%s NOTICE %s :Can't DLINE a server silly",
454 me.name, source_p->name);
455 return;
456 }
457
458 if (!MyConnect(target_p))
459 {
460 sendto_one(source_p,
461 ":%s NOTICE %s :Can't DLINE nick on another server",
462 me.name, source_p->name);
463 return;
464 }
465
466 if (IsExemptKline(target_p))
467 {
468 sendto_one(source_p,
469 ":%s NOTICE %s :%s is E-lined",me.name,
470 source_p->name, target_p->name);
471 return;
472 }
473
474 if ((dlhost = make_cidr(dlhost, target_p)) == NULL)
475 return;
476
477 bits = 0xFFFFFF00UL;
478 #endif
479 }
480
481 if (bits < 8)
482 {
483 sendto_one(source_p,
484 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
485 me.name, source_p->name);
486 return;
487 }
488
489
490 #ifdef IPV6
491 if (t == HM_IPV6)
492 t = AF_INET6;
493 else
494 #endif
495 t = AF_INET;
496
497 parse_netmask(dlhost, &daddr, NULL);
498
499 if ((aconf = find_dline_conf(&daddr, t)) != NULL)
500 {
501 creason = aconf->reason ? aconf->reason : def_reason;
502 if (IsConfExemptKline(aconf))
503 sendto_one(source_p,
504 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
505 me.name, source_p->name, dlhost, aconf->host, creason);
506 else
507 sendto_one(source_p,
508 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
509 me.name, source_p->name, dlhost, aconf->host, creason);
510 return;
511 }
512
513 cur_time = CurrentTime;
514 current_date = smalldate(cur_time);
515
516 /* Look for an oper reason */
517 if ((oper_reason = strchr(reason, '|')) != NULL)
518 *oper_reason++ = '\0';
519
520 if (!valid_comment(source_p, reason, YES))
521 return;
522
523 conf = make_conf_item(DLINE_TYPE);
524 aconf = &conf->conf.AccessItem;
525 DupString(aconf->host, dlhost);
526
527 if (tkline_time != 0)
528 {
529 ircsprintf(buffer, "Temporary D-line %d min. - %s (%s)",
530 (int)(tkline_time/60), reason, current_date);
531 DupString(aconf->reason, buffer);
532 if (oper_reason != NULL)
533 DupString(aconf->oper_reason, oper_reason);
534 apply_tdline(source_p, conf, current_date, tkline_time);
535 }
536 else
537 {
538 ircsprintf(buffer, "%s (%s)", reason, current_date);
539 DupString(aconf->reason, buffer);
540 if (oper_reason != NULL)
541 DupString(aconf->oper_reason, oper_reason);
542 add_conf_by_address(CONF_DLINE, aconf);
543 write_conf_line(source_p, conf, current_date, cur_time);
544 }
545
546 rehashed_klines = 1;
547 } /* mo_dline() */
548
549
550 /* already_placed_kline()
551 * inputs - user to complain to, username & host to check for
552 * outputs - returns 1 on existing K-line, 0 if doesn't exist
553 * side effects - notifies source_p if the K-line already exists
554 */
555 /*
556 * Note: This currently works if the new K-line is a special case of an
557 * existing K-line, but not the other way round. To do that we would
558 * have to walk the hash and check every existing K-line. -A1kmm.
559 */
560 static int
561 already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
562 {
563 const char *reason;
564 struct irc_ssaddr iphost, *piphost;
565 struct AccessItem *aconf;
566 int t;
567
568 if ((t = parse_netmask(lhost, &iphost, &t)) != HM_HOST)
569 {
570 #ifdef IPV6
571 if (t == HM_IPV6)
572 t = AF_INET6;
573 else
574 #endif
575 t = AF_INET;
576 piphost = &iphost;
577 }
578 else
579 {
580 t = 0;
581 piphost = NULL;
582 }
583
584 if ((aconf = find_conf_by_address(lhost, piphost, CONF_KILL, t, luser, NULL)))
585 {
586 if (warn)
587 {
588 reason = aconf->reason ? aconf->reason : "No reason";
589 sendto_one(source_p,
590 ":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s",
591 me.name, source_p->name, luser, lhost, aconf->user,
592 aconf->host, reason);
593 }
594 return(1);
595 }
596
597 return(0);
598 }
599
600 #ifndef IPV6
601 static char *
602 make_cidr(char *dlhost, struct Client *target_p)
603 {
604 static char cidr_form_host[HOSTLEN + 2];
605 char *p;
606
607 strlcpy(cidr_form_host, inetntoa((const char *)&target_p->localClient->ip),
608 sizeof(cidr_form_host));
609
610 if ((p = strchr(cidr_form_host,'.')) == NULL)
611 return(NULL);
612
613 /* 192. <- p */
614 p++;
615 if ((p = strchr(p,'.')) == NULL)
616 return(NULL);
617
618 /* 192.168. <- p */
619 p++;
620 if ((p = strchr(p,'.')) == NULL)
621 return(NULL);
622
623 /* 192.168.0. <- p */
624 p++;
625 *p++ = '0';
626 *p++ = '/';
627 *p++ = '2';
628 *p++ = '4';
629 *p++ = '\0';
630
631 return(cidr_form_host);
632 }
633 #endif
634
635 /*
636 ** mo_unkline
637 ** Added Aug 31, 1997
638 ** common (Keith Fralick) fralick@gate.net
639 **
640 ** parv[0] = sender
641 ** parv[1] = address to remove
642 *
643 *
644 */
645 static void
646 mo_unkline(struct Client *client_p,struct Client *source_p,
647 int parc, char *parv[])
648 {
649 char *target_server = NULL;
650 char *user, *host;
651
652 if (!IsOperUnkline(source_p))
653 {
654 sendto_one(source_p, form_str(ERR_NOPRIVS),
655 me.name, source_p->name, "unkline");
656 return;
657 }
658
659 if (parc < 2 || EmptyString(parv[1]))
660 {
661 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
662 me.name, source_p->name, "UNKLINE");
663 return;
664 }
665
666 if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user,
667 &host, NULL, &target_server, NULL) < 0)
668 return;
669
670 if (target_server != NULL)
671 {
672 sendto_match_servs(source_p, target_server, CAP_UNKLN,
673 "UNKLINE %s %s %s",
674 target_server, user, host);
675
676 /* Allow ON to apply local unkline as well if it matches */
677 if (!match(target_server, me.name))
678 return;
679 }
680 else
681 cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE,
682 "%s %s", user, host);
683
684 if (remove_tkline_match(host, user))
685 {
686 sendto_one(source_p,
687 ":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines",
688 me.name, source_p->name, user, host);
689 sendto_realops_flags(UMODE_ALL, L_ALL,
690 "%s has removed the temporary K-Line for: [%s@%s]",
691 get_oper_name(source_p), user, host);
692 ilog(L_NOTICE, "%s removed temporary K-Line for [%s@%s]",
693 source_p->name, user, host);
694 return;
695 }
696
697 if (remove_conf_line(KLINE_TYPE, source_p, user, host) > 0)
698 {
699 sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed",
700 me.name, source_p->name, user,host);
701 sendto_realops_flags(UMODE_ALL, L_ALL,
702 "%s has removed the K-Line for: [%s@%s]",
703 get_oper_name(source_p), user, host);
704 ilog(L_NOTICE, "%s removed K-Line for [%s@%s]",
705 source_p->name, user, host);
706 }
707 else
708 sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
709 me.name, source_p->name, user, host);
710 }
711
712 /* me_unkline()
713 *
714 * inputs - server
715 * - client
716 * - parc
717 * - parv
718 * outputs - none
719 * side effects - if server is authorized, kline is removed
720 * does not propagate message
721 */
722 static void
723 me_unkline(struct Client *client_p, struct Client *source_p,
724 int parc, char *parv[])
725 {
726 const char *kuser, *khost;
727
728 if (parc != 4)
729 return;
730
731 kuser = parv[2];
732 khost = parv[3];
733
734 if (!IsClient(source_p) || !match(parv[1], me.name))
735 return;
736
737 if (find_matching_name_conf(ULINE_TYPE,
738 source_p->servptr->name,
739 source_p->username, source_p->host,
740 SHARED_UNKLINE))
741 {
742 if (remove_tkline_match(khost, kuser))
743 {
744 sendto_one(source_p,
745 ":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines",
746 me.name, source_p->name, kuser, khost);
747 sendto_realops_flags(UMODE_ALL, L_ALL,
748 "%s has removed the temporary K-Line for: [%s@%s]",
749 get_oper_name(source_p), kuser, khost);
750 ilog(L_NOTICE, "%s removed temporary K-Line for [%s@%s]",
751 source_p->name, kuser, khost);
752 return;
753 }
754
755 if (remove_conf_line(KLINE_TYPE, source_p, kuser, khost) > 0)
756 {
757 sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed",
758 me.name, source_p->name, kuser, khost);
759 sendto_realops_flags(UMODE_ALL, L_ALL,
760 "%s has removed the K-Line for: [%s@%s]",
761 get_oper_name(source_p), kuser, khost);
762
763 ilog(L_NOTICE, "%s removed K-Line for [%s@%s]",
764 source_p->name, kuser, khost);
765 }
766 else
767 sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
768 me.name, source_p->name, kuser, khost);
769 }
770 }
771
772 /* ms_unkline - propagates and handles a remote unkline message */
773 static void
774 ms_unkline(struct Client *client_p, struct Client *source_p,
775 int parc, char *parv[])
776 {
777 if (parc != 4)
778 return;
779
780 sendto_match_servs(source_p, parv[1], CAP_UNKLN,
781 "UNKLINE %s %s %s",
782 parv[1], parv[2], parv[3]);
783
784 me_unkline(client_p, source_p, parc, parv);
785 }
786
787 /* static int remove_tkline_match(const char *host, const char *user)
788 * Input: A hostname, a username to unkline.
789 * Output: returns YES on success, NO if no tkline removed.
790 * Side effects: Any matching tklines are removed.
791 */
792 static int
793 remove_tkline_match(const char *host, const char *user)
794 {
795 struct AccessItem *tk_c;
796 dlink_node *tk_n;
797 struct irc_ssaddr addr, caddr;
798 int nm_t, cnm_t, bits, cbits;
799 nm_t = parse_netmask(host, &addr, &bits);
800
801 DLINK_FOREACH(tk_n, temporary_klines.head)
802 {
803 tk_c = &((struct ConfItem *)(tk_n->data))->conf.AccessItem;
804 cnm_t = parse_netmask(tk_c->host, &caddr, &cbits);
805 if (cnm_t != nm_t || irccmp(user, tk_c->user))
806 continue;
807 if ((nm_t==HM_HOST && !irccmp(tk_c->host, host)) ||
808 (nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits))
809 #ifdef IPV6
810 || (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits))
811 #endif
812 )
813 {
814 dlinkDelete(tk_n, &temporary_klines);
815 delete_one_address_conf(tk_c->host, tk_c);
816 return(YES);
817 }
818 }
819
820 return(NO);
821 }
822
823 /* static int remove_tdline_match(const char *host, const char *user)
824 * Input: An ip to undline.
825 * Output: returns YES on success, NO if no tdline removed.
826 * Side effects: Any matching tdlines are removed.
827 */
828 static int
829 remove_tdline_match(const char *cidr)
830 {
831 struct AccessItem *td_conf;
832 dlink_node *td_node;
833 struct irc_ssaddr addr, caddr;
834 int nm_t, cnm_t, bits, cbits;
835 nm_t = parse_netmask(cidr, &addr, &bits);
836
837 DLINK_FOREACH(td_node, temporary_dlines.head)
838 {
839 td_conf = &((struct ConfItem *)(td_node->data))->conf.AccessItem;
840 cnm_t = parse_netmask(td_conf->host, &caddr, &cbits);
841
842 if (cnm_t != nm_t)
843 continue;
844
845 if((nm_t==HM_HOST && !irccmp(td_conf->host, cidr)) ||
846 (nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits))
847 #ifdef IPV6
848 || (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits))
849 #endif
850 )
851 {
852 dlinkDelete(td_node, &temporary_dlines);
853 delete_one_address_conf(td_conf->host, td_conf);
854 return(YES);
855 }
856 }
857
858 return(NO);
859 }
860
861 /*
862 ** m_undline
863 ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
864 ** based totally on m_unkline
865 ** added to hybrid-7 7/11/2000 --is
866 **
867 ** parv[0] = sender nick
868 ** parv[1] = dline to remove
869 */
870 static void
871 mo_undline(struct Client *client_p, struct Client *source_p,
872 int parc, char *parv[])
873 {
874 const char *cidr;
875
876 if (!IsOperUnkline(source_p))
877 {
878 sendto_one(source_p, form_str(ERR_NOPRIVS),
879 me.name, source_p->name, "undline");
880 return;
881 }
882
883 cidr = parv[1];
884
885 if (remove_tdline_match(cidr))
886 {
887 sendto_one(source_p,
888 ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
889 me.name, source_p->name, cidr);
890 sendto_realops_flags(UMODE_ALL, L_ALL,
891 "%s has removed the temporary D-Line for: [%s]",
892 get_oper_name(source_p), cidr);
893 ilog(L_NOTICE, "%s removed temporary D-Line for [%s]", source_p->name, cidr);
894 return;
895 }
896
897 if (remove_conf_line(DLINE_TYPE, source_p, cidr, NULL) > 0)
898 {
899 sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
900 me.name, source_p->name, cidr);
901 sendto_realops_flags(UMODE_ALL, L_ALL,
902 "%s has removed the D-Line for: [%s]",
903 get_oper_name(source_p), cidr);
904 ilog(L_NOTICE, "%s removed D-Line for [%s]",
905 get_oper_name(source_p), cidr);
906 }
907 else
908 sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
909 me.name, source_p->name, cidr);
910 }

Properties

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