ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_kline.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (14 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 15940 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

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

Properties

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