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: 7422
Committed: Mon Mar 7 16:48:08 2016 UTC (10 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 9600 byte(s)
Log Message:
- m_dline.c, m_kline.c: expiry time for *LINES set by remote clients is no longer capped at MAX_TDKLINE_TIME

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2016 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 "conf_cluster.h"
33 #include "conf_shared.h"
34 #include "ircd.h"
35 #include "hostmask.h"
36 #include "numeric.h"
37 #include "log.h"
38 #include "misc.h"
39 #include "send.h"
40 #include "server.h"
41 #include "parse.h"
42 #include "modules.h"
43 #include "memory.h"
44
45
46 static void
47 dline_check(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, CLIENT_BAN_DLINE, arec->conf->reason);
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, CLIENT_BAN_DLINE, arec->conf->reason);
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, CLIENT_BAN_DLINE, arec->conf->reason);
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, CLIENT_BAN_DLINE, arec->conf->reason);
92 break;
93 default: break;
94 }
95 }
96 }
97
98 /* dline_add()
99 *
100 * inputs -
101 * output - NONE
102 * side effects - dline as given is placed
103 */
104 static void
105 dline_handle(struct Client *source_p, const char *addr, const char *reason,
106 uintmax_t duration)
107 {
108 char buf[IRCD_BUFSIZE];
109 struct irc_ssaddr daddr;
110 int bits = 0, aftype = 0;
111 struct MaskItem *conf = NULL;
112
113 switch (parse_netmask(addr, &daddr, &bits))
114 {
115 case HM_IPV4:
116 if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr)
117 {
118 if (IsClient(source_p))
119 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
120 ConfigGeneral.dline_min_cidr);
121 return;
122 }
123
124 aftype = AF_INET;
125 break;
126 case HM_IPV6:
127 if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr6)
128 {
129 if (IsClient(source_p))
130 sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
131 ConfigGeneral.dline_min_cidr6);
132 return;
133 }
134
135 aftype = AF_INET6;
136 break;
137 default: /* HM_HOST */
138 return;
139 }
140
141 if ((conf = find_conf_by_address(NULL, &daddr, CONF_DLINE, aftype, NULL, NULL, 1)))
142 {
143 if (IsClient(source_p))
144 sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
145 addr, conf->host, conf->reason);
146 return;
147 }
148
149 if (duration)
150 snprintf(buf, sizeof(buf), "Temporary D-line %ju min. - %.*s (%s)",
151 duration / 60, REASONLEN, reason, date_iso8601(0));
152 else
153 snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, date_iso8601(0));
154
155 conf = conf_make(CONF_DLINE);
156 conf->host = xstrdup(addr);
157 conf->reason = xstrdup(buf);
158 conf->setat = CurrentTime;
159 SetConfDatabase(conf);
160
161 if (duration)
162 {
163 conf->until = CurrentTime + duration;
164
165 if (IsClient(source_p))
166 sendto_one_notice(source_p, &me, ":Added temporary %ju min. D-Line [%s]",
167 duration / 60, conf->host);
168
169 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
170 "%s added temporary %ju min. D-Line for [%s] [%s]",
171 get_oper_name(source_p), duration / 60,
172 conf->host, conf->reason);
173 ilog(LOG_TYPE_DLINE, "%s added temporary %ju min. D-Line for [%s] [%s]",
174 get_oper_name(source_p), duration / 60, conf->host, conf->reason);
175 }
176 else
177 {
178 if (IsClient(source_p))
179 sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
180
181 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
182 "%s added D-Line for [%s] [%s]",
183 get_oper_name(source_p), conf->host, conf->reason);
184 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
185 get_oper_name(source_p), conf->host, conf->reason);
186 }
187
188 dline_check(add_conf_by_address(CONF_DLINE, conf));
189 }
190
191 /* mo_dline()
192 *
193 * inputs - pointer to server
194 * - pointer to client
195 * - parameter count
196 * - parameter list
197 * output -
198 * side effects - D line is added
199 *
200 */
201 static int
202 mo_dline(struct Client *source_p, int parc, char *parv[])
203 {
204 char *dlhost = NULL, *reason = NULL;
205 char *target_server = NULL;
206 const struct Client *target_p = NULL;
207 uintmax_t duration = 0;
208 int t = 0;
209 char hostip[HOSTIPLEN + 1];
210
211 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
212 {
213 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
214 return 0;
215 }
216
217 if (!parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
218 NULL, &duration, &target_server, &reason))
219 return 0;
220
221 if (target_server)
222 {
223 sendto_match_servs(source_p, target_server, CAPAB_DLN, "DLINE %s %ju %s :%s",
224 target_server, duration,
225 dlhost, reason);
226
227 /* Allow ON to apply local dline as well if it matches */
228 if (match(target_server, me.name))
229 return 0;
230 }
231 else
232 cluster_distribute(source_p, "DLINE", CAPAB_DLN, CLUSTER_DLINE,
233 "%ju %s :%s", duration, dlhost, reason);
234
235 if ((t = parse_netmask(dlhost, NULL, NULL)) == HM_HOST)
236 {
237 if ((target_p = find_chasing(source_p, dlhost)) == NULL)
238 return 0; /* find_chasing sends ERR_NOSUCHNICK */
239
240 if (!MyConnect(target_p))
241 {
242 sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server");
243 return 0;
244 }
245
246 if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
247 {
248 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
249 return 0;
250 }
251
252 getnameinfo((const struct sockaddr *)&target_p->connection->ip,
253 target_p->connection->ip.ss_len, hostip,
254 sizeof(hostip), NULL, 0, NI_NUMERICHOST);
255 dlhost = hostip;
256 }
257
258 dline_handle(source_p, dlhost, reason, duration);
259 return 0;
260 }
261
262 /*! \brief DLINE command handler
263 *
264 * \param source_p Pointer to allocated Client struct from which the message
265 * originally comes from. This can be a local or remote client.
266 * \param parc Integer holding the number of supplied arguments.
267 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
268 * pointers.
269 * \note Valid arguments for this command are:
270 * - parv[0] = command
271 * - parv[1] = target server mask
272 * - parv[2] = duration in seconds
273 * - parv[3] = IP address
274 * - parv[4] = reason
275 */
276 static int
277 ms_dline(struct Client *source_p, int parc, char *parv[])
278 {
279 const char *dlhost, *reason;
280
281 if (parc != 5 || EmptyString(parv[4]))
282 return 0;
283
284 sendto_match_servs(source_p, parv[1], CAPAB_DLN, "DLINE %s %s %s :%s",
285 parv[1], parv[2], parv[3], parv[4]);
286
287 if (match(parv[1], me.name))
288 return 0;
289
290 dlhost = parv[3];
291 reason = parv[4];
292
293 if (HasFlag(source_p, FLAGS_SERVICE) ||
294 shared_find(SHARED_DLINE, source_p->servptr->name,
295 source_p->username, source_p->host))
296 dline_handle(source_p, dlhost, reason, strtoumax(parv[2], NULL, 10));
297
298 return 0;
299 }
300
301 static struct Message dline_msgtab =
302 {
303 .cmd = "DLINE",
304 .args_min = 2,
305 .args_max = MAXPARA,
306 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
307 .handlers[CLIENT_HANDLER] = m_not_oper,
308 .handlers[SERVER_HANDLER] = ms_dline,
309 .handlers[ENCAP_HANDLER] = m_ignore,
310 .handlers[OPER_HANDLER] = mo_dline
311 };
312
313 static void
314 module_init(void)
315 {
316 mod_add_cmd(&dline_msgtab);
317 add_capability("DLN", CAPAB_DLN);
318 }
319
320 static void
321 module_exit(void)
322 {
323 mod_del_cmd(&dline_msgtab);
324 delete_capability("DLN");
325 }
326
327 struct module module_entry =
328 {
329 .version = "$Revision$",
330 .modinit = module_init,
331 .modexit = module_exit,
332 };

Properties

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