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