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