ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_dline.c
Revision: 3156
Committed: Fri Mar 14 19:57:38 2014 UTC (12 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_dline.c
File size: 13620 byte(s)
Log Message:
- Removed client_p pointers from everywhere

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 time_t cur_time;
147 char hostip[HOSTIPLEN + 1];
148 char buffer[IRCD_BUFSIZE];
149
150 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
151 {
152 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
153 return 0;
154 }
155
156 if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
157 NULL, &tkline_time, &target_server, &reason) < 0)
158 return 0;
159
160 if (target_server != NULL)
161 {
162 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
163 target_server, (unsigned long)tkline_time,
164 dlhost, reason);
165
166 /* Allow ON to apply local kline as well if it matches */
167 if (match(target_server, me.name))
168 return 0;
169 }
170 else
171 cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
172 "%d %s :%s", tkline_time, dlhost, reason);
173
174 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
175 {
176 if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
177 return 0;
178
179 if (!MyConnect(target_p))
180 {
181 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
182 return 0;
183 }
184
185 if (IsExemptKline(target_p))
186 {
187 sendto_one_notice(source_p, &me, ":%s is E-lined",
188 target_p->name);
189 return 0;
190 }
191
192 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
193 target_p->localClient->ip.ss_len, hostip,
194 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
195 dlhost = hostip;
196 t = parse_netmask(dlhost, NULL, &bits);
197 assert(t == HM_IPV4 || t == HM_IPV6);
198 }
199
200 if (bits < 8)
201 {
202 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
203 return 0;
204 }
205
206 #ifdef IPV6
207 if (t == HM_IPV6)
208 aftype = AF_INET6;
209 else
210 #endif
211 aftype = AF_INET;
212
213 parse_netmask(dlhost, &daddr, NULL);
214
215 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
216 {
217 creason = conf->reason ? conf->reason : def_reason;
218
219 if (IsConfExemptKline(conf))
220 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
221 dlhost, conf->host, creason);
222 else
223 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
224 dlhost, conf->host, creason);
225 return 0;
226 }
227
228 cur_time = CurrentTime;
229 current_date = smalldate(cur_time);
230
231 if (!valid_comment(source_p, reason, 1))
232 return 0;
233
234 conf = conf_make(CONF_DLINE);
235 conf->host = xstrdup(dlhost);
236
237 if (tkline_time != 0)
238 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
239 (int)(tkline_time/60), reason, current_date);
240 else
241 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
242
243 conf->reason = xstrdup(buffer);
244 apply_dline(source_p, conf, tkline_time);
245 rehashed_klines = 1;
246 return 0;
247 }
248
249 static int
250 ms_dline(struct Client *source_p, int parc, char *parv[])
251 {
252 char def_reason[] = CONF_NOREASON;
253 char *dlhost, *reason;
254 const char *creason;
255 const struct Client *target_p = NULL;
256 struct irc_ssaddr daddr;
257 struct MaskItem *conf=NULL;
258 time_t tkline_time=0;
259 int bits = 0, aftype = 0, t = 0;
260 const char *current_date = NULL;
261 time_t cur_time;
262 char hostip[HOSTIPLEN + 1];
263 char buffer[IRCD_BUFSIZE];
264
265 if (parc != 5 || EmptyString(parv[4]))
266 return 0;
267
268 /* parv[0] parv[1] parv[2] parv[3] parv[4] */
269 /* oper target_server tkline_time host reason */
270 sendto_match_servs(source_p, parv[1], CAP_DLN,
271 "DLINE %s %s %s :%s",
272 parv[1], parv[2], parv[3], parv[4]);
273
274 if (match(parv[1], me.name))
275 return 0;
276
277 tkline_time = valid_tkline(parv[2], TK_SECONDS);
278 dlhost = parv[3];
279 reason = parv[4];
280
281 if (HasFlag(source_p, FLAGS_SERVICE) ||
282 find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
283 source_p->username, source_p->host,
284 SHARED_DLINE))
285 {
286 if (!IsClient(source_p))
287 return 0;
288
289 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
290 {
291 if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
292 return 0;
293
294 if (!MyConnect(target_p))
295 {
296 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
297 return 0;
298 }
299
300 if (IsExemptKline(target_p))
301 {
302 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
303 return 0;
304 }
305
306 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
307 target_p->localClient->ip.ss_len, hostip,
308 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
309 dlhost = hostip;
310 t = parse_netmask(dlhost, NULL, &bits);
311 assert(t == HM_IPV4 || t == HM_IPV6);
312 }
313
314 if (bits < 8)
315 {
316 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
317 return 0;
318 }
319
320 #ifdef IPV6
321 if (t == HM_IPV6)
322 aftype= AF_INET6;
323 else
324 #endif
325 aftype = AF_INET;
326
327 parse_netmask(dlhost, &daddr, NULL);
328
329 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
330 {
331 creason = conf->reason ? conf->reason : def_reason;
332 if (IsConfExemptKline(conf))
333 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
334 dlhost, conf->host, creason);
335 else
336 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
337 dlhost, conf->host, creason);
338 return 0;
339 }
340
341 cur_time = CurrentTime;
342 current_date = smalldate(cur_time);
343
344 if (!valid_comment(source_p, reason, 1))
345 return 0;
346
347 conf = conf_make(CONF_DLINE);
348 conf->host = xstrdup(dlhost);
349
350 if (tkline_time != 0)
351 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
352 (int)(tkline_time/60), reason, current_date);
353 else
354 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
355
356 conf->reason = xstrdup(buffer);
357 apply_dline(source_p, conf, tkline_time);
358 rehashed_klines = 1;
359 }
360
361 return 0;
362 }
363
364 /*
365 ** m_undline
366 ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
367 ** based totally on m_unkline
368 ** added to hybrid-7 7/11/2000 --is
369 **
370 ** parv[0] = command
371 ** parv[1] = dline to remove
372 */
373 static int
374 mo_undline(struct Client *source_p, int parc, char *parv[])
375 {
376 char *addr = NULL, *user = NULL;
377 char *target_server = NULL;
378
379 if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
380 {
381 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "undline");
382 return 0;
383 }
384
385 if (parc < 2 || EmptyString(parv[1]))
386 {
387 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNDLINE");
388 return 0;
389 }
390
391 if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
392 &addr, NULL, &target_server, NULL) < 0)
393 return 0;
394
395 if (target_server != NULL)
396 {
397 sendto_match_servs(source_p, target_server, CAP_UNDLN,
398 "UNDLINE %s %s", target_server, addr);
399
400 /* Allow ON to apply local unkline as well if it matches */
401 if (match(target_server, me.name))
402 return 0;
403 }
404 else
405 cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
406 "%s", addr);
407
408 if (remove_dline_match(addr))
409 {
410 sendto_one_notice(source_p, &me, ":D-Line for [%s] is removed", addr);
411 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
412 "%s has removed the D-Line for: [%s]",
413 get_oper_name(source_p), addr);
414 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
415 get_oper_name(source_p), addr);
416 }
417 else
418 sendto_one_notice(source_p, &me, ":No D-Line for [%s] found", addr);
419 return 0;
420 }
421
422 static int
423 ms_undline(struct Client *source_p, int parc, char *parv[])
424 {
425 const char *addr = parv[1];
426
427 if (parc != 3 || EmptyString(parv[2]))
428 return 0;
429
430 sendto_match_servs(source_p, parv[1], CAP_UNDLN,
431 "UNDLINE %s %s",
432 parv[1], parv[2]);
433
434 if (!IsClient(source_p) || match(parv[1], me.name))
435 return 0;
436
437 if (HasFlag(source_p, FLAGS_SERVICE) ||
438 find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
439 source_p->username, source_p->host,
440 SHARED_UNDLINE))
441 {
442 if (remove_dline_match(addr))
443 {
444 sendto_one_notice(source_p, &me, ":D-Line for [%s] is removed", addr);
445 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
446 "%s has removed the D-Line for: [%s]",
447 get_oper_name(source_p), addr);
448 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
449 get_oper_name(source_p), addr);
450 }
451 else
452 sendto_one_notice(source_p, &me, ":No D-Line for [%s] found", addr);
453 }
454
455 return 0;
456 }
457
458 static struct Message dline_msgtab =
459 {
460 "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
461 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
462 };
463
464 static struct Message undline_msgtab =
465 {
466 "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
467 { m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore }
468 };
469
470 static void
471 module_init(void)
472 {
473 mod_add_cmd(&dline_msgtab);
474 mod_add_cmd(&undline_msgtab);
475 add_capability("DLN", CAP_DLN, 1);
476 add_capability("UNDLN", CAP_UNDLN, 1);
477 }
478
479 static void
480 module_exit(void)
481 {
482 mod_del_cmd(&dline_msgtab);
483 mod_del_cmd(&undline_msgtab);
484 delete_capability("UNDLN");
485 delete_capability("DLN");
486 }
487
488 struct module module_entry =
489 {
490 .node = { NULL, NULL, NULL },
491 .name = NULL,
492 .version = "$Revision$",
493 .handle = NULL,
494 .modinit = module_init,
495 .modexit = module_exit,
496 .flags = 0
497 };

Properties

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