ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 4639
Committed: Sun Sep 21 11:17:58 2014 UTC (10 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 11277 byte(s)
Log Message:
- m_dline.c, m_undline.c: allow servers to add/remove DLINEs

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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 michael 1058 * USA
20     */
21    
22 michael 2810 /*! \file m_dline.c
23 michael 3348 * \brief Includes required functions for processing the DLINE command.
24 michael 2810 * \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 michael 3929 static void
47     check_dline(struct AddressRec *arec)
48     {
49     dlink_node *ptr = NULL, *ptr_next = NULL;
50    
51     DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head)
52     {
53     struct Client *client_p = ptr->data;
54    
55     if (IsDead(client_p))
56     continue;
57    
58     switch (arec->masktype)
59     {
60     case HM_IPV4:
61 michael 4588 if (client_p->connection->aftype == AF_INET)
62     if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
63 michael 3929 conf_try_ban(client_p, arec->conf);
64     break;
65     case HM_IPV6:
66 michael 4588 if (client_p->connection->aftype == AF_INET6)
67     if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
68 michael 3929 conf_try_ban(client_p, arec->conf);
69     break;
70     default: break;
71     }
72     }
73    
74     DLINK_FOREACH_SAFE(ptr, ptr_next, unknown_list.head)
75     {
76     struct Client *client_p = ptr->data;
77    
78     if (IsDead(client_p))
79     continue;
80    
81     switch (arec->masktype)
82     {
83     case HM_IPV4:
84 michael 4588 if (client_p->connection->aftype == AF_INET)
85     if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
86 michael 3929 conf_try_ban(client_p, arec->conf);
87     break;
88     case HM_IPV6:
89 michael 4588 if (client_p->connection->aftype == AF_INET6)
90     if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
91 michael 3929 conf_try_ban(client_p, arec->conf);
92     break;
93     default: break;
94     }
95     }
96     }
97    
98    
99 michael 1058 /* apply_tdline()
100     *
101     * inputs -
102     * output - NONE
103     * side effects - tkline as given is placed
104     */
105     static void
106 michael 1632 apply_dline(struct Client *source_p, struct MaskItem *conf,
107 michael 1622 time_t tkline_time)
108 michael 1058 {
109 michael 1622 if (tkline_time)
110     {
111 michael 1649 conf->until = CurrentTime + tkline_time;
112 michael 4639
113     if (IsClient(source_p))
114     sendto_one_notice(source_p, &me, ":Added temporary %d min. D-Line [%s]",
115     tkline_time/60, conf->host);
116 michael 1622 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
117     "%s added temporary %d min. D-Line for [%s] [%s]",
118     get_oper_name(source_p), tkline_time/60,
119 michael 1632 conf->host, conf->reason);
120 michael 1622 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
121 michael 1632 get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
122 michael 1622 }
123     else
124     {
125 michael 4639 if (IsClient(source_p))
126     sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
127    
128 michael 1622 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
129     "%s added D-Line for [%s] [%s]",
130 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
131 michael 1622 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
132 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
133 michael 1058
134 michael 1622 }
135    
136 michael 1632 SetConfDatabase(conf);
137     conf->setat = CurrentTime;
138 michael 3929 check_dline(add_conf_by_address(CONF_DLINE, conf));
139 michael 1058 }
140    
141     /* mo_dline()
142     *
143     * inputs - pointer to server
144     * - pointer to client
145     * - parameter count
146     * - parameter list
147     * output -
148     * side effects - D line is added
149     *
150     */
151 michael 2820 static int
152 michael 3156 mo_dline(struct Client *source_p, int parc, char *parv[])
153 michael 1058 {
154 michael 1794 char def_reason[] = CONF_NOREASON;
155 michael 1622 char *dlhost = NULL, *reason = NULL;
156 michael 1301 char *target_server = NULL;
157 michael 1058 const char *creason;
158     const struct Client *target_p = NULL;
159     struct irc_ssaddr daddr;
160 michael 1632 struct MaskItem *conf=NULL;
161 michael 1058 time_t tkline_time=0;
162 michael 1644 int bits = 0, aftype = 0, t = 0;
163 michael 1058 const char *current_date = NULL;
164 michael 1398 char hostip[HOSTIPLEN + 1];
165 michael 1230 char buffer[IRCD_BUFSIZE];
166 michael 1058
167 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
168 michael 1058 {
169 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
170 michael 2820 return 0;
171 michael 1058 }
172    
173     if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
174 michael 1301 NULL, &tkline_time, &target_server, &reason) < 0)
175 michael 2820 return 0;
176 michael 1058
177 michael 3368 if (target_server)
178 michael 1301 {
179 michael 2807 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
180     target_server, (unsigned long)tkline_time,
181     dlhost, reason);
182 michael 1301
183     /* Allow ON to apply local kline as well if it matches */
184 michael 1652 if (match(target_server, me.name))
185 michael 2820 return 0;
186 michael 1301 }
187     else
188     cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
189     "%d %s :%s", tkline_time, dlhost, reason);
190    
191 michael 1058 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
192     {
193 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
194 michael 3737 return 0; /* find_chasing sends ERR_NOSUCHNICK */
195 michael 1058
196     if (!MyConnect(target_p))
197     {
198 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
199 michael 2820 return 0;
200 michael 1058 }
201    
202     if (IsExemptKline(target_p))
203     {
204 michael 3110 sendto_one_notice(source_p, &me, ":%s is E-lined",
205     target_p->name);
206 michael 2820 return 0;
207 michael 1058 }
208    
209 michael 4588 getnameinfo((struct sockaddr *)&target_p->connection->ip,
210     target_p->connection->ip.ss_len, hostip,
211 michael 1123 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
212 michael 1058 dlhost = hostip;
213     t = parse_netmask(dlhost, NULL, &bits);
214     assert(t == HM_IPV4 || t == HM_IPV6);
215     }
216    
217     if (bits < 8)
218     {
219 michael 3110 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
220 michael 2820 return 0;
221 michael 1058 }
222    
223     if (t == HM_IPV6)
224 michael 1644 aftype = AF_INET6;
225 michael 1058 else
226 michael 1644 aftype = AF_INET;
227 michael 1058
228     parse_netmask(dlhost, &daddr, NULL);
229    
230 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
231 michael 1058 {
232 michael 1632 creason = conf->reason ? conf->reason : def_reason;
233 michael 2810
234 michael 1632 if (IsConfExemptKline(conf))
235 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
236     dlhost, conf->host, creason);
237 michael 1058 else
238 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
239     dlhost, conf->host, creason);
240 michael 2820 return 0;
241 michael 1058 }
242    
243 michael 3208 current_date = smalldate(0);
244 michael 1058
245 michael 1243 if (!valid_comment(source_p, reason, 1))
246 michael 2820 return 0;
247 michael 1058
248 michael 1632 conf = conf_make(CONF_DLINE);
249 michael 1646 conf->host = xstrdup(dlhost);
250 michael 1058
251 michael 3368 if (tkline_time)
252 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
253     (int)(tkline_time/60), reason, current_date);
254 michael 1058 else
255 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
256 michael 1058
257 michael 1646 conf->reason = xstrdup(buffer);
258 michael 1632 apply_dline(source_p, conf, tkline_time);
259 michael 2820 return 0;
260 michael 1058 }
261    
262 michael 2820 static int
263 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
264 michael 1301 {
265 michael 1794 char def_reason[] = CONF_NOREASON;
266 michael 1622 char *dlhost, *reason;
267 michael 1301 const char *creason;
268     const struct Client *target_p = NULL;
269     struct irc_ssaddr daddr;
270 michael 1632 struct MaskItem *conf=NULL;
271 michael 1301 time_t tkline_time=0;
272 michael 1644 int bits = 0, aftype = 0, t = 0;
273 michael 1301 const char *current_date = NULL;
274 michael 1398 char hostip[HOSTIPLEN + 1];
275 michael 1301 char buffer[IRCD_BUFSIZE];
276    
277     if (parc != 5 || EmptyString(parv[4]))
278 michael 2820 return 0;
279 michael 1301
280     /* parv[0] parv[1] parv[2] parv[3] parv[4] */
281 michael 4639 /* command target_server tkline_time host reason */
282 michael 1301 sendto_match_servs(source_p, parv[1], CAP_DLN,
283     "DLINE %s %s %s :%s",
284     parv[1], parv[2], parv[3], parv[4]);
285    
286 michael 1652 if (match(parv[1], me.name))
287 michael 2820 return 0;
288 michael 1301
289     tkline_time = valid_tkline(parv[2], TK_SECONDS);
290     dlhost = parv[3];
291     reason = parv[4];
292    
293 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
294     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
295 michael 1301 source_p->username, source_p->host,
296     SHARED_DLINE))
297     {
298     if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
299     {
300 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
301 michael 3737 return 0; /* find_chasing sends ERR_NOSUCHNICK */
302 michael 1301
303     if (!MyConnect(target_p))
304     {
305 michael 4639 if (IsClient(source_p))
306     sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
307 michael 2820 return 0;
308 michael 1301 }
309    
310     if (IsExemptKline(target_p))
311     {
312 michael 4639 if (IsClient(source_p))
313     sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
314 michael 2820 return 0;
315 michael 1301 }
316    
317 michael 4588 getnameinfo((struct sockaddr *)&target_p->connection->ip,
318     target_p->connection->ip.ss_len, hostip,
319 michael 1301 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
320     dlhost = hostip;
321     t = parse_netmask(dlhost, NULL, &bits);
322     assert(t == HM_IPV4 || t == HM_IPV6);
323     }
324    
325     if (bits < 8)
326     {
327 michael 4639 if (IsClient(source_p))
328     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
329 michael 2820 return 0;
330 michael 1301 }
331    
332     if (t == HM_IPV6)
333 michael 1644 aftype= AF_INET6;
334 michael 1301 else
335 michael 1644 aftype = AF_INET;
336 michael 1301
337     parse_netmask(dlhost, &daddr, NULL);
338    
339 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
340 michael 1301 {
341 michael 4639 if (!IsClient(source_p))
342     return 0;
343    
344 michael 1632 creason = conf->reason ? conf->reason : def_reason;
345     if (IsConfExemptKline(conf))
346 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
347     dlhost, conf->host, creason);
348 michael 1301 else
349 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
350     dlhost, conf->host, creason);
351 michael 2820 return 0;
352 michael 1301 }
353    
354 michael 3208 current_date = smalldate(0);
355 michael 1301
356     if (!valid_comment(source_p, reason, 1))
357 michael 2820 return 0;
358 michael 1301
359 michael 1632 conf = conf_make(CONF_DLINE);
360 michael 1646 conf->host = xstrdup(dlhost);
361 michael 1301
362 michael 3368 if (tkline_time)
363 michael 1301 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
364     (int)(tkline_time/60), reason, current_date);
365     else
366     snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
367    
368 michael 1646 conf->reason = xstrdup(buffer);
369 michael 1632 apply_dline(source_p, conf, tkline_time);
370 michael 1301 }
371 michael 2820
372     return 0;
373 michael 1301 }
374    
375 michael 2810 static struct Message dline_msgtab =
376     {
377 michael 4545 "DLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
378 michael 2810 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
379 michael 1230 };
380    
381     static void
382     module_init(void)
383     {
384     mod_add_cmd(&dline_msgtab);
385 michael 1301 add_capability("DLN", CAP_DLN, 1);
386 michael 1230 }
387    
388     static void
389     module_exit(void)
390     {
391     mod_del_cmd(&dline_msgtab);
392 michael 1301 delete_capability("DLN");
393 michael 1230 }
394    
395 michael 2810 struct module module_entry =
396     {
397 michael 1230 .node = { NULL, NULL, NULL },
398     .name = NULL,
399     .version = "$Revision$",
400     .handle = NULL,
401     .modinit = module_init,
402     .modexit = module_exit,
403     .flags = 0
404     };

Properties

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