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: 4889
Committed: Wed Nov 19 17:10:25 2014 UTC (11 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 10178 byte(s)
Log Message:
- Style corrections

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 4564 * 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 3930 static void
47     check_dline(struct AddressRec *arec)
48     {
49 michael 4816 dlink_node *node = NULL, *node_next = NULL;
50 michael 3930
51 michael 4816 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
52 michael 3930 {
53 michael 4816 struct Client *client_p = node->data;
54 michael 3930
55     if (IsDead(client_p))
56     continue;
57    
58     switch (arec->masktype)
59     {
60     case HM_IPV4:
61 michael 4589 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 3930 conf_try_ban(client_p, arec->conf);
64     break;
65     case HM_IPV6:
66 michael 4589 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 3930 conf_try_ban(client_p, arec->conf);
69     break;
70     default: break;
71     }
72     }
73    
74 michael 4816 DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
75 michael 3930 {
76 michael 4816 struct Client *client_p = node->data;
77 michael 3930
78     if (IsDead(client_p))
79     continue;
80    
81     switch (arec->masktype)
82     {
83     case HM_IPV4:
84 michael 4589 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 3930 conf_try_ban(client_p, arec->conf);
87     break;
88     case HM_IPV6:
89 michael 4589 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 3930 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 4640
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 4889
117 michael 1622 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
118     "%s added temporary %d min. D-Line for [%s] [%s]",
119     get_oper_name(source_p), tkline_time/60,
120 michael 1632 conf->host, conf->reason);
121 michael 1622 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
122 michael 1632 get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
123 michael 1622 }
124     else
125     {
126 michael 4640 if (IsClient(source_p))
127     sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
128    
129 michael 1622 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
130     "%s added D-Line for [%s] [%s]",
131 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
132 michael 1622 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
133 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
134 michael 1622 }
135    
136 michael 1632 SetConfDatabase(conf);
137     conf->setat = CurrentTime;
138 michael 3930 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 4889 struct MaskItem *conf = NULL;
161 michael 1058 time_t tkline_time=0;
162 michael 1644 int bits = 0, aftype = 0, t = 0;
163 michael 1398 char hostip[HOSTIPLEN + 1];
164 michael 1230 char buffer[IRCD_BUFSIZE];
165 michael 1058
166 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
167 michael 1058 {
168 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
169 michael 2820 return 0;
170 michael 1058 }
171    
172     if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
173 michael 1301 NULL, &tkline_time, &target_server, &reason) < 0)
174 michael 2820 return 0;
175 michael 1058
176 michael 3368 if (target_server)
177 michael 1301 {
178 michael 2807 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
179     target_server, (unsigned long)tkline_time,
180     dlhost, reason);
181 michael 1301
182     /* Allow ON to apply local kline as well if it matches */
183 michael 1652 if (match(target_server, me.name))
184 michael 2820 return 0;
185 michael 1301 }
186     else
187     cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
188     "%d %s :%s", tkline_time, dlhost, reason);
189    
190 michael 1058 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
191     {
192 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
193 michael 3736 return 0; /* find_chasing sends ERR_NOSUCHNICK */
194 michael 1058
195     if (!MyConnect(target_p))
196     {
197 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
198 michael 2820 return 0;
199 michael 1058 }
200    
201     if (IsExemptKline(target_p))
202     {
203 michael 3110 sendto_one_notice(source_p, &me, ":%s is E-lined",
204     target_p->name);
205 michael 2820 return 0;
206 michael 1058 }
207    
208 michael 4589 getnameinfo((struct sockaddr *)&target_p->connection->ip,
209     target_p->connection->ip.ss_len, hostip,
210 michael 1123 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
211 michael 1058 dlhost = hostip;
212     t = parse_netmask(dlhost, NULL, &bits);
213     assert(t == HM_IPV4 || t == HM_IPV6);
214     }
215    
216     if (bits < 8)
217     {
218 michael 3110 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
219 michael 2820 return 0;
220 michael 1058 }
221    
222     if (t == HM_IPV6)
223 michael 1644 aftype = AF_INET6;
224 michael 1058 else
225 michael 1644 aftype = AF_INET;
226 michael 1058
227     parse_netmask(dlhost, &daddr, NULL);
228    
229 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
230 michael 1058 {
231 michael 1632 creason = conf->reason ? conf->reason : def_reason;
232 michael 2810
233 michael 1632 if (IsConfExemptKline(conf))
234 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
235     dlhost, conf->host, creason);
236 michael 1058 else
237 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
238     dlhost, conf->host, creason);
239 michael 2820 return 0;
240 michael 1058 }
241    
242 michael 1632 conf = conf_make(CONF_DLINE);
243 michael 1646 conf->host = xstrdup(dlhost);
244 michael 1058
245 michael 3368 if (tkline_time)
246 michael 4672 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %.*s (%s)",
247 michael 4889 (int)(tkline_time/60), REASONLEN, reason, smalldate(0));
248 michael 1058 else
249 michael 4889 snprintf(buffer, sizeof(buffer), "%.*s (%s)", REASONLEN, reason, smalldate(0));
250 michael 1058
251 michael 1646 conf->reason = xstrdup(buffer);
252 michael 1632 apply_dline(source_p, conf, tkline_time);
253 michael 2820 return 0;
254 michael 1058 }
255    
256 michael 2820 static int
257 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
258 michael 1301 {
259 michael 1794 char def_reason[] = CONF_NOREASON;
260 michael 1622 char *dlhost, *reason;
261 michael 1301 const char *creason;
262     struct irc_ssaddr daddr;
263 michael 4889 struct MaskItem *conf = NULL;
264 michael 1301 time_t tkline_time=0;
265 michael 1644 int bits = 0, aftype = 0, t = 0;
266 michael 1301 char buffer[IRCD_BUFSIZE];
267    
268     if (parc != 5 || EmptyString(parv[4]))
269 michael 2820 return 0;
270 michael 1301
271     /* parv[0] parv[1] parv[2] parv[3] parv[4] */
272 michael 4640 /* command target_server tkline_time host reason */
273 michael 4889 sendto_match_servs(source_p, parv[1], CAP_DLN, "DLINE %s %s %s :%s",
274 michael 1301 parv[1], parv[2], parv[3], parv[4]);
275    
276 michael 1652 if (match(parv[1], me.name))
277 michael 2820 return 0;
278 michael 1301
279     tkline_time = valid_tkline(parv[2], TK_SECONDS);
280     dlhost = parv[3];
281     reason = parv[4];
282    
283 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
284     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
285 michael 1301 source_p->username, source_p->host,
286     SHARED_DLINE))
287     {
288 michael 4644 if ((t = parse_netmask(dlhost, &daddr, &bits)) == HM_HOST)
289     return 0;
290 michael 1301
291     if (bits < 8)
292     {
293 michael 4640 if (IsClient(source_p))
294     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
295 michael 2820 return 0;
296 michael 1301 }
297    
298     if (t == HM_IPV6)
299 michael 4648 aftype = AF_INET6;
300 michael 1301 else
301 michael 1644 aftype = AF_INET;
302 michael 1301
303 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
304 michael 1301 {
305 michael 4640 if (!IsClient(source_p))
306     return 0;
307    
308 michael 1632 creason = conf->reason ? conf->reason : def_reason;
309 michael 4889
310 michael 1632 if (IsConfExemptKline(conf))
311 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
312     dlhost, conf->host, creason);
313 michael 1301 else
314 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
315     dlhost, conf->host, creason);
316 michael 2820 return 0;
317 michael 1301 }
318    
319 michael 1632 conf = conf_make(CONF_DLINE);
320 michael 1646 conf->host = xstrdup(dlhost);
321 michael 1301
322 michael 3368 if (tkline_time)
323 michael 4672 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %.*s (%s)",
324 michael 4889 (int)(tkline_time/60), REASONLEN, reason, smalldate(0));
325 michael 1301 else
326 michael 4889 snprintf(buffer, sizeof(buffer), "%.*s (%s)", REASONLEN, reason, smalldate(0));
327 michael 1301
328 michael 1646 conf->reason = xstrdup(buffer);
329 michael 1632 apply_dline(source_p, conf, tkline_time);
330 michael 1301 }
331 michael 2820
332     return 0;
333 michael 1301 }
334    
335 michael 2810 static struct Message dline_msgtab =
336     {
337 michael 4546 "DLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
338 michael 2810 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
339 michael 1230 };
340    
341     static void
342     module_init(void)
343     {
344     mod_add_cmd(&dline_msgtab);
345 michael 1301 add_capability("DLN", CAP_DLN, 1);
346 michael 1230 }
347    
348     static void
349     module_exit(void)
350     {
351     mod_del_cmd(&dline_msgtab);
352 michael 1301 delete_capability("DLN");
353 michael 1230 }
354    
355 michael 2810 struct module module_entry =
356     {
357 michael 1230 .node = { NULL, NULL, NULL },
358     .name = NULL,
359     .version = "$Revision$",
360     .handle = NULL,
361     .modinit = module_init,
362     .modexit = module_exit,
363     .flags = 0
364     };

Properties

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