ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 1632
Committed: Sun Nov 4 15:37:10 2012 UTC (12 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 15330 byte(s)
Log Message:
- Initial rewrite of the configuration subsystem

File Contents

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

Properties

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