ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 1666
Committed: Sun Nov 18 17:03:18 2012 UTC (12 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 11941 byte(s)
Log Message:
- Cleanup unused header file includes
- Fixed minor compile warning in conf.c

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

Properties

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