2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net>
|
|
|
|
* and Jilles Tjoelker <jilles -at- stack.nl>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution in both source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice remains unchanged.
|
|
|
|
*
|
|
|
|
* m_chghost.c: A module for handling spoofing dynamically.
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char chghost_desc[] = "Provides commands used to change and retrieve client hostnames";
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void me_realhost(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void ms_chghost(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void me_chghost(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void mo_chghost(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message realhost_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"REALHOST", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_realhost, 2}, mg_ignore}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Message chghost_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"CHGHOST", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_ignore, mg_not_oper, {ms_chghost, 3}, {ms_chghost, 3}, {me_chghost, 3}, {mo_chghost, 3}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 chghost_clist[] = { &chghost_msgtab, &realhost_msgtab, NULL };
|
|
|
|
|
2016-03-07 08:52:16 +01:00
|
|
|
DECLARE_MODULE_AV2(chghost, NULL, NULL, chghost_clist, NULL, NULL, NULL, NULL, chghost_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* clean_host()
|
|
|
|
*
|
|
|
|
* input - host to check
|
2016-03-09 08:44:05 +01:00
|
|
|
* output - false if erroneous, else true
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects -
|
|
|
|
*/
|
2016-03-09 08:44:05 +01:00
|
|
|
static bool
|
2007-01-25 07:40:21 +01:00
|
|
|
clean_host(const char *host)
|
|
|
|
{
|
|
|
|
int len = 0;
|
2009-04-20 15:37:13 +02:00
|
|
|
const char *last_slash = 0;
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2007-04-25 17:21:34 +02:00
|
|
|
if (*host == '\0' || *host == ':')
|
2016-03-09 08:44:05 +01:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
for(; *host; host++)
|
|
|
|
{
|
|
|
|
len++;
|
|
|
|
|
2016-08-16 11:12:01 +02:00
|
|
|
if(!rfc1459::is_host(*host))
|
2016-03-09 08:44:05 +01:00
|
|
|
return false;
|
2009-04-20 15:37:13 +02:00
|
|
|
if(*host == '/')
|
|
|
|
last_slash = host;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(len > HOSTLEN)
|
2016-03-09 08:44:05 +01:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-16 11:12:01 +02:00
|
|
|
if(last_slash && rfc1459::is_digit(last_slash[1]))
|
2016-03-09 08:44:05 +01:00
|
|
|
return false;
|
2009-04-20 15:37:13 +02:00
|
|
|
|
2016-03-09 08:44:05 +01:00
|
|
|
return true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* me_realhost
|
|
|
|
* parv[1] = real host
|
|
|
|
*
|
|
|
|
* Yes this contains a little race condition if someone does a whois
|
|
|
|
* in between the UID and REALHOST and use_whois_actually is enabled.
|
|
|
|
* I don't think that's a big problem as the whole thing is a
|
|
|
|
* race condition.
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
me_realhost(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
2007-01-25 07:40:21 +01:00
|
|
|
int parc, const char *parv[])
|
|
|
|
{
|
|
|
|
if (!IsPerson(source_p))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
del_from_hostname_hash(source_p->orighost, source_p);
|
2008-04-20 06:40:40 +02:00
|
|
|
rb_strlcpy(source_p->orighost, parv[1], sizeof source_p->orighost);
|
2007-01-25 07:40:21 +01:00
|
|
|
if (irccmp(source_p->host, source_p->orighost))
|
|
|
|
SetDynSpoof(source_p);
|
|
|
|
else
|
|
|
|
ClearDynSpoof(source_p);
|
|
|
|
add_to_hostname_hash(source_p->orighost, source_p);
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:44:05 +01:00
|
|
|
static bool
|
2007-01-25 07:40:21 +01:00
|
|
|
do_chghost(struct Client *source_p, struct Client *target_p,
|
|
|
|
const char *newhost, int is_encap)
|
|
|
|
{
|
|
|
|
if (!clean_host(newhost))
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, is_encap ? L_ALL : L_NETWIDE, "%s attempted to change hostname for %s to %s (invalid)",
|
|
|
|
IsServer(source_p) ? source_p->name : get_oper_name(source_p),
|
|
|
|
target_p->name, newhost);
|
|
|
|
/* sending this remotely may disclose important
|
|
|
|
* routing information -- jilles */
|
|
|
|
if (is_encap ? MyClient(target_p) : !ConfigServerHide.flatten_links)
|
|
|
|
sendto_one_notice(target_p, ":*** Notice -- %s attempted to change your hostname to %s (invalid)",
|
|
|
|
source_p->name, newhost);
|
2016-03-09 08:44:05 +01:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
change_nick_user_host(target_p, target_p->name, target_p->username, newhost, 0, "Changing host");
|
|
|
|
if (irccmp(target_p->host, target_p->orighost))
|
|
|
|
{
|
|
|
|
SetDynSpoof(target_p);
|
|
|
|
if (MyClient(target_p))
|
|
|
|
sendto_one_numeric(target_p, RPL_HOSTHIDDEN, "%s :is now your hidden host (set by %s)", target_p->host, source_p->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClearDynSpoof(target_p);
|
|
|
|
if (MyClient(target_p))
|
|
|
|
sendto_one_numeric(target_p, RPL_HOSTHIDDEN, "%s :hostname reset by %s", target_p->host, source_p->name);
|
|
|
|
}
|
|
|
|
if (MyClient(source_p))
|
|
|
|
sendto_one_notice(source_p, ":Changed hostname for %s to %s", target_p->name, target_p->host);
|
|
|
|
if (!IsServer(source_p) && !IsService(source_p))
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s changed hostname for %s to %s", get_oper_name(source_p), target_p->name, target_p->host);
|
2016-03-09 08:44:05 +01:00
|
|
|
return true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ms_chghost
|
|
|
|
* parv[1] = target
|
|
|
|
* parv[2] = host
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
ms_chghost(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
2007-01-25 07:40:21 +01:00
|
|
|
int parc, const char *parv[])
|
|
|
|
{
|
|
|
|
struct Client *target_p;
|
|
|
|
|
|
|
|
if (!(target_p = find_person(parv[1])))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if (do_chghost(source_p, target_p, parv[2], 0))
|
|
|
|
{
|
|
|
|
sendto_server(client_p, NULL,
|
|
|
|
CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s %s",
|
|
|
|
use_id(source_p), use_id(target_p), parv[2]);
|
|
|
|
sendto_server(client_p, NULL,
|
|
|
|
CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s",
|
|
|
|
use_id(source_p), use_id(target_p), parv[2]);
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* me_chghost
|
|
|
|
* parv[1] = target
|
|
|
|
* parv[2] = host
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
me_chghost(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
2007-01-25 07:40:21 +01:00
|
|
|
int parc, const char *parv[])
|
|
|
|
{
|
|
|
|
struct Client *target_p;
|
|
|
|
|
|
|
|
if (!(target_p = find_person(parv[1])))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
do_chghost(source_p, target_p, parv[2], 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mo_chghost
|
|
|
|
* parv[1] = target
|
|
|
|
* parv[2] = host
|
|
|
|
*/
|
|
|
|
/* Disable this because of the abuse potential -- jilles
|
|
|
|
* No, make it toggleable via ./configure. --nenolod
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
mo_chghost(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
2007-01-25 07:40:21 +01:00
|
|
|
int parc, const char *parv[])
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_OPER_CHGHOST
|
|
|
|
struct Client *target_p;
|
|
|
|
|
|
|
|
if(!IsOperAdmin(source_p))
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source_p->name, "admin");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(target_p = find_named_person(parv[1])))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHNICK,
|
|
|
|
form_str(ERR_NOSUCHNICK), parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!clean_host(parv[2]))
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":Hostname %s is invalid", parv[2]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
do_chghost(source_p, target_p, parv[2], 0);
|
|
|
|
|
|
|
|
sendto_server(NULL, NULL,
|
|
|
|
CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s %s",
|
|
|
|
use_id(source_p), use_id(target_p), parv[2]);
|
|
|
|
sendto_server(NULL, NULL,
|
|
|
|
CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s",
|
|
|
|
use_id(source_p), use_id(target_p), parv[2]);
|
|
|
|
#else
|
2008-03-30 20:02:55 +02:00
|
|
|
sendto_one_numeric(source_p, ERR_DISABLED, form_str(ERR_DISABLED),
|
|
|
|
"CHGHOST");
|
2007-01-25 07:40:21 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|