]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_kill.c: Kills a user. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
26 | #include "client.h" | |
27 | #include "hash.h" /* for find_client() */ | |
28 | #include "ircd.h" | |
29 | #include "numeric.h" | |
4016731b | 30 | #include "logger.h" |
212380e3 AC |
31 | #include "s_serv.h" |
32 | #include "s_conf.h" | |
33 | #include "send.h" | |
34 | #include "whowas.h" | |
4562c604 | 35 | #include "match.h" |
212380e3 AC |
36 | #include "msg.h" |
37 | #include "parse.h" | |
38 | #include "modules.h" | |
39 | #include "s_newconf.h" | |
40 | ||
9d745dbd | 41 | static int h_can_kill; |
212380e3 AC |
42 | static char buf[BUFSIZE]; |
43 | ||
428ca87b AC |
44 | static int ms_kill(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
45 | static int mo_kill(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
46 | static void relay_kill(struct Client *, struct Client *, struct Client *, |
47 | const char *, const char *); | |
ac1b809c | 48 | static const char kill_desc[] = "Provides the KILL command to remove a user from the network"; |
212380e3 AC |
49 | |
50 | struct Message kill_msgtab = { | |
7baa37a9 | 51 | "KILL", 0, 0, 0, 0, |
212380e3 AC |
52 | {mg_unreg, mg_not_oper, {ms_kill, 2}, {ms_kill, 2}, mg_ignore, {mo_kill, 2}} |
53 | }; | |
54 | ||
55 | mapi_clist_av1 kill_clist[] = { &kill_msgtab, NULL }; | |
56 | ||
9d745dbd EM |
57 | mapi_hlist_av1 kill_hlist[] = { |
58 | { "can_kill", &h_can_kill }, | |
59 | { NULL, NULL}, | |
60 | }; | |
61 | ||
ac1b809c | 62 | DECLARE_MODULE_AV2(kill, NULL, NULL, kill_clist, kill_hlist, NULL, NULL, NULL, kill_desc); |
212380e3 AC |
63 | |
64 | /* | |
65 | ** mo_kill | |
212380e3 AC |
66 | ** parv[1] = kill victim |
67 | ** parv[2] = kill path | |
68 | */ | |
69 | static int | |
428ca87b | 70 | mo_kill(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
71 | { |
72 | struct Client *target_p; | |
73 | const char *inpath = client_p->name; | |
74 | const char *user; | |
75 | const char *reason; | |
9d745dbd | 76 | hook_data_client_approval moduledata; |
212380e3 AC |
77 | |
78 | user = parv[1]; | |
79 | ||
80 | if(!IsOperLocalKill(source_p)) | |
81 | { | |
82 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "local_kill"); | |
83 | return 0; | |
84 | } | |
85 | ||
86 | if(!EmptyString(parv[2])) | |
87 | { | |
88 | char *s; | |
89 | s = LOCAL_COPY(parv[2]); | |
90 | if(strlen(s) > (size_t) KILLLEN) | |
91 | s[KILLLEN] = '\0'; | |
92 | reason = s; | |
93 | } | |
94 | else | |
95 | reason = "<No reason given>"; | |
96 | ||
97 | if((target_p = find_named_person(user)) == NULL) | |
98 | { | |
99 | /* | |
100 | ** If the user has recently changed nick, automatically | |
101 | ** rewrite the KILL for this new nickname--this keeps | |
102 | ** servers in synch when nick change and kill collide | |
103 | */ | |
b47f8a4f | 104 | if((target_p = whowas_get_history(user, (long) KILLCHASETIMELIMIT)) == NULL) |
212380e3 AC |
105 | { |
106 | if (strchr(user, '.')) | |
107 | sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); | |
108 | else | |
109 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
110 | form_str(ERR_NOSUCHNICK), user); | |
111 | return 0; | |
112 | } | |
5366977b | 113 | sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name); |
212380e3 AC |
114 | } |
115 | ||
116 | if(!MyConnect(target_p) && (!IsOperGlobalKill(source_p))) | |
117 | { | |
5366977b AC |
118 | sendto_one_notice(source_p, ":Nick %s is not on your server " |
119 | "and you do not have the global_kill flag", | |
120 | target_p->name); | |
212380e3 AC |
121 | return 0; |
122 | } | |
123 | ||
9d745dbd EM |
124 | /* Last chance to stop the kill */ |
125 | moduledata.client = source_p; | |
126 | moduledata.target = target_p; | |
127 | moduledata.approved = 1; | |
128 | call_hook(h_can_kill, &moduledata); | |
129 | ||
130 | if (moduledata.approved == 0) | |
373a0439 | 131 | /* The callee should have sent a message. */ |
9d745dbd EM |
132 | return 0; |
133 | ||
212380e3 AC |
134 | if(MyConnect(target_p)) |
135 | sendto_one(target_p, ":%s!%s@%s KILL %s :%s", | |
136 | source_p->name, source_p->username, source_p->host, | |
137 | target_p->name, reason); | |
138 | ||
139 | /* Do not change the format of this message. There's no point in changing messages | |
140 | * that have been around for ever, for no reason.. */ | |
141 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
8d090389 | 142 | "Received KILL message for %s!%s@%s. From %s Path: %s (%s)", |
55abcbb2 | 143 | target_p->name, target_p->username, target_p->orighost, |
3dfaa671 | 144 | source_p->name, me.name, reason); |
212380e3 AC |
145 | |
146 | ilog(L_KILL, "%c %s %s!%s@%s %s %s", | |
147 | MyConnect(target_p) ? 'L' : 'G', get_oper_name(source_p), | |
c88cdb00 | 148 | target_p->name, target_p->username, target_p->host, target_p->servptr->name, reason); |
212380e3 AC |
149 | |
150 | /* | |
151 | ** And pass on the message to other servers. Note, that if KILL | |
152 | ** was changed, the message has to be sent to all links, also | |
153 | ** back. | |
154 | ** Suicide kills are NOT passed on --SRB | |
155 | */ | |
156 | if(!MyConnect(target_p)) | |
157 | { | |
158 | relay_kill(client_p, source_p, target_p, inpath, reason); | |
159 | /* | |
160 | ** Set FLAGS_KILLED. This prevents exit_one_client from sending | |
161 | ** the unnecessary QUIT for this. (This flag should never be | |
162 | ** set in any other place) | |
163 | */ | |
164 | target_p->flags |= FLAGS_KILLED; | |
165 | } | |
166 | ||
5203cba5 | 167 | sprintf(buf, "Killed (%s (%s))", source_p->name, reason); |
212380e3 AC |
168 | |
169 | exit_client(client_p, target_p, source_p, buf); | |
170 | ||
171 | return 0; | |
172 | } | |
173 | ||
174 | /* | |
175 | * ms_kill | |
212380e3 AC |
176 | * parv[1] = kill victim |
177 | * parv[2] = kill path and reason | |
178 | */ | |
179 | static int | |
428ca87b | 180 | ms_kill(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
181 | { |
182 | struct Client *target_p; | |
183 | const char *user; | |
184 | const char *reason; | |
185 | char default_reason[] = "<No reason given>"; | |
186 | const char *path; | |
212380e3 AC |
187 | |
188 | *buf = '\0'; | |
189 | ||
190 | user = parv[1]; | |
191 | ||
192 | if(EmptyString(parv[2])) | |
193 | { | |
194 | reason = default_reason; | |
195 | ||
196 | /* hyb6 takes the nick of the killer from the path *sigh* --fl_ */ | |
197 | path = source_p->name; | |
198 | } | |
199 | else | |
200 | { | |
201 | char *s = LOCAL_COPY(parv[2]), *t; | |
202 | t = strchr(s, ' '); | |
203 | ||
204 | if(t) | |
205 | { | |
206 | *t = '\0'; | |
207 | t++; | |
208 | reason = t; | |
209 | } | |
210 | else | |
211 | reason = default_reason; | |
212 | ||
213 | path = s; | |
214 | } | |
215 | ||
216 | if((target_p = find_person(user)) == NULL) | |
217 | { | |
218 | /* | |
55abcbb2 | 219 | * If the user has recently changed nick, but only if its |
212380e3 AC |
220 | * not an uid, automatically rewrite the KILL for this new nickname. |
221 | * --this keeps servers in synch when nick change and kill collide | |
222 | */ | |
b47f8a4f | 223 | if(IsDigit(*user) || (!(target_p = whowas_get_history(user, (long) KILLCHASETIMELIMIT)))) |
212380e3 AC |
224 | { |
225 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
226 | form_str(ERR_NOSUCHNICK), IsDigit(*user) ? "*" : user); | |
227 | return 0; | |
228 | } | |
229 | sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name); | |
212380e3 AC |
230 | } |
231 | ||
232 | if(IsServer(target_p) || IsMe(target_p)) | |
233 | { | |
234 | sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); | |
235 | return 0; | |
236 | } | |
237 | ||
238 | if(MyConnect(target_p)) | |
239 | { | |
240 | if(IsServer(source_p)) | |
241 | { | |
242 | sendto_one(target_p, ":%s KILL %s :%s", | |
243 | source_p->name, target_p->name, reason); | |
244 | } | |
245 | else | |
246 | sendto_one(target_p, ":%s!%s@%s KILL %s :%s", | |
247 | source_p->name, source_p->username, source_p->host, | |
248 | target_p->name, reason); | |
249 | } | |
250 | ||
251 | /* Be warned, this message must be From %s, or it confuses clients | |
252 | * so dont change it to From: or the case or anything! -- fl -- db */ | |
253 | /* path must contain at least 2 !'s, or bitchx falsely declares it | |
254 | * local --fl | |
255 | */ | |
256 | if(IsOper(source_p)) /* send it normally */ | |
257 | { | |
258 | sendto_realops_snomask(IsService(source_p) ? SNO_SKILL : SNO_GENERAL, L_ALL, | |
8d090389 | 259 | "Received KILL message for %s!%s@%s. From %s Path: %s!%s!%s!%s %s", |
55abcbb2 | 260 | target_p->name, target_p->username, target_p->orighost, source_p->name, |
c88cdb00 | 261 | source_p->servptr->name, source_p->host, source_p->username, |
5366977b | 262 | source_p->name, reason); |
212380e3 AC |
263 | |
264 | ilog(L_KILL, "%c %s %s!%s@%s %s %s", | |
265 | MyConnect(target_p) ? 'O' : 'R', get_oper_name(source_p), | |
266 | target_p->name, target_p->username, target_p->host, | |
c88cdb00 | 267 | target_p->servptr->name, reason); |
212380e3 AC |
268 | } |
269 | else | |
270 | { | |
271 | sendto_realops_snomask(SNO_SKILL, L_ALL, | |
8d090389 | 272 | "Received KILL message for %s!%s@%s. From %s %s", |
d1d0629f | 273 | target_p->name, target_p->username, target_p->orighost, |
3dfaa671 | 274 | source_p->name, reason); |
212380e3 AC |
275 | |
276 | ilog(L_KILL, "S %s %s!%s@%s %s %s", | |
277 | source_p->name, target_p->name, target_p->username, | |
c88cdb00 | 278 | target_p->host, target_p->servptr->name, reason); |
212380e3 AC |
279 | } |
280 | ||
281 | relay_kill(client_p, source_p, target_p, path, reason); | |
282 | ||
283 | /* FLAGS_KILLED prevents a quit being sent out */ | |
284 | target_p->flags |= FLAGS_KILLED; | |
285 | ||
5203cba5 | 286 | sprintf(buf, "Killed (%s %s)", source_p->name, reason); |
212380e3 AC |
287 | |
288 | exit_client(client_p, target_p, source_p, buf); | |
289 | ||
290 | return 0; | |
291 | } | |
292 | ||
293 | static void | |
294 | relay_kill(struct Client *one, struct Client *source_p, | |
295 | struct Client *target_p, const char *inpath, const char *reason) | |
296 | { | |
297 | struct Client *client_p; | |
5b96d9a6 | 298 | rb_dlink_node *ptr; |
212380e3 AC |
299 | char buffer[BUFSIZE]; |
300 | ||
301 | if(MyClient(source_p)) | |
5203cba5 | 302 | snprintf(buffer, sizeof(buffer), |
212380e3 AC |
303 | "%s!%s!%s!%s (%s)", |
304 | me.name, source_p->host, source_p->username, source_p->name, reason); | |
305 | else | |
5203cba5 | 306 | snprintf(buffer, sizeof(buffer), "%s %s", inpath, reason); |
212380e3 | 307 | |
5b96d9a6 | 308 | RB_DLINK_FOREACH(ptr, serv_list.head) |
212380e3 AC |
309 | { |
310 | client_p = ptr->data; | |
311 | ||
312 | if(!client_p || client_p == one) | |
313 | continue; | |
314 | ||
315 | sendto_one(client_p, ":%s KILL %s :%s", | |
316 | get_id(source_p, client_p), get_id(target_p, client_p), buffer); | |
317 | } | |
318 | } |