/[svn]/ircd-hybrid-7.2/modules/m_xline.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/modules/m_xline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1011 - (show annotations)
Fri Sep 18 10:14:09 2009 UTC (9 years, 11 months ago) by michael
File MIME type: text/x-chdr
File size: 12533 byte(s)
- move list manipulation routines from tools.c to list.c
- mem_frob() goes to memory.c
- sort out redundant/unneeded header includes

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26