ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 3110
Committed: Thu Mar 6 20:33:17 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 13822 byte(s)
Log Message:
- Added sendto_one_notice()

File Contents

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

Properties

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