ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 2888
Committed: Tue Jan 21 17:47:11 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 12317 byte(s)
Log Message:
- Fixed improper use of the ID_or_name macro in several places

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2003-2014 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file m_xline.c
23 * \brief Includes required functions for processing the XLINE/UNXLINE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "channel.h"
30 #include "client.h"
31 #include "irc_string.h"
32 #include "ircd.h"
33 #include "conf.h"
34 #include "hostmask.h"
35 #include "numeric.h"
36 #include "fdlist.h"
37 #include "s_bsd.h"
38 #include "log.h"
39 #include "s_misc.h"
40 #include "send.h"
41 #include "hash.h"
42 #include "s_serv.h"
43 #include "parse.h"
44 #include "modules.h"
45 #include "resv.h"
46 #include "conf_db.h"
47 #include "memory.h"
48
49
50 static int valid_xline(struct Client *, char *, char *, int);
51 static void write_xline(struct Client *, char *, char *, time_t);
52 static void remove_xline(struct Client *, char *);
53 static int remove_xline_match(const char *);
54
55 static void relay_xline(struct Client *, char *[]);
56
57 static void
58 check_xline(struct MaskItem *conf)
59 {
60 dlink_node *ptr = NULL, *ptr_next = NULL;
61
62 DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head)
63 {
64 struct Client *client_p = ptr->data;
65
66 if (IsDead(client_p))
67 continue;
68
69 if (!match(conf->name, client_p->username))
70 conf_try_ban(client_p, conf);
71 }
72 }
73
74 /* mo_xline()
75 *
76 * inputs - pointer to server
77 * - pointer to client
78 * - parameter count
79 * - parameter list
80 * output -
81 * side effects - x line is added
82 *
83 */
84 static int
85 mo_xline(struct Client *client_p, struct Client *source_p,
86 int parc, char *parv[])
87 {
88 char *reason = NULL;
89 char *gecos = NULL;
90 struct MaskItem *conf = NULL;
91 char *target_server = NULL;
92 time_t tkline_time = 0;
93
94 if (!HasOFlag(source_p, OPER_FLAG_XLINE))
95 {
96 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
97 source_p->name, "xline");
98 return 0;
99 }
100
101 /*
102 * XLINE <gecos> <time> ON <mask> :<reason>
103 * XLINE <gecos> ON <mask> :<reason>
104 */
105 if (parse_aline("XLINE", source_p, parc, parv, AWILD, &gecos, NULL,
106 &tkline_time, &target_server, &reason) < 0)
107 return 0;
108
109 if (target_server != NULL)
110 {
111 /* if a given expire time is given, ENCAP it */
112 if (tkline_time != 0)
113 sendto_match_servs(source_p, target_server, CAP_ENCAP,
114 "ENCAP %s XLINE %d %s 0 :%s",
115 target_server, (int)tkline_time, gecos, reason);
116 else
117 sendto_match_servs(source_p, target_server, CAP_CLUSTER,
118 "XLINE %s %s %d :%s",
119 target_server, gecos, (int)tkline_time, reason);
120
121 /* Allow ON to apply local xline as well if it matches */
122 if (match(target_server, me.name))
123 return 0;
124 }
125 else
126 {
127 if (tkline_time != 0)
128 cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE,
129 "XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason);
130 else
131 cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE,
132 "%s 0 :%s", gecos, reason);
133 }
134
135 if (!valid_xline(source_p, gecos, reason, 0))
136 return 0;
137
138 if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0)))
139 {
140 sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
141 me.name, source_p->name, gecos,
142 conf->name, conf->reason);
143 return 0;
144 }
145
146 write_xline(source_p, gecos, reason, tkline_time);
147 return 0;
148 }
149
150 /* ms_xline()
151 *
152 * inputs - oper, target server, xline, {type}, reason
153 *
154 * outputs - none
155 * side effects - propagates xline, applies it if we are a target
156 */
157 static int
158 ms_xline(struct Client *client_p, struct Client *source_p,
159 int parc, char *parv[])
160 {
161 if (parc != 5 || EmptyString(parv[4]))
162 return 0;
163
164 if (!IsClient(source_p))
165 return 0;
166
167 if (!valid_xline(source_p, parv[2], parv[4], 0))
168 return 0;
169
170 relay_xline(source_p, parv);
171 return 0;
172 }
173
174 /* me_xline()
175 *
176 * inputs - server
177 * - client (oper)
178 * - parc number of arguments
179 * - parv list of arguments
180 * via parv[]
181 * parv[1] = target server
182 * parv[2] = xline
183 * parv[3] = time
184 * parv[4] = reason
185 *
186 * outputs - none
187 * side effects -
188 */
189 static int
190 me_xline(struct Client *client_p, struct Client *source_p,
191 int parc, char *parv[])
192 {
193 if (!IsClient(source_p) || parc != 5)
194 return 0;
195
196 relay_xline(source_p, parv);
197 return 0;
198 }
199
200 static void
201 relay_xline(struct Client *source_p, char *parv[])
202 {
203 struct MaskItem *conf = NULL;
204 int t_sec;
205
206 t_sec = atoi(parv[3]);
207
208 sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
209 "XLINE %s %s %s :%s",
210 parv[1], parv[2], parv[3], parv[4]);
211
212 if (match(parv[1], me.name))
213 return;
214
215 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
216 source_p->username, source_p->host,
217 SHARED_XLINE))
218 {
219 if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], NULL, NULL, 0)))
220 {
221 sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
222 ID_or_name(&me, source_p),
223 ID_or_name(source_p, source_p),
224 parv[2], conf->name, conf->reason);
225 return;
226 }
227
228 write_xline(source_p, parv[2], parv[4], t_sec);
229 }
230 }
231
232 /* mo_unxline()
233 *
234 * inputs - pointer to server
235 * - pointer to client
236 * - parameter count
237 * - parameter list
238 * output -
239 * side effects - removes a xline
240 */
241 static int
242 mo_unxline(struct Client *client_p, struct Client *source_p,
243 int parc, char *parv[])
244 {
245 char *gecos = NULL;
246 char *target_server = NULL;
247
248 if (!HasOFlag(source_p, OPER_FLAG_UNXLINE))
249 {
250 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
251 source_p->name, "unxline");
252 return 0;
253 }
254
255 /* UNXLINE bill ON irc.server.com */
256 if (parse_aline("UNXLINE", source_p, parc, parv, 0, &gecos,
257 NULL, NULL, &target_server, NULL) < 0)
258 return 0;
259
260 if (target_server != NULL)
261 {
262 sendto_match_servs(source_p, target_server, CAP_CLUSTER,
263 "UNXLINE %s %s", target_server, gecos);
264
265 /* Allow ON to apply local unxline as well if it matches */
266 if (match(target_server, me.name))
267 return 0;
268 }
269 else
270 cluster_a_line(source_p, "UNXLINE", CAP_CLUSTER, SHARED_UNXLINE,
271 "%s", gecos);
272
273 remove_xline(source_p, gecos);
274 return 0;
275 }
276
277 /* ms_unxline()
278 *
279 * inputs - oper, target server, gecos
280 * outputs - none
281 * side effects - propagates unxline, applies it if we are a target
282 */
283 static int
284 ms_unxline(struct Client *client_p, struct Client *source_p,
285 int parc, char *parv[])
286 {
287 if (parc != 3)
288 return 0;
289
290 if (!IsClient(source_p) || EmptyString(parv[2]))
291 return 0;
292
293 sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
294 "UNXLINE %s %s", parv[1], parv[2]);
295
296 if (match(parv[1], me.name))
297 return 0;
298
299 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
300 source_p->username, source_p->host,
301 SHARED_UNXLINE))
302 remove_xline(source_p, parv[2]);
303 return 0;
304 }
305
306 /* valid_xline()
307 *
308 * inputs - client to complain to, gecos, reason, whether to complain
309 * outputs - 1 for valid, else 0
310 * side effects - complains to client, when warn != 0
311 */
312 static int
313 valid_xline(struct Client *source_p, char *gecos, char *reason, int warn)
314 {
315 if (EmptyString(reason))
316 {
317 if (warn)
318 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
319 me.name, source_p->name, "XLINE");
320 return 0;
321 }
322
323 if (!valid_wild_card_simple(gecos))
324 {
325 if (warn)
326 sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the xline",
327 me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple);
328
329 return 0;
330 }
331
332 return 1;
333 }
334
335 /* write_xline()
336 *
337 * inputs - client taking credit for xline, gecos, reason, xline type
338 * outputs - none
339 * side effects - when successful, adds an xline to the conf
340 */
341 static void
342 write_xline(struct Client *source_p, char *gecos, char *reason,
343 time_t tkline_time)
344 {
345 struct MaskItem *conf = conf_make(CONF_XLINE);
346
347 collapse(gecos);
348 conf->name = xstrdup(gecos);
349 conf->reason = xstrdup(reason);
350 conf->setat = CurrentTime;
351
352 SetConfDatabase(conf);
353
354 if (tkline_time != 0)
355 {
356 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
357 "%s added temporary %d min. X-Line for [%s] [%s]",
358 get_oper_name(source_p), (int)tkline_time/60,
359 conf->name, conf->reason);
360 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]",
361 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p),
362 source_p->name, (int)tkline_time/60, conf->name);
363 ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]",
364 source_p->name, (int)tkline_time/60, conf->name, conf->reason);
365 conf->until = CurrentTime + tkline_time;
366 }
367 else
368 {
369 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
370 "%s added X-Line for [%s] [%s]",
371 get_oper_name(source_p), conf->name,
372 conf->reason);
373 sendto_one(source_p,
374 ":%s NOTICE %s :Added X-Line [%s] [%s]",
375 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p),
376 source_p->name, conf->name, conf->reason);
377 ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]",
378 get_oper_name(source_p), conf->name, conf->reason);
379 }
380
381 check_xline(conf);
382 }
383
384 static void
385 remove_xline(struct Client *source_p, char *gecos)
386 {
387 if (remove_xline_match(gecos))
388 {
389 sendto_one(source_p,
390 ":%s NOTICE %s :X-Line for [%s] is removed",
391 me.name, source_p->name, gecos);
392 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
393 "%s has removed the X-Line for: [%s]",
394 get_oper_name(source_p), gecos);
395 ilog(LOG_TYPE_XLINE, "%s removed X-Line for [%s]",
396 get_oper_name(source_p), gecos);
397 }
398 else
399 sendto_one(source_p, ":%s NOTICE %s :No X-Line for %s",
400 me.name, source_p->name, gecos);
401 }
402
403 /* static int remove_tkline_match(const char *host, const char *user)
404 *
405 * Inputs: gecos
406 * Output: returns YES on success, NO if no tkline removed.
407 * Side effects: Any matching tklines are removed.
408 */
409 static int
410 remove_xline_match(const char *gecos)
411 {
412 dlink_node *ptr = NULL, *next_ptr = NULL;
413
414 DLINK_FOREACH_SAFE(ptr, next_ptr, xconf_items.head)
415 {
416 struct MaskItem *conf = ptr->data;
417
418 if (!IsConfDatabase(conf))
419 continue;
420
421 if (!irccmp(gecos, conf->name))
422 {
423 conf_free(conf);
424 return 1;
425 }
426 }
427
428 return 0;
429 }
430
431 static struct Message xline_msgtab =
432 {
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 {
439 "UNXLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
440 { m_unregistered, m_not_oper, ms_unxline, m_ignore, mo_unxline, m_ignore }
441 };
442
443 static void
444 module_init(void)
445 {
446 mod_add_cmd(&xline_msgtab);
447 mod_add_cmd(&unxline_msgtab);
448 }
449
450 static void
451 module_exit(void)
452 {
453 mod_del_cmd(&xline_msgtab);
454 mod_del_cmd(&unxline_msgtab);
455 }
456
457 struct module module_entry =
458 {
459 .node = { NULL, NULL, NULL },
460 .name = NULL,
461 .version = "$Revision$",
462 .handle = NULL,
463 .modinit = module_init,
464 .modexit = module_exit,
465 .flags = 0
466 };

Properties

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