/[svn]/branches/newio/modules/m_dline.c
ViewVC logotype

Contents of /branches/newio/modules/m_dline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2806 - (show annotations)
Sun Jan 12 17:18:48 2014 UTC (6 years, 5 months ago) by michael
File MIME type: text/x-chdr
File size: 14902 byte(s)
- m_dline.c:mo_dline(). if a target server exists, use sendto_match_servs()
  instead of sendto_server()

1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_dline.c: Bans a 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 "conf.h"
31 #include "ircd.h"
32 #include "hostmask.h"
33 #include "numeric.h"
34 #include "s_bsd.h"
35 #include "log.h"
36 #include "s_misc.h"
37 #include "send.h"
38 #include "hash.h"
39 #include "s_serv.h"
40 #include "parse.h"
41 #include "modules.h"
42 #include "conf_db.h"
43 #include "memory.h"
44 #include "xsnprintf.h"
45
46
47 /* apply_tdline()
48 *
49 * inputs -
50 * output - NONE
51 * side effects - tkline as given is placed
52 */
53 static void
54 apply_dline(struct Client *source_p, struct MaskItem *conf,
55 time_t tkline_time)
56 {
57 if (tkline_time)
58 {
59 conf->until = CurrentTime + tkline_time;
60 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
61 "%s added temporary %d min. D-Line for [%s] [%s]",
62 get_oper_name(source_p), tkline_time/60,
63 conf->host, conf->reason);
64 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
65 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
66 source_p->name, tkline_time/60, conf->host);
67 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
68 get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
69 }
70 else
71 {
72 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
73 "%s added D-Line for [%s] [%s]",
74 get_oper_name(source_p), conf->host, conf->reason);
75 sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s]",
76 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
77 source_p->name, conf->host);
78 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
79 get_oper_name(source_p), conf->host, conf->reason);
80
81 }
82
83 SetConfDatabase(conf);
84 conf->setat = CurrentTime;
85 add_conf_by_address(CONF_DLINE, conf);
86 rehashed_klines = 1;
87 }
88
89 /* static int remove_tdline_match(const char *host, const char *user)
90 * Input: An ip to undline.
91 * Output: returns YES on success, NO if no tdline removed.
92 * Side effects: Any matching tdlines are removed.
93 */
94 static int
95 remove_dline_match(const char *host)
96 {
97 struct irc_ssaddr iphost, *piphost;
98 struct MaskItem *conf;
99 int t = 0;
100 int aftype = 0;
101
102 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
103 {
104 if (t == HM_IPV6)
105 aftype = AF_INET6;
106 else
107 aftype = AF_INET;
108 piphost = &iphost;
109 }
110 else
111 piphost = NULL;
112
113 if ((conf = find_conf_by_address(host, piphost, CONF_DLINE | 1, aftype, NULL, NULL, 0)))
114 {
115 if (IsConfDatabase(conf))
116 {
117 delete_one_address_conf(host, conf);
118 return 1;
119 }
120 }
121
122 return 0;
123 }
124
125 /* mo_dline()
126 *
127 * inputs - pointer to server
128 * - pointer to client
129 * - parameter count
130 * - parameter list
131 * output -
132 * side effects - D line is added
133 *
134 */
135 static int
136 mo_dline(struct Client *client_p, struct Client *source_p,
137 int parc, char *parv[])
138 {
139 char def_reason[] = CONF_NOREASON;
140 char *dlhost = NULL, *reason = NULL;
141 char *target_server = NULL;
142 const char *creason;
143 const struct Client *target_p = NULL;
144 struct irc_ssaddr daddr;
145 struct MaskItem *conf=NULL;
146 time_t tkline_time=0;
147 int bits = 0, aftype = 0, t = 0;
148 const char *current_date = NULL;
149 time_t cur_time;
150 char hostip[HOSTIPLEN + 1];
151 char buffer[IRCD_BUFSIZE];
152
153 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
154 {
155 sendto_one(source_p, form_str(ERR_NOPRIVS),
156 me.name, source_p->name, "dline");
157 return 0;
158 }
159
160 if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
161 NULL, &tkline_time, &target_server, &reason) < 0)
162 return 0;
163
164 if (target_server != NULL)
165 {
166 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %Tu %s :%s",
167 target_server, tkline_time, dlhost, reason);
168
169 /* Allow ON to apply local kline as well if it matches */
170 if (match(target_server, me.name))
171 return 0;
172 }
173 else
174 cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
175 "%d %s :%s", tkline_time, dlhost, reason);
176
177 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
178 {
179 if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
180 return 0;
181
182 if (!MyConnect(target_p))
183 {
184 sendto_one(source_p,
185 ":%s NOTICE %s :Can't DLINE nick on another server",
186 me.name, source_p->name);
187 return 0;
188 }
189
190 if (IsExemptKline(target_p))
191 {
192 sendto_one(source_p,
193 ":%s NOTICE %s :%s is E-lined", me.name,
194 source_p->name, target_p->name);
195 return 0;
196 }
197
198 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
199 target_p->localClient->ip.ss_len, hostip,
200 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
201 dlhost = hostip;
202 t = parse_netmask(dlhost, NULL, &bits);
203 assert(t == HM_IPV4 || t == HM_IPV6);
204 }
205
206 if (bits < 8)
207 {
208 sendto_one(source_p,
209 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
210 me.name, source_p->name);
211 return 0;
212 }
213
214 if (t == HM_IPV6)
215 aftype = AF_INET6;
216 else
217 aftype = AF_INET;
218
219 parse_netmask(dlhost, &daddr, NULL);
220
221 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
222 {
223 creason = conf->reason ? conf->reason : def_reason;
224 if (IsConfExemptKline(conf))
225 sendto_one(source_p,
226 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
227 me.name, source_p->name, dlhost, conf->host, creason);
228 else
229 sendto_one(source_p,
230 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
231 me.name, source_p->name, dlhost, conf->host, creason);
232 return 0;
233 }
234
235 cur_time = CurrentTime;
236 current_date = smalldate(cur_time);
237
238 if (!valid_comment(source_p, reason, 1))
239 return 0;
240
241 conf = conf_make(CONF_DLINE);
242 conf->host = xstrdup(dlhost);
243
244 if (tkline_time != 0)
245 xsnprintf(NULL, buffer, sizeof(buffer), "Temporary D-line %Tu min. - %s (%s)",
246 (tkline_time/60), reason, current_date);
247 else
248 xsnprintf(NULL, buffer, sizeof(buffer), "%s (%s)", reason, current_date);
249
250 conf->reason = xstrdup(buffer);
251 apply_dline(source_p, conf, tkline_time);
252 rehashed_klines = 1;
253 return 0;
254 }
255
256 static int
257 ms_dline(struct Client *client_p, struct Client *source_p,
258 int parc, char *parv[])
259 {
260 char def_reason[] = CONF_NOREASON;
261 char *dlhost, *reason;
262 const char *creason;
263 const struct Client *target_p = NULL;
264 struct irc_ssaddr daddr;
265 struct MaskItem *conf=NULL;
266 time_t tkline_time=0;
267 int bits = 0, aftype = 0, t = 0;
268 const char *current_date = NULL;
269 time_t cur_time;
270 char hostip[HOSTIPLEN + 1];
271 char buffer[IRCD_BUFSIZE];
272
273 if (parc != 5 || EmptyString(parv[4]))
274 return 0;
275
276 /* parv[0] parv[1] parv[2] parv[3] parv[4] */
277 /* oper target_server tkline_time host reason */
278 sendto_match_servs(source_p, parv[1], CAP_DLN,
279 "DLINE %s %s %s :%s",
280 parv[1], parv[2], parv[3], parv[4]);
281
282 if (match(parv[1], me.name))
283 return 0;
284
285 tkline_time = valid_tkline(parv[2], TK_SECONDS);
286 dlhost = parv[3];
287 reason = parv[4];
288
289 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
290 source_p->username, source_p->host,
291 SHARED_DLINE))
292 {
293 if (!IsClient(source_p))
294 return 0;
295 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
296 {
297 if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
298 return 0;
299
300 if (!MyConnect(target_p))
301 {
302 sendto_one(source_p,
303 ":%s NOTICE %s :Can't DLINE nick on another server",
304 me.name, source_p->name);
305 return 0;
306 }
307
308 if (IsExemptKline(target_p))
309 {
310 sendto_one(source_p,
311 ":%s NOTICE %s :%s is E-lined", me.name,
312 source_p->name, target_p->name);
313 return 0;
314 }
315
316 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
317 target_p->localClient->ip.ss_len, hostip,
318 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
319 dlhost = hostip;
320 t = parse_netmask(dlhost, NULL, &bits);
321 assert(t == HM_IPV4 || t == HM_IPV6);
322 }
323
324 if (bits < 8)
325 {
326 sendto_one(source_p,
327 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
328 me.name, source_p->name);
329 return 0;
330 }
331
332 if (t == HM_IPV6)
333 aftype= AF_INET6;
334 else
335 aftype = AF_INET;
336
337 parse_netmask(dlhost, &daddr, NULL);
338
339 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
340 {
341 creason = conf->reason ? conf->reason : def_reason;
342 if (IsConfExemptKline(conf))
343 sendto_one(source_p,
344 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
345 me.name, source_p->name, dlhost, conf->host, creason);
346 else
347 sendto_one(source_p,
348 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
349 me.name, source_p->name, dlhost, conf->host, creason);
350 return 0;
351 }
352
353 cur_time = CurrentTime;
354 current_date = smalldate(cur_time);
355
356 if (!valid_comment(source_p, reason, 1))
357 return 0;
358
359 conf = conf_make(CONF_DLINE);
360 conf->host = xstrdup(dlhost);
361
362 if (tkline_time != 0)
363 xsnprintf(NULL, buffer, sizeof(buffer), "Temporary D-line %Tu min. - %s (%s)",
364 (tkline_time/60), reason, current_date);
365 else
366 xsnprintf(NULL, buffer, sizeof(buffer), "%s (%s)", reason, current_date);
367
368 conf->reason = xstrdup(buffer);
369 apply_dline(source_p, conf, tkline_time);
370 rehashed_klines = 1;
371 }
372
373 return 0;
374 }
375
376 /*
377 ** m_undline
378 ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
379 ** based totally on m_unkline
380 ** added to hybrid-7 7/11/2000 --is
381 **
382 ** parv[0] = sender nick
383 ** parv[1] = dline to remove
384 */
385 static int
386 mo_undline(struct Client *client_p, struct Client *source_p,
387 int parc, char *parv[])
388 {
389 char *addr = NULL, *user = NULL;
390 char *target_server = NULL;
391
392 if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
393 {
394 sendto_one(source_p, form_str(ERR_NOPRIVS),
395 me.name, source_p->name, "undline");
396 return 0;
397 }
398
399 if (parc < 2 || EmptyString(parv[1]))
400 {
401 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
402 me.name, source_p->name, "UNDLINE");
403 return 0;
404 }
405
406 if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
407 &addr, NULL, &target_server, NULL) < 0)
408 return 0;
409
410 if (target_server != NULL)
411 {
412 sendto_match_servs(source_p, target_server, CAP_UNDLN,
413 "UNDLINE %s %s", target_server, addr);
414
415 /* Allow ON to apply local unkline as well if it matches */
416 if (match(target_server, me.name))
417 return 0;
418 }
419 else
420 cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
421 "%s", addr);
422
423 if (remove_dline_match(addr))
424 {
425 sendto_one(source_p,
426 ":%s NOTICE %s :D-Line for [%s] is removed",
427 me.name, source_p->name, addr);
428 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
429 "%s has removed the D-Line for: [%s]",
430 get_oper_name(source_p), addr);
431 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
432 get_oper_name(source_p), addr);
433 }
434 else
435 sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
436 me.name, source_p->name, addr);
437 return 0;
438 }
439
440 static int
441 me_undline(struct Client *client_p, struct Client *source_p,
442 int parc, char *parv[])
443 {
444 const char *addr = NULL;
445
446 if (parc != 3 || EmptyString(parv[2]))
447 return 0;
448
449 addr = parv[2];
450
451 if (!IsClient(source_p) || match(parv[1], me.name))
452 return 0;
453
454 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
455 source_p->servptr->name,
456 source_p->username, source_p->host,
457 SHARED_UNDLINE))
458 {
459 if (remove_dline_match(addr))
460 {
461 sendto_one(source_p,
462 ":%s NOTICE %s :D-Line for [%s] is removed",
463 me.name, source_p->name, addr);
464 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
465 "%s has removed the D-Line for: [%s]",
466 get_oper_name(source_p), addr);
467 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
468 get_oper_name(source_p), addr);
469 }
470 else
471 sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
472 me.name, source_p->name, addr);
473 }
474
475 return 0;
476 }
477
478 static int
479 ms_undline(struct Client *client_p, struct Client *source_p,
480 int parc, char *parv[])
481 {
482 if (parc != 3 || EmptyString(parv[2]))
483 return 0;
484
485 sendto_match_servs(source_p, parv[1], CAP_UNDLN,
486 "UNDLINE %s %s",
487 parv[1], parv[2]);
488
489 return me_undline(client_p, source_p, parc, parv);
490 }
491
492 static struct Message dline_msgtab =
493 {
494 "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
495 {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
496 };
497
498 static struct Message undline_msgtab =
499 {
500 "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
501 {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
502 };
503
504 static void
505 module_init(void)
506 {
507 mod_add_cmd(&dline_msgtab);
508 mod_add_cmd(&undline_msgtab);
509 add_capability("DLN", CAP_DLN, 1);
510 add_capability("UNDLN", CAP_UNDLN, 1);
511 }
512
513 static void
514 module_exit(void)
515 {
516 mod_del_cmd(&dline_msgtab);
517 mod_del_cmd(&undline_msgtab);
518 delete_capability("UNDLN");
519 delete_capability("DLN");
520 }
521
522 struct module module_entry =
523 {
524 .node = { NULL, NULL, NULL },
525 .name = NULL,
526 .version = "$Revision$",
527 .handle = NULL,
528 .modinit = module_init,
529 .modexit = module_exit,
530 .flags = 0
531 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28