ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_xline.c
Revision: 139
Committed: Sun Oct 16 06:01:13 2005 UTC (20 years, 9 months ago) by db
Content type: text/x-csrc
File size: 12424 byte(s)
Log Message:
- get rid of map_conf_item and unmap_conf_item
- Use an union in struct ConfItem, but only allocate memory needed


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

Properties

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