ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 2362
Committed: Thu Jul 4 21:15:32 2013 UTC (13 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 11696 byte(s)
Log Message:
- m_xline.c:ms_xline(): removed already solved XXX comment

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

Properties

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