ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 3118
Committed: Fri Mar 7 19:32:34 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 13764 byte(s)
Log Message:
- numeric.c, m_dline.c: fixed inconsistent use of "can't" and "cannot"

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

Properties

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