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