1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_dline.c: Bans a user. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.h" |
27 |
#include "channel.h" |
28 |
#include "client.h" |
29 |
#include "irc_string.h" |
30 |
#include "sprintf_irc.h" |
31 |
#include "ircd.h" |
32 |
#include "hostmask.h" |
33 |
#include "numeric.h" |
34 |
#include "fdlist.h" |
35 |
#include "s_bsd.h" |
36 |
#include "s_conf.h" |
37 |
#include "s_log.h" |
38 |
#include "s_misc.h" |
39 |
#include "send.h" |
40 |
#include "hash.h" |
41 |
#include "s_serv.h" |
42 |
#include "s_gline.h" |
43 |
#include "parse.h" |
44 |
#include "modules.h" |
45 |
|
46 |
|
47 |
/* apply_tdline() |
48 |
* |
49 |
* inputs - |
50 |
* output - NONE |
51 |
* side effects - tkline as given is placed |
52 |
*/ |
53 |
static void |
54 |
apply_tdline(struct Client *source_p, struct ConfItem *conf, |
55 |
const char *current_date, int tkline_time) |
56 |
{ |
57 |
struct AccessItem *aconf; |
58 |
|
59 |
aconf = map_to_conf(conf); |
60 |
aconf->hold = CurrentTime + tkline_time; |
61 |
|
62 |
add_temp_line(conf); |
63 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
64 |
"%s added temporary %d min. D-Line for [%s] [%s]", |
65 |
get_oper_name(source_p), tkline_time/60, |
66 |
aconf->host, aconf->reason); |
67 |
|
68 |
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]", |
69 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
70 |
source_p->name, tkline_time/60, aconf->host); |
71 |
ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]", |
72 |
source_p->name, tkline_time/60, aconf->host, aconf->reason); |
73 |
|
74 |
rehashed_klines = 1; |
75 |
} |
76 |
|
77 |
/* static int remove_tdline_match(const char *host, const char *user) |
78 |
* Input: An ip to undline. |
79 |
* Output: returns YES on success, NO if no tdline removed. |
80 |
* Side effects: Any matching tdlines are removed. |
81 |
*/ |
82 |
static int |
83 |
remove_tdline_match(const char *host) |
84 |
{ |
85 |
struct AccessItem *td_conf; |
86 |
dlink_node *td_node; |
87 |
struct irc_ssaddr addr, caddr; |
88 |
int nm_t, cnm_t, bits, cbits; |
89 |
|
90 |
nm_t = parse_netmask(host, &addr, &bits); |
91 |
|
92 |
DLINK_FOREACH(td_node, temporary_dlines.head) |
93 |
{ |
94 |
td_conf = map_to_conf(td_node->data); |
95 |
cnm_t = parse_netmask(td_conf->host, &caddr, &cbits); |
96 |
|
97 |
if (cnm_t != nm_t) |
98 |
continue; |
99 |
|
100 |
if ((nm_t == HM_HOST && !irccmp(td_conf->host, host)) || |
101 |
(nm_t == HM_IPV4 && bits == cbits && match_ipv4(&addr, &caddr, bits)) |
102 |
#ifdef IPV6 |
103 |
|| (nm_t == HM_IPV6 && bits == cbits && match_ipv6(&addr, &caddr, bits)) |
104 |
#endif |
105 |
) |
106 |
{ |
107 |
dlinkDelete(td_node, &temporary_dlines); |
108 |
delete_one_address_conf(td_conf->host, td_conf); |
109 |
return 1; |
110 |
} |
111 |
} |
112 |
|
113 |
return 0; |
114 |
} |
115 |
|
116 |
/* mo_dline() |
117 |
* |
118 |
* inputs - pointer to server |
119 |
* - pointer to client |
120 |
* - parameter count |
121 |
* - parameter list |
122 |
* output - |
123 |
* side effects - D line is added |
124 |
* |
125 |
*/ |
126 |
static void |
127 |
mo_dline(struct Client *client_p, struct Client *source_p, |
128 |
int parc, char *parv[]) |
129 |
{ |
130 |
char def_reason[] = "No reason"; |
131 |
char *dlhost, *oper_reason, *reason; |
132 |
const char *creason; |
133 |
const struct Client *target_p = NULL; |
134 |
struct irc_ssaddr daddr; |
135 |
struct ConfItem *conf=NULL; |
136 |
struct AccessItem *aconf=NULL; |
137 |
time_t tkline_time=0; |
138 |
int bits, t; |
139 |
const char *current_date = NULL; |
140 |
time_t cur_time; |
141 |
char hostip[HOSTIPLEN]; |
142 |
char buffer[IRCD_BUFSIZE]; |
143 |
|
144 |
if (!HasOFlag(source_p, OPER_FLAG_K)) |
145 |
{ |
146 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
147 |
me.name, source_p->name, "kline"); |
148 |
return; |
149 |
} |
150 |
|
151 |
if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost, |
152 |
NULL, &tkline_time, NULL, &reason) < 0) |
153 |
return; |
154 |
|
155 |
if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST) |
156 |
{ |
157 |
if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL) |
158 |
return; |
159 |
|
160 |
if (!MyConnect(target_p)) |
161 |
{ |
162 |
sendto_one(source_p, |
163 |
":%s NOTICE %s :Can't DLINE nick on another server", |
164 |
me.name, source_p->name); |
165 |
return; |
166 |
} |
167 |
|
168 |
if (IsExemptKline(target_p)) |
169 |
{ |
170 |
sendto_one(source_p, |
171 |
":%s NOTICE %s :%s is E-lined", me.name, |
172 |
source_p->name, target_p->name); |
173 |
return; |
174 |
} |
175 |
|
176 |
getnameinfo((struct sockaddr *)&target_p->localClient->ip, |
177 |
target_p->localClient->ip.ss_len, hostip, |
178 |
sizeof(hostip), NULL, 0, NI_NUMERICHOST); |
179 |
dlhost = hostip; |
180 |
t = parse_netmask(dlhost, NULL, &bits); |
181 |
assert(t == HM_IPV4 || t == HM_IPV6); |
182 |
} |
183 |
|
184 |
if (bits < 8) |
185 |
{ |
186 |
sendto_one(source_p, |
187 |
":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.", |
188 |
me.name, source_p->name); |
189 |
return; |
190 |
} |
191 |
|
192 |
#ifdef IPV6 |
193 |
if (t == HM_IPV6) |
194 |
t = AF_INET6; |
195 |
else |
196 |
#endif |
197 |
t = AF_INET; |
198 |
|
199 |
parse_netmask(dlhost, &daddr, NULL); |
200 |
|
201 |
if ((aconf = find_dline_conf(&daddr, t)) != NULL) |
202 |
{ |
203 |
creason = aconf->reason ? aconf->reason : def_reason; |
204 |
if (IsConfExemptKline(aconf)) |
205 |
sendto_one(source_p, |
206 |
":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", |
207 |
me.name, source_p->name, dlhost, aconf->host, creason); |
208 |
else |
209 |
sendto_one(source_p, |
210 |
":%s NOTICE %s :[%s] already D-lined by [%s] - %s", |
211 |
me.name, source_p->name, dlhost, aconf->host, creason); |
212 |
return; |
213 |
} |
214 |
|
215 |
cur_time = CurrentTime; |
216 |
current_date = smalldate(cur_time); |
217 |
|
218 |
/* Look for an oper reason */ |
219 |
if ((oper_reason = strchr(reason, '|')) != NULL) |
220 |
*oper_reason++ = '\0'; |
221 |
|
222 |
if (!valid_comment(source_p, reason, 1)) |
223 |
return; |
224 |
|
225 |
conf = make_conf_item(DLINE_TYPE); |
226 |
aconf = map_to_conf(conf); |
227 |
DupString(aconf->host, dlhost); |
228 |
|
229 |
if (tkline_time != 0) |
230 |
{ |
231 |
snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)", |
232 |
(int)(tkline_time/60), reason, current_date); |
233 |
DupString(aconf->reason, buffer); |
234 |
if (oper_reason != NULL) |
235 |
DupString(aconf->oper_reason, oper_reason); |
236 |
apply_tdline(source_p, conf, current_date, tkline_time); |
237 |
} |
238 |
else |
239 |
{ |
240 |
snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); |
241 |
DupString(aconf->reason, buffer); |
242 |
if (oper_reason != NULL) |
243 |
DupString(aconf->oper_reason, oper_reason); |
244 |
add_conf_by_address(CONF_DLINE, aconf); |
245 |
write_conf_line(source_p, conf, current_date, cur_time); |
246 |
} |
247 |
|
248 |
rehashed_klines = 1; |
249 |
} |
250 |
|
251 |
/* |
252 |
** m_undline |
253 |
** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk> |
254 |
** based totally on m_unkline |
255 |
** added to hybrid-7 7/11/2000 --is |
256 |
** |
257 |
** parv[0] = sender nick |
258 |
** parv[1] = dline to remove |
259 |
*/ |
260 |
static void |
261 |
mo_undline(struct Client *client_p, struct Client *source_p, |
262 |
int parc, char *parv[]) |
263 |
{ |
264 |
const char *addr = NULL; |
265 |
|
266 |
if (!HasOFlag(source_p, OPER_FLAG_UNKLINE)) |
267 |
{ |
268 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
269 |
me.name, source_p->name, "undline"); |
270 |
return; |
271 |
} |
272 |
|
273 |
addr = parv[1]; |
274 |
|
275 |
if (remove_tdline_match(addr)) |
276 |
{ |
277 |
sendto_one(source_p, |
278 |
":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines", |
279 |
me.name, source_p->name, addr); |
280 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
281 |
"%s has removed the temporary D-Line for: [%s]", |
282 |
get_oper_name(source_p), addr); |
283 |
ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]", source_p->name, addr); |
284 |
return; |
285 |
} |
286 |
|
287 |
if (remove_conf_line(DLINE_TYPE, source_p, addr, NULL) > 0) |
288 |
{ |
289 |
sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", |
290 |
me.name, source_p->name, addr); |
291 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
292 |
"%s has removed the D-Line for: [%s]", |
293 |
get_oper_name(source_p), addr); |
294 |
ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]", |
295 |
get_oper_name(source_p), addr); |
296 |
} |
297 |
else |
298 |
sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found", |
299 |
me.name, source_p->name, addr); |
300 |
} |
301 |
|
302 |
static struct Message dline_msgtab = { |
303 |
"DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
304 |
{m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_dline, m_ignore} |
305 |
}; |
306 |
|
307 |
static struct Message undline_msgtab = { |
308 |
"UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
309 |
{m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_undline, m_ignore} |
310 |
}; |
311 |
|
312 |
static void |
313 |
module_init(void) |
314 |
{ |
315 |
mod_add_cmd(&dline_msgtab); |
316 |
mod_add_cmd(&undline_msgtab); |
317 |
} |
318 |
|
319 |
static void |
320 |
module_exit(void) |
321 |
{ |
322 |
mod_del_cmd(&dline_msgtab); |
323 |
mod_del_cmd(&undline_msgtab); |
324 |
} |
325 |
|
326 |
struct module module_entry = { |
327 |
.node = { NULL, NULL, NULL }, |
328 |
.name = NULL, |
329 |
.version = "$Revision$", |
330 |
.handle = NULL, |
331 |
.modinit = module_init, |
332 |
.modexit = module_exit, |
333 |
.flags = 0 |
334 |
}; |