| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* m_kill.c: Kills a user. |
| 4 |
* |
| 5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
* USA |
| 21 |
* |
| 22 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "list.h" |
| 27 |
#include "client.h" |
| 28 |
#include "hash.h" /* for find_client() */ |
| 29 |
#include "ircd.h" |
| 30 |
#include "numeric.h" |
| 31 |
#include "log.h" |
| 32 |
#include "s_serv.h" |
| 33 |
#include "conf.h" |
| 34 |
#include "send.h" |
| 35 |
#include "whowas.h" |
| 36 |
#include "irc_string.h" |
| 37 |
#include "parse.h" |
| 38 |
#include "modules.h" |
| 39 |
|
| 40 |
|
| 41 |
static char buf[IRCD_BUFSIZE]; |
| 42 |
|
| 43 |
static void |
| 44 |
relay_kill(struct Client *one, struct Client *source_p, |
| 45 |
struct Client *target_p, const char *inpath, |
| 46 |
const char *reason) |
| 47 |
{ |
| 48 |
dlink_node *ptr = NULL; |
| 49 |
|
| 50 |
DLINK_FOREACH(ptr, serv_list.head) |
| 51 |
{ |
| 52 |
struct Client *client_p = ptr->data; |
| 53 |
|
| 54 |
if (client_p == one) |
| 55 |
continue; |
| 56 |
|
| 57 |
if (MyClient(source_p)) |
| 58 |
sendto_one(client_p, ":%s KILL %s :%s!%s!%s!%s (%s)", |
| 59 |
ID_or_name(source_p, client_p), |
| 60 |
ID_or_name(target_p, client_p), |
| 61 |
me.name, source_p->host, source_p->username, |
| 62 |
source_p->name, reason); |
| 63 |
else |
| 64 |
sendto_one(client_p, ":%s KILL %s :%s %s", |
| 65 |
ID_or_name(source_p, client_p), |
| 66 |
ID_or_name(target_p, client_p), inpath, reason); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/* mo_kill() |
| 71 |
* parv[0] = sender prefix |
| 72 |
* parv[1] = kill victim |
| 73 |
* parv[2] = kill path |
| 74 |
*/ |
| 75 |
static void |
| 76 |
mo_kill(struct Client *client_p, struct Client *source_p, |
| 77 |
int parc, char *parv[]) |
| 78 |
{ |
| 79 |
struct Client *target_p; |
| 80 |
const char *inpath = client_p->name; |
| 81 |
char *user; |
| 82 |
char *reason; |
| 83 |
char def_reason[] = "No reason"; |
| 84 |
|
| 85 |
user = parv[1]; |
| 86 |
reason = parv[2]; /* Either defined or NULL (parc >= 2!!) */ |
| 87 |
|
| 88 |
if (*user == '\0') |
| 89 |
{ |
| 90 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
| 91 |
me.name, source_p->name, "KILL"); |
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
if (!HasOFlag(source_p, OPER_FLAG_GLOBAL_KILL|OPER_FLAG_K)) |
| 96 |
{ |
| 97 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
| 98 |
me.name, source_p->name); |
| 99 |
return; |
| 100 |
} |
| 101 |
|
| 102 |
if (!EmptyString(reason)) |
| 103 |
{ |
| 104 |
if (strlen(reason) > (size_t)KILLLEN) |
| 105 |
reason[KILLLEN] = '\0'; |
| 106 |
} |
| 107 |
else |
| 108 |
reason = def_reason; |
| 109 |
|
| 110 |
if ((target_p = hash_find_client(user)) == NULL) |
| 111 |
{ |
| 112 |
/* |
| 113 |
* If the user has recently changed nick, automatically |
| 114 |
* rewrite the KILL for this new nickname--this keeps |
| 115 |
* servers in synch when nick change and kill collide |
| 116 |
*/ |
| 117 |
if ((target_p = get_history(user, |
| 118 |
(time_t)ConfigFileEntry.kill_chase_time_limit)) |
| 119 |
== NULL) |
| 120 |
{ |
| 121 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
| 122 |
me.name, source_p->name, user); |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
sendto_one(source_p, ":%s NOTICE %s :KILL changed from %s to %s", |
| 127 |
me.name, source_p->name, user, target_p->name); |
| 128 |
} |
| 129 |
|
| 130 |
if (IsServer(target_p) || IsMe(target_p)) |
| 131 |
{ |
| 132 |
sendto_one(source_p, form_str(ERR_CANTKILLSERVER), |
| 133 |
me.name, source_p->name); |
| 134 |
return; |
| 135 |
} |
| 136 |
|
| 137 |
if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_GLOBAL_KILL)) |
| 138 |
{ |
| 139 |
sendto_one(source_p, ":%s NOTICE %s :Nick %s isnt on your server", |
| 140 |
me.name, source_p->name, target_p->name); |
| 141 |
return; |
| 142 |
} |
| 143 |
|
| 144 |
if (MyConnect(target_p)) |
| 145 |
sendto_one(target_p, ":%s!%s@%s KILL %s :%s", |
| 146 |
source_p->name, source_p->username, source_p->host, |
| 147 |
target_p->name, reason); |
| 148 |
|
| 149 |
/* |
| 150 |
* Do not change the format of this message. There's no point in changing messages |
| 151 |
* that have been around for ever, for no reason.. |
| 152 |
*/ |
| 153 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 154 |
"Received KILL message for %s. From %s Path: %s (%s)", |
| 155 |
target_p->name, source_p->name, me.name, reason); |
| 156 |
|
| 157 |
ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s (%s)", |
| 158 |
source_p->name, target_p->name, me.name, reason); |
| 159 |
|
| 160 |
/* |
| 161 |
* And pass on the message to other servers. Note, that if KILL |
| 162 |
* was changed, the message has to be sent to all links, also |
| 163 |
* back. |
| 164 |
* Suicide kills are NOT passed on --SRB |
| 165 |
*/ |
| 166 |
if (!MyConnect(target_p)) |
| 167 |
{ |
| 168 |
relay_kill(client_p, source_p, target_p, inpath, reason); |
| 169 |
/* |
| 170 |
* Set FLAGS_KILLED. This prevents exit_one_client from sending |
| 171 |
* the unnecessary QUIT for this. (This flag should never be |
| 172 |
* set in any other place) |
| 173 |
*/ |
| 174 |
AddFlag(target_p, FLAGS_KILLED); |
| 175 |
} |
| 176 |
|
| 177 |
snprintf(buf, sizeof(buf), "Killed (%s (%s))", source_p->name, reason); |
| 178 |
exit_client(target_p, source_p, buf); |
| 179 |
} |
| 180 |
|
| 181 |
/* ms_kill() |
| 182 |
* parv[0] = sender prefix |
| 183 |
* parv[1] = kill victim |
| 184 |
* parv[2] = kill path and reason |
| 185 |
*/ |
| 186 |
static void |
| 187 |
ms_kill(struct Client *client_p, struct Client *source_p, |
| 188 |
int parc, char *parv[]) |
| 189 |
{ |
| 190 |
struct Client *target_p; |
| 191 |
char *user; |
| 192 |
char *reason; |
| 193 |
const char *path; |
| 194 |
char def_reason[] = "No reason"; |
| 195 |
|
| 196 |
if (EmptyString(parv[1])) |
| 197 |
{ |
| 198 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
| 199 |
me.name, source_p->name, "KILL"); |
| 200 |
return; |
| 201 |
} |
| 202 |
|
| 203 |
user = parv[1]; |
| 204 |
|
| 205 |
if (EmptyString(parv[2])) |
| 206 |
{ |
| 207 |
reason = def_reason; |
| 208 |
|
| 209 |
/* hyb6 takes the nick of the killer from the path *sigh* --fl_ */ |
| 210 |
path = source_p->name; |
| 211 |
} |
| 212 |
else |
| 213 |
{ |
| 214 |
reason = strchr(parv[2], ' '); |
| 215 |
|
| 216 |
if (reason != NULL) |
| 217 |
*reason++ = '\0'; |
| 218 |
else |
| 219 |
reason = def_reason; |
| 220 |
|
| 221 |
path = parv[2]; |
| 222 |
} |
| 223 |
|
| 224 |
if ((target_p = find_person(client_p, user)) == NULL) |
| 225 |
{ |
| 226 |
/* |
| 227 |
* If the user has recently changed nick, but only if its |
| 228 |
* not an uid, automatically rewrite the KILL for this new nickname. |
| 229 |
* --this keeps servers in synch when nick change and kill collide |
| 230 |
*/ |
| 231 |
if (IsDigit(*user)) /* Somehow an uid was not found in the hash ! */ |
| 232 |
return; |
| 233 |
if ((target_p = get_history(user, |
| 234 |
(time_t)ConfigFileEntry.kill_chase_time_limit)) |
| 235 |
== NULL) |
| 236 |
{ |
| 237 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
| 238 |
me.name, source_p->name, user); |
| 239 |
return; |
| 240 |
} |
| 241 |
|
| 242 |
sendto_one(source_p,":%s NOTICE %s :KILL changed from %s to %s", |
| 243 |
me.name, source_p->name, user, target_p->name); |
| 244 |
} |
| 245 |
|
| 246 |
if (IsServer(target_p) || IsMe(target_p)) |
| 247 |
{ |
| 248 |
sendto_one(source_p, form_str(ERR_CANTKILLSERVER), |
| 249 |
me.name, source_p->name); |
| 250 |
return; |
| 251 |
} |
| 252 |
|
| 253 |
if (MyConnect(target_p)) |
| 254 |
{ |
| 255 |
if (IsServer(source_p)) |
| 256 |
{ |
| 257 |
/* dont send clients kills from a hidden server */ |
| 258 |
if ((IsHidden(source_p) || ConfigServerHide.hide_servers) && !HasUMode(target_p, UMODE_OPER)) |
| 259 |
sendto_one(target_p, ":%s KILL %s :%s", |
| 260 |
me.name, target_p->name, reason); |
| 261 |
else |
| 262 |
sendto_one(target_p, ":%s KILL %s :%s", |
| 263 |
source_p->name, target_p->name, reason); |
| 264 |
} |
| 265 |
else |
| 266 |
sendto_one(target_p, ":%s!%s@%s KILL %s :%s", |
| 267 |
source_p->name, source_p->username, source_p->host, |
| 268 |
target_p->name, reason); |
| 269 |
} |
| 270 |
|
| 271 |
/* |
| 272 |
* Be warned, this message must be From %s, or it confuses clients |
| 273 |
* so dont change it to From: or the case or anything! -- fl -- db |
| 274 |
*/ |
| 275 |
/* |
| 276 |
* path must contain at least 2 !'s, or bitchx falsely declares it |
| 277 |
* local --fl |
| 278 |
*/ |
| 279 |
if (HasUMode(source_p, UMODE_OPER)) /* send it normally */ |
| 280 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 281 |
"Received KILL message for %s. From %s Path: %s!%s!%s!%s %s", |
| 282 |
target_p->name, source_p->name, source_p->servptr->name, |
| 283 |
source_p->host, source_p->username, source_p->name, reason); |
| 284 |
else |
| 285 |
sendto_realops_flags(UMODE_SKILL, L_ALL, SEND_NOTICE, |
| 286 |
"Received KILL message for %s. From %s %s", |
| 287 |
target_p->name, source_p->name, reason); |
| 288 |
|
| 289 |
ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s %s", |
| 290 |
source_p->name, target_p->name, source_p->name, reason); |
| 291 |
|
| 292 |
relay_kill(client_p, source_p, target_p, path, reason); |
| 293 |
AddFlag(target_p, FLAGS_KILLED); |
| 294 |
|
| 295 |
/* reason comes supplied with its own ()'s */ |
| 296 |
if (IsServer(source_p) && (IsHidden(source_p) || ConfigServerHide.hide_servers)) |
| 297 |
snprintf(buf, sizeof(buf), "Killed (%s %s)", me.name, reason); |
| 298 |
else |
| 299 |
snprintf(buf, sizeof(buf), "Killed (%s %s)", source_p->name, reason); |
| 300 |
|
| 301 |
exit_client(target_p, source_p, buf); |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
static struct Message kill_msgtab = { |
| 306 |
"KILL", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
| 307 |
{m_unregistered, m_not_oper, ms_kill, m_ignore, mo_kill, m_ignore} |
| 308 |
}; |
| 309 |
|
| 310 |
static void |
| 311 |
module_init(void) |
| 312 |
{ |
| 313 |
mod_add_cmd(&kill_msgtab); |
| 314 |
} |
| 315 |
|
| 316 |
static void |
| 317 |
module_exit(void) |
| 318 |
{ |
| 319 |
mod_del_cmd(&kill_msgtab); |
| 320 |
} |
| 321 |
|
| 322 |
struct module module_entry = { |
| 323 |
.node = { NULL, NULL, NULL }, |
| 324 |
.name = NULL, |
| 325 |
.version = "$Revision$", |
| 326 |
.handle = NULL, |
| 327 |
.modinit = module_init, |
| 328 |
.modexit = module_exit, |
| 329 |
.flags = MODULE_FLAG_CORE |
| 330 |
}; |