ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.3/modules/m_xline.c
Revision: 1121
Committed: Sun Jan 9 11:03:03 2011 UTC (15 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 12503 byte(s)
Log Message:
- removed all instances of STATIC_MODULES since we don't have
  static modules anymore
- removed m_mkpasswd module from contrib

File Contents

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

Properties

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