]>
Commit | Line | Data |
---|---|---|
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 | |
23 | * | |
24 | * $Id: m_kill.c 3408 2007-04-14 20:58:56Z jilles $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "client.h" | |
29 | #include "hash.h" /* for find_client() */ | |
30 | #include "ircd.h" | |
31 | #include "numeric.h" | |
32 | #include "logger.h" | |
33 | #include "s_serv.h" | |
34 | #include "s_conf.h" | |
35 | #include "send.h" | |
36 | #include "whowas.h" | |
37 | #include "match.h" | |
38 | #include "msg.h" | |
39 | #include "parse.h" | |
40 | #include "modules.h" | |
41 | #include "s_newconf.h" | |
42 | ||
43 | static int h_can_kill; | |
44 | static char buf[BUFSIZE]; | |
45 | ||
46 | static int ms_kill(struct Client *, struct Client *, int, const char **); | |
47 | static int mo_kill(struct Client *, struct Client *, int, const char **); | |
48 | static void relay_kill(struct Client *, struct Client *, struct Client *, | |
49 | const char *, const char *); | |
50 | ||
51 | struct Message kill_msgtab = { | |
52 | "KILL", 0, 0, 0, MFLG_SLOW, | |
53 | {mg_unreg, mg_not_oper, {ms_kill, 2}, {ms_kill, 2}, mg_ignore, {mo_kill, 2}} | |
54 | }; | |
55 | ||
56 | mapi_clist_av1 kill_clist[] = { &kill_msgtab, NULL }; | |
57 | ||
58 | mapi_hlist_av1 kill_hlist[] = { | |
59 | { "can_kill", &h_can_kill }, | |
60 | { NULL, NULL}, | |
61 | }; | |
62 | ||
63 | DECLARE_MODULE_AV1(kill, NULL, NULL, kill_clist, kill_hlist, NULL, "$Revision: 3408 $"); | |
64 | ||
65 | /* | |
66 | ** mo_kill | |
67 | ** parv[1] = kill victim | |
68 | ** parv[2] = kill path | |
69 | */ | |
70 | static int | |
71 | mo_kill(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
72 | { | |
73 | struct Client *target_p; | |
74 | const char *inpath = client_p->name; | |
75 | const char *user; | |
76 | const char *reason; | |
77 | hook_data_client_approval moduledata; | |
78 | ||
79 | user = parv[1]; | |
80 | ||
81 | if(!IsOperLocalKill(source_p)) | |
82 | { | |
83 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "local_kill"); | |
84 | return 0; | |
85 | } | |
86 | ||
87 | if(!EmptyString(parv[2])) | |
88 | { | |
89 | char *s; | |
90 | s = LOCAL_COPY(parv[2]); | |
91 | if(strlen(s) > (size_t) KILLLEN) | |
92 | s[KILLLEN] = '\0'; | |
93 | reason = s; | |
94 | } | |
95 | else | |
96 | reason = "<No reason given>"; | |
97 | ||
98 | if((target_p = find_named_person(user)) == NULL) | |
99 | { | |
100 | /* | |
101 | ** If the user has recently changed nick, automatically | |
102 | ** rewrite the KILL for this new nickname--this keeps | |
103 | ** servers in synch when nick change and kill collide | |
104 | */ | |
105 | if((target_p = get_history(user, (long) KILLCHASETIMELIMIT)) == NULL) | |
106 | { | |
107 | if (strchr(user, '.')) | |
108 | sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); | |
109 | else | |
110 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
111 | form_str(ERR_NOSUCHNICK), user); | |
112 | return 0; | |
113 | } | |
114 | sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name); | |
115 | } | |
116 | ||
117 | if(!MyConnect(target_p) && (!IsOperGlobalKill(source_p))) | |
118 | { | |
119 | sendto_one_notice(source_p, ":Nick %s is not on your server " | |
120 | "and you do not have the global_kill flag", | |
121 | target_p->name); | |
122 | return 0; | |
123 | } | |
124 | ||
125 | /* Last chance to stop the kill */ | |
126 | moduledata.client = source_p; | |
127 | moduledata.target = target_p; | |
128 | moduledata.approved = 1; | |
129 | call_hook(h_can_kill, &moduledata); | |
130 | ||
131 | if (moduledata.approved == 0) | |
132 | /* The callee should have sent a message. */ | |
133 | return 0; | |
134 | ||
135 | if(MyConnect(target_p)) | |
136 | sendto_one(target_p, ":%s!%s@%s KILL %s :%s", | |
137 | source_p->name, source_p->username, source_p->host, | |
138 | target_p->name, reason); | |
139 | ||
140 | /* Do not change the format of this message. There's no point in changing messages | |
141 | * that have been around for ever, for no reason.. */ | |
142 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
143 | "Received KILL message for %s!%s@%s. From %s Path: %s (%s)", | |
144 | target_p->name, target_p->username, target_p->orighost, | |
145 | source_p->name, me.name, reason); | |
146 | ||
147 | ilog(L_KILL, "%c %s %s!%s@%s %s %s", | |
148 | MyConnect(target_p) ? 'L' : 'G', get_oper_name(source_p), | |
149 | target_p->name, target_p->username, target_p->host, target_p->servptr->name, reason); | |
150 | ||
151 | /* | |
152 | ** And pass on the message to other servers. Note, that if KILL | |
153 | ** was changed, the message has to be sent to all links, also | |
154 | ** back. | |
155 | ** Suicide kills are NOT passed on --SRB | |
156 | */ | |
157 | if(!MyConnect(target_p)) | |
158 | { | |
159 | relay_kill(client_p, source_p, target_p, inpath, reason); | |
160 | /* | |
161 | ** Set FLAGS_KILLED. This prevents exit_one_client from sending | |
162 | ** the unnecessary QUIT for this. (This flag should never be | |
163 | ** set in any other place) | |
164 | */ | |
165 | target_p->flags |= FLAGS_KILLED; | |
166 | } | |
167 | ||
168 | rb_sprintf(buf, "Killed (%s (%s))", source_p->name, reason); | |
169 | ||
170 | exit_client(client_p, target_p, source_p, buf); | |
171 | ||
172 | return 0; | |
173 | } | |
174 | ||
175 | /* | |
176 | * ms_kill | |
177 | * parv[1] = kill victim | |
178 | * parv[2] = kill path and reason | |
179 | */ | |
180 | static int | |
181 | ms_kill(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
182 | { | |
183 | struct Client *target_p; | |
184 | const char *user; | |
185 | const char *reason; | |
186 | char default_reason[] = "<No reason given>"; | |
187 | const char *path; | |
188 | ||
189 | *buf = '\0'; | |
190 | ||
191 | user = parv[1]; | |
192 | ||
193 | if(EmptyString(parv[2])) | |
194 | { | |
195 | reason = default_reason; | |
196 | ||
197 | /* hyb6 takes the nick of the killer from the path *sigh* --fl_ */ | |
198 | path = source_p->name; | |
199 | } | |
200 | else | |
201 | { | |
202 | char *s = LOCAL_COPY(parv[2]), *t; | |
203 | t = strchr(s, ' '); | |
204 | ||
205 | if(t) | |
206 | { | |
207 | *t = '\0'; | |
208 | t++; | |
209 | reason = t; | |
210 | } | |
211 | else | |
212 | reason = default_reason; | |
213 | ||
214 | path = s; | |
215 | } | |
216 | ||
217 | if((target_p = find_person(user)) == NULL) | |
218 | { | |
219 | /* | |
220 | * If the user has recently changed nick, but only if its | |
221 | * not an uid, automatically rewrite the KILL for this new nickname. | |
222 | * --this keeps servers in synch when nick change and kill collide | |
223 | */ | |
224 | if(IsDigit(*user) || (!(target_p = get_history(user, (long) KILLCHASETIMELIMIT)))) | |
225 | { | |
226 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
227 | form_str(ERR_NOSUCHNICK), IsDigit(*user) ? "*" : user); | |
228 | return 0; | |
229 | } | |
230 | sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name); | |
231 | } | |
232 | ||
233 | if(IsServer(target_p) || IsMe(target_p)) | |
234 | { | |
235 | sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); | |
236 | return 0; | |
237 | } | |
238 | ||
239 | if(MyConnect(target_p)) | |
240 | { | |
241 | if(IsServer(source_p)) | |
242 | { | |
243 | sendto_one(target_p, ":%s KILL %s :%s", | |
244 | source_p->name, target_p->name, reason); | |
245 | } | |
246 | else | |
247 | sendto_one(target_p, ":%s!%s@%s KILL %s :%s", | |
248 | source_p->name, source_p->username, source_p->host, | |
249 | target_p->name, reason); | |
250 | } | |
251 | ||
252 | /* Be warned, this message must be From %s, or it confuses clients | |
253 | * so dont change it to From: or the case or anything! -- fl -- db */ | |
254 | /* path must contain at least 2 !'s, or bitchx falsely declares it | |
255 | * local --fl | |
256 | */ | |
257 | if(IsOper(source_p)) /* send it normally */ | |
258 | { | |
259 | sendto_realops_snomask(IsService(source_p) ? SNO_SKILL : SNO_GENERAL, L_ALL, | |
260 | "Received KILL message for %s!%s@%s. From %s Path: %s!%s!%s!%s %s", | |
261 | target_p->name, target_p->username, target_p->orighost, source_p->name, | |
262 | source_p->servptr->name, source_p->host, source_p->username, | |
263 | source_p->name, reason); | |
264 | ||
265 | ilog(L_KILL, "%c %s %s!%s@%s %s %s", | |
266 | MyConnect(target_p) ? 'O' : 'R', get_oper_name(source_p), | |
267 | target_p->name, target_p->username, target_p->host, | |
268 | target_p->servptr->name, reason); | |
269 | } | |
270 | else | |
271 | { | |
272 | sendto_realops_snomask(SNO_SKILL, L_ALL, | |
273 | "Received KILL message for %s!%s@%s. From %s %s", | |
274 | target_p->name, target_p->username, target_p->orighost, | |
275 | source_p->name, reason); | |
276 | ||
277 | ilog(L_KILL, "S %s %s!%s@%s %s %s", | |
278 | source_p->name, target_p->name, target_p->username, | |
279 | target_p->host, target_p->servptr->name, reason); | |
280 | } | |
281 | ||
282 | relay_kill(client_p, source_p, target_p, path, reason); | |
283 | ||
284 | /* FLAGS_KILLED prevents a quit being sent out */ | |
285 | target_p->flags |= FLAGS_KILLED; | |
286 | ||
287 | rb_sprintf(buf, "Killed (%s %s)", source_p->name, reason); | |
288 | ||
289 | exit_client(client_p, target_p, source_p, buf); | |
290 | ||
291 | return 0; | |
292 | } | |
293 | ||
294 | static void | |
295 | relay_kill(struct Client *one, struct Client *source_p, | |
296 | struct Client *target_p, const char *inpath, const char *reason) | |
297 | { | |
298 | struct Client *client_p; | |
299 | rb_dlink_node *ptr; | |
300 | char buffer[BUFSIZE]; | |
301 | ||
302 | if(MyClient(source_p)) | |
303 | rb_snprintf(buffer, sizeof(buffer), | |
304 | "%s!%s!%s!%s (%s)", | |
305 | me.name, source_p->host, source_p->username, source_p->name, reason); | |
306 | else | |
307 | rb_snprintf(buffer, sizeof(buffer), "%s %s", inpath, reason); | |
308 | ||
309 | RB_DLINK_FOREACH(ptr, serv_list.head) | |
310 | { | |
311 | client_p = ptr->data; | |
312 | ||
313 | if(!client_p || client_p == one) | |
314 | continue; | |
315 | ||
316 | sendto_one(client_p, ":%s KILL %s :%s", | |
317 | get_id(source_p, client_p), get_id(target_p, client_p), buffer); | |
318 | } | |
319 | } |