ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_xline.c
Revision: 470
Committed: Fri Feb 17 05:07:43 2006 UTC (20 years, 5 months ago) by db
Content type: text/x-csrc
File size: 12369 byte(s)
Log Message:
- fix compile errors with moved modules.h
- fix a few missing includes, msg.h and parse.h


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

Properties

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