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: 4655
Committed: Tue Sep 23 14:53:00 2014 UTC (11 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 10389 byte(s)
Log Message:
- m_dline.c: 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 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     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 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     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 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 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 4640 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 1622 }
134    
135 michael 1632 SetConfDatabase(conf);
136     conf->setat = CurrentTime;
137 michael 3930 check_dline(add_conf_by_address(CONF_DLINE, conf));
138 michael 1058 }
139    
140     /* mo_dline()
141     *
142     * inputs - pointer to server
143     * - pointer to client
144     * - parameter count
145     * - parameter list
146     * output -
147     * side effects - D line is added
148     *
149     */
150 michael 2820 static int
151 michael 3156 mo_dline(struct Client *source_p, int parc, char *parv[])
152 michael 1058 {
153 michael 1794 char def_reason[] = CONF_NOREASON;
154 michael 1622 char *dlhost = NULL, *reason = NULL;
155 michael 1301 char *target_server = NULL;
156 michael 1058 const char *creason;
157     const struct Client *target_p = NULL;
158     struct irc_ssaddr daddr;
159 michael 1632 struct MaskItem *conf=NULL;
160 michael 1058 time_t tkline_time=0;
161 michael 1644 int bits = 0, aftype = 0, t = 0;
162 michael 1058 const char *current_date = NULL;
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 3208 current_date = smalldate(0);
243 michael 1058
244 michael 1243 if (!valid_comment(source_p, reason, 1))
245 michael 2820 return 0;
246 michael 1058
247 michael 1632 conf = conf_make(CONF_DLINE);
248 michael 1646 conf->host = xstrdup(dlhost);
249 michael 1058
250 michael 3368 if (tkline_time)
251 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
252     (int)(tkline_time/60), reason, current_date);
253 michael 1058 else
254 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
255 michael 1058
256 michael 1646 conf->reason = xstrdup(buffer);
257 michael 1632 apply_dline(source_p, conf, tkline_time);
258 michael 2820 return 0;
259 michael 1058 }
260    
261 michael 2820 static int
262 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
263 michael 1301 {
264 michael 1794 char def_reason[] = CONF_NOREASON;
265 michael 1622 char *dlhost, *reason;
266 michael 1301 const char *creason;
267     struct irc_ssaddr daddr;
268 michael 1632 struct MaskItem *conf=NULL;
269 michael 1301 time_t tkline_time=0;
270 michael 1644 int bits = 0, aftype = 0, t = 0;
271 michael 1301 const char *current_date = NULL;
272     char buffer[IRCD_BUFSIZE];
273    
274     if (parc != 5 || EmptyString(parv[4]))
275 michael 2820 return 0;
276 michael 1301
277     /* parv[0] parv[1] parv[2] parv[3] parv[4] */
278 michael 4640 /* command target_server tkline_time host reason */
279 michael 1301 sendto_match_servs(source_p, parv[1], CAP_DLN,
280     "DLINE %s %s %s :%s",
281     parv[1], parv[2], parv[3], parv[4]);
282    
283 michael 1652 if (match(parv[1], me.name))
284 michael 2820 return 0;
285 michael 1301
286     tkline_time = valid_tkline(parv[2], TK_SECONDS);
287     dlhost = parv[3];
288     reason = parv[4];
289    
290 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
291     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
292 michael 1301 source_p->username, source_p->host,
293     SHARED_DLINE))
294     {
295 michael 4644 if ((t = parse_netmask(dlhost, &daddr, &bits)) == HM_HOST)
296     return 0;
297 michael 1301
298     if (bits < 8)
299     {
300 michael 4640 if (IsClient(source_p))
301     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
302 michael 2820 return 0;
303 michael 1301 }
304    
305     if (t == HM_IPV6)
306 michael 4648 aftype = AF_INET6;
307 michael 1301 else
308 michael 1644 aftype = AF_INET;
309 michael 1301
310 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
311 michael 1301 {
312 michael 4640 if (!IsClient(source_p))
313     return 0;
314    
315 michael 1632 creason = conf->reason ? conf->reason : def_reason;
316     if (IsConfExemptKline(conf))
317 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
318     dlhost, conf->host, creason);
319 michael 1301 else
320 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
321     dlhost, conf->host, creason);
322 michael 2820 return 0;
323 michael 1301 }
324    
325 michael 3208 current_date = smalldate(0);
326 michael 1301
327     if (!valid_comment(source_p, reason, 1))
328 michael 2820 return 0;
329 michael 1301
330 michael 1632 conf = conf_make(CONF_DLINE);
331 michael 1646 conf->host = xstrdup(dlhost);
332 michael 1301
333 michael 3368 if (tkline_time)
334 michael 1301 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
335     (int)(tkline_time/60), reason, current_date);
336     else
337     snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
338    
339 michael 1646 conf->reason = xstrdup(buffer);
340 michael 1632 apply_dline(source_p, conf, tkline_time);
341 michael 1301 }
342 michael 2820
343     return 0;
344 michael 1301 }
345    
346 michael 2810 static struct Message dline_msgtab =
347     {
348 michael 4546 "DLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
349 michael 2810 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
350 michael 1230 };
351    
352     static void
353     module_init(void)
354     {
355     mod_add_cmd(&dline_msgtab);
356 michael 1301 add_capability("DLN", CAP_DLN, 1);
357 michael 1230 }
358    
359     static void
360     module_exit(void)
361     {
362     mod_del_cmd(&dline_msgtab);
363 michael 1301 delete_capability("DLN");
364 michael 1230 }
365    
366 michael 2810 struct module module_entry =
367     {
368 michael 1230 .node = { NULL, NULL, NULL },
369     .name = NULL,
370     .version = "$Revision$",
371     .handle = NULL,
372     .modinit = module_init,
373     .modexit = module_exit,
374     .flags = 0
375     };

Properties

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