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: 3347
Committed: Sun Apr 20 14:03:06 2014 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_dline.c
File size: 13500 byte(s)
Log Message:
- Moved files:
  s_user.c -> user.c
  s_misc.c -> misc.c
  s_serv.c -> server.c

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 "client.h"
30     #include "irc_string.h"
31 michael 1632 #include "conf.h"
32 michael 1058 #include "ircd.h"
33     #include "hostmask.h"
34     #include "numeric.h"
35 michael 1309 #include "log.h"
36 michael 3347 #include "misc.h"
37 michael 1058 #include "send.h"
38     #include "hash.h"
39 michael 3347 #include "server.h"
40 michael 1058 #include "parse.h"
41     #include "modules.h"
42 michael 1622 #include "conf_db.h"
43 michael 1666 #include "memory.h"
44 michael 1058
45    
46     /* apply_tdline()
47     *
48     * inputs -
49     * output - NONE
50     * side effects - tkline as given is placed
51     */
52     static void
53 michael 1632 apply_dline(struct Client *source_p, struct MaskItem *conf,
54 michael 1622 time_t tkline_time)
55 michael 1058 {
56 michael 1622 if (tkline_time)
57     {
58 michael 1649 conf->until = CurrentTime + tkline_time;
59 michael 1622 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 michael 1632 conf->host, conf->reason);
63 michael 3110 sendto_one_notice(source_p, &me, ":Added temporary %d min. D-Line [%s]",
64     tkline_time/60, conf->host);
65 michael 1622 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
66 michael 1632 get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
67 michael 1622 }
68     else
69     {
70     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
71     "%s added D-Line for [%s] [%s]",
72 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
73 michael 3110 sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
74 michael 1622 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
75 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
76 michael 1058
77 michael 1622 }
78    
79 michael 1632 SetConfDatabase(conf);
80     conf->setat = CurrentTime;
81     add_conf_by_address(CONF_DLINE, conf);
82 michael 1058 rehashed_klines = 1;
83     }
84    
85 michael 1298 /* 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 michael 1622 remove_dline_match(const char *host)
92 michael 1298 {
93 michael 1369 struct irc_ssaddr iphost, *piphost;
94 michael 1632 struct MaskItem *conf;
95 michael 1644 int t = 0;
96     int aftype = 0;
97 michael 1298
98 michael 1369 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
99 michael 1298 {
100     #ifdef IPV6
101 michael 1369 if (t == HM_IPV6)
102 michael 1644 aftype = AF_INET6;
103 michael 1369 else
104 michael 1298 #endif
105 michael 1644 aftype = AF_INET;
106 michael 1369 piphost = &iphost;
107     }
108     else
109     piphost = NULL;
110    
111 michael 2997 if ((conf = find_conf_by_address(host, piphost, CONF_DLINE, aftype, NULL, NULL, 0)))
112 michael 1369 {
113 michael 1632 if (IsConfDatabase(conf))
114 michael 1298 {
115 michael 1632 delete_one_address_conf(host, conf);
116 michael 1298 return 1;
117     }
118     }
119    
120     return 0;
121     }
122    
123 michael 1058 /* 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 michael 2820 static int
134 michael 3156 mo_dline(struct Client *source_p, int parc, char *parv[])
135 michael 1058 {
136 michael 1794 char def_reason[] = CONF_NOREASON;
137 michael 1622 char *dlhost = NULL, *reason = NULL;
138 michael 1301 char *target_server = NULL;
139 michael 1058 const char *creason;
140     const struct Client *target_p = NULL;
141     struct irc_ssaddr daddr;
142 michael 1632 struct MaskItem *conf=NULL;
143 michael 1058 time_t tkline_time=0;
144 michael 1644 int bits = 0, aftype = 0, t = 0;
145 michael 1058 const char *current_date = NULL;
146 michael 1398 char hostip[HOSTIPLEN + 1];
147 michael 1230 char buffer[IRCD_BUFSIZE];
148 michael 1058
149 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
150 michael 1058 {
151 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
152 michael 2820 return 0;
153 michael 1058 }
154    
155     if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
156 michael 1301 NULL, &tkline_time, &target_server, &reason) < 0)
157 michael 2820 return 0;
158 michael 1058
159 michael 1301 if (target_server != NULL)
160     {
161 michael 2807 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 michael 1301
165     /* Allow ON to apply local kline as well if it matches */
166 michael 1652 if (match(target_server, me.name))
167 michael 2820 return 0;
168 michael 1301 }
169     else
170     cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
171     "%d %s :%s", tkline_time, dlhost, reason);
172    
173 michael 1058 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
174     {
175 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
176 michael 2820 return 0;
177 michael 1058
178     if (!MyConnect(target_p))
179     {
180 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
181 michael 2820 return 0;
182 michael 1058 }
183    
184     if (IsExemptKline(target_p))
185     {
186 michael 3110 sendto_one_notice(source_p, &me, ":%s is E-lined",
187     target_p->name);
188 michael 2820 return 0;
189 michael 1058 }
190    
191 michael 1123 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
192     target_p->localClient->ip.ss_len, hostip,
193     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
194 michael 1058 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 michael 3110 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
202 michael 2820 return 0;
203 michael 1058 }
204    
205     #ifdef IPV6
206     if (t == HM_IPV6)
207 michael 1644 aftype = AF_INET6;
208 michael 1058 else
209     #endif
210 michael 1644 aftype = AF_INET;
211 michael 1058
212     parse_netmask(dlhost, &daddr, NULL);
213    
214 michael 1644 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
215 michael 1058 {
216 michael 1632 creason = conf->reason ? conf->reason : def_reason;
217 michael 2810
218 michael 1632 if (IsConfExemptKline(conf))
219 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
220     dlhost, conf->host, creason);
221 michael 1058 else
222 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
223     dlhost, conf->host, creason);
224 michael 2820 return 0;
225 michael 1058 }
226    
227 michael 3208 current_date = smalldate(0);
228 michael 1058
229 michael 1243 if (!valid_comment(source_p, reason, 1))
230 michael 2820 return 0;
231 michael 1058
232 michael 1632 conf = conf_make(CONF_DLINE);
233 michael 1646 conf->host = xstrdup(dlhost);
234 michael 1058
235     if (tkline_time != 0)
236 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
237     (int)(tkline_time/60), reason, current_date);
238 michael 1058 else
239 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
240 michael 1058
241 michael 1646 conf->reason = xstrdup(buffer);
242 michael 1632 apply_dline(source_p, conf, tkline_time);
243 michael 1058 rehashed_klines = 1;
244 michael 2820 return 0;
245 michael 1058 }
246    
247 michael 2820 static int
248 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
249 michael 1301 {
250 michael 1794 char def_reason[] = CONF_NOREASON;
251 michael 1622 char *dlhost, *reason;
252 michael 1301 const char *creason;
253     const struct Client *target_p = NULL;
254     struct irc_ssaddr daddr;
255 michael 1632 struct MaskItem *conf=NULL;
256 michael 1301 time_t tkline_time=0;
257 michael 1644 int bits = 0, aftype = 0, t = 0;
258 michael 1301 const char *current_date = NULL;
259 michael 1398 char hostip[HOSTIPLEN + 1];
260 michael 1301 char buffer[IRCD_BUFSIZE];
261    
262     if (parc != 5 || EmptyString(parv[4]))
263 michael 2820 return 0;
264 michael 1301
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 michael 1652 if (match(parv[1], me.name))
272 michael 2820 return 0;
273 michael 1301
274     tkline_time = valid_tkline(parv[2], TK_SECONDS);
275     dlhost = parv[3];
276     reason = parv[4];
277    
278 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
279     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
280 michael 1301 source_p->username, source_p->host,
281     SHARED_DLINE))
282     {
283     if (!IsClient(source_p))
284 michael 2820 return 0;
285    
286 michael 1301 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
287     {
288 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
289 michael 2820 return 0;
290 michael 1301
291     if (!MyConnect(target_p))
292     {
293 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
294 michael 2820 return 0;
295 michael 1301 }
296    
297     if (IsExemptKline(target_p))
298     {
299 michael 3110 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
300 michael 2820 return 0;
301 michael 1301 }
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 michael 3110 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
314 michael 2820 return 0;
315 michael 1301 }
316    
317     #ifdef IPV6
318     if (t == HM_IPV6)
319 michael 1644 aftype= AF_INET6;
320 michael 1301 else
321     #endif
322 michael 1644 aftype = AF_INET;
323 michael 1301
324     parse_netmask(dlhost, &daddr, NULL);
325    
326 michael 1644 if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
327 michael 1301 {
328 michael 1632 creason = conf->reason ? conf->reason : def_reason;
329     if (IsConfExemptKline(conf))
330 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
331     dlhost, conf->host, creason);
332 michael 1301 else
333 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
334     dlhost, conf->host, creason);
335 michael 2820 return 0;
336 michael 1301 }
337    
338 michael 3208 current_date = smalldate(0);
339 michael 1301
340     if (!valid_comment(source_p, reason, 1))
341 michael 2820 return 0;
342 michael 1301
343 michael 1632 conf = conf_make(CONF_DLINE);
344 michael 1646 conf->host = xstrdup(dlhost);
345 michael 1301
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 michael 1646 conf->reason = xstrdup(buffer);
353 michael 1632 apply_dline(source_p, conf, tkline_time);
354 michael 1301 rehashed_klines = 1;
355     }
356 michael 2820
357     return 0;
358 michael 1301 }
359    
360 michael 1058 /*
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 michael 3120 ** parv[0] = command
367 michael 1058 ** parv[1] = dline to remove
368     */
369 michael 2820 static int
370 michael 3156 mo_undline(struct Client *source_p, int parc, char *parv[])
371 michael 1058 {
372 michael 1301 char *addr = NULL, *user = NULL;
373     char *target_server = NULL;
374 michael 1058
375 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
376 michael 1058 {
377 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "undline");
378 michael 2820 return 0;
379 michael 1058 }
380    
381 michael 1301 if (parc < 2 || EmptyString(parv[1]))
382     {
383 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNDLINE");
384 michael 2820 return 0;
385 michael 1301 }
386 michael 1058
387 michael 1301 if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
388     &addr, NULL, &target_server, NULL) < 0)
389 michael 2820 return 0;
390 michael 1301
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 michael 1652 if (match(target_server, me.name))
398 michael 2820 return 0;
399 michael 1301 }
400     else
401     cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
402     "%s", addr);
403    
404 michael 1622 if (remove_dline_match(addr))
405 michael 1058 {
406 michael 3110 sendto_one_notice(source_p, &me, ":D-Line for [%s] is removed", addr);
407 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
408 michael 1622 "%s has removed the D-Line for: [%s]",
409 michael 1298 get_oper_name(source_p), addr);
410 michael 1247 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
411 michael 1298 get_oper_name(source_p), addr);
412 michael 1058 }
413     else
414 michael 3110 sendto_one_notice(source_p, &me, ":No D-Line for [%s] found", addr);
415 michael 2820 return 0;
416 michael 1058 }
417 michael 1230
418 michael 2820 static int
419 michael 3156 ms_undline(struct Client *source_p, int parc, char *parv[])
420 michael 1301 {
421 michael 2857 const char *addr = parv[1];
422 michael 1301
423     if (parc != 3 || EmptyString(parv[2]))
424 michael 2820 return 0;
425 michael 1301
426 michael 2857 sendto_match_servs(source_p, parv[1], CAP_UNDLN,
427     "UNDLINE %s %s",
428     parv[1], parv[2]);
429 michael 1301
430 michael 1652 if (!IsClient(source_p) || match(parv[1], me.name))
431 michael 2820 return 0;
432 michael 1301
433 michael 2810 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 michael 1301 {
438 michael 1622 if (remove_dline_match(addr))
439 michael 1301 {
440 michael 3110 sendto_one_notice(source_p, &me, ":D-Line for [%s] is removed", addr);
441 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
442 michael 1622 "%s has removed the D-Line for: [%s]",
443 michael 1301 get_oper_name(source_p), addr);
444 michael 2340 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
445 michael 1301 get_oper_name(source_p), addr);
446     }
447     else
448 michael 3110 sendto_one_notice(source_p, &me, ":No D-Line for [%s] found", addr);
449 michael 1301 }
450 michael 2820
451     return 0;
452 michael 1301 }
453    
454 michael 2810 static struct Message dline_msgtab =
455     {
456 michael 1230 "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
457 michael 2810 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
458 michael 1230 };
459    
460 michael 2810 static struct Message undline_msgtab =
461     {
462 michael 1230 "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
463 michael 2810 { m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore }
464 michael 1230 };
465    
466     static void
467     module_init(void)
468     {
469     mod_add_cmd(&dline_msgtab);
470     mod_add_cmd(&undline_msgtab);
471 michael 1301 add_capability("DLN", CAP_DLN, 1);
472     add_capability("UNDLN", CAP_UNDLN, 1);
473 michael 1230 }
474    
475     static void
476     module_exit(void)
477     {
478     mod_del_cmd(&dline_msgtab);
479     mod_del_cmd(&undline_msgtab);
480 michael 1301 delete_capability("UNDLN");
481     delete_capability("DLN");
482 michael 1230 }
483    
484 michael 2810 struct module module_entry =
485     {
486 michael 1230 .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