ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_rxline.c
Revision: 1156
Committed: Tue Aug 9 20:29:20 2011 UTC (15 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 11332 byte(s)
Log Message:
- create ircd-hybrid-8 "branch"

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_rxline.c: xlines a user with regular expression support.
4     *
5     * Copyright (C) 2005 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     static void mo_rxline(struct Client *, struct Client *, int, char *[]);
50     static void ms_rxline(struct Client *, struct Client *, int, char *[]);
51     static void mo_unrxline(struct Client *, struct Client *, int, char *[]);
52     static void ms_unrxline(struct Client *, struct Client *, int, char *[]);
53    
54     static int valid_xline(struct Client *, char *, char *, int);
55     static void write_rxline(struct Client *, const char *, char *, time_t);
56     static void remove_xline(struct Client *, char *);
57     static int remove_txline(const char *);
58    
59     struct Message rxline_msgtab = {
60     "RXLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
61     { m_unregistered, m_not_oper, ms_rxline, m_ignore, mo_rxline, m_ignore }
62     };
63    
64     struct Message unrxline_msgtab = {
65     "UNRXLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
66     { m_unregistered, m_not_oper, ms_unrxline, m_ignore, mo_unrxline, m_ignore }
67     };
68    
69     void
70     _modinit(void)
71     {
72     mod_add_cmd(&rxline_msgtab);
73     mod_add_cmd(&unrxline_msgtab);
74     }
75    
76     void
77     _moddeinit(void)
78     {
79     mod_del_cmd(&rxline_msgtab);
80     mod_del_cmd(&unrxline_msgtab);
81     }
82    
83 knight 31 const char *_version = "$Revision$";
84 adx 30
85     static int
86     already_placed_rxline(struct Client *source_p, const char *gecos)
87     {
88     const dlink_node *ptr = NULL;
89    
90     DLINK_FOREACH(ptr, rxconf_items.head)
91     {
92     struct ConfItem *aptr = ptr->data;
93     const struct MatchItem *match_item = map_to_conf(aptr);
94    
95     if (!strcmp(gecos, aptr->name))
96     {
97     sendto_one(source_p, ":%s NOTICE %s :[%s] already RX-Lined by [%s] - %s",
98     me.name, source_p->name, gecos,
99     aptr->name, match_item->reason);
100     return 1;
101     }
102     }
103    
104     return 0;
105     }
106    
107     /* mo_rxline()
108     *
109     * inputs - pointer to server
110     * - pointer to client
111     * - parameter count
112     * - parameter list
113     * output -
114     * side effects - regular expression x line is added
115     *
116     */
117     static void
118     mo_rxline(struct Client *client_p, struct Client *source_p,
119     int parc, char *parv[])
120     {
121     char *reason = NULL;
122     char *gecos = NULL;
123     char *target_server = NULL;
124     time_t tkline_time = 0;
125    
126     if (!IsOperX(source_p))
127     {
128     sendto_one(source_p, form_str(ERR_NOPRIVS),
129     me.name, source_p->name, "rxline");
130     return;
131     }
132    
133     if (parse_aline("RXLINE", source_p, parc, parv, AWILD, &gecos,
134     NULL, &tkline_time, NULL, &reason) < 0)
135     return;
136    
137     if (target_server != NULL)
138     {
139     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
140     "RXLINE %s %s %d :%s",
141     target_server, gecos, (int)tkline_time, reason);
142    
143     /* Allow ON to apply local rxline as well if it matches */
144     if (!match(target_server, me.name))
145     return;
146     }
147    
148     #if 0
149     cluster_a_line(source_p, "RXLINE", CAP_KLN, SHARED_XLINE,
150     "%s 0 :%s", gecos, reason);
151     #endif
152    
153     if (!valid_xline(source_p, gecos, reason, 0))
154     return;
155    
156     if (!already_placed_rxline(source_p, gecos))
157     write_rxline(source_p, gecos, reason, tkline_time);
158     }
159    
160     /* ms_rxline()
161     *
162     * inputs - oper, target server, rxline, {type}, reason
163     * deprecate {type} reserve for temp xlines later? XXX
164     *
165     * outputs - none
166     * side effects - propagates rxline, applies it if we are a target
167     */
168     static void
169     ms_rxline(struct Client *client_p, struct Client *source_p,
170     int parc, char *parv[])
171     {
172     int t_sec = 0;
173    
174     if (parc != 5 || EmptyString(parv[4]))
175     return;
176    
177     if (!IsClient(source_p))
178     return;
179    
180     if (!valid_xline(source_p, parv[2], parv[4], 0))
181     return;
182    
183     t_sec = atoi(parv[3]);
184     /* XXX kludge! */
185     if (t_sec < 3)
186     t_sec = 0;
187    
188     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
189     "RXLINE %s %s %s :%s",
190     parv[1], parv[2], parv[3], parv[4]);
191    
192     if (!match(parv[1], me.name))
193     return;
194    
195     if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
196     source_p->username, source_p->host,
197     SHARED_XLINE))
198     if (!already_placed_rxline(source_p, parv[2]))
199     write_rxline(source_p, parv[2], parv[4], t_sec);
200     }
201    
202     static void
203     mo_unrxline(struct Client *client_p, struct Client *source_p,
204     int parc, char *parv[])
205     {
206     char *gecos = NULL;
207     char *target_server = NULL;
208    
209     if (!IsOperX(source_p))
210     {
211     sendto_one(source_p, form_str(ERR_NOPRIVS),
212     me.name, source_p->name, "unrxline");
213     return;
214     }
215    
216     if (parse_aline("UNRXLINE", source_p, parc, parv, 0, &gecos,
217     NULL, NULL, &target_server, NULL) < 0)
218     return;
219    
220     if (target_server != NULL)
221     {
222    
223     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
224     "UNRXLINE %s %s", target_server, gecos);
225    
226     /* Allow ON to apply local unrxline as well if it matches */
227     if (!match(target_server, me.name))
228     return;
229     }
230    
231     #if 0
232     cluster_a_line(source_p, "UNRXLINE", CAP_CLUSTER, SHARED_UNXLINE,
233     "%s", gecos);
234     #endif
235    
236     remove_xline(source_p, gecos);
237     }
238    
239     /* ms_unrxline()
240     *
241     * inputs - oper, target server, gecos
242     * outputs - none
243     * side effects - propagates unrxline, applies it if we are a target
244     */
245     static void
246     ms_unrxline(struct Client *client_p, struct Client *source_p,
247     int parc, char *parv[])
248     {
249     if (parc != 3 || EmptyString(parv[2]))
250     return;
251    
252     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
253     "UNRXLINE %s %s",
254     parv[1], parv[2]);
255    
256     if (!IsClient(source_p) || !match(parv[1], me.name))
257     return;
258    
259     if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
260     source_p->username, source_p->host,
261     SHARED_UNXLINE))
262     remove_xline(source_p, parv[2]);
263     }
264    
265     /* valid_xline()
266     *
267     * inputs - client to complain to, gecos, reason, whether to complain
268     * outputs - 1 for valid, else 0
269     * side effects - complains to client, when warn != 0
270     */
271     static int
272     valid_xline(struct Client *source_p, char *gecos, char *reason, int warn)
273     {
274     if (EmptyString(reason))
275     {
276     if (warn)
277     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
278     me.name, source_p->name, "RXLINE");
279     return 0;
280     }
281    
282     if (strchr(gecos, '"'))
283     {
284     sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"'",
285     me.name, source_p->name);
286     return 0;
287     }
288    
289     if (!valid_wild_card_simple(gecos))
290     {
291     if (warn)
292     sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the rxline",
293     me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple);
294    
295     return 0;
296     }
297    
298     return 1;
299     }
300    
301     /* write_rxline()
302     *
303     * inputs - client taking credit for rxline
304     * outputs - none
305     * side effects - when successful, adds an rxline to the conf
306     */
307     static void
308     write_rxline(struct Client *source_p, const char *gecos, char *reason,
309     time_t tkline_time)
310     {
311     struct ConfItem *conf = NULL;
312     struct MatchItem *match_item = NULL;
313     const char *current_date = NULL;
314     time_t cur_time = 0;
315 michael 1011 void *exp_gecos = NULL;
316 adx 30 const char *errptr = NULL;
317    
318     if (!(exp_gecos = ircd_pcre_compile(gecos, &errptr)))
319     {
320     sendto_realops_flags(UMODE_ALL, L_ALL,
321     "Failed to add regular expression based X-Line: %s", errptr);
322     return;
323     }
324    
325     conf = make_conf_item(RXLINE_TYPE);
326     conf->regexpname = exp_gecos;
327    
328     match_item = map_to_conf(conf);
329    
330     DupString(conf->name, gecos);
331     DupString(match_item->reason, reason);
332     DupString(match_item->oper_reason, ""); /* XXX */
333    
334     cur_time = CurrentTime;
335     current_date = smalldate(cur_time);
336    
337     if (tkline_time)
338     {
339     sendto_realops_flags(UMODE_ALL, L_ALL,
340     "%s added temporary %d min. RX-Line for [%s] [%s]",
341     get_oper_name(source_p), (int)tkline_time/60,
342     conf->name, match_item->reason);
343     sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. RX-Line [%s]",
344     MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
345     source_p->name, (int)tkline_time/60, conf->name);
346     ilog(L_TRACE, "%s added temporary %d min. RX-Line for [%s] [%s]",
347     source_p->name, (int)tkline_time/60,
348     conf->name, match_item->reason);
349     match_item->hold = CurrentTime + tkline_time;
350     add_temp_line(conf);
351     }
352     else
353     write_conf_line(source_p, conf, current_date, cur_time);
354     rehashed_klines = 1;
355     }
356    
357     static void
358     remove_xline(struct Client *source_p, char *gecos)
359     {
360     /* XXX use common temporary un function later */
361     if (remove_txline(gecos))
362     {
363     sendto_one(source_p,
364     ":%s NOTICE %s :Un-rxlined [%s] from temporary RX-Lines",
365     me.name, source_p->name, gecos);
366     sendto_realops_flags(UMODE_ALL, L_ALL,
367     "%s has removed the temporary RX-Line for: [%s]",
368     get_oper_name(source_p), gecos);
369     ilog(L_NOTICE, "%s removed temporary RX-Line for [%s]",
370     source_p->name, gecos);
371     return;
372     }
373    
374     if (remove_conf_line(RXLINE_TYPE, source_p, gecos, NULL) > 0)
375     {
376     sendto_one(source_p, ":%s NOTICE %s :RX-Line for [%s] is removed",
377     me.name, source_p->name, gecos);
378     sendto_realops_flags(UMODE_ALL, L_ALL,
379     "%s has removed the RX-Line for: [%s]",
380     get_oper_name(source_p), gecos);
381     ilog(L_NOTICE, "%s removed RX-Line for [%s]",
382     get_oper_name(source_p), gecos);
383     }
384     else
385     sendto_one(source_p, ":%s NOTICE %s :No RX-Line for %s",
386     me.name, source_p->name, gecos);
387     }
388    
389     /* static int remove_tkline_match(const char *host, const char *user)
390     *
391     * Inputs: gecos
392     * Output: returns YES on success, NO if no tkline removed.
393     * Side effects: Any matching tklines are removed.
394     */
395     static int
396     remove_txline(const char *const gecos)
397     {
398     dlink_node *ptr = NULL;
399    
400     DLINK_FOREACH(ptr, temporary_rxlines.head)
401     {
402     struct ConfItem *conf = ptr->data;
403    
404     if (!strcmp(gecos, conf->name))
405     {
406     dlinkDelete(ptr, &temporary_rxlines);
407     free_dlink_node(ptr);
408     delete_conf_item(conf);
409     return 1;
410     }
411     }
412    
413     return 0;
414     }

Properties

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