X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/799483e7ea4c6d002d47b95ea36404c6c3b41da5..4ea91f08c5bb337f31c66abbe247f0894a2c56bd:/extensions/ip_cloaking.c diff --git a/extensions/ip_cloaking.c b/extensions/ip_cloaking.c index e60ef4c..150a719 100644 --- a/extensions/ip_cloaking.c +++ b/extensions/ip_cloaking.c @@ -19,7 +19,7 @@ static int _modinit(void) { /* add the usermode to the available slot */ - user_modes['h'] = find_umode_slot(); + user_modes['x'] = find_umode_slot(); construct_umodebuf(); return 0; @@ -29,7 +29,7 @@ static void _moddeinit(void) { /* disable the umode and remove it from the available list */ - user_modes['h'] = 0; + user_modes['x'] = 0; construct_umodebuf(); } @@ -66,8 +66,6 @@ distribute_hostchange(struct Client *client) ClearDynSpoof(client); } -#define HOSTLEN 63 - static void do_host_cloak_ip(const char *inbuf, char *outbuf) { @@ -79,7 +77,7 @@ do_host_cloak_ip(const char *inbuf, char *outbuf) int totalcount = 0; int ipv6 = 0; - strncpy(outbuf, inbuf, HOSTLEN); + rb_strlcpy(outbuf, inbuf, HOSTLEN + 1); if (strchr(outbuf, ':')) { @@ -94,16 +92,11 @@ do_host_cloak_ip(const char *inbuf, char *outbuf) * the actual cloaking would get ugly */ for (tptr = outbuf; *tptr != '\0'; tptr++) - { - if (*tptr == ':') { + if (*tptr == ':') totalcount++; - } - } } else if (!strchr(outbuf, '.')) - { return; - } for (tptr = outbuf; *tptr != '\0'; tptr++) { @@ -113,19 +106,13 @@ do_host_cloak_ip(const char *inbuf, char *outbuf) continue; } - switch (ipv6) - { - case 1: - if (sepcount < totalcount / 2) - break; - case 0: - if (sepcount < 2) - break; - default: - *tptr = chartable[(*tptr + accum) % 20]; + if (ipv6 && sepcount < totalcount / 2) + continue; - } + if (!ipv6 && sepcount < 2) + continue; + *tptr = chartable[(*tptr + accum) % 20]; accum = (accum << 1) | (accum >> 31); } } @@ -137,7 +124,7 @@ do_host_cloak_host(const char *inbuf, char *outbuf) char *tptr; uint32_t accum = fnv_hash((const unsigned char*) inbuf, 32); - strncpy(outbuf, inbuf, HOSTLEN); + rb_strlcpy(outbuf, inbuf, HOSTLEN + 1); /* pass 1: scramble first section of hostname using base26 * alphabet toasted against the FNV hash of the string. @@ -162,9 +149,7 @@ do_host_cloak_host(const char *inbuf, char *outbuf) for (tptr = outbuf; *tptr != '\0'; tptr++) { if (isdigit(*tptr)) - { - *tptr = (*tptr + accum) % 10; - } + *tptr = '0' + (*tptr + accum) % 10; accum = (accum << 1) | (accum >> 31); } @@ -180,31 +165,31 @@ check_umode_change(void *vdata) return; /* didn't change +h umode, we don't need to do anything */ - if (!((data->oldumodes ^ source_p->umodes) & user_modes['h'])) + if (!((data->oldumodes ^ source_p->umodes) & user_modes['x'])) return; - if (source_p->umodes & user_modes['h']) + if (source_p->umodes & user_modes['x']) { if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost))) { - source_p->umodes &= ~user_modes['h']; + source_p->umodes &= ~user_modes['x']; return; } if (strcmp(source_p->host, source_p->localClient->mangledhost)) { - rb_strlcpy(source_p->host, source_p->localClient->mangledhost, HOSTLEN); + rb_strlcpy(source_p->host, source_p->localClient->mangledhost, HOSTLEN + 1); distribute_hostchange(source_p); } else /* not really nice, but we need to send this numeric here */ sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", source_p->host); } - else if (!(source_p->umodes & user_modes['h'])) + else if (!(source_p->umodes & user_modes['x'])) { if (source_p->localClient->mangledhost != NULL && !strcmp(source_p->host, source_p->localClient->mangledhost)) { - rb_strlcpy(source_p->host, source_p->orighost, HOSTLEN); + rb_strlcpy(source_p->host, source_p->orighost, HOSTLEN + 1); distribute_hostchange(source_p); } } @@ -217,17 +202,17 @@ check_new_user(void *vdata) if (IsIPSpoof(source_p)) { - source_p->umodes &= ~user_modes['h']; + source_p->umodes &= ~user_modes['x']; return; } - source_p->localClient->mangledhost = rb_malloc(HOSTLEN); + source_p->localClient->mangledhost = rb_malloc(HOSTLEN + 1); if (!irccmp(source_p->orighost, source_p->sockhost)) do_host_cloak_ip(source_p->orighost, source_p->localClient->mangledhost); else do_host_cloak_host(source_p->orighost, source_p->localClient->mangledhost); if (IsDynSpoof(source_p)) - source_p->umodes &= ~user_modes['h']; - if (source_p->umodes & user_modes['h']) + source_p->umodes &= ~user_modes['x']; + if (source_p->umodes & user_modes['x']) { rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host)); if (irccmp(source_p->host, source_p->orighost))