ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (14 years, 10 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_xline.c
File size: 12378 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_xline.c: xlines an 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 "parse.h"
46     #include "modules.h"
47     #include "resv.h"
48    
49    
50     static int valid_xline(struct Client *, char *, char *, int);
51     static void write_xline(struct Client *, char *, char *, time_t);
52     static void remove_xline(struct Client *, char *);
53     static int remove_txline_match(const char *);
54    
55     static void relay_xline(struct Client *, char *[]);
56    
57     /* mo_xline()
58     *
59     * inputs - pointer to server
60     * - pointer to client
61     * - parameter count
62     * - parameter list
63     * output -
64     * side effects - x line is added
65     *
66     */
67     static void
68     mo_xline(struct Client *client_p, struct Client *source_p,
69     int parc, char *parv[])
70     {
71     char *reason = NULL;
72     char *gecos = NULL;
73     struct ConfItem *conf = NULL;
74     struct MatchItem *match_item = NULL;
75     char *target_server = NULL;
76     time_t tkline_time = 0;
77    
78 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_X))
79 adx 30 {
80     sendto_one(source_p, form_str(ERR_NOPRIVS),
81     me.name, source_p->name, "xline");
82     return;
83     }
84    
85     /*
86     * XLINE <gecos> <time> ON <mask> :<reason>
87     * XLINE <gecos> ON <mask> :<reason>
88     */
89     if (parse_aline("XLINE", source_p, parc, parv, AWILD, &gecos, NULL,
90     &tkline_time, &target_server, &reason) < 0)
91     return;
92    
93     if (target_server != NULL)
94     {
95     /* if a given expire time is given, ENCAP it */
96     if (tkline_time != 0)
97     sendto_match_servs(source_p, target_server, CAP_ENCAP,
98     "ENCAP %s XLINE %d %s 0 :%s",
99     target_server, (int)tkline_time, gecos, reason);
100     else
101     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
102     "XLINE %s %s %d :%s",
103     target_server, gecos, (int)tkline_time, reason);
104    
105     /* Allow ON to apply local xline as well if it matches */
106     if (!match(target_server, me.name))
107     return;
108     }
109     else
110     {
111     if (tkline_time != 0)
112     cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE,
113     "XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason);
114     else
115     cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE,
116     "%s 0 :%s", gecos, reason);
117     }
118    
119     if (!valid_xline(source_p, gecos, reason, 0))
120     return;
121    
122     if ((conf = find_matching_name_conf(XLINE_TYPE, gecos,
123     NULL, NULL, 0)) != NULL)
124     {
125     match_item = map_to_conf(conf);
126    
127     sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
128     me.name, source_p->name, gecos,
129     conf->name, match_item->reason);
130     return;
131     }
132    
133     write_xline(source_p, gecos, reason, tkline_time);
134     }
135    
136     /* ms_xline()
137     *
138     * inputs - oper, target server, xline, {type}, reason
139     * deprecate {type} reserve for temp xlines later? XXX
140     *
141     * outputs - none
142     * side effects - propagates xline, applies it if we are a target
143     */
144     static void
145     ms_xline(struct Client *client_p, struct Client *source_p,
146     int parc, char *parv[])
147     {
148     if (parc != 5 || EmptyString(parv[4]))
149     return;
150    
151     if (!IsClient(source_p))
152     return;
153    
154     if (!valid_xline(source_p, parv[2], parv[4], 0))
155     return;
156    
157     relay_xline(source_p, parv);
158     }
159    
160     /* me_xline()
161     *
162     * inputs - server
163     * - client (oper)
164     * - parc number of arguments
165     * - parv list of arguments
166     * via parv[]
167     * parv[1] = target
168     * parv[2] = server
169     * parv[3] = xline
170     * parv[4] = time
171     * parv[5] = reason
172     *
173     * outputs - none
174     * side effects -
175     */
176     static void
177     me_xline(struct Client *client_p, struct Client *source_p,
178     int parc, char *parv[])
179     {
180     if (!IsClient(source_p) || parc != 5)
181     return;
182    
183     relay_xline(source_p, parv);
184     }
185    
186     static void
187     relay_xline(struct Client *source_p, char *parv[])
188     {
189     struct ConfItem *conf;
190     struct MatchItem *match_item;
191     int t_sec;
192    
193     t_sec = atoi(parv[3]);
194     /* XXX kludge! */
195     if (t_sec < 3)
196     t_sec = 0;
197    
198     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
199     "XLINE %s %s %s :%s",
200     parv[1], parv[2], parv[3], parv[4]);
201    
202 michael 382 if (!match(parv[1], me.name))
203 adx 30 return;
204    
205     if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
206     source_p->username, source_p->host,
207     SHARED_XLINE))
208     {
209     if ((conf = find_matching_name_conf(XLINE_TYPE, parv[2],
210     NULL, NULL, 0)) != NULL)
211     {
212     match_item = map_to_conf(conf);
213     sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
214     ID_or_name(&me, source_p->from),
215     ID_or_name(source_p, source_p->from),
216     parv[2], conf->name, match_item->reason);
217     return;
218     }
219    
220     write_xline(source_p, parv[2], parv[4], t_sec);
221     }
222     }
223    
224     /* mo_unxline()
225     *
226     * inputs - pointer to server
227     * - pointer to client
228     * - parameter count
229     * - parameter list
230     * output -
231     * side effects - removes a xline
232     */
233     static void
234     mo_unxline(struct Client *client_p, struct Client *source_p,
235     int parc, char *parv[])
236     {
237     char *gecos = NULL;
238     char *target_server = NULL;
239    
240 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_X))
241 adx 30 {
242     sendto_one(source_p, form_str(ERR_NOPRIVS),
243     me.name, source_p->name, "unxline");
244     return;
245     }
246    
247     /* UNXLINE bill ON irc.server.com */
248     if (parse_aline("UNXLINE", source_p, parc, parv, 0, &gecos,
249     NULL, NULL, &target_server, NULL) < 0)
250     return;
251    
252     if (target_server != NULL)
253     {
254     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
255     "UNXLINE %s %s", target_server, gecos);
256    
257     /* Allow ON to apply local unxline as well if it matches */
258     if (!match(target_server, me.name))
259     return;
260     }
261     else
262     cluster_a_line(source_p, "UNXLINE", CAP_CLUSTER, SHARED_UNXLINE,
263     "%s", gecos);
264    
265     remove_xline(source_p, gecos);
266     }
267    
268     /* ms_unxline()
269     *
270     * inputs - oper, target server, gecos
271     * outputs - none
272     * side effects - propagates unxline, applies it if we are a target
273     */
274     static void
275     ms_unxline(struct Client *client_p, struct Client *source_p,
276     int parc, char *parv[])
277     {
278     if (parc != 3)
279     return;
280    
281     if (!IsClient(source_p) || EmptyString(parv[2]))
282     return;
283    
284     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
285     "UNXLINE %s %s", parv[1], parv[2]);
286    
287     if (!match(parv[1], me.name))
288     return;
289    
290     if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
291     source_p->username, source_p->host,
292     SHARED_UNXLINE))
293     remove_xline(source_p, parv[2]);
294     }
295    
296     /* valid_xline()
297     *
298     * inputs - client to complain to, gecos, reason, whether to complain
299     * outputs - 1 for valid, else 0
300     * side effects - complains to client, when warn != 0
301     */
302     static int
303     valid_xline(struct Client *source_p, char *gecos, char *reason, int warn)
304     {
305     if (EmptyString(reason))
306     {
307     if (warn)
308     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
309     me.name, source_p->name, "XLINE");
310     return 0;
311     }
312    
313     if (strchr(gecos, '"'))
314     {
315     sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"'",
316     me.name, source_p->name);
317     return 0;
318     }
319    
320     if (!valid_wild_card_simple(gecos))
321     {
322     if (warn)
323     sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the xline",
324     me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple);
325    
326     return 0;
327     }
328    
329     return 1;
330     }
331    
332     /* write_xline()
333     *
334     * inputs - client taking credit for xline, gecos, reason, xline type
335     * outputs - none
336     * side effects - when successful, adds an xline to the conf
337     */
338     static void
339     write_xline(struct Client *source_p, char *gecos, char *reason,
340     time_t tkline_time)
341     {
342     struct ConfItem *conf;
343     struct MatchItem *match_item;
344     const char *current_date;
345     time_t cur_time;
346    
347     conf = make_conf_item(XLINE_TYPE);
348     match_item = map_to_conf(conf);
349    
350     collapse(gecos);
351     DupString(conf->name, gecos);
352     DupString(match_item->reason, reason);
353     DupString(match_item->oper_reason, ""); /* XXX */
354     cur_time = CurrentTime;
355     current_date = smalldate(cur_time);
356    
357     if (tkline_time != 0)
358     {
359     sendto_realops_flags(UMODE_ALL, L_ALL,
360     "%s added temporary %d min. X-Line for [%s] [%s]",
361     get_oper_name(source_p), (int)tkline_time/60,
362     conf->name, match_item->reason);
363     sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]",
364     MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
365     source_p->name, (int)tkline_time/60, conf->name);
366     ilog(L_TRACE, "%s added temporary %d min. X-Line for [%s] [%s]",
367     source_p->name, (int)tkline_time/60,
368     conf->name, match_item->reason);
369     match_item->hold = CurrentTime + tkline_time;
370     add_temp_line(conf);
371     }
372     else
373     write_conf_line(source_p, conf, current_date, cur_time);
374     rehashed_klines = 1;
375     }
376    
377     static void
378     remove_xline(struct Client *source_p, char *gecos)
379     {
380     /* XXX use common temporary un function later */
381     if (remove_txline_match(gecos))
382     {
383     sendto_one(source_p,
384     ":%s NOTICE %s :Un-xlined [%s] from temporary X-Lines",
385     me.name, source_p->name, gecos);
386     sendto_realops_flags(UMODE_ALL, L_ALL,
387     "%s has removed the temporary X-Line for: [%s]",
388     get_oper_name(source_p), gecos);
389     ilog(L_NOTICE, "%s removed temporary X-Line for [%s]",
390     source_p->name, gecos);
391     return;
392     }
393    
394     if (remove_conf_line(XLINE_TYPE, source_p, gecos, NULL) > 0)
395     {
396     sendto_one(source_p, ":%s NOTICE %s :X-Line for [%s] is removed",
397     me.name, source_p->name, gecos);
398     sendto_realops_flags(UMODE_ALL, L_ALL,
399     "%s has removed the X-Line for: [%s]",
400     get_oper_name(source_p), gecos);
401     ilog(L_NOTICE, "%s removed X-Line for [%s]",
402     get_oper_name(source_p), gecos);
403     }
404     else
405     sendto_one(source_p, ":%s NOTICE %s :No X-Line for %s",
406     me.name, source_p->name, gecos);
407     }
408    
409     /* static int remove_tkline_match(const char *host, const char *user)
410     *
411     * Inputs: gecos
412     * Output: returns YES on success, NO if no tkline removed.
413     * Side effects: Any matching tklines are removed.
414     */
415     static int
416     remove_txline_match(const char *gecos)
417     {
418     dlink_node *ptr = NULL, *next_ptr = NULL;
419     struct ConfItem *conf = NULL;
420    
421     DLINK_FOREACH_SAFE(ptr, next_ptr, temporary_xlines.head)
422     {
423     conf = ptr->data;
424    
425     if (irccmp(gecos, conf->name) == 0)
426     {
427     dlinkDelete(ptr, &temporary_xlines);
428     free_dlink_node(ptr);
429     delete_conf_item(conf);
430    
431     return 1;
432     }
433     }
434    
435     return 0;
436     }
437 michael 1230
438     static struct Message xline_msgtab = {
439     "XLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
440     { m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore }
441     };
442    
443     static struct Message unxline_msgtab = {
444     "UNXLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
445     { m_unregistered, m_not_oper, ms_unxline, m_ignore, mo_unxline, m_ignore }
446     };
447    
448     static void
449     module_init(void)
450     {
451     mod_add_cmd(&xline_msgtab);
452     mod_add_cmd(&unxline_msgtab);
453     }
454    
455     static void
456     module_exit(void)
457     {
458     mod_del_cmd(&xline_msgtab);
459     mod_del_cmd(&unxline_msgtab);
460     }
461    
462     struct module module_entry = {
463     .node = { NULL, NULL, NULL },
464     .name = NULL,
465     .version = "$Revision$",
466     .handle = NULL,
467     .modinit = module_init,
468     .modexit = module_exit,
469     .flags = 0
470     };

Properties

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