ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 2828
Committed: Wed Jan 15 23:34:31 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 11997 byte(s)
Log Message:
- m_xline.c:me_xline(): fixed misleading comment

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 michael 2828 * parv[1] = target server
165     * parv[2] = xline
166     * parv[3] = time
167     * parv[4] = reason
168 adx 30 *
169     * outputs - none
170 michael 2820 * side effects -
171 adx 30 */
172 michael 2820 static int
173 adx 30 me_xline(struct Client *client_p, struct Client *source_p,
174     int parc, char *parv[])
175     {
176     if (!IsClient(source_p) || parc != 5)
177 michael 2820 return 0;
178 adx 30
179     relay_xline(source_p, parv);
180 michael 2820 return 0;
181 adx 30 }
182    
183     static void
184     relay_xline(struct Client *source_p, char *parv[])
185     {
186 michael 1632 struct MaskItem *conf = NULL;
187 adx 30 int t_sec;
188    
189     t_sec = atoi(parv[3]);
190    
191     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
192     "XLINE %s %s %s :%s",
193     parv[1], parv[2], parv[3], parv[4]);
194    
195 michael 1652 if (match(parv[1], me.name))
196 adx 30 return;
197    
198 michael 1632 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
199 adx 30 source_p->username, source_p->host,
200     SHARED_XLINE))
201     {
202 michael 2820 if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], NULL, NULL, 0)))
203 adx 30 {
204     sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
205     ID_or_name(&me, source_p->from),
206     ID_or_name(source_p, source_p->from),
207 michael 1632 parv[2], conf->name, conf->reason);
208 adx 30 return;
209     }
210    
211     write_xline(source_p, parv[2], parv[4], t_sec);
212     }
213     }
214    
215     /* mo_unxline()
216     *
217     * inputs - pointer to server
218     * - pointer to client
219     * - parameter count
220     * - parameter list
221     * output -
222     * side effects - removes a xline
223     */
224 michael 2820 static int
225 adx 30 mo_unxline(struct Client *client_p, struct Client *source_p,
226     int parc, char *parv[])
227     {
228     char *gecos = NULL;
229     char *target_server = NULL;
230    
231 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_X))
232 adx 30 {
233 michael 2820 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
234     source_p->name, "xline");
235     return 0;
236 adx 30 }
237    
238     /* UNXLINE bill ON irc.server.com */
239     if (parse_aline("UNXLINE", source_p, parc, parv, 0, &gecos,
240     NULL, NULL, &target_server, NULL) < 0)
241 michael 2820 return 0;
242 adx 30
243     if (target_server != NULL)
244     {
245     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
246     "UNXLINE %s %s", target_server, gecos);
247    
248     /* Allow ON to apply local unxline as well if it matches */
249 michael 1652 if (match(target_server, me.name))
250 michael 2820 return 0;
251 adx 30 }
252     else
253     cluster_a_line(source_p, "UNXLINE", CAP_CLUSTER, SHARED_UNXLINE,
254 michael 2820 "%s", gecos);
255 adx 30
256     remove_xline(source_p, gecos);
257 michael 2820 return 0;
258 adx 30 }
259    
260     /* ms_unxline()
261     *
262     * inputs - oper, target server, gecos
263     * outputs - none
264     * side effects - propagates unxline, applies it if we are a target
265     */
266 michael 2820 static int
267 adx 30 ms_unxline(struct Client *client_p, struct Client *source_p,
268     int parc, char *parv[])
269     {
270     if (parc != 3)
271 michael 2820 return 0;
272 adx 30
273     if (!IsClient(source_p) || EmptyString(parv[2]))
274 michael 2820 return 0;
275 adx 30
276     sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
277     "UNXLINE %s %s", parv[1], parv[2]);
278    
279 michael 1652 if (match(parv[1], me.name))
280 michael 2820 return 0;
281 adx 30
282 michael 1632 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
283 adx 30 source_p->username, source_p->host,
284     SHARED_UNXLINE))
285     remove_xline(source_p, parv[2]);
286 michael 2820 return 0;
287 adx 30 }
288    
289     /* valid_xline()
290     *
291     * inputs - client to complain to, gecos, reason, whether to complain
292     * outputs - 1 for valid, else 0
293     * side effects - complains to client, when warn != 0
294     */
295     static int
296     valid_xline(struct Client *source_p, char *gecos, char *reason, int warn)
297     {
298     if (EmptyString(reason))
299     {
300     if (warn)
301 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
302 adx 30 me.name, source_p->name, "XLINE");
303     return 0;
304     }
305    
306     if (!valid_wild_card_simple(gecos))
307     {
308     if (warn)
309     sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the xline",
310     me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple);
311    
312     return 0;
313     }
314    
315     return 1;
316     }
317    
318     /* write_xline()
319     *
320     * inputs - client taking credit for xline, gecos, reason, xline type
321     * outputs - none
322     * side effects - when successful, adds an xline to the conf
323     */
324     static void
325     write_xline(struct Client *source_p, char *gecos, char *reason,
326 michael 2820 time_t tkline_time)
327 adx 30 {
328 michael 1845 struct MaskItem *conf = conf_make(CONF_XLINE);
329 adx 30
330     collapse(gecos);
331 michael 1646 conf->name = xstrdup(gecos);
332     conf->reason = xstrdup(reason);
333 michael 1632 conf->setat = CurrentTime;
334 adx 30
335 michael 1632 SetConfDatabase(conf);
336 michael 1628
337 adx 30 if (tkline_time != 0)
338     {
339 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
340 michael 2820 "%s added temporary %d min. X-Line for [%s] [%s]",
341     get_oper_name(source_p), (int)tkline_time/60,
342     conf->name, conf->reason);
343 adx 30 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]",
344 michael 2820 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
345     source_p->name, (int)tkline_time/60, conf->name);
346 michael 2336 ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]",
347 michael 2820 source_p->name, (int)tkline_time/60, conf->name, conf->reason);
348 michael 1649 conf->until = CurrentTime + tkline_time;
349 adx 30 }
350     else
351 michael 1622 {
352     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
353     "%s added X-Line for [%s] [%s]",
354     get_oper_name(source_p), conf->name,
355 michael 1632 conf->reason);
356 michael 1622 sendto_one(source_p,
357 michael 1644 ":%s NOTICE %s :Added X-Line [%s] [%s]",
358 michael 1622 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
359 michael 1644 source_p->name, conf->name, conf->reason);
360 michael 2336 ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]",
361 michael 1632 get_oper_name(source_p), conf->name, conf->reason);
362 michael 1622 }
363    
364 adx 30 rehashed_klines = 1;
365     }
366    
367     static void
368     remove_xline(struct Client *source_p, char *gecos)
369     {
370 michael 1622 if (remove_xline_match(gecos))
371 adx 30 {
372     sendto_one(source_p,
373 michael 1622 ":%s NOTICE %s :X-Line for [%s] is removed",
374 adx 30 me.name, source_p->name, gecos);
375 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
376 adx 30 "%s has removed the X-Line for: [%s]",
377     get_oper_name(source_p), gecos);
378 michael 2336 ilog(LOG_TYPE_XLINE, "%s removed X-Line for [%s]",
379 michael 2340 get_oper_name(source_p), gecos);
380 adx 30 }
381     else
382     sendto_one(source_p, ":%s NOTICE %s :No X-Line for %s",
383     me.name, source_p->name, gecos);
384     }
385    
386     /* static int remove_tkline_match(const char *host, const char *user)
387     *
388     * Inputs: gecos
389     * Output: returns YES on success, NO if no tkline removed.
390     * Side effects: Any matching tklines are removed.
391     */
392     static int
393 michael 1622 remove_xline_match(const char *gecos)
394 adx 30 {
395     dlink_node *ptr = NULL, *next_ptr = NULL;
396    
397 michael 1622 DLINK_FOREACH_SAFE(ptr, next_ptr, xconf_items.head)
398 adx 30 {
399 michael 1632 struct MaskItem *conf = ptr->data;
400 adx 30
401 michael 1632 if (!IsConfDatabase(conf))
402 michael 1622 continue;
403    
404     if (!irccmp(gecos, conf->name))
405 adx 30 {
406 michael 1632 conf_free(conf);
407 adx 30 return 1;
408     }
409     }
410    
411     return 0;
412     }
413 michael 1230
414 michael 2820 static struct Message xline_msgtab =
415     {
416 michael 1230 "XLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
417     { m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore }
418     };
419    
420 michael 2820 static struct Message unxline_msgtab =
421     {
422 michael 1230 "UNXLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
423     { m_unregistered, m_not_oper, ms_unxline, m_ignore, mo_unxline, m_ignore }
424     };
425    
426     static void
427     module_init(void)
428     {
429     mod_add_cmd(&xline_msgtab);
430     mod_add_cmd(&unxline_msgtab);
431     }
432    
433     static void
434     module_exit(void)
435     {
436     mod_del_cmd(&xline_msgtab);
437     mod_del_cmd(&unxline_msgtab);
438     }
439    
440 michael 2820 struct module module_entry =
441     {
442 michael 1230 .node = { NULL, NULL, NULL },
443     .name = NULL,
444     .version = "$Revision$",
445     .handle = NULL,
446     .modinit = module_init,
447     .modexit = module_exit,
448     .flags = 0
449     };

Properties

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