2 * IRC - Internet Relay Chat, ircd/m_kill.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
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 1, or (at your option)
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
88 #include "ircd_policy.h"
89 #include "ircd_reply.h"
90 #include "ircd_snprintf.h"
91 #include "ircd_string.h"
103 * ms_kill - server message handler template
105 * NOTE: IsServer(cptr) == true;
107 * parv[0] = sender prefix
108 * parv[1] = kill victim
109 * parv[parc-1] = kill path
111 int ms_kill(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
113 struct Client* victim;
122 assert(IsServer(cptr));
125 * XXX - a server sending less than 3 params could really desync
129 protocol_violation(sptr,"Too few arguments for KILL");
130 return need_more_params(sptr, "KILL");
134 path = parv[parc - 1]; /* Either defined or NULL (parc >= 3) */
136 if (!(victim = findNUser(parv[1]))) {
138 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :KILL target disconnected "
139 "before I got him :(", sptr);
144 * Notify all *local* opers about the KILL (this includes the one
145 * originating the kill, if from this server--the special numeric
146 * reply message is not generated anymore).
148 * Note: "victim->name" is used instead of "user" because we may
149 * have changed the target because of the nickname change.
151 inpath = cli_name(cptr);
153 sendto_opmask_butone(0, IsServer(sptr) ? SNO_SERVKILL : SNO_OPERKILL,
154 "Received KILL message for %s. From %s Path: %C!%s",
155 get_client_name(victim,SHOW_IP), parv[0], cptr, path);
157 log_write_kill(victim, sptr, cli_name(cptr), path);
159 * And pass on the message to other servers. Note, that if KILL
160 * was changed, the message has to be sent to all links, also
163 sendcmdto_serv_butone(sptr, CMD_KILL, cptr, "%C :%s!%s", victim, cli_name(cptr),
166 * We *can* have crossed a NICK with this numeric... --Run
168 * Note the following situation:
170 * <-- S NICK ... SAA | <-- SAA QUIT <-- S NICK ... SAA <-- SQUIT S
171 * Where the KILL reaches point X before the QUIT does.
172 * This would then *still* cause an orphan because the KILL doesn't reach S
173 * (because of the SQUIT), the QUIT is ignored (because of the KILL)
174 * and the second NICK ... SAA causes an orphan on the server at the
175 * right (which then isn't removed when the SQUIT arrives).
176 * Therefore we still need to detect numeric nick collisions too.
178 * Bounce the kill back to the originator, if the client can't be found
179 * by the next hop (short lag) the bounce won't propagate further.
181 if (MyConnect(victim))
182 sendcmdto_one(&me, CMD_KILL, cptr, "%C :%s!%s (Ghost 5 Numeric Collided)",
183 victim, cli_name(cptr), path);
185 * Set FLAGS_KILLED. This prevents exit_one_client from sending
186 * the unnecessary QUIT for this. (This flag should never be
187 * set in any other place)
189 cli_flags(victim) |= FLAGS_KILLED;
192 * the first space in path will be at the end of the
194 * bla.bla.bla!host.net.dom!opername (comment)
196 if (!(comment = strchr(path, ' ')))
197 comment = " (No reason given)";
199 * Tell the victim she/he has been zapped, but *only* if
200 * the victim is on current server--no sense in sending the
201 * notification chasing the above kill, it won't get far
202 * anyway (as this user don't exist there any more either)
204 if (MyConnect(victim))
205 sendcmdto_one(IsServer(sptr) ? &me : sptr, CMD_KILL, victim,
206 "%C :%s%s", victim, IsServer(sptr) ? HEAD_IN_SAND_SERVERNAME :
207 cli_name(sptr), comment);
209 ircd_snprintf(0, buf, sizeof(buf), "Killed (%s%s)", IsServer(sptr) ?
210 HEAD_IN_SAND_SERVERNAME : cli_name(sptr), comment);
212 return exit_client(cptr, victim, sptr, buf);
216 * mo_kill - oper message handler template
218 * NOTE: IsPrivileged(sptr), IsAnOper(sptr) == true
219 * IsServer(cptr), IsServer(sptr) == false
221 * parv[0] = sender prefix
222 * parv[1] = kill victim
223 * parv[parc-1] = kill path
225 int mo_kill(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
227 struct Client* victim;
237 * oper connection to this server, cptr is always sptr
239 assert(cptr == sptr);
240 assert(IsAnOper(sptr));
242 if (parc < 3 || EmptyString(parv[parc - 1]))
243 return need_more_params(sptr, "KILL");
246 if (!(victim = FindClient(user))) {
248 * If the user has recently changed nick, we automaticly
249 * rewrite the KILL for this new nickname--this keeps
250 * servers in synch when nick change and kill collide
252 if (!(victim = get_history(user, (long)15)))
253 return send_reply(sptr, ERR_NOSUCHNICK, user);
255 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Changed KILL %s into %s", sptr,
256 user, cli_name(victim));
258 if (!HasPriv(sptr, MyConnect(victim) ? PRIV_LOCAL_KILL : PRIV_KILL))
259 return send_reply(sptr, ERR_NOPRIVILEGES);
261 if (IsServer(victim) || IsMe(victim)) {
262 return send_reply(sptr, ERR_CANTKILLSERVER);
265 * if the user is +k, prevent a kill from local user
267 if (IsChannelService(victim))
268 return send_reply(sptr, ERR_ISCHANSERVICE, "KILL", cli_name(victim));
271 if (!MyConnect(victim) && !HasPriv(sptr, PRIV_KILL)) {
272 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Nick %s isnt on your server",
273 sptr, cli_name(victim));
278 * The kill originates from this server, initialize path.
279 * (In which case the 'path' may contain user suplied
280 * explanation ...or some nasty comment, sigh... >;-)
283 * ...!operhost!oper (comment)
286 comment = parv[parc - 1]; /* Either defined or NULL (parc >= 3) */
288 if (strlen(comment) > TOPICLEN)
289 comment[TOPICLEN] = '\0';
291 inpath = cli_user(sptr)->host;
293 ircd_snprintf(0, buf, sizeof(buf), "%s (%s)", cli_name(cptr), comment);
297 * Notify all *local* opers about the KILL (this includes the one
298 * originating the kill, if from this server--the special numeric
299 * reply message is not generated anymore).
301 * Note: "victim->name" is used instead of "user" because we may
302 * have changed the target because of the nickname change.
304 sendto_opmask_butone(0, SNO_OPERKILL,
305 "Received KILL message for %s. From %s Path: %s!%s",
306 get_client_name(victim,SHOW_IP), parv[0], inpath, path);
308 log_write_kill(victim, sptr, inpath, path);
310 * And pass on the message to other servers. Note, that if KILL
311 * was changed, the message has to be sent to all links, also
313 * Suicide kills are NOT passed on --SRB
315 if (!MyConnect(victim)) {
316 sendcmdto_serv_butone(sptr, CMD_KILL, cptr, "%C :%s!%s", victim, inpath,
320 * Set FLAGS_KILLED. This prevents exit_one_client from sending
321 * the unnecessary QUIT for this. (This flag should never be
322 * set in any other place)
324 cli_flags(victim) |= FLAGS_KILLED;
329 * Tell the victim she/he has been zapped, but *only* if
330 * the victim is on current server--no sense in sending the
331 * notification chasing the above kill, it won't get far
332 * anyway (as this user don't exist there any more either)
334 sendcmdto_one(sptr, CMD_KILL, victim, "%C :%s", victim, path);
337 ircd_snprintf(0, buf, sizeof(buf), "Killed (%s (%s))", cli_name(sptr),
340 return exit_client(cptr, victim, sptr, buf);