ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 2820
Committed: Wed Jan 15 23:10:26 2014 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 12010 byte(s)
Log Message:
- Clean up all files in modules/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years
- Made module handlers int type for later use

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 2003-2014 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22 michael 2820 /*! \file m_xline.c
23     * \brief Includes required functions for processing the XLINE/UNXLINE command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "channel.h"
30     #include "client.h"
31     #include "irc_string.h"
32     #include "ircd.h"
33 michael 1632 #include "conf.h"
34 adx 30 #include "hostmask.h"
35     #include "numeric.h"
36     #include "fdlist.h"
37     #include "s_bsd.h"
38 michael 1309 #include "log.h"
39 adx 30 #include "s_misc.h"
40     #include "send.h"
41     #include "hash.h"
42     #include "s_serv.h"
43     #include "parse.h"
44     #include "modules.h"
45     #include "resv.h"
46 michael 1622 #include "conf_db.h"
47 michael 1666 #include "memory.h"
48 adx 30
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 michael 1622 static int remove_xline_match(const char *);
54 adx 30
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 michael 2820 static int
68 adx 30 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 michael 1632 struct MaskItem *conf = NULL;
74 adx 30 char *target_server = NULL;
75     time_t tkline_time = 0;
76    
77 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_X))
78 adx 30 {
79 michael 2820 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
80     source_p->name, "xline");
81     return 0;
82 adx 30 }
83    
84     /*
85     * XLINE <gecos> <time> ON <mask> :<reason>
86     * XLINE <gecos> ON <mask> :<reason>
87     */
88     if (parse_aline("XLINE", source_p, parc, parv, AWILD, &gecos, NULL,
89     &tkline_time, &target_server, &reason) < 0)
90 michael 2820 return 0;
91 adx 30
92     if (target_server != NULL)
93     {
94     /* if a given expire time is given, ENCAP it */
95     if (tkline_time != 0)
96     sendto_match_servs(source_p, target_server, CAP_ENCAP,
97 michael 2820 "ENCAP %s XLINE %d %s 0 :%s",
98     target_server, (int)tkline_time, gecos, reason);
99 adx 30 else
100     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
101 michael 2820 "XLINE %s %s %d :%s",
102     target_server, gecos, (int)tkline_time, reason);
103 adx 30
104     /* Allow ON to apply local xline as well if it matches */
105 michael 1652 if (match(target_server, me.name))
106 michael 2820 return 0;
107 adx 30 }
108 michael 2820 else
109 adx 30 {
110     if (tkline_time != 0)
111     cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE,
112 michael 2820 "XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason);
113 adx 30 else
114     cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE,
115 michael 2820 "%s 0 :%s", gecos, reason);
116 adx 30 }
117    
118     if (!valid_xline(source_p, gecos, reason, 0))
119 michael 2820 return 0;
120 adx 30
121 michael 2820 if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0)))
122 adx 30 {
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 michael 2820 return 0;
127 adx 30 }
128    
129     write_xline(source_p, gecos, reason, tkline_time);
130 michael 2820 return 0;
131 adx 30 }
132    
133     /* ms_xline()
134     *
135     * inputs - oper, target server, xline, {type}, reason
136     *
137     * outputs - none
138     * side effects - propagates xline, applies it if we are a target
139     */
140 michael 2820 static int
141 adx 30 ms_xline(struct Client *client_p, struct Client *source_p,
142     int parc, char *parv[])
143     {
144     if (parc != 5 || EmptyString(parv[4]))
145 michael 2820 return 0;
146 adx 30
147     if (!IsClient(source_p))
148 michael 2820 return 0;
149 adx 30
150     if (!valid_xline(source_p, parv[2], parv[4], 0))
151 michael 2820 return 0;
152 adx 30
153     relay_xline(source_p, parv);
154 michael 2820 return 0;
155 adx 30 }
156    
157     /* me_xline()
158     *
159     * inputs - server
160     * - client (oper)
161     * - parc number of arguments
162     * - parv list of arguments
163     * via parv[]
164     * parv[1] = target
165     * parv[2] = server
166     * parv[3] = xline
167     * parv[4] = time
168     * parv[5] = reason
169     *
170     * outputs - none
171 michael 2820 * side effects -
172 adx 30 */
173 michael 2820 static int
174 adx 30 me_xline(struct Client *client_p, struct Client *source_p,
175     int parc, char *parv[])
176     {
177     if (!IsClient(source_p) || parc != 5)
178 michael 2820 return 0;
179 adx 30
180     relay_xline(source_p, parv);
181 michael 2820 return 0;
182 adx 30 }
183    
184     static void
185     relay_xline(struct Client *source_p, char *parv[])
186     {
187 michael 1632 struct MaskItem *conf = NULL;
188 adx 30 int t_sec;
189    
190     t_sec = atoi(parv[3]);
191    
192     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
193     "XLINE %s %s %s :%s",
194     parv[1], parv[2], parv[3], parv[4]);
195    
196 michael 1652 if (match(parv[1], me.name))
197 adx 30 return;
198    
199 michael 1632 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
200 adx 30 source_p->username, source_p->host,
201     SHARED_XLINE))
202     {
203 michael 2820 if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], NULL, NULL, 0)))
204 adx 30 {
205     sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
206     ID_or_name(&me, source_p->from),
207     ID_or_name(source_p, source_p->from),
208 michael 1632 parv[2], conf->name, conf->reason);
209 adx 30 return;
210     }
211    
212     write_xline(source_p, parv[2], parv[4], t_sec);
213     }
214     }
215    
216     /* mo_unxline()
217     *
218     * inputs - pointer to server
219     * - pointer to client
220     * - parameter count
221     * - parameter list
222     * output -
223     * side effects - removes a xline
224     */
225 michael 2820 static int
226 adx 30 mo_unxline(struct Client *client_p, struct Client *source_p,
227     int parc, char *parv[])
228     {
229     char *gecos = NULL;
230     char *target_server = NULL;
231    
232 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_X))
233 adx 30 {
234 michael 2820 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
235     source_p->name, "xline");
236     return 0;
237 adx 30 }
238    
239     /* UNXLINE bill ON irc.server.com */
240     if (parse_aline("UNXLINE", source_p, parc, parv, 0, &gecos,
241     NULL, NULL, &target_server, NULL) < 0)
242 michael 2820 return 0;
243 adx 30
244     if (target_server != NULL)
245     {
246     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
247     "UNXLINE %s %s", target_server, gecos);
248    
249     /* Allow ON to apply local unxline as well if it matches */
250 michael 1652 if (match(target_server, me.name))
251 michael 2820 return 0;
252 adx 30 }
253     else
254     cluster_a_line(source_p, "UNXLINE", CAP_CLUSTER, SHARED_UNXLINE,
255 michael 2820 "%s", gecos);
256 adx 30
257     remove_xline(source_p, gecos);
258 michael 2820 return 0;
259 adx 30 }
260    
261     /* ms_unxline()
262     *
263     * inputs - oper, target server, gecos
264     * outputs - none
265     * side effects - propagates unxline, applies it if we are a target
266     */
267 michael 2820 static int
268 adx 30 ms_unxline(struct Client *client_p, struct Client *source_p,
269     int parc, char *parv[])
270     {
271     if (parc != 3)
272 michael 2820 return 0;
273 adx 30
274     if (!IsClient(source_p) || EmptyString(parv[2]))
275 michael 2820 return 0;
276 adx 30
277     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
278     "UNXLINE %s %s", parv[1], parv[2]);
279    
280 michael 1652 if (match(parv[1], me.name))
281 michael 2820 return 0;
282 adx 30
283 michael 1632 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
284 adx 30 source_p->username, source_p->host,
285     SHARED_UNXLINE))
286     remove_xline(source_p, parv[2]);
287 michael 2820 return 0;
288 adx 30 }
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 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
303 adx 30 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 michael 2820 time_t tkline_time)
328 adx 30 {
329 michael 1845 struct MaskItem *conf = conf_make(CONF_XLINE);
330 adx 30
331     collapse(gecos);
332 michael 1646 conf->name = xstrdup(gecos);
333     conf->reason = xstrdup(reason);
334 michael 1632 conf->setat = CurrentTime;
335 adx 30
336 michael 1632 SetConfDatabase(conf);
337 michael 1628
338 adx 30 if (tkline_time != 0)
339     {
340 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
341 michael 2820 "%s added temporary %d min. X-Line for [%s] [%s]",
342     get_oper_name(source_p), (int)tkline_time/60,
343     conf->name, conf->reason);
344 adx 30 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]",
345 michael 2820 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
346     source_p->name, (int)tkline_time/60, conf->name);
347 michael 2336 ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]",
348 michael 2820 source_p->name, (int)tkline_time/60, conf->name, conf->reason);
349 michael 1649 conf->until = CurrentTime + tkline_time;
350 adx 30 }
351     else
352 michael 1622 {
353     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
354     "%s added X-Line for [%s] [%s]",
355     get_oper_name(source_p), conf->name,
356 michael 1632 conf->reason);
357 michael 1622 sendto_one(source_p,
358 michael 1644 ":%s NOTICE %s :Added X-Line [%s] [%s]",
359 michael 1622 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
360 michael 1644 source_p->name, conf->name, conf->reason);
361 michael 2336 ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]",
362 michael 1632 get_oper_name(source_p), conf->name, conf->reason);
363 michael 1622 }
364    
365 adx 30 rehashed_klines = 1;
366     }
367    
368     static void
369     remove_xline(struct Client *source_p, char *gecos)
370     {
371 michael 1622 if (remove_xline_match(gecos))
372 adx 30 {
373     sendto_one(source_p,
374 michael 1622 ":%s NOTICE %s :X-Line for [%s] is removed",
375 adx 30 me.name, source_p->name, gecos);
376 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
377 adx 30 "%s has removed the X-Line for: [%s]",
378     get_oper_name(source_p), gecos);
379 michael 2336 ilog(LOG_TYPE_XLINE, "%s removed X-Line for [%s]",
380 michael 2340 get_oper_name(source_p), gecos);
381 adx 30 }
382     else
383     sendto_one(source_p, ":%s NOTICE %s :No X-Line for %s",
384     me.name, source_p->name, gecos);
385     }
386    
387     /* static int remove_tkline_match(const char *host, const char *user)
388     *
389     * Inputs: gecos
390     * Output: returns YES on success, NO if no tkline removed.
391     * Side effects: Any matching tklines are removed.
392     */
393     static int
394 michael 1622 remove_xline_match(const char *gecos)
395 adx 30 {
396     dlink_node *ptr = NULL, *next_ptr = NULL;
397    
398 michael 1622 DLINK_FOREACH_SAFE(ptr, next_ptr, xconf_items.head)
399 adx 30 {
400 michael 1632 struct MaskItem *conf = ptr->data;
401 adx 30
402 michael 1632 if (!IsConfDatabase(conf))
403 michael 1622 continue;
404    
405     if (!irccmp(gecos, conf->name))
406 adx 30 {
407 michael 1632 conf_free(conf);
408 adx 30 return 1;
409     }
410     }
411    
412     return 0;
413     }
414 michael 1230
415 michael 2820 static struct Message xline_msgtab =
416     {
417 michael 1230 "XLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
418     { m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore }
419     };
420    
421 michael 2820 static struct Message unxline_msgtab =
422     {
423 michael 1230 "UNXLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
424     { m_unregistered, m_not_oper, ms_unxline, m_ignore, mo_unxline, m_ignore }
425     };
426    
427     static void
428     module_init(void)
429     {
430     mod_add_cmd(&xline_msgtab);
431     mod_add_cmd(&unxline_msgtab);
432     }
433    
434     static void
435     module_exit(void)
436     {
437     mod_del_cmd(&xline_msgtab);
438     mod_del_cmd(&unxline_msgtab);
439     }
440    
441 michael 2820 struct module module_entry =
442     {
443 michael 1230 .node = { NULL, NULL, NULL },
444     .name = NULL,
445     .version = "$Revision$",
446     .handle = NULL,
447     .modinit = module_init,
448     .modexit = module_exit,
449     .flags = 0
450     };

Properties

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