ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.1.x/modules/m_xline.c
Revision: 1622
Committed: Thu Nov 1 13:16:37 2012 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_xline.c
File size: 12280 byte(s)
Log Message:
- klines, dlines, xlines, glines and resv now make use of the new database;
  also, temporary *lines are now stored, so they're not lost after
  restarting the ircd. This also applies to G-lines.

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

Properties

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