1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2820 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
adx |
30 |
* |
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 |
michael |
2820 |
/*! \file m_kill.c |
23 |
|
|
* \brief Includes required functions for processing the KILL command. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "client.h" |
30 |
michael |
2820 |
#include "hash.h" |
31 |
adx |
30 |
#include "ircd.h" |
32 |
|
|
#include "numeric.h" |
33 |
michael |
1309 |
#include "log.h" |
34 |
adx |
30 |
#include "s_serv.h" |
35 |
michael |
1309 |
#include "conf.h" |
36 |
adx |
30 |
#include "send.h" |
37 |
|
|
#include "whowas.h" |
38 |
|
|
#include "irc_string.h" |
39 |
|
|
#include "parse.h" |
40 |
|
|
#include "modules.h" |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
static char buf[IRCD_BUFSIZE]; |
44 |
|
|
|
45 |
michael |
1451 |
static void |
46 |
|
|
relay_kill(struct Client *one, struct Client *source_p, |
47 |
|
|
struct Client *target_p, const char *inpath, |
48 |
|
|
const char *reason) |
49 |
|
|
{ |
50 |
|
|
dlink_node *ptr = NULL; |
51 |
adx |
30 |
|
52 |
michael |
1451 |
DLINK_FOREACH(ptr, serv_list.head) |
53 |
|
|
{ |
54 |
|
|
struct Client *client_p = ptr->data; |
55 |
|
|
|
56 |
|
|
if (client_p == one) |
57 |
|
|
continue; |
58 |
|
|
|
59 |
|
|
if (MyClient(source_p)) |
60 |
|
|
sendto_one(client_p, ":%s KILL %s :%s!%s!%s!%s (%s)", |
61 |
|
|
ID_or_name(source_p, client_p), |
62 |
|
|
ID_or_name(target_p, client_p), |
63 |
|
|
me.name, source_p->host, source_p->username, |
64 |
|
|
source_p->name, reason); |
65 |
|
|
else |
66 |
|
|
sendto_one(client_p, ":%s KILL %s :%s %s", |
67 |
|
|
ID_or_name(source_p, client_p), |
68 |
|
|
ID_or_name(target_p, client_p), inpath, reason); |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
|
72 |
adx |
30 |
/* mo_kill() |
73 |
|
|
* parv[0] = sender prefix |
74 |
|
|
* parv[1] = kill victim |
75 |
|
|
* parv[2] = kill path |
76 |
|
|
*/ |
77 |
michael |
2820 |
static int |
78 |
adx |
30 |
mo_kill(struct Client *client_p, struct Client *source_p, |
79 |
|
|
int parc, char *parv[]) |
80 |
|
|
{ |
81 |
|
|
struct Client *target_p; |
82 |
|
|
const char *inpath = client_p->name; |
83 |
|
|
char *user; |
84 |
|
|
char *reason; |
85 |
michael |
1794 |
char def_reason[] = CONF_NOREASON; |
86 |
adx |
30 |
|
87 |
|
|
user = parv[1]; |
88 |
|
|
reason = parv[2]; /* Either defined or NULL (parc >= 2!!) */ |
89 |
|
|
|
90 |
|
|
if (*user == '\0') |
91 |
|
|
{ |
92 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
93 |
adx |
30 |
me.name, source_p->name, "KILL"); |
94 |
michael |
2820 |
return 0; |
95 |
adx |
30 |
} |
96 |
|
|
|
97 |
|
|
if (!EmptyString(reason)) |
98 |
|
|
{ |
99 |
|
|
if (strlen(reason) > (size_t)KILLLEN) |
100 |
|
|
reason[KILLLEN] = '\0'; |
101 |
|
|
} |
102 |
|
|
else |
103 |
|
|
reason = def_reason; |
104 |
|
|
|
105 |
michael |
1169 |
if ((target_p = hash_find_client(user)) == NULL) |
106 |
adx |
30 |
{ |
107 |
michael |
1136 |
/* |
108 |
|
|
* If the user has recently changed nick, automatically |
109 |
adx |
30 |
* rewrite the KILL for this new nickname--this keeps |
110 |
|
|
* servers in synch when nick change and kill collide |
111 |
|
|
*/ |
112 |
michael |
2820 |
if ((target_p = whowas_get_history(user, |
113 |
michael |
1451 |
(time_t)ConfigFileEntry.kill_chase_time_limit)) |
114 |
|
|
== NULL) |
115 |
adx |
30 |
{ |
116 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
117 |
adx |
30 |
me.name, source_p->name, user); |
118 |
michael |
2820 |
return 0; |
119 |
adx |
30 |
} |
120 |
|
|
|
121 |
|
|
sendto_one(source_p, ":%s NOTICE %s :KILL changed from %s to %s", |
122 |
|
|
me.name, source_p->name, user, target_p->name); |
123 |
|
|
} |
124 |
|
|
|
125 |
michael |
2801 |
if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_KILL_REMOTE)) |
126 |
adx |
30 |
{ |
127 |
michael |
2801 |
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, |
128 |
|
|
source_p->name, "kill:remote"); |
129 |
michael |
2820 |
return 0; |
130 |
adx |
30 |
} |
131 |
|
|
|
132 |
michael |
2801 |
if (MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_KILL)) |
133 |
|
|
{ |
134 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, |
135 |
|
|
source_p->name, "kill"); |
136 |
michael |
2820 |
return 0; |
137 |
michael |
2801 |
} |
138 |
|
|
|
139 |
michael |
2012 |
if (IsServer(target_p) || IsMe(target_p)) |
140 |
adx |
30 |
{ |
141 |
michael |
2012 |
sendto_one(source_p, form_str(ERR_CANTKILLSERVER), |
142 |
|
|
me.name, source_p->name); |
143 |
michael |
2820 |
return 0; |
144 |
adx |
30 |
} |
145 |
|
|
|
146 |
|
|
if (MyConnect(target_p)) |
147 |
michael |
2820 |
sendto_one(target_p, ":%s!%s@%s KILL %s :%s", |
148 |
adx |
30 |
source_p->name, source_p->username, source_p->host, |
149 |
|
|
target_p->name, reason); |
150 |
|
|
|
151 |
michael |
1136 |
/* |
152 |
|
|
* Do not change the format of this message. There's no point in changing messages |
153 |
|
|
* that have been around for ever, for no reason.. |
154 |
|
|
*/ |
155 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
156 |
michael |
2820 |
"Received KILL message for %s!%s@%s[%s/%s]. From %s Path: %s (%s)", |
157 |
michael |
2037 |
target_p->name, target_p->username, target_p->host, |
158 |
|
|
target_p->servptr->name, |
159 |
|
|
target_p->servptr->id[0] ? target_p->servptr->id : "<>", |
160 |
|
|
source_p->name, me.name, reason); |
161 |
adx |
30 |
|
162 |
michael |
1247 |
ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s (%s)", |
163 |
adx |
30 |
source_p->name, target_p->name, me.name, reason); |
164 |
|
|
|
165 |
|
|
/* |
166 |
michael |
1136 |
* And pass on the message to other servers. Note, that if KILL |
167 |
|
|
* was changed, the message has to be sent to all links, also |
168 |
|
|
* back. |
169 |
|
|
* Suicide kills are NOT passed on --SRB |
170 |
|
|
*/ |
171 |
adx |
30 |
if (!MyConnect(target_p)) |
172 |
|
|
{ |
173 |
|
|
relay_kill(client_p, source_p, target_p, inpath, reason); |
174 |
|
|
/* |
175 |
michael |
1136 |
* Set FLAGS_KILLED. This prevents exit_one_client from sending |
176 |
|
|
* the unnecessary QUIT for this. (This flag should never be |
177 |
|
|
* set in any other place) |
178 |
|
|
*/ |
179 |
michael |
1219 |
AddFlag(target_p, FLAGS_KILLED); |
180 |
adx |
30 |
} |
181 |
|
|
|
182 |
michael |
1136 |
snprintf(buf, sizeof(buf), "Killed (%s (%s))", source_p->name, reason); |
183 |
adx |
30 |
exit_client(target_p, source_p, buf); |
184 |
michael |
2820 |
return 0; |
185 |
adx |
30 |
} |
186 |
|
|
|
187 |
|
|
/* ms_kill() |
188 |
|
|
* parv[0] = sender prefix |
189 |
|
|
* parv[1] = kill victim |
190 |
|
|
* parv[2] = kill path and reason |
191 |
|
|
*/ |
192 |
michael |
2820 |
static int |
193 |
adx |
30 |
ms_kill(struct Client *client_p, struct Client *source_p, |
194 |
|
|
int parc, char *parv[]) |
195 |
|
|
{ |
196 |
|
|
struct Client *target_p; |
197 |
|
|
char *user; |
198 |
|
|
char *reason; |
199 |
|
|
const char *path; |
200 |
michael |
1794 |
char def_reason[] = CONF_NOREASON; |
201 |
adx |
30 |
|
202 |
michael |
1136 |
if (EmptyString(parv[1])) |
203 |
adx |
30 |
{ |
204 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
205 |
adx |
30 |
me.name, source_p->name, "KILL"); |
206 |
michael |
2820 |
return 0; |
207 |
adx |
30 |
} |
208 |
|
|
|
209 |
|
|
user = parv[1]; |
210 |
|
|
|
211 |
|
|
if (EmptyString(parv[2])) |
212 |
|
|
{ |
213 |
|
|
reason = def_reason; |
214 |
|
|
|
215 |
|
|
/* hyb6 takes the nick of the killer from the path *sigh* --fl_ */ |
216 |
|
|
path = source_p->name; |
217 |
|
|
} |
218 |
|
|
else |
219 |
|
|
{ |
220 |
|
|
reason = strchr(parv[2], ' '); |
221 |
|
|
|
222 |
|
|
if (reason != NULL) |
223 |
|
|
*reason++ = '\0'; |
224 |
|
|
else |
225 |
|
|
reason = def_reason; |
226 |
|
|
|
227 |
|
|
path = parv[2]; |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
if ((target_p = find_person(client_p, user)) == NULL) |
231 |
|
|
{ |
232 |
michael |
1451 |
/* |
233 |
michael |
2820 |
* If the user has recently changed nick, but only if its |
234 |
michael |
1451 |
* not an uid, automatically rewrite the KILL for this new nickname. |
235 |
|
|
* --this keeps servers in synch when nick change and kill collide |
236 |
|
|
*/ |
237 |
|
|
if (IsDigit(*user)) /* Somehow an uid was not found in the hash ! */ |
238 |
michael |
2820 |
return 0; |
239 |
michael |
2300 |
if ((target_p = whowas_get_history(user, |
240 |
michael |
1451 |
(time_t)ConfigFileEntry.kill_chase_time_limit)) |
241 |
adx |
30 |
== NULL) |
242 |
|
|
{ |
243 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
244 |
michael |
1451 |
me.name, source_p->name, user); |
245 |
michael |
2820 |
return 0; |
246 |
adx |
30 |
} |
247 |
michael |
1136 |
|
248 |
adx |
30 |
sendto_one(source_p,":%s NOTICE %s :KILL changed from %s to %s", |
249 |
michael |
1451 |
me.name, source_p->name, user, target_p->name); |
250 |
adx |
30 |
} |
251 |
|
|
|
252 |
|
|
if (IsServer(target_p) || IsMe(target_p)) |
253 |
|
|
{ |
254 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_CANTKILLSERVER), |
255 |
adx |
30 |
me.name, source_p->name); |
256 |
michael |
2820 |
return 0; |
257 |
adx |
30 |
} |
258 |
|
|
|
259 |
|
|
if (MyConnect(target_p)) |
260 |
|
|
{ |
261 |
|
|
if (IsServer(source_p)) |
262 |
|
|
{ |
263 |
|
|
/* dont send clients kills from a hidden server */ |
264 |
michael |
1219 |
if ((IsHidden(source_p) || ConfigServerHide.hide_servers) && !HasUMode(target_p, UMODE_OPER)) |
265 |
adx |
30 |
sendto_one(target_p, ":%s KILL %s :%s", |
266 |
michael |
1451 |
me.name, target_p->name, reason); |
267 |
adx |
30 |
else |
268 |
michael |
1451 |
sendto_one(target_p, ":%s KILL %s :%s", |
269 |
|
|
source_p->name, target_p->name, reason); |
270 |
adx |
30 |
} |
271 |
|
|
else |
272 |
|
|
sendto_one(target_p, ":%s!%s@%s KILL %s :%s", |
273 |
michael |
1451 |
source_p->name, source_p->username, source_p->host, |
274 |
|
|
target_p->name, reason); |
275 |
adx |
30 |
} |
276 |
|
|
|
277 |
michael |
1451 |
/* |
278 |
|
|
* Be warned, this message must be From %s, or it confuses clients |
279 |
|
|
* so dont change it to From: or the case or anything! -- fl -- db |
280 |
|
|
*/ |
281 |
|
|
/* |
282 |
|
|
* path must contain at least 2 !'s, or bitchx falsely declares it |
283 |
adx |
30 |
* local --fl |
284 |
|
|
*/ |
285 |
michael |
1219 |
if (HasUMode(source_p, UMODE_OPER)) /* send it normally */ |
286 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
287 |
michael |
2037 |
"Received KILL message for %s!%s@%s[%s/%s]. From %s Path: %s!%s!%s!%s %s", |
288 |
|
|
target_p->name, target_p->username, target_p->host, |
289 |
|
|
target_p->servptr->name, |
290 |
|
|
target_p->servptr->id[0] ? target_p->servptr->id : "<>", source_p->name, |
291 |
|
|
source_p->servptr->name, source_p->host, source_p->username, |
292 |
|
|
source_p->name, reason); |
293 |
adx |
30 |
else |
294 |
michael |
1618 |
sendto_realops_flags(UMODE_SKILL, L_ALL, SEND_NOTICE, |
295 |
michael |
2037 |
"Received KILL message for %s!%s@%s[%s/%s]. From %s %s", |
296 |
|
|
target_p->name, target_p->username, target_p->host, |
297 |
|
|
target_p->servptr->name, |
298 |
|
|
target_p->servptr->id[0] ? target_p->servptr->id : "<>", |
299 |
|
|
source_p->name, reason); |
300 |
adx |
30 |
|
301 |
michael |
1247 |
ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s %s", |
302 |
adx |
30 |
source_p->name, target_p->name, source_p->name, reason); |
303 |
|
|
|
304 |
|
|
relay_kill(client_p, source_p, target_p, path, reason); |
305 |
michael |
1219 |
AddFlag(target_p, FLAGS_KILLED); |
306 |
adx |
30 |
|
307 |
|
|
/* reason comes supplied with its own ()'s */ |
308 |
|
|
if (IsServer(source_p) && (IsHidden(source_p) || ConfigServerHide.hide_servers)) |
309 |
michael |
1136 |
snprintf(buf, sizeof(buf), "Killed (%s %s)", me.name, reason); |
310 |
adx |
30 |
else |
311 |
michael |
1136 |
snprintf(buf, sizeof(buf), "Killed (%s %s)", source_p->name, reason); |
312 |
adx |
30 |
|
313 |
|
|
exit_client(target_p, source_p, buf); |
314 |
michael |
2820 |
return 0; |
315 |
adx |
30 |
} |
316 |
|
|
|
317 |
|
|
|
318 |
michael |
2820 |
static struct Message kill_msgtab = |
319 |
|
|
{ |
320 |
michael |
1230 |
"KILL", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
321 |
michael |
2820 |
{ m_unregistered, m_not_oper, ms_kill, m_ignore, mo_kill, m_ignore } |
322 |
michael |
1230 |
}; |
323 |
|
|
|
324 |
|
|
static void |
325 |
|
|
module_init(void) |
326 |
|
|
{ |
327 |
|
|
mod_add_cmd(&kill_msgtab); |
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
static void |
331 |
|
|
module_exit(void) |
332 |
|
|
{ |
333 |
|
|
mod_del_cmd(&kill_msgtab); |
334 |
|
|
} |
335 |
|
|
|
336 |
michael |
2820 |
struct module module_entry = |
337 |
|
|
{ |
338 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
339 |
|
|
.name = NULL, |
340 |
|
|
.version = "$Revision$", |
341 |
|
|
.handle = NULL, |
342 |
|
|
.modinit = module_init, |
343 |
|
|
.modexit = module_exit, |
344 |
|
|
.flags = MODULE_FLAG_CORE |
345 |
|
|
}; |