ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 1845
Committed: Mon Apr 22 18:33:02 2013 UTC (13 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 11796 byte(s)
Log Message:
- Fixed some compile warnings

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

Properties

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