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: 4935
Committed: Tue Nov 25 21:09:24 2014 UTC (11 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 10154 byte(s)
Log Message:
- Style corrections; constifications

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_dline.c
23 * \brief Includes required functions for processing the DLINE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "irc_string.h"
31 #include "conf.h"
32 #include "ircd.h"
33 #include "hostmask.h"
34 #include "numeric.h"
35 #include "log.h"
36 #include "misc.h"
37 #include "send.h"
38 #include "hash.h"
39 #include "server.h"
40 #include "parse.h"
41 #include "modules.h"
42 #include "conf_db.h"
43 #include "memory.h"
44
45
46 static void
47 check_dline(struct AddressRec *arec)
48 {
49 dlink_node *node = NULL, *node_next = NULL;
50
51 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
52 {
53 struct Client *client_p = node->data;
54
55 if (IsDead(client_p))
56 continue;
57
58 switch (arec->masktype)
59 {
60 case HM_IPV4:
61 if (client_p->connection->aftype == AF_INET)
62 if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
63 conf_try_ban(client_p, arec->conf);
64 break;
65 case HM_IPV6:
66 if (client_p->connection->aftype == AF_INET6)
67 if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
68 conf_try_ban(client_p, arec->conf);
69 break;
70 default: break;
71 }
72 }
73
74 DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
75 {
76 struct Client *client_p = node->data;
77
78 if (IsDead(client_p))
79 continue;
80
81 switch (arec->masktype)
82 {
83 case HM_IPV4:
84 if (client_p->connection->aftype == AF_INET)
85 if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
86 conf_try_ban(client_p, arec->conf);
87 break;
88 case HM_IPV6:
89 if (client_p->connection->aftype == AF_INET6)
90 if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
91 conf_try_ban(client_p, arec->conf);
92 break;
93 default: break;
94 }
95 }
96 }
97
98
99 /* apply_tdline()
100 *
101 * inputs -
102 * output - NONE
103 * side effects - tkline as given is placed
104 */
105 static void
106 apply_dline(struct Client *source_p, struct MaskItem *conf,
107 time_t tkline_time)
108 {
109 if (tkline_time)
110 {
111 conf->until = CurrentTime + tkline_time;
112
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
117 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 conf->host, conf->reason);
121 ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
122 get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
123 }
124 else
125 {
126 if (IsClient(source_p))
127 sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
128
129 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
130 "%s added D-Line for [%s] [%s]",
131 get_oper_name(source_p), conf->host, conf->reason);
132 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
133 get_oper_name(source_p), conf->host, conf->reason);
134 }
135
136 SetConfDatabase(conf);
137 conf->setat = CurrentTime;
138 check_dline(add_conf_by_address(CONF_DLINE, conf));
139 }
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 static int
152 mo_dline(struct Client *source_p, int parc, char *parv[])
153 {
154 char def_reason[] = CONF_NOREASON;
155 char *dlhost = NULL, *reason = NULL;
156 char *target_server = NULL;
157 const char *creason;
158 const struct Client *target_p = NULL;
159 struct irc_ssaddr daddr;
160 struct MaskItem *conf = NULL;
161 time_t tkline_time=0;
162 int bits = 0, aftype = 0, t = 0;
163 char hostip[HOSTIPLEN + 1];
164 char buffer[IRCD_BUFSIZE];
165
166 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
167 {
168 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
169 return 0;
170 }
171
172 if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
173 NULL, &tkline_time, &target_server, &reason) < 0)
174 return 0;
175
176 if (target_server)
177 {
178 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
182 /* Allow ON to apply local kline as well if it matches */
183 if (match(target_server, me.name))
184 return 0;
185 }
186 else
187 cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
188 "%d %s :%s", tkline_time, dlhost, reason);
189
190 if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
191 {
192 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
193 return 0; /* find_chasing sends ERR_NOSUCHNICK */
194
195 if (!MyConnect(target_p))
196 {
197 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
198 return 0;
199 }
200
201 if (IsExemptKline(target_p))
202 {
203 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
204 return 0;
205 }
206
207 getnameinfo((struct sockaddr *)&target_p->connection->ip,
208 target_p->connection->ip.ss_len, hostip,
209 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
210 dlhost = hostip;
211 t = parse_netmask(dlhost, NULL, &bits);
212 assert(t == HM_IPV4 || t == HM_IPV6);
213 }
214
215 if (bits < 8)
216 {
217 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
218 return 0;
219 }
220
221 if (t == HM_IPV6)
222 aftype = AF_INET6;
223 else
224 aftype = AF_INET;
225
226 parse_netmask(dlhost, &daddr, NULL);
227
228 if ((conf = find_dline_conf(&daddr, aftype)))
229 {
230 creason = conf->reason ? conf->reason : def_reason;
231
232 if (IsConfExemptKline(conf))
233 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
234 dlhost, conf->host, creason);
235 else
236 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
237 dlhost, conf->host, creason);
238 return 0;
239 }
240
241 conf = conf_make(CONF_DLINE);
242 conf->host = xstrdup(dlhost);
243
244 if (tkline_time)
245 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %.*s (%s)",
246 (int)(tkline_time/60), REASONLEN, reason, smalldate(0));
247 else
248 snprintf(buffer, sizeof(buffer), "%.*s (%s)", REASONLEN, reason, smalldate(0));
249
250 conf->reason = xstrdup(buffer);
251 apply_dline(source_p, conf, tkline_time);
252 return 0;
253 }
254
255 static int
256 ms_dline(struct Client *source_p, int parc, char *parv[])
257 {
258 char def_reason[] = CONF_NOREASON;
259 char *dlhost, *reason;
260 const char *creason;
261 struct irc_ssaddr daddr;
262 struct MaskItem *conf = NULL;
263 time_t tkline_time=0;
264 int bits = 0, aftype = 0, t = 0;
265 char buffer[IRCD_BUFSIZE];
266
267 if (parc != 5 || EmptyString(parv[4]))
268 return 0;
269
270 /* parv[0] parv[1] parv[2] parv[3] parv[4] */
271 /* command target_server tkline_time host reason */
272 sendto_match_servs(source_p, parv[1], CAP_DLN, "DLINE %s %s %s :%s",
273 parv[1], parv[2], parv[3], parv[4]);
274
275 if (match(parv[1], me.name))
276 return 0;
277
278 tkline_time = valid_tkline(parv[2], TK_SECONDS);
279 dlhost = parv[3];
280 reason = parv[4];
281
282 if (HasFlag(source_p, FLAGS_SERVICE) ||
283 find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
284 source_p->username, source_p->host,
285 SHARED_DLINE))
286 {
287 if ((t = parse_netmask(dlhost, &daddr, &bits)) == HM_HOST)
288 return 0;
289
290 if (bits < 8)
291 {
292 if (IsClient(source_p))
293 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than 8 require conf access.");
294 return 0;
295 }
296
297 if (t == HM_IPV6)
298 aftype = AF_INET6;
299 else
300 aftype = AF_INET;
301
302 if ((conf = find_dline_conf(&daddr, aftype)))
303 {
304 if (!IsClient(source_p))
305 return 0;
306
307 creason = conf->reason ? conf->reason : def_reason;
308
309 if (IsConfExemptKline(conf))
310 sendto_one_notice(source_p, &me, ":[%s] is (E)d-lined by [%s] - %s",
311 dlhost, conf->host, creason);
312 else
313 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
314 dlhost, conf->host, creason);
315 return 0;
316 }
317
318 conf = conf_make(CONF_DLINE);
319 conf->host = xstrdup(dlhost);
320
321 if (tkline_time)
322 snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %.*s (%s)",
323 (int)(tkline_time/60), REASONLEN, reason, smalldate(0));
324 else
325 snprintf(buffer, sizeof(buffer), "%.*s (%s)", REASONLEN, reason, smalldate(0));
326
327 conf->reason = xstrdup(buffer);
328 apply_dline(source_p, conf, tkline_time);
329 }
330
331 return 0;
332 }
333
334 static struct Message dline_msgtab =
335 {
336 "DLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
337 { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
338 };
339
340 static void
341 module_init(void)
342 {
343 mod_add_cmd(&dline_msgtab);
344 add_capability("DLN", CAP_DLN, 1);
345 }
346
347 static void
348 module_exit(void)
349 {
350 mod_del_cmd(&dline_msgtab);
351 delete_capability("DLN");
352 }
353
354 struct module module_entry =
355 {
356 .node = { NULL, NULL, NULL },
357 .name = NULL,
358 .version = "$Revision$",
359 .handle = NULL,
360 .modinit = module_init,
361 .modexit = module_exit,
362 .flags = 0
363 };

Properties

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