ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_kline.c
Revision: 1121
Committed: Sun Jan 9 11:03:03 2011 UTC (13 years, 2 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.3/modules/m_kline.c
File size: 16159 byte(s)
Log Message:
- removed all instances of STATIC_MODULES since we don't have
  static modules anymore
- removed m_mkpasswd module from contrib

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 michael 1011 #include "list.h"
27 adx 30 #include "channel.h"
28     #include "client.h"
29     #include "common.h"
30     #include "irc_string.h"
31     #include "sprintf_irc.h"
32     #include "ircd.h"
33     #include "hostmask.h"
34     #include "numeric.h"
35     #include "fdlist.h"
36     #include "s_bsd.h"
37     #include "s_conf.h"
38     #include "s_log.h"
39     #include "s_misc.h"
40     #include "send.h"
41     #include "hash.h"
42     #include "handlers.h"
43     #include "s_serv.h"
44     #include "msg.h"
45     #include "s_gline.h"
46     #include "parse.h"
47     #include "modules.h"
48 michael 611 #include "irc_getnameinfo.h"
49 adx 30
50 michael 611
51 adx 30 static void me_kline(struct Client *, struct Client *, int, char **);
52     static void mo_kline(struct Client *, struct Client *, int, char **);
53     static void ms_kline(struct Client *, struct Client *, int, char **);
54     static void me_unkline(struct Client *, struct Client *, int, char **);
55     static void mo_unkline(struct Client *, struct Client *, int, char **);
56     static void ms_unkline(struct Client *, struct Client *, int, char **);
57    
58 michael 1058 static int already_placed_kline(struct Client *, const char *, const char *, int);
59     static void apply_kline(struct Client *, struct ConfItem *, const char *, time_t);
60     static void apply_tkline(struct Client *, struct ConfItem *, int);
61    
62     static char buffer[IRCD_BUFSIZE];
63 adx 30 static int remove_tkline_match(const char *, const char *);
64    
65     struct Message kline_msgtab = {
66     "KLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
67     {m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore}
68     };
69    
70     struct Message unkline_msgtab = {
71     "UNKLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
72     {m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore}
73     };
74    
75     void
76     _modinit(void)
77     {
78     mod_add_cmd(&kline_msgtab);
79     mod_add_cmd(&unkline_msgtab);
80     add_capability("KLN", CAP_KLN, 1);
81     add_capability("UNKLN", CAP_UNKLN, 1);
82     }
83    
84     void
85     _moddeinit(void)
86     {
87     mod_del_cmd(&kline_msgtab);
88     mod_del_cmd(&unkline_msgtab);
89     delete_capability("UNKLN");
90     delete_capability("KLN");
91     }
92    
93 knight 31 const char *_version = "$Revision$";
94 adx 30
95     /* mo_kline()
96     *
97     * inputs - pointer to server
98     * - pointer to client
99     * - parameter count
100     * - parameter list
101     * output -
102     * side effects - k line is added
103     */
104     static void
105     mo_kline(struct Client *client_p, struct Client *source_p,
106 michael 1058 int parc, char **parv)
107 adx 30 {
108     char *reason = NULL;
109     char *oper_reason;
110     char *user = NULL;
111     char *host = NULL;
112     const char *current_date;
113     char *target_server = NULL;
114     struct ConfItem *conf;
115     struct AccessItem *aconf;
116     time_t tkline_time = 0;
117     time_t cur_time;
118    
119     if (!IsOperK(source_p))
120     {
121     sendto_one(source_p, form_str(ERR_NOPRIVS),
122     me.name, source_p->name, "kline");
123     return;
124     }
125    
126     if (parse_aline("KLINE", source_p, parc, parv,
127     AWILD, &user, &host, &tkline_time, &target_server, &reason) < 0)
128     return;
129    
130     if (target_server != NULL)
131     {
132     if (HasID(source_p))
133     {
134 michael 885 sendto_server(NULL, NULL, CAP_KLN|CAP_TS6, NOCAPS,
135 adx 30 ":%s KLINE %s %lu %s %s :%s",
136     source_p->id, target_server, (unsigned long)tkline_time,
137     user, host, reason);
138 michael 885 sendto_server(NULL, NULL, CAP_KLN, CAP_TS6,
139 adx 30 ":%s KLINE %s %lu %s %s :%s",
140     source_p->name, target_server, (unsigned long)tkline_time,
141     user, host, reason);
142     }
143     else
144 michael 885 sendto_server(NULL, NULL, CAP_KLN, NOCAPS,
145 adx 30 ":%s KLINE %s %lu %s %s :%s",
146     source_p->name, target_server, (unsigned long)tkline_time,
147     user, host, reason);
148    
149     /* Allow ON to apply local kline as well if it matches */
150     if (!match(target_server, me.name))
151     return;
152     }
153     else
154     cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
155 michael 1058 "%d %s %s :%s", tkline_time, user, host, reason);
156 adx 30
157     if (already_placed_kline(source_p, user, host, YES))
158     return;
159    
160     /* Look for an oper reason */
161     if ((oper_reason = strchr(reason, '|')) != NULL)
162     *oper_reason++ = '\0';
163    
164     cur_time = CurrentTime;
165     current_date = smalldate(cur_time);
166     conf = make_conf_item(KLINE_TYPE);
167     aconf = map_to_conf(conf);
168    
169     DupString(aconf->host, host);
170     DupString(aconf->user, user);
171    
172     if (tkline_time != 0)
173     {
174     ircsprintf(buffer, "Temporary K-line %d min. - %s (%s)",
175     (int)(tkline_time/60), reason, current_date);
176     DupString(aconf->reason, buffer);
177    
178     if (oper_reason != NULL)
179     DupString(aconf->oper_reason, oper_reason);
180     apply_tkline(source_p, conf, tkline_time);
181     }
182     else
183     {
184     ircsprintf(buffer, "%s (%s)", reason, current_date);
185     DupString(aconf->reason, buffer);
186    
187     if (oper_reason != NULL)
188     DupString(aconf->oper_reason, oper_reason);
189     apply_kline(source_p, conf, current_date, cur_time);
190     }
191     }
192    
193     /* me_kline - handle remote kline. no propagation */
194     static void
195     me_kline(struct Client *client_p, struct Client *source_p,
196     int parc, char *parv[])
197     {
198     struct ConfItem *conf=NULL;
199     struct AccessItem *aconf=NULL;
200     int tkline_time;
201     const char* current_date;
202     time_t cur_time;
203     char *kuser, *khost, *kreason, *oper_reason;
204    
205 michael 352 if (parc != 6 || EmptyString(parv[5]))
206 adx 30 return;
207    
208     if (!match(parv[1], me.name))
209     return;
210    
211     tkline_time = valid_tkline(parv[2], TK_SECONDS);
212     kuser = parv[3];
213     khost = parv[4];
214     kreason = parv[5];
215    
216     if ((oper_reason = strchr(kreason, '|')) != NULL)
217     *oper_reason++ = '\0';
218    
219     cur_time = CurrentTime;
220     current_date = smalldate(cur_time);
221    
222     if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
223     source_p->username, source_p->host,
224     SHARED_KLINE))
225     {
226     if (!IsClient(source_p) ||
227     already_placed_kline(source_p, kuser, khost, YES))
228     return;
229    
230     conf = make_conf_item(KLINE_TYPE);
231     aconf = map_to_conf(conf);
232     DupString(aconf->host, khost);
233     DupString(aconf->user, kuser);
234    
235     if (tkline_time != 0)
236     {
237     ircsprintf(buffer, "Temporary K-line %d min. - %s (%s)",
238     (int)(tkline_time/60), kreason, current_date);
239     DupString(aconf->reason, buffer);
240    
241     if (oper_reason != NULL)
242     DupString(aconf->oper_reason, oper_reason);
243     apply_tkline(source_p, conf, tkline_time);
244     }
245     else
246     {
247     ircsprintf(buffer, "%s (%s)", kreason, current_date);
248     DupString(aconf->reason, buffer);
249    
250     if (oper_reason != NULL)
251     DupString(aconf->oper_reason, oper_reason);
252     apply_kline(source_p, conf, current_date, cur_time);
253     }
254     }
255     }
256    
257     static void
258     ms_kline(struct Client *client_p, struct Client *source_p,
259 michael 1058 int parc, char *parv[])
260 adx 30 {
261 michael 352 if (parc != 6 || EmptyString(parv[5]))
262 adx 30 return;
263    
264     /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
265     /* oper target_server tkline_time user host reason */
266     sendto_match_servs(source_p, parv[1], CAP_KLN,
267     "KLINE %s %s %s %s :%s",
268     parv[1], parv[2], parv[3], parv[4], parv[5]);
269    
270     me_kline(client_p, source_p, parc, parv);
271     }
272    
273     /* apply_kline()
274     *
275     * inputs -
276     * output - NONE
277     * side effects - kline as given, is added to the hashtable
278     * and conf file
279     */
280     static void
281     apply_kline(struct Client *source_p, struct ConfItem *conf,
282 michael 1058 const char *current_date, time_t cur_time)
283 adx 30 {
284     struct AccessItem *aconf = map_to_conf(conf);
285    
286     add_conf_by_address(CONF_KILL, aconf);
287     write_conf_line(source_p, conf, current_date, cur_time);
288     /* Now, activate kline against current online clients */
289     rehashed_klines = 1;
290     }
291    
292     /* apply_tkline()
293     *
294     * inputs -
295     * output - NONE
296     * side effects - tkline as given is placed
297     */
298     static void
299     apply_tkline(struct Client *source_p, struct ConfItem *conf,
300     int tkline_time)
301     {
302     struct AccessItem *aconf;
303    
304     aconf = (struct AccessItem *)map_to_conf(conf);
305     aconf->hold = CurrentTime + tkline_time;
306     add_temp_line(conf);
307     sendto_realops_flags(UMODE_ALL, L_ALL,
308     "%s added temporary %d min. K-Line for [%s@%s] [%s]",
309     get_oper_name(source_p), tkline_time/60,
310     aconf->user, aconf->host,
311     aconf->reason);
312     sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
313     MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
314     source_p->name, tkline_time/60, aconf->user, aconf->host);
315     ilog(L_TRACE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
316     source_p->name, tkline_time/60,
317     aconf->user, aconf->host, aconf->reason);
318     log_oper_action(LOG_TEMP_KLINE_TYPE, source_p, "[%s@%s] [%s]\n",
319     aconf->user, aconf->host, aconf->reason);
320     rehashed_klines = 1;
321     }
322    
323     /* already_placed_kline()
324     * inputs - user to complain to, username & host to check for
325     * outputs - returns 1 on existing K-line, 0 if doesn't exist
326     * side effects - notifies source_p if the K-line already exists
327     */
328     /*
329     * Note: This currently works if the new K-line is a special case of an
330     * existing K-line, but not the other way round. To do that we would
331     * have to walk the hash and check every existing K-line. -A1kmm.
332     */
333     static int
334     already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
335     {
336     const char *reason;
337     struct irc_ssaddr iphost, *piphost;
338     struct AccessItem *aconf;
339     int t;
340    
341     if ((t = parse_netmask(lhost, &iphost, &t)) != HM_HOST)
342     {
343     #ifdef IPV6
344     if (t == HM_IPV6)
345     t = AF_INET6;
346     else
347     #endif
348     t = AF_INET;
349     piphost = &iphost;
350     }
351     else
352     {
353     t = 0;
354     piphost = NULL;
355     }
356    
357     if ((aconf = find_conf_by_address(lhost, piphost, CONF_KILL, t, luser, NULL)))
358     {
359     if (warn)
360     {
361     reason = aconf->reason ? aconf->reason : "No reason";
362     sendto_one(source_p,
363     ":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s",
364     me.name, source_p->name, luser, lhost, aconf->user,
365     aconf->host, reason);
366     }
367     return(1);
368     }
369    
370     return(0);
371     }
372    
373     /*
374     ** mo_unkline
375     ** Added Aug 31, 1997
376     ** common (Keith Fralick) fralick@gate.net
377     **
378     ** parv[0] = sender
379     ** parv[1] = address to remove
380     *
381     *
382     */
383     static void
384     mo_unkline(struct Client *client_p,struct Client *source_p,
385     int parc, char *parv[])
386     {
387     char *target_server = NULL;
388     char *user, *host;
389    
390     if (!IsOperUnkline(source_p))
391     {
392     sendto_one(source_p, form_str(ERR_NOPRIVS),
393     me.name, source_p->name, "unkline");
394     return;
395     }
396    
397     if (parc < 2 || EmptyString(parv[1]))
398     {
399     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
400     me.name, source_p->name, "UNKLINE");
401     return;
402     }
403    
404     if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user,
405     &host, NULL, &target_server, NULL) < 0)
406     return;
407    
408     if (target_server != NULL)
409     {
410     sendto_match_servs(source_p, target_server, CAP_UNKLN,
411     "UNKLINE %s %s %s",
412     target_server, user, host);
413    
414     /* Allow ON to apply local unkline as well if it matches */
415     if (!match(target_server, me.name))
416     return;
417     }
418     else
419     cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE,
420 michael 1058 "%s %s", user, host);
421 adx 30
422     if (remove_tkline_match(host, user))
423     {
424     sendto_one(source_p,
425     ":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines",
426     me.name, source_p->name, user, host);
427     sendto_realops_flags(UMODE_ALL, L_ALL,
428     "%s has removed the temporary K-Line for: [%s@%s]",
429     get_oper_name(source_p), user, host);
430     ilog(L_NOTICE, "%s removed temporary K-Line for [%s@%s]",
431     source_p->name, user, host);
432     return;
433     }
434    
435     if (remove_conf_line(KLINE_TYPE, source_p, user, host) > 0)
436     {
437     sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed",
438 michael 1058 me.name, source_p->name, user,host);
439 adx 30 sendto_realops_flags(UMODE_ALL, L_ALL,
440 michael 1058 "%s has removed the K-Line for: [%s@%s]",
441     get_oper_name(source_p), user, host);
442 adx 30 ilog(L_NOTICE, "%s removed K-Line for [%s@%s]",
443 michael 1058 source_p->name, user, host);
444 adx 30 }
445     else
446     sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
447     me.name, source_p->name, user, host);
448     }
449    
450     /* me_unkline()
451     *
452     * inputs - server
453     * - client
454     * - parc
455     * - parv
456     * outputs - none
457     * side effects - if server is authorized, kline is removed
458     * does not propagate message
459     */
460     static void
461     me_unkline(struct Client *client_p, struct Client *source_p,
462     int parc, char *parv[])
463     {
464     const char *kuser, *khost;
465    
466     if (parc != 4)
467     return;
468    
469     kuser = parv[2];
470     khost = parv[3];
471    
472     if (!IsClient(source_p) || !match(parv[1], me.name))
473     return;
474    
475     if (find_matching_name_conf(ULINE_TYPE,
476     source_p->servptr->name,
477     source_p->username, source_p->host,
478     SHARED_UNKLINE))
479     {
480     if (remove_tkline_match(khost, kuser))
481     {
482     sendto_one(source_p,
483     ":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines",
484     me.name, source_p->name, kuser, khost);
485     sendto_realops_flags(UMODE_ALL, L_ALL,
486     "%s has removed the temporary K-Line for: [%s@%s]",
487     get_oper_name(source_p), kuser, khost);
488     ilog(L_NOTICE, "%s removed temporary K-Line for [%s@%s]",
489     source_p->name, kuser, khost);
490     return;
491     }
492    
493     if (remove_conf_line(KLINE_TYPE, source_p, kuser, khost) > 0)
494     {
495     sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed",
496     me.name, source_p->name, kuser, khost);
497     sendto_realops_flags(UMODE_ALL, L_ALL,
498     "%s has removed the K-Line for: [%s@%s]",
499     get_oper_name(source_p), kuser, khost);
500    
501     ilog(L_NOTICE, "%s removed K-Line for [%s@%s]",
502     source_p->name, kuser, khost);
503     }
504     else
505     sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
506     me.name, source_p->name, kuser, khost);
507     }
508     }
509    
510     /* ms_unkline - propagates and handles a remote unkline message */
511     static void
512     ms_unkline(struct Client *client_p, struct Client *source_p,
513     int parc, char *parv[])
514     {
515     if (parc != 4)
516     return;
517    
518     sendto_match_servs(source_p, parv[1], CAP_UNKLN,
519     "UNKLINE %s %s %s",
520     parv[1], parv[2], parv[3]);
521    
522     me_unkline(client_p, source_p, parc, parv);
523     }
524    
525     /* static int remove_tkline_match(const char *host, const char *user)
526     * Input: A hostname, a username to unkline.
527     * Output: returns YES on success, NO if no tkline removed.
528     * Side effects: Any matching tklines are removed.
529     */
530     static int
531     remove_tkline_match(const char *host, const char *user)
532     {
533     struct AccessItem *tk_c;
534     dlink_node *tk_n;
535     struct irc_ssaddr addr, caddr;
536     int nm_t, cnm_t, bits, cbits;
537     nm_t = parse_netmask(host, &addr, &bits);
538    
539     DLINK_FOREACH(tk_n, temporary_klines.head)
540     {
541     tk_c = map_to_conf(tk_n->data);
542     cnm_t = parse_netmask(tk_c->host, &caddr, &cbits);
543     if (cnm_t != nm_t || irccmp(user, tk_c->user))
544     continue;
545     if ((nm_t==HM_HOST && !irccmp(tk_c->host, host)) ||
546 michael 1058 (nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits))
547 adx 30 #ifdef IPV6
548 michael 1058 || (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits))
549 adx 30 #endif
550 michael 1058 )
551 adx 30 {
552 michael 1058 dlinkDelete(tk_n, &temporary_klines);
553     delete_one_address_conf(tk_c->host, tk_c);
554     return 1;
555 adx 30 }
556     }
557    
558 michael 1058 return 0;
559 adx 30 }

Properties

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