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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_kline.c |
23 |
* \brief Includes required functions for processing the KLINE 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 "ircd.h" |
32 |
#include "conf.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_kline(struct AddressRec *arec) |
48 |
{ |
49 |
dlink_node *ptr = NULL, *ptr_next = NULL; |
50 |
|
51 |
DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head) |
52 |
{ |
53 |
struct Client *client_p = ptr->data; |
54 |
|
55 |
if (IsDead(client_p)) |
56 |
continue; |
57 |
|
58 |
if (match(arec->username, client_p->username)) |
59 |
continue; |
60 |
|
61 |
switch (arec->masktype) |
62 |
{ |
63 |
case HM_IPV4: |
64 |
if (client_p->localClient->aftype == AF_INET) |
65 |
if (match_ipv4(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits)) |
66 |
conf_try_ban(client_p, arec->conf); |
67 |
break; |
68 |
case HM_IPV6: |
69 |
if (client_p->localClient->aftype == AF_INET6) |
70 |
if (match_ipv6(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits)) |
71 |
conf_try_ban(client_p, arec->conf); |
72 |
break; |
73 |
default: /* HM_HOST */ |
74 |
if (!match(arec->Mask.hostname, client_p->host)) |
75 |
conf_try_ban(client_p, arec->conf); |
76 |
break; |
77 |
} |
78 |
} |
79 |
} |
80 |
|
81 |
/* apply_tkline() |
82 |
* |
83 |
* inputs - |
84 |
* output - NONE |
85 |
* side effects - tkline as given is placed |
86 |
*/ |
87 |
static void |
88 |
m_kline_add_kline(struct Client *source_p, struct MaskItem *conf, |
89 |
time_t tkline_time) |
90 |
{ |
91 |
if (tkline_time) |
92 |
{ |
93 |
conf->until = CurrentTime + tkline_time; |
94 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
95 |
"%s added temporary %d min. K-Line for [%s@%s] [%s]", |
96 |
get_oper_name(source_p), tkline_time/60, |
97 |
conf->user, conf->host, |
98 |
conf->reason); |
99 |
sendto_one_notice(source_p, &me, ":Added temporary %d min. K-Line [%s@%s]", |
100 |
tkline_time/60, conf->user, conf->host); |
101 |
ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]", |
102 |
get_oper_name(source_p), tkline_time/60, |
103 |
conf->user, conf->host, conf->reason); |
104 |
} |
105 |
else |
106 |
{ |
107 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
108 |
"%s added K-Line for [%s@%s] [%s]", |
109 |
get_oper_name(source_p), |
110 |
conf->user, conf->host, conf->reason); |
111 |
sendto_one_notice(source_p, &me, ":Added K-Line [%s@%s]", |
112 |
conf->user, conf->host); |
113 |
ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]", |
114 |
get_oper_name(source_p), conf->user, conf->host, conf->reason); |
115 |
} |
116 |
|
117 |
conf->setat = CurrentTime; |
118 |
SetConfDatabase(conf); |
119 |
|
120 |
check_kline(add_conf_by_address(CONF_KLINE, conf)); |
121 |
} |
122 |
|
123 |
/* already_placed_kline() |
124 |
* inputs - user to complain to, username & host to check for |
125 |
* outputs - returns 1 on existing K-line, 0 if doesn't exist |
126 |
* side effects - notifies source_p if the K-line already exists |
127 |
*/ |
128 |
/* |
129 |
* Note: This currently works if the new K-line is a special case of an |
130 |
* existing K-line, but not the other way round. To do that we would |
131 |
* have to walk the hash and check every existing K-line. -A1kmm. |
132 |
*/ |
133 |
static int |
134 |
already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn) |
135 |
{ |
136 |
const char *reason; |
137 |
struct irc_ssaddr iphost, *piphost; |
138 |
struct MaskItem *conf = NULL; |
139 |
int t = 0; |
140 |
int aftype = 0; |
141 |
|
142 |
if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST) |
143 |
{ |
144 |
#ifdef IPV6 |
145 |
if (t == HM_IPV6) |
146 |
aftype = AF_INET6; |
147 |
else |
148 |
#endif |
149 |
aftype = AF_INET; |
150 |
piphost = &iphost; |
151 |
} |
152 |
else |
153 |
piphost = NULL; |
154 |
|
155 |
if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0))) |
156 |
{ |
157 |
if (warn) |
158 |
{ |
159 |
reason = conf->reason ? conf->reason : CONF_NOREASON; |
160 |
sendto_one_notice(source_p, &me, ":[%s@%s] already K-Lined by [%s@%s] - %s", |
161 |
luser, lhost, conf->user, conf->host, reason); |
162 |
} |
163 |
|
164 |
return 1; |
165 |
} |
166 |
|
167 |
return 0; |
168 |
} |
169 |
|
170 |
/* mo_kline() |
171 |
* |
172 |
* inputs - pointer to server |
173 |
* - pointer to client |
174 |
* - parameter count |
175 |
* - parameter list |
176 |
* output - |
177 |
* side effects - k line is added |
178 |
*/ |
179 |
static int |
180 |
mo_kline(struct Client *source_p, int parc, char *parv[]) |
181 |
{ |
182 |
char buffer[IRCD_BUFSIZE]; |
183 |
char *reason = NULL; |
184 |
char *user = NULL; |
185 |
char *host = NULL; |
186 |
const char *current_date; |
187 |
char *target_server = NULL; |
188 |
struct MaskItem *conf; |
189 |
time_t tkline_time = 0; |
190 |
|
191 |
if (!HasOFlag(source_p, OPER_FLAG_K)) |
192 |
{ |
193 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kline"); |
194 |
return 0; |
195 |
} |
196 |
|
197 |
if (parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host, |
198 |
&tkline_time, &target_server, &reason) < 0) |
199 |
return 0; |
200 |
|
201 |
if (target_server) |
202 |
{ |
203 |
sendto_match_servs(source_p, target_server, CAP_KLN, "KLINE %s %lu %s %s :%s", |
204 |
target_server, (unsigned long)tkline_time, |
205 |
user, host, reason); |
206 |
|
207 |
/* Allow ON to apply local kline as well if it matches */ |
208 |
if (match(target_server, me.name)) |
209 |
return 0; |
210 |
} |
211 |
else |
212 |
cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE, |
213 |
"%d %s %s :%s", tkline_time, user, host, reason); |
214 |
|
215 |
if (already_placed_kline(source_p, user, host, 1)) |
216 |
return 0; |
217 |
|
218 |
current_date = smalldate(0); |
219 |
conf = conf_make(CONF_KLINE); |
220 |
|
221 |
conf->host = xstrdup(host); |
222 |
conf->user = xstrdup(user); |
223 |
|
224 |
if (tkline_time) |
225 |
snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)", |
226 |
(int)(tkline_time/60), reason, current_date); |
227 |
else |
228 |
snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); |
229 |
|
230 |
conf->reason = xstrdup(buffer); |
231 |
m_kline_add_kline(source_p, conf, tkline_time); |
232 |
return 0; |
233 |
} |
234 |
|
235 |
/* me_kline - handle remote kline. no propagation */ |
236 |
static int |
237 |
me_kline(struct Client *source_p, int parc, char *parv[]) |
238 |
{ |
239 |
char buffer[IRCD_BUFSIZE]; |
240 |
struct MaskItem *conf = NULL; |
241 |
int tkline_time = 0; |
242 |
const char *current_date; |
243 |
char *kuser, *khost, *kreason; |
244 |
|
245 |
if (parc != 6 || EmptyString(parv[5])) |
246 |
return 0; |
247 |
|
248 |
if (match(parv[1], me.name)) |
249 |
return 0; |
250 |
|
251 |
tkline_time = valid_tkline(parv[2], TK_SECONDS); |
252 |
kuser = parv[3]; |
253 |
khost = parv[4]; |
254 |
kreason = parv[5]; |
255 |
|
256 |
current_date = smalldate(0); |
257 |
|
258 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
259 |
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
260 |
source_p->username, source_p->host, |
261 |
SHARED_KLINE)) |
262 |
{ |
263 |
if (!IsClient(source_p) || |
264 |
already_placed_kline(source_p, kuser, khost, 1)) |
265 |
return 0; |
266 |
|
267 |
conf = conf_make(CONF_KLINE); |
268 |
conf->host = xstrdup(khost); |
269 |
conf->user = xstrdup(kuser); |
270 |
|
271 |
if (tkline_time) |
272 |
snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)", |
273 |
(int)(tkline_time/60), kreason, current_date); |
274 |
else |
275 |
snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date); |
276 |
|
277 |
conf->reason = xstrdup(buffer); |
278 |
m_kline_add_kline(source_p, conf, tkline_time); |
279 |
} |
280 |
|
281 |
return 0; |
282 |
} |
283 |
|
284 |
static int |
285 |
ms_kline(struct Client *source_p, int parc, char *parv[]) |
286 |
{ |
287 |
if (parc != 6 || EmptyString(parv[5])) |
288 |
return 0; |
289 |
|
290 |
/* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */ |
291 |
/* oper target_server tkline_time user host reason */ |
292 |
sendto_match_servs(source_p, parv[1], CAP_KLN, "KLINE %s %s %s %s :%s", |
293 |
parv[1], parv[2], parv[3], parv[4], parv[5]); |
294 |
|
295 |
return me_kline(source_p, parc, parv); |
296 |
} |
297 |
|
298 |
static struct Message kline_msgtab = |
299 |
{ |
300 |
"KLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
301 |
{ m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore } |
302 |
}; |
303 |
|
304 |
static void |
305 |
module_init(void) |
306 |
{ |
307 |
mod_add_cmd(&kline_msgtab); |
308 |
add_capability("KLN", CAP_KLN, 1); |
309 |
} |
310 |
|
311 |
static void |
312 |
module_exit(void) |
313 |
{ |
314 |
mod_del_cmd(&kline_msgtab); |
315 |
delete_capability("KLN"); |
316 |
} |
317 |
|
318 |
struct module module_entry = |
319 |
{ |
320 |
.node = { NULL, NULL, NULL }, |
321 |
.name = NULL, |
322 |
.version = "$Revision$", |
323 |
.handle = NULL, |
324 |
.modinit = module_init, |
325 |
.modexit = module_exit, |
326 |
.flags = 0 |
327 |
}; |