ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_kline.c
Revision: 615
Committed: Sun May 21 12:44:31 2006 UTC (17 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 26692 byte(s)
Log Message:
- Moved logging and announcement of *LINES out of csvlib into their
  specific modules where they belong to.


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

Properties

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