ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 3208
Committed: Tue Mar 25 15:31:30 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 13502 byte(s)
Log Message:
- Minor cleanup to m_dline.c, m_gline.c, m_kline.c

File Contents

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

Properties

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