ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 3368
Committed: Mon Apr 21 14:24:16 2014 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 9661 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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * 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     /* 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     /* mo_dline()
86     *
87     * inputs - pointer to server
88     * - pointer to client
89     * - parameter count
90     * - parameter list
91     * output -
92     * side effects - D line is added
93     *
94     */
95 michael 2820 static int
96 michael 3156 mo_dline(struct Client *source_p, int parc, char *parv[])
97 michael 1058 {
98 michael 1794 char def_reason[] = CONF_NOREASON;
99 michael 1622 char *dlhost = NULL, *reason = NULL;
100 michael 1301 char *target_server = NULL;
101 michael 1058 const char *creason;
102     const struct Client *target_p = NULL;
103     struct irc_ssaddr daddr;
104 michael 1632 struct MaskItem *conf=NULL;
105 michael 1058 time_t tkline_time=0;
106 michael 1644 int bits = 0, aftype = 0, t = 0;
107 michael 1058 const char *current_date = NULL;
108 michael 1398 char hostip[HOSTIPLEN + 1];
109 michael 1230 char buffer[IRCD_BUFSIZE];
110 michael 1058
111 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
112 michael 1058 {
113 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
114 michael 2820 return 0;
115 michael 1058 }
116    
117     if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
118 michael 1301 NULL, &tkline_time, &target_server, &reason) < 0)
119 michael 2820 return 0;
120 michael 1058
121 michael 3368 if (target_server)
122 michael 1301 {
123 michael 2807 sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
124     target_server, (unsigned long)tkline_time,
125     dlhost, reason);
126 michael 1301
127     /* Allow ON to apply local kline as well if it matches */
128 michael 1652 if (match(target_server, me.name))
129 michael 2820 return 0;
130 michael 1301 }
131     else
132     cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
133     "%d %s :%s", tkline_time, dlhost, reason);
134    
135 michael 1058 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
136     {
137 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
138 michael 2820 return 0;
139 michael 1058
140     if (!MyConnect(target_p))
141     {
142 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
143 michael 2820 return 0;
144 michael 1058 }
145    
146     if (IsExemptKline(target_p))
147     {
148 michael 3110 sendto_one_notice(source_p, &me, ":%s is E-lined",
149     target_p->name);
150 michael 2820 return 0;
151 michael 1058 }
152    
153 michael 1123 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
154     target_p->localClient->ip.ss_len, hostip,
155     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
156 michael 1058 dlhost = hostip;
157     t = parse_netmask(dlhost, NULL, &bits);
158     assert(t == HM_IPV4 || t == HM_IPV6);
159     }
160    
161     if (bits < 8)
162     {
163 michael 3110 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
164 michael 2820 return 0;
165 michael 1058 }
166    
167     #ifdef IPV6
168     if (t == HM_IPV6)
169 michael 1644 aftype = AF_INET6;
170 michael 1058 else
171     #endif
172 michael 1644 aftype = AF_INET;
173 michael 1058
174     parse_netmask(dlhost, &daddr, NULL);
175    
176 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
177 michael 1058 {
178 michael 1632 creason = conf->reason ? conf->reason : def_reason;
179 michael 2810
180 michael 1632 if (IsConfExemptKline(conf))
181 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
182     dlhost, conf->host, creason);
183 michael 1058 else
184 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
185     dlhost, conf->host, creason);
186 michael 2820 return 0;
187 michael 1058 }
188    
189 michael 3208 current_date = smalldate(0);
190 michael 1058
191 michael 1243 if (!valid_comment(source_p, reason, 1))
192 michael 2820 return 0;
193 michael 1058
194 michael 1632 conf = conf_make(CONF_DLINE);
195 michael 1646 conf->host = xstrdup(dlhost);
196 michael 1058
197 michael 3368 if (tkline_time)
198 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
199     (int)(tkline_time/60), reason, current_date);
200 michael 1058 else
201 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
202 michael 1058
203 michael 1646 conf->reason = xstrdup(buffer);
204 michael 1632 apply_dline(source_p, conf, tkline_time);
205 michael 1058 rehashed_klines = 1;
206 michael 2820 return 0;
207 michael 1058 }
208    
209 michael 2820 static int
210 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
211 michael 1301 {
212 michael 1794 char def_reason[] = CONF_NOREASON;
213 michael 1622 char *dlhost, *reason;
214 michael 1301 const char *creason;
215     const struct Client *target_p = NULL;
216     struct irc_ssaddr daddr;
217 michael 1632 struct MaskItem *conf=NULL;
218 michael 1301 time_t tkline_time=0;
219 michael 1644 int bits = 0, aftype = 0, t = 0;
220 michael 1301 const char *current_date = NULL;
221 michael 1398 char hostip[HOSTIPLEN + 1];
222 michael 1301 char buffer[IRCD_BUFSIZE];
223    
224     if (parc != 5 || EmptyString(parv[4]))
225 michael 2820 return 0;
226 michael 1301
227     /* parv[0] parv[1] parv[2] parv[3] parv[4] */
228     /* oper target_server tkline_time host reason */
229     sendto_match_servs(source_p, parv[1], CAP_DLN,
230     "DLINE %s %s %s :%s",
231     parv[1], parv[2], parv[3], parv[4]);
232    
233 michael 1652 if (match(parv[1], me.name))
234 michael 2820 return 0;
235 michael 1301
236     tkline_time = valid_tkline(parv[2], TK_SECONDS);
237     dlhost = parv[3];
238     reason = parv[4];
239    
240 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
241     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
242 michael 1301 source_p->username, source_p->host,
243     SHARED_DLINE))
244     {
245     if (!IsClient(source_p))
246 michael 2820 return 0;
247    
248 michael 1301 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
249     {
250 michael 3192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
251 michael 2820 return 0;
252 michael 1301
253     if (!MyConnect(target_p))
254     {
255 michael 3118 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
256 michael 2820 return 0;
257 michael 1301 }
258    
259     if (IsExemptKline(target_p))
260     {
261 michael 3110 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
262 michael 2820 return 0;
263 michael 1301 }
264    
265     getnameinfo((struct sockaddr *)&target_p->localClient->ip,
266     target_p->localClient->ip.ss_len, hostip,
267     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
268     dlhost = hostip;
269     t = parse_netmask(dlhost, NULL, &bits);
270     assert(t == HM_IPV4 || t == HM_IPV6);
271     }
272    
273     if (bits < 8)
274     {
275 michael 3110 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
276 michael 2820 return 0;
277 michael 1301 }
278    
279     #ifdef IPV6
280     if (t == HM_IPV6)
281 michael 1644 aftype= AF_INET6;
282 michael 1301 else
283     #endif
284 michael 1644 aftype = AF_INET;
285 michael 1301
286     parse_netmask(dlhost, &daddr, NULL);
287    
288 michael 3368 if ((conf = find_dline_conf(&daddr, aftype)))
289 michael 1301 {
290 michael 1632 creason = conf->reason ? conf->reason : def_reason;
291     if (IsConfExemptKline(conf))
292 michael 3110 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
293     dlhost, conf->host, creason);
294 michael 1301 else
295 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
296     dlhost, conf->host, creason);
297 michael 2820 return 0;
298 michael 1301 }
299    
300 michael 3208 current_date = smalldate(0);
301 michael 1301
302     if (!valid_comment(source_p, reason, 1))
303 michael 2820 return 0;
304 michael 1301
305 michael 1632 conf = conf_make(CONF_DLINE);
306 michael 1646 conf->host = xstrdup(dlhost);
307 michael 1301
308 michael 3368 if (tkline_time)
309 michael 1301 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
310     (int)(tkline_time/60), reason, current_date);
311     else
312     snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
313    
314 michael 1646 conf->reason = xstrdup(buffer);
315 michael 1632 apply_dline(source_p, conf, tkline_time);
316 michael 1301 rehashed_klines = 1;
317     }
318 michael 2820
319     return 0;
320 michael 1301 }
321    
322 michael 2810 static struct Message dline_msgtab =
323     {
324 michael 1230 "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
325 michael 2810 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
326 michael 1230 };
327    
328     static void
329     module_init(void)
330     {
331     mod_add_cmd(&dline_msgtab);
332 michael 1301 add_capability("DLN", CAP_DLN, 1);
333 michael 1230 }
334    
335     static void
336     module_exit(void)
337     {
338     mod_del_cmd(&dline_msgtab);
339 michael 1301 delete_capability("DLN");
340 michael 1230 }
341    
342 michael 2810 struct module module_entry =
343     {
344 michael 1230 .node = { NULL, NULL, NULL },
345     .name = NULL,
346     .version = "$Revision$",
347     .handle = NULL,
348     .modinit = module_init,
349     .modexit = module_exit,
350     .flags = 0
351     };

Properties

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