ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 3110
Committed: Thu Mar 6 20:33:17 2014 UTC (12 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 11411 byte(s)
Log Message:
- Added sendto_one_notice()

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

Properties

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