ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 2820
Committed: Wed Jan 15 23:10:26 2014 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 12010 byte(s)
Log Message:
- Clean up all files in modules/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years
- Made module handlers int type for later use

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 /* mo_xline()
58 *
59 * inputs - pointer to server
60 * - pointer to client
61 * - parameter count
62 * - parameter list
63 * output -
64 * side effects - x line is added
65 *
66 */
67 static int
68 mo_xline(struct Client *client_p, struct Client *source_p,
69 int parc, char *parv[])
70 {
71 char *reason = NULL;
72 char *gecos = NULL;
73 struct MaskItem *conf = NULL;
74 char *target_server = NULL;
75 time_t tkline_time = 0;
76
77 if (!HasOFlag(source_p, OPER_FLAG_X))
78 {
79 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
80 source_p->name, "xline");
81 return 0;
82 }
83
84 /*
85 * XLINE <gecos> <time> ON <mask> :<reason>
86 * XLINE <gecos> ON <mask> :<reason>
87 */
88 if (parse_aline("XLINE", source_p, parc, parv, AWILD, &gecos, NULL,
89 &tkline_time, &target_server, &reason) < 0)
90 return 0;
91
92 if (target_server != NULL)
93 {
94 /* if a given expire time is given, ENCAP it */
95 if (tkline_time != 0)
96 sendto_match_servs(source_p, target_server, CAP_ENCAP,
97 "ENCAP %s XLINE %d %s 0 :%s",
98 target_server, (int)tkline_time, gecos, reason);
99 else
100 sendto_match_servs(source_p, target_server, CAP_CLUSTER,
101 "XLINE %s %s %d :%s",
102 target_server, gecos, (int)tkline_time, reason);
103
104 /* Allow ON to apply local xline as well if it matches */
105 if (match(target_server, me.name))
106 return 0;
107 }
108 else
109 {
110 if (tkline_time != 0)
111 cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE,
112 "XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason);
113 else
114 cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE,
115 "%s 0 :%s", gecos, reason);
116 }
117
118 if (!valid_xline(source_p, gecos, reason, 0))
119 return 0;
120
121 if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0)))
122 {
123 sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
124 me.name, source_p->name, gecos,
125 conf->name, conf->reason);
126 return 0;
127 }
128
129 write_xline(source_p, gecos, reason, tkline_time);
130 return 0;
131 }
132
133 /* ms_xline()
134 *
135 * inputs - oper, target server, xline, {type}, reason
136 *
137 * outputs - none
138 * side effects - propagates xline, applies it if we are a target
139 */
140 static int
141 ms_xline(struct Client *client_p, struct Client *source_p,
142 int parc, char *parv[])
143 {
144 if (parc != 5 || EmptyString(parv[4]))
145 return 0;
146
147 if (!IsClient(source_p))
148 return 0;
149
150 if (!valid_xline(source_p, parv[2], parv[4], 0))
151 return 0;
152
153 relay_xline(source_p, parv);
154 return 0;
155 }
156
157 /* me_xline()
158 *
159 * inputs - server
160 * - client (oper)
161 * - parc number of arguments
162 * - parv list of arguments
163 * via parv[]
164 * parv[1] = target
165 * parv[2] = server
166 * parv[3] = xline
167 * parv[4] = time
168 * parv[5] = reason
169 *
170 * outputs - none
171 * side effects -
172 */
173 static int
174 me_xline(struct Client *client_p, struct Client *source_p,
175 int parc, char *parv[])
176 {
177 if (!IsClient(source_p) || parc != 5)
178 return 0;
179
180 relay_xline(source_p, parv);
181 return 0;
182 }
183
184 static void
185 relay_xline(struct Client *source_p, char *parv[])
186 {
187 struct MaskItem *conf = NULL;
188 int t_sec;
189
190 t_sec = atoi(parv[3]);
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], NULL, NULL, 0)))
204 {
205 sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
206 ID_or_name(&me, source_p->from),
207 ID_or_name(source_p, source_p->from),
208 parv[2], conf->name, conf->reason);
209 return;
210 }
211
212 write_xline(source_p, parv[2], parv[4], t_sec);
213 }
214 }
215
216 /* mo_unxline()
217 *
218 * inputs - pointer to server
219 * - pointer to client
220 * - parameter count
221 * - parameter list
222 * output -
223 * side effects - removes a xline
224 */
225 static int
226 mo_unxline(struct Client *client_p, struct Client *source_p,
227 int parc, char *parv[])
228 {
229 char *gecos = NULL;
230 char *target_server = NULL;
231
232 if (!HasOFlag(source_p, OPER_FLAG_X))
233 {
234 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
235 source_p->name, "xline");
236 return 0;
237 }
238
239 /* UNXLINE bill ON irc.server.com */
240 if (parse_aline("UNXLINE", source_p, parc, parv, 0, &gecos,
241 NULL, NULL, &target_server, NULL) < 0)
242 return 0;
243
244 if (target_server != NULL)
245 {
246 sendto_match_servs(source_p, target_server, CAP_CLUSTER,
247 "UNXLINE %s %s", target_server, gecos);
248
249 /* Allow ON to apply local unxline as well if it matches */
250 if (match(target_server, me.name))
251 return 0;
252 }
253 else
254 cluster_a_line(source_p, "UNXLINE", CAP_CLUSTER, SHARED_UNXLINE,
255 "%s", gecos);
256
257 remove_xline(source_p, gecos);
258 return 0;
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 int
268 ms_unxline(struct Client *client_p, struct Client *source_p,
269 int parc, char *parv[])
270 {
271 if (parc != 3)
272 return 0;
273
274 if (!IsClient(source_p) || EmptyString(parv[2]))
275 return 0;
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 0;
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 return 0;
288 }
289
290 /* valid_xline()
291 *
292 * inputs - client to complain to, gecos, reason, whether to complain
293 * outputs - 1 for valid, else 0
294 * side effects - complains to client, when warn != 0
295 */
296 static int
297 valid_xline(struct Client *source_p, char *gecos, char *reason, int warn)
298 {
299 if (EmptyString(reason))
300 {
301 if (warn)
302 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
303 me.name, source_p->name, "XLINE");
304 return 0;
305 }
306
307 if (!valid_wild_card_simple(gecos))
308 {
309 if (warn)
310 sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the xline",
311 me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple);
312
313 return 0;
314 }
315
316 return 1;
317 }
318
319 /* write_xline()
320 *
321 * inputs - client taking credit for xline, gecos, reason, xline type
322 * outputs - none
323 * side effects - when successful, adds an xline to the conf
324 */
325 static void
326 write_xline(struct Client *source_p, char *gecos, char *reason,
327 time_t tkline_time)
328 {
329 struct MaskItem *conf = conf_make(CONF_XLINE);
330
331 collapse(gecos);
332 conf->name = xstrdup(gecos);
333 conf->reason = xstrdup(reason);
334 conf->setat = CurrentTime;
335
336 SetConfDatabase(conf);
337
338 if (tkline_time != 0)
339 {
340 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
341 "%s added temporary %d min. X-Line for [%s] [%s]",
342 get_oper_name(source_p), (int)tkline_time/60,
343 conf->name, conf->reason);
344 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]",
345 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
346 source_p->name, (int)tkline_time/60, conf->name);
347 ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]",
348 source_p->name, (int)tkline_time/60, 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_XLINE, "%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_XLINE, "%s removed X-Line for [%s]",
380 get_oper_name(source_p), 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 {
417 "XLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
418 { m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore }
419 };
420
421 static struct Message unxline_msgtab =
422 {
423 "UNXLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
424 { m_unregistered, m_not_oper, ms_unxline, m_ignore, mo_unxline, m_ignore }
425 };
426
427 static void
428 module_init(void)
429 {
430 mod_add_cmd(&xline_msgtab);
431 mod_add_cmd(&unxline_msgtab);
432 }
433
434 static void
435 module_exit(void)
436 {
437 mod_del_cmd(&xline_msgtab);
438 mod_del_cmd(&unxline_msgtab);
439 }
440
441 struct module module_entry =
442 {
443 .node = { NULL, NULL, NULL },
444 .name = NULL,
445 .version = "$Revision$",
446 .handle = NULL,
447 .modinit = module_init,
448 .modexit = module_exit,
449 .flags = 0
450 };

Properties

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