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