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