2010-01-29 23:29:00 +00:00
|
|
|
#include "stdinc.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "hook.h"
|
|
|
|
#include "client.h"
|
2017-11-25 22:53:45 +00:00
|
|
|
#include "hostmask.h"
|
2010-01-29 23:29:00 +00:00
|
|
|
#include "ircd.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_user.h"
|
|
|
|
#include "s_serv.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2020-01-02 03:35:37 +00:00
|
|
|
static const char sasl_usercloak_desc[] =
|
|
|
|
"Insert the SASL account name into certain iline spoofed hosts";
|
|
|
|
|
2010-01-29 23:29:00 +00:00
|
|
|
static void check_new_user(void *data);
|
|
|
|
mapi_hfn_list_av1 sasl_usercloak_hfnlist[] = {
|
2020-01-02 03:35:37 +00:00
|
|
|
{ "new_local_user", check_new_user },
|
2010-01-29 23:29:00 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2017-11-25 22:53:45 +00:00
|
|
|
|
2010-01-29 23:29:00 +00:00
|
|
|
unsigned int fnv_hash_string(char *str)
|
|
|
|
{
|
|
|
|
unsigned int hash = 0x811c9dc5; // Magic value for 32-bit fnv1 hash initialisation.
|
|
|
|
unsigned char *p = (unsigned char *)str;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
hash += (hash<<1) + (hash<<4) + (hash<<7) + (hash<<8) + (hash<<24);
|
|
|
|
hash ^= *p++;
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_new_user(void *vdata)
|
|
|
|
{
|
2020-01-02 03:35:37 +00:00
|
|
|
struct Client *source_p = vdata;
|
2010-01-29 23:29:00 +00:00
|
|
|
|
|
|
|
if (!IsIPSpoof(source_p))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (EmptyString(source_p->user->suser))
|
|
|
|
return;
|
|
|
|
|
2020-01-02 15:49:15 +00:00
|
|
|
char *accountpart = strstr(source_p->orighost, "/account");
|
|
|
|
if (!accountpart || accountpart[8] != '\0')
|
2010-01-29 23:29:00 +00:00
|
|
|
return;
|
|
|
|
|
2020-01-02 15:49:15 +00:00
|
|
|
accountpart += 1;
|
|
|
|
|
2010-01-29 23:29:00 +00:00
|
|
|
char buf[HOSTLEN];
|
2010-01-30 19:57:35 +00:00
|
|
|
memset(buf, 0, sizeof(buf));
|
2010-01-29 23:29:00 +00:00
|
|
|
char *dst = buf;
|
|
|
|
|
2010-02-02 21:31:50 +00:00
|
|
|
strncpy(buf, source_p->orighost, accountpart - source_p->orighost);
|
|
|
|
dst += accountpart - source_p->orighost;
|
2010-01-29 23:29:00 +00:00
|
|
|
|
|
|
|
int needhash = 0;
|
|
|
|
|
|
|
|
for (char *src = source_p->user->suser; *src ; src++ )
|
|
|
|
{
|
2017-11-25 22:53:45 +00:00
|
|
|
if (dst >= buf + sizeof(buf))
|
2010-01-29 23:29:00 +00:00
|
|
|
{
|
|
|
|
/* Doesn't fit. Warn opers and bail. */
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
|
|
|
|
"Couldn't fit account name part %s in hostname for %s!%s@%s",
|
2010-02-02 21:31:50 +00:00
|
|
|
source_p->user->suser, source_p->name, source_p->username, source_p->orighost);
|
2010-01-29 23:29:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-02 03:35:37 +00:00
|
|
|
char c = tolower(*src);
|
2010-01-29 23:29:00 +00:00
|
|
|
|
|
|
|
if (IsHostChar(c))
|
|
|
|
*dst++ = c;
|
|
|
|
else
|
|
|
|
needhash = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needhash)
|
|
|
|
{
|
|
|
|
if (dst > buf + sizeof(buf) - 12) /* '/x-' plus eight digit hash plus null terminator */
|
|
|
|
{
|
|
|
|
/* Doesn't fit. Warn opers and bail. */
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
|
|
|
|
"Couldn't fit account name part %s in hostname for %s!%s@%s",
|
2010-02-02 21:31:50 +00:00
|
|
|
source_p->user->suser, source_p->name, source_p->username, source_p->orighost);
|
2010-01-29 23:29:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst++ = '/';
|
|
|
|
*dst++ = 'x';
|
|
|
|
*dst++ = '-';
|
|
|
|
|
|
|
|
unsigned int hashval = fnv_hash_string(source_p->user->suser);
|
|
|
|
hashval %= 100000000; // eight digits only please.
|
2020-01-02 16:29:23 +00:00
|
|
|
snprintf(dst, 9, "%08u", hashval);
|
2010-01-29 23:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* just in case */
|
|
|
|
buf[HOSTLEN-1] = '\0';
|
|
|
|
|
2010-02-02 21:31:50 +00:00
|
|
|
/* If hostname has been changed already (probably by services cloak on SASL login), then
|
|
|
|
* leave it intact. If not, change it. In either case, update the original hostname.
|
|
|
|
*/
|
|
|
|
if (0 == irccmp(source_p->host, source_p->orighost))
|
|
|
|
change_nick_user_host(source_p, source_p->name, source_p->username, buf, 0, "Changing host");
|
|
|
|
strncpy(source_p->orighost, buf, HOSTLEN);
|
2017-11-25 22:53:45 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
struct ConfItem *aconf = find_kline(source_p);
|
|
|
|
|
|
|
|
if(aconf == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(IsExemptKline(source_p))
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
|
|
|
|
"KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
|
|
|
|
get_client_name(source_p, HIDE_IP),
|
|
|
|
aconf->user, aconf->host);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-08 19:30:41 +00:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
|
2017-11-25 22:53:45 +00:00
|
|
|
"KLINE active for %s",
|
|
|
|
get_client_name(source_p, HIDE_IP));
|
|
|
|
|
|
|
|
notify_banned_client(source_p, aconf, K_LINED);
|
|
|
|
}
|
2010-01-29 23:29:00 +00:00
|
|
|
}
|
2020-01-02 03:35:37 +00:00
|
|
|
|
|
|
|
DECLARE_MODULE_AV2(sasl_usercloak, NULL, NULL, NULL, NULL, sasl_usercloak_hfnlist, NULL, NULL, sasl_usercloak_desc);
|