* note: it is guaranteed that parv[0]..parv[parc-1] are all
* non-NULL pointers.
*/
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
#include "client.h"
#include "hash.h"
#include "ircd.h"
+#include "ircd_features.h"
#include "ircd_log.h"
#include "ircd_reply.h"
+#include "ircd_snprintf.h"
#include "ircd_string.h"
#include "msg.h"
#include "numeric.h"
#include "send.h"
#include "whowas.h"
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
#include <string.h>
-#if defined(DEBUGMODE)
-#define SYSLOG_KILL
-#endif
+/*
+ * do_kill - Performs the generic work involved in killing a client
+ *
+ */
+static int do_kill(struct Client* cptr, struct Client* sptr,
+ struct Client* victim, char* inpath, char* path, char* msg)
+{
+ assert(0 != cptr);
+ assert(0 != sptr);
+ assert(!IsServer(victim));
+
+ /*
+ * Notify all *local* opers about the KILL (this includes the one
+ * originating the kill, if from this server--the special numeric
+ * reply message is not generated anymore).
+ *
+ * Note: "victim->name" is used instead of "user" because we may
+ * have changed the target because of the nickname change.
+ */
+ sendto_opmask_butone(0, IsServer(sptr) ? SNO_SERVKILL : SNO_OPERKILL,
+ "Received KILL message for %s from %s Path: %s!%s %s",
+ get_client_name(victim, SHOW_IP), cli_name(sptr),
+ inpath, path, msg);
+ log_write_kill(victim, sptr, inpath, path, msg);
+
+ /*
+ * And pass on the message to other servers. Note, that if KILL
+ * was changed, the message has to be sent to all links, also
+ * back.
+ * Client suicide kills are NOT passed on --SRB
+ */
+ if (IsServer(cptr) || !MyConnect(victim)) {
+ sendcmdto_serv_butone(sptr, CMD_KILL, cptr, "%C :%s!%s %s", victim,
+ inpath, path, msg);
+
+ /*
+ * Set FLAG_KILLED. This prevents exit_one_client from sending
+ * the unnecessary QUIT for this. (This flag should never be
+ * set in any other place)
+ */
+ SetFlag(victim, FLAG_KILLED);
+ }
+
+ /*
+ * Tell the victim she/he has been zapped, but *only* if
+ * the victim is on current server--no sense in sending the
+ * notification chasing the above kill, it won't get far
+ * anyway (as this user don't exist there any more either)
+ * In accordance with the new hiding rules, the victim
+ * always sees the kill as coming from me.
+ */
+ if (MyConnect(victim))
+ sendcmdto_one(feature_bool(FEAT_HIS_KILLWHO) ? &his : sptr, CMD_KILL,
+ victim, "%C :%s %s", victim, feature_bool(FEAT_HIS_KILLWHO)
+ ? feature_str(FEAT_HIS_SERVERNAME) : cli_name(sptr), msg);
+ return exit_client_msg(cptr, victim, feature_bool(FEAT_HIS_KILLWHO)
+ ? &me : sptr, "Killed (%s %s)",
+ feature_bool(FEAT_HIS_KILLWHO) ?
+ feature_str(FEAT_HIS_SERVERNAME) : cli_name(sptr),
+ msg);
+}
/*
- * ms_kill - server message handler template
+ * ms_kill - server message handler
*
* NOTE: IsServer(cptr) == true;
*
int ms_kill(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
struct Client* victim;
- const char* inpath;
- char* user;
char* path;
- char* killer;
- char buf[BUFSIZE];
+ char* msg;
assert(0 != cptr);
assert(0 != sptr);
* XXX - a server sending less than 3 params could really desync
* things
*/
- if (parc < 3)
+ if (parc < 3) {
+ protocol_violation(sptr,"Too few arguments for KILL");
return need_more_params(sptr, "KILL");
+ }
- user = parv[1];
path = parv[parc - 1]; /* Either defined or NULL (parc >= 3) */
+ if (!(msg = strchr(path, ' '))) /* Extract out the message */
+ msg = "(No reason supplied)";
+ else
+ *(msg++) = '\0'; /* Remove first character (space) and terminate path */
+
if (!(victim = findNUser(parv[1]))) {
if (IsUser(sptr))
- sendto_one(sptr,
- "%s NOTICE %s%s :KILL target disconnected before I got him :(",
- NumServ(&me), NumNick(sptr));
- return 0;
- }
-#if 0
- /*
- * XXX - strictly speaking, the next 2 checks shouldn't be needed
- * this function only handles kills from servers, and the check
- * is done before the message is propagated --Bleep
- */
- if (IsServer(victim) || IsMe(victim)) {
- return send_error_to_client(sptr, ERR_CANTKILLSERVER);
- return 0;
- }
- if (IsLocOp(sptr) && !MyConnect(victim)) {
- return send_error_to_client(sptr, ERR_NOPRIVILEGES);
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :KILL target disconnected "
+ "before I got him :(", sptr);
return 0;
}
- /*
- * XXX - this is guaranteed by the parser not to happen
- */
- if (EmptyString(path))
- path = "*no-path*"; /* Bogus server sending??? */
-#endif
- /*
- * Notify all *local* opers about the KILL (this includes the one
- * originating the kill, if from this server--the special numeric
- * reply message is not generated anymore).
- *
- * Note: "victim->name" is used instead of "user" because we may
- * have changed the target because of the nickname change.
- */
- inpath = cptr->name;
-
- sendto_op_mask(IsServer(sptr) ? SNO_SERVKILL : SNO_OPERKILL,
- "Received KILL message for %s. From %s Path: %s!%s",
- victim->name, parv[0], cptr->name, path);
-#if defined(SYSLOG_KILL)
- ircd_log_kill(victim, sptr, cptr->name, path);
-#endif
- /*
- * And pass on the message to other servers. Note, that if KILL
- * was changed, the message has to be sent to all links, also
- * back.
- */
-#if defined(EVERYONE_SENDS_NUMERICS)
- /*
- * just pass parv[0] here, it's the numeric nick of the sender
- */
- sendto_highprot_butone(cptr, 10, "%s " TOK_KILL " %s%s :%s!%s",
- parv[0], NumNick(victim), cptr->name, path);
-#else
- /*
- * translate to numerics
- */
- if (IsServer(sptr))
- sendto_highprot_butone(cptr, 10, "%s " TOK_KILL " %s%s :%s!%s",
- NumServ(sptr), NumNick(victim), cptr->name, path);
- else
- sendto_highprot_butone(cptr, 10, "%s%s " TOK_KILL " %s%s :%s!%s",
- NumNick(sptr), NumNick(victim), cptr->name, path);
-#endif
/*
* We *can* have crossed a NICK with this numeric... --Run
*
* Bounce the kill back to the originator, if the client can't be found
* by the next hop (short lag) the bounce won't propagate further.
*/
- if (MyConnect(victim))
- sendto_one(cptr, "%s " TOK_KILL " %s%s :%s!%s (Ghost 5 Numeric Collided)",
- NumServ(&me), NumNick(victim), cptr->name, path);
- /*
- * Set FLAGS_KILLED. This prevents exit_one_client from sending
- * the unnecessary QUIT for this. (This flag should never be
- * set in any other place)
- */
- victim->flags |= FLAGS_KILLED;
-
- /*
- * Tell the victim she/he has been zapped, but *only* if
- * the victim is on current server--no sense in sending the
- * notification chasing the above kill, it won't get far
- * anyway (as this user don't exist there any more either)
- */
- if (MyConnect(victim))
- sendto_prefix_one(victim, sptr, ":%s KILL %s :%s!%s",
- sptr->name, victim->name, cptr->name, path);
- /*
- * the first space in path will be at the end of the
- * opers name:
- * bla.bla.bla!host.net.dom!opername (comment)
- */
- if ((killer = strchr(path, ' '))) {
- while (killer > path && '!' != *killer)
- --killer;
- if ('!' == *killer)
- ++killer;
+ if (MyConnect(victim)) {
+ sendcmdto_one(&me, CMD_KILL, cptr, "%C :%s (Ghost 5 Numeric Collided)",
+ victim, path);
}
- else
- killer = path;
- sprintf_irc(buf, "Killed (%s)", killer);
-
- return exit_client(cptr, victim, sptr, buf);
+ return do_kill(cptr, sptr, victim, cli_name(cptr), path, msg);
}
/*
- * mo_kill - oper message handler template
+ * mo_kill - oper message handler
*
* NOTE: IsPrivileged(sptr), IsAnOper(sptr) == true
* IsServer(cptr), IsServer(sptr) == false
int mo_kill(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
struct Client* victim;
- const char* inpath;
char* user;
- char* path;
- char* comment;
- char buf[BUFSIZE];
+ char msg[TOPICLEN + 3]; /* (, ), and \0 */
assert(0 != cptr);
assert(0 != sptr);
assert(cptr == sptr);
assert(IsAnOper(sptr));
-#if defined(OPER_KILL)
-
if (parc < 3 || EmptyString(parv[parc - 1]))
return need_more_params(sptr, "KILL");
user = parv[1];
+ ircd_snprintf(0, msg, sizeof(msg), "(%.*s)", TOPICLEN, parv[parc - 1]);
+
if (!(victim = FindClient(user))) {
/*
- * If the user has recently changed nick, we automaticly
+ * If the user has recently changed nick, we automatically
* rewrite the KILL for this new nickname--this keeps
* servers in synch when nick change and kill collide
*/
if (!(victim = get_history(user, (long)15)))
- return send_error_to_client(sptr, ERR_NOSUCHNICK, user);
+ return send_reply(sptr, ERR_NOSUCHNICK, user);
- sendto_one(sptr, ":%s NOTICE %s :Changed KILL %s into %s",
- me.name, parv[0], user, victim->name);
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Changed KILL %s into %s", sptr,
+ user, cli_name(victim));
}
- if (!MyConnect(victim) && IsLocOp(cptr))
- return send_error_to_client(sptr, ERR_NOPRIVILEGES);
+ if (!HasPriv(sptr, MyConnect(victim) ? PRIV_LOCAL_KILL : PRIV_KILL))
+ return send_reply(sptr, ERR_NOPRIVILEGES);
if (IsServer(victim) || IsMe(victim)) {
- return send_error_to_client(sptr, ERR_CANTKILLSERVER);
+ return send_reply(sptr, ERR_CANTKILLSERVER);
}
/*
* if the user is +k, prevent a kill from local user
*/
if (IsChannelService(victim))
- return send_error_to_client(sptr, ERR_ISCHANSERVICE, "KILL", victim->name);
+ return send_reply(sptr, ERR_ISCHANSERVICE, "KILL", cli_name(victim));
-#ifdef LOCAL_KILL_ONLY
- if (!MyConnect(victim)) {
- sendto_one(sptr, ":%s NOTICE %s :Nick %s isnt on your server",
- me.name, parv[0], victim->name);
+ if (!MyConnect(victim) && !HasPriv(sptr, PRIV_KILL)) {
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Nick %s isn't on your server",
+ sptr, cli_name(victim));
return 0;
}
-#endif
- /*
- * The kill originates from this server, initialize path.
- * (In which case the 'path' may contain user suplied
- * explanation ...or some nasty comment, sigh... >;-)
- *
- * ...!operhost!oper
- * ...!operhost!oper (comment)
- */
-
- comment = parv[parc - 1]; /* Either defined or NULL (parc >= 3) */
-
- if (strlen(comment) > TOPICLEN)
- comment[TOPICLEN] = '\0';
-
- inpath = sptr->user->host;
-
- sprintf_irc(buf,
- "%s%s (%s)", cptr->name, IsOper(sptr) ? "" : "(L)", comment);
- path = buf;
-
- /*
- * Notify all *local* opers about the KILL (this includes the one
- * originating the kill, if from this server--the special numeric
- * reply message is not generated anymore).
- *
- * Note: "victim->name" is used instead of "user" because we may
- * have changed the target because of the nickname change.
- */
- sendto_op_mask(SNO_OPERKILL,
- "Received KILL message for %s. From %s Path: %s!%s",
- victim->name, parv[0], inpath, path);
-
-#if defined(SYSLOG_KILL)
- ircd_log_kill(victim, sptr, inpath, path);
-#endif
- /*
- * And pass on the message to other servers. Note, that if KILL
- * was changed, the message has to be sent to all links, also
- * back.
- * Suicide kills are NOT passed on --SRB
- */
- if (!MyConnect(victim)) {
- sendto_highprot_butone(cptr, 10, "%s%s " TOK_KILL " %s%s :%s!%s",
- NumNick(sptr), NumNick(victim), inpath, path);
-
- /*
- * Set FLAGS_KILLED. This prevents exit_one_client from sending
- * the unnecessary QUIT for this. (This flag should never be
- * set in any other place)
- */
- victim->flags |= FLAGS_KILLED;
-
- sprintf_irc(buf, "Killed by %s (%s)", sptr->name, comment);
- }
- else {
- /*
- * Tell the victim she/he has been zapped, but *only* if
- * the victim is on current server--no sense in sending the
- * notification chasing the above kill, it won't get far
- * anyway (as this user don't exist there any more either)
- */
- sendto_prefix_one(victim, sptr, ":%s KILL %s :%s!%s",
- parv[0], victim->name, inpath, path);
- sprintf_irc(buf, "Local kill by %s (%s)", sptr->name, comment);
- }
-
- return exit_client(cptr, victim, sptr, buf);
-
-#else /* !defined(OPER_KILL) */
-
- return send_error_to_client(sptr, ERR_NOPRIVILEGES);
-
-#endif /* !defined(OPER_KILL) */
-}
-
-#if 0
-/*
- * m_kill
- *
- * parv[0] = sender prefix
- * parv[1] = kill victim
- * parv[parc-1] = kill path
- */
-int m_kill(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
-{
- struct Client* acptr;
- const char* inpath = get_client_name(cptr, HIDE_IP);
- char* user;
- char* path;
- char* killer;
- int chasing = 0;
- char buf[BUFSIZE];
- char buf2[BUFSIZE];
-
- if (parc < 3 || *parv[1] == '\0')
- return need_more_params(sptr, parv[0], "KILL");
-
- user = parv[1];
- path = parv[parc - 1]; /* Either defined or NULL (parc >= 3) */
-
-#ifdef OPER_KILL
- if (!IsPrivileged(cptr))
- {
- sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
- return 0;
- }
-#else
- if (!IsServer(cptr))
- {
- sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
- return 0;
- }
-#endif
- if (IsAnOper(cptr))
- {
- if (EmptyString(path))
- return need_more_params(sptr, parv[0], "KILL");
-
- if (strlen(path) > (size_t)TOPICLEN)
- path[TOPICLEN] = '\0';
- }
-
- if (MyUser(sptr))
- {
- if (!(acptr = FindClient(user)))
- {
- /*
- * If the user has recently changed nick, we automaticly
- * rewrite the KILL for this new nickname--this keeps
- * servers in synch when nick change and kill collide
- */
- if (!(acptr = get_history(user, (long)15)))
- {
- sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], user);
- return 0;
- }
- sendto_one(sptr, ":%s NOTICE %s :Changed KILL %s into %s",
- me.name, parv[0], user, acptr->name);
- chasing = 1;
- }
- }
- else if (!(acptr = findNUser(user)))
- {
- if (IsUser(sptr))
- sendto_one(sptr,
- "%s NOTICE %s%s :KILL target disconnected before I got him :(",
- NumServ(&me), NumNick(sptr));
- return 0;
- }
- if (!MyConnect(acptr) && IsLocOp(cptr))
- {
- sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
- return 0;
- }
- if (IsServer(acptr) || IsMe(acptr))
- {
- sendto_one(sptr, err_str(ERR_CANTKILLSERVER), me.name, parv[0]);
- return 0;
- }
-
- /* if the user is +k, prevent a kill from local user */
- if (IsChannelService(acptr) && MyUser(sptr))
- {
- sendto_one(sptr, err_str(ERR_ISCHANSERVICE), me.name,
- parv[0], "KILL", acptr->name);
- return 0;
- }
-
-#ifdef LOCAL_KILL_ONLY
- if (MyConnect(sptr) && !MyConnect(acptr))
- {
- sendto_one(sptr, ":%s NOTICE %s :Nick %s isnt on your server",
- me.name, parv[0], acptr->name);
- return 0;
- }
-#endif
- if (!IsServer(cptr))
- {
- /*
- * The kill originates from this server, initialize path.
- * (In which case the 'path' may contain user suplied
- * explanation ...or some nasty comment, sigh... >;-)
- *
- * ...!operhost!oper
- * ...!operhost!oper (comment)
- */
- inpath = cptr->sockhost;
-
- if (!EmptyString(path))
- {
- sprintf_irc(buf,
- "%s%s (%s)", cptr->name, IsOper(sptr) ? "" : "(L)", path);
- path = buf;
- }
- else
- path = cptr->name;
- }
- else if (EmptyString(path))
- path = "*no-path*"; /* Bogus server sending??? */
- /*
- * Notify all *local* opers about the KILL (this includes the one
- * originating the kill, if from this server--the special numeric
- * reply message is not generated anymore).
- *
- * Note: "acptr->name" is used instead of "user" because we may
- * have changed the target because of the nickname change.
- */
- if (IsLocOp(sptr) && !MyConnect(acptr))
- {
- sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
- return 0;
- }
- sendto_op_mask(IsServer(sptr) ? SNO_SERVKILL : SNO_OPERKILL,
- "Received KILL message for %s. From %s Path: %s!%s",
- acptr->name, parv[0], inpath, path);
-#if defined(USE_SYSLOG) && defined(SYSLOG_KILL)
- if (MyUser(acptr))
- { /* get more infos when your local
- clients are killed -- _dl */
- if (IsServer(sptr))
- ircd_log(L_TRACE,
- "A local client %s!%s@%s KILLED from %s [%s] Path: %s!%s)",
- acptr->name, acptr->user->username, acptr->user->host,
- parv[0], sptr->name, inpath, path);
- else
- ircd_log(L_TRACE,
- "A local client %s!%s@%s KILLED by %s [%s!%s@%s] (%s!%s)",
- acptr->name, acptr->user->username, acptr->user->host,
- parv[0], sptr->name, sptr->user->username, sptr->user->host,
- inpath, path);
- }
- else if (IsOper(sptr))
- ircd_log(L_TRACE, "KILL From %s For %s Path %s!%s",
- parv[0], acptr->name, inpath, path);
-#endif
- /*
- * And pass on the message to other servers. Note, that if KILL
- * was changed, the message has to be sent to all links, also
- * back.
- * Suicide kills are NOT passed on --SRB
- */
- if (!MyConnect(acptr) || !MyConnect(sptr) || !IsAnOper(sptr))
- {
- sendto_highprot_butone(cptr, 10, ":%s " TOK_KILL " %s%s :%s!%s",
- parv[0], NumNick(acptr), inpath, path);
- /* We *can* have crossed a NICK with this numeric... --Run */
- /* Note the following situation:
- * KILL SAA --> X
- * <-- S NICK ... SAA | <-- SAA QUIT <-- S NICK ... SAA <-- SQUIT S
- * Where the KILL reaches point X before the QUIT does.
- * This would then *still* cause an orphan because the KILL doesn't reach S
- * (because of the SQUIT), the QUIT is ignored (because of the KILL)
- * and the second NICK ... SAA causes an orphan on the server at the
- * right (which then isn't removed when the SQUIT arrives).
- * Therefore we still need to detect numeric nick collisions too.
- */
- if (MyConnect(acptr) && IsServer(cptr))
- sendto_one(cptr, "%s " TOK_KILL " %s%s :%s!%s (Ghost5)",
- NumServ(&me), NumNick(acptr), inpath, path);
- acptr->flags |= FLAGS_KILLED;
- }
-
- /*
- * Tell the victim she/he has been zapped, but *only* if
- * the victim is on current server--no sense in sending the
- * notification chasing the above kill, it won't get far
- * anyway (as this user don't exist there any more either)
- */
- if (MyConnect(acptr))
- sendto_prefix_one(acptr, sptr, ":%s KILL %s :%s!%s",
- parv[0], acptr->name, inpath, path);
- /*
- * Set FLAGS_KILLED. This prevents exit_one_client from sending
- * the unnecessary QUIT for this. (This flag should never be
- * set in any other place)
- */
- if (MyConnect(acptr) && MyConnect(sptr) && IsAnOper(sptr))
- sprintf_irc(buf2, "Local kill by %s (%s)", sptr->name,
- EmptyString(parv[parc - 1]) ? sptr->name : parv[parc - 1]);
- else
- {
- if ((killer = strchr(path, ' ')))
- {
- while (*killer && *killer != '!')
- killer--;
- if (!*killer)
- killer = path;
- else
- killer++;
- }
- else
- killer = path;
- sprintf_irc(buf2, "Killed (%s)", killer);
- }
- return exit_client(cptr, acptr, sptr, buf2);
+ return do_kill(cptr, sptr, victim, cli_user(sptr)->host, cli_name(sptr),
+ msg);
}
-
-#endif /* 0 */
-