ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 2974
Committed: Fri Jan 31 11:56:51 2014 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 11951 byte(s)
Log Message:
- m_xline.c: reorder functions, removed unused header includes, constifications

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

Properties

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