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: 5775
Committed: Sat Apr 4 17:31:06 2015 UTC (9 years ago) by michael
Content type: text/x-csrc
File size: 10139 byte(s)
Log Message:
- Changed some function to void if we don't need a return value
- Have some other functions return saner values

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

Properties

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