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: 8675
Committed: Sat Nov 24 17:25:23 2018 UTC (7 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 9100 byte(s)
Log Message:
- Further parse_aline() cleanups; get rid of find_user_host()
- /KLINE and /DLINE now no longer supports nick names

File Contents

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

Properties

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