ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 4647
Committed: Sun Sep 21 16:35:21 2014 UTC (10 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 10390 byte(s)
Log Message:
- m_dline.c:ms_dline(): whitespace changes

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     struct irc_ssaddr daddr;
269 michael 1632 struct MaskItem *conf=NULL;
270 michael 1301 time_t tkline_time=0;
271 michael 1644 int bits = 0, aftype = 0, t = 0;
272 michael 1301 const char *current_date = NULL;
273     char buffer[IRCD_BUFSIZE];
274    
275     if (parc != 5 || EmptyString(parv[4]))
276 michael 2820 return 0;
277 michael 1301
278     /* parv[0] parv[1] parv[2] parv[3] parv[4] */
279 michael 4639 /* command target_server tkline_time host reason */
280 michael 1301 sendto_match_servs(source_p, parv[1], CAP_DLN,
281     "DLINE %s %s %s :%s",
282     parv[1], parv[2], parv[3], parv[4]);
283    
284 michael 1652 if (match(parv[1], me.name))
285 michael 2820 return 0;
286 michael 1301
287     tkline_time = valid_tkline(parv[2], TK_SECONDS);
288     dlhost = parv[3];
289     reason = parv[4];
290    
291 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
292     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
293 michael 1301 source_p->username, source_p->host,
294     SHARED_DLINE))
295     {
296 michael 4643 if ((t = parse_netmask(dlhost, &daddr, &bits)) == HM_HOST)
297     return 0;
298 michael 1301
299     if (bits < 8)
300     {
301 michael 4639 if (IsClient(source_p))
302     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
303 michael 2820 return 0;
304 michael 1301 }
305    
306     if (t == HM_IPV6)
307 michael 4647 aftype = AF_INET6;
308 michael 1301 else
309 michael 1644 aftype = AF_INET;
310 michael 1301
311 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
312 michael 1301 {
313 michael 4639 if (!IsClient(source_p))
314     return 0;
315    
316 michael 1632 creason = conf->reason ? conf->reason : def_reason;
317     if (IsConfExemptKline(conf))
318 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
319     dlhost, conf->host, creason);
320 michael 1301 else
321 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
322     dlhost, conf->host, creason);
323 michael 2820 return 0;
324 michael 1301 }
325    
326 michael 3208 current_date = smalldate(0);
327 michael 1301
328     if (!valid_comment(source_p, reason, 1))
329 michael 2820 return 0;
330 michael 1301
331 michael 1632 conf = conf_make(CONF_DLINE);
332 michael 1646 conf->host = xstrdup(dlhost);
333 michael 1301
334 michael 3368 if (tkline_time)
335 michael 1301 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
336     (int)(tkline_time/60), reason, current_date);
337     else
338     snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
339    
340 michael 1646 conf->reason = xstrdup(buffer);
341 michael 1632 apply_dline(source_p, conf, tkline_time);
342 michael 1301 }
343 michael 2820
344     return 0;
345 michael 1301 }
346    
347 michael 2810 static struct Message dline_msgtab =
348     {
349 michael 4545 "DLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
350 michael 2810 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
351 michael 1230 };
352    
353     static void
354     module_init(void)
355     {
356     mod_add_cmd(&dline_msgtab);
357 michael 1301 add_capability("DLN", CAP_DLN, 1);
358 michael 1230 }
359    
360     static void
361     module_exit(void)
362     {
363     mod_del_cmd(&dline_msgtab);
364 michael 1301 delete_capability("DLN");
365 michael 1230 }
366    
367 michael 2810 struct module module_entry =
368     {
369 michael 1230 .node = { NULL, NULL, NULL },
370     .name = NULL,
371     .version = "$Revision$",
372     .handle = NULL,
373     .modinit = module_init,
374     .modexit = module_exit,
375     .flags = 0
376     };

Properties

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