ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_kline.c
Revision: 613
Committed: Fri May 19 09:23:10 2006 UTC (20 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 25272 byte(s)
Log Message:
- Got rid of several pointless irc_getnameinfo() calls in places where we
  can simply use client->sockhost.
- Removed contrib/m_ltrace.c.  Use TRACE instead.
- Fixed compile errors in m_gline.c and m_info.c

File Contents

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

Properties

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