Skip to content

Commit

Permalink
remove use of deprecated inet_aton and inet_ntoa
Browse files Browse the repository at this point in the history
Fixes: cheusov#19
Signed-off-by: Carlos Rodriguez-Fernandez <carlosrodrifernandez@gmail.com>
  • Loading branch information
carlosrodfern committed Mar 12, 2024
1 parent 845bbff commit 73abec3
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions dictd/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

#include <mkc_macro.h>

#define ADDR_LEN 64

int stdin2stdout_mode = 0; /* copy stdin to stdout( dict_dictd function ) */

static int _dict_defines, _dict_matches;
Expand Down Expand Up @@ -240,7 +242,7 @@ static int daemon_check_mask(const char *spec, const char *ip)
{
char *tmp = xstrdup(spec);
char *pt;
char tstring[64], mstring[64];
char tstring[ADDR_LEN], mstring[ADDR_LEN];
struct in_addr target, mask;
int bits;
unsigned long bitmask;
Expand All @@ -258,11 +260,17 @@ static int daemon_check_mask(const char *spec, const char *ip)
return DICT_DENY;
}

inet_aton(ip, &target);
inet_aton(tmp, &mask);
bits = strtol(pt, NULL, 10);
strcpy(tstring, inet_ntoa(target));
strcpy(mstring, inet_ntoa(mask));
if (inet_pton(AF_INET, ip, &target) < 1) {
log_info( ":E: Unable to parse '%s' as an IPv4 address\n", ip);
return DICT_DENY;
}
if (inet_pton(AF_INET, tmp, &mask) < 1) {
log_info( ":E: Unable to parse '%s' as an IPv4 address\n", tmp);
return DICT_DENY;
}
bits = strtol(pt, NULL, 10);
inet_ntop(AF_INET, &target, tstring, ADDR_LEN);
inet_ntop(AF_INET, &mask, mstring, ADDR_LEN);
if (bits < 0 || bits > 32) {
log_info( ":E: Bit count (%d) out of range, denying access to %s\n",
bits, ip);
Expand All @@ -285,7 +293,7 @@ static int daemon_check_range(const char *spec, const char *ip)
{
char *tmp = xstrdup(spec);
char *pt;
char tstring[64], minstring[64], maxstring[64];
char tstring[ADDR_LEN], minstring[ADDR_LEN], maxstring[ADDR_LEN];
struct in_addr target, min, max;

if (!(pt = strchr(tmp, ':'))) {
Expand All @@ -306,12 +314,22 @@ static int daemon_check_range(const char *spec, const char *ip)
return DICT_DENY;
}

inet_aton(ip, &target);
inet_aton(tmp, &min);
inet_aton(pt, &max);
strcpy(tstring, inet_ntoa(target));
strcpy(minstring, inet_ntoa(min));
strcpy(maxstring, inet_ntoa(max));
if (inet_pton(AF_INET, ip, &target) < 1) {
log_info( ":E: Unable to parse '%s' as an IPv4 address\n", ip);
return DICT_DENY;
}
if (inet_pton(AF_INET, tmp, &min) < 1) {
log_info( ":E: Unable to parse '%s' as an IPv4 address\n", tmp);
return DICT_DENY;
}
if (inet_pton(AF_INET, pt, &max) < 1) {
log_info( ":E: Unable to parse '%s' as an IPv4 address\n", pt);
return DICT_DENY;
}

inet_ntop(AF_INET, &target, tstring, ADDR_LEN);
inet_ntop(AF_INET, &min, minstring, ADDR_LEN);
inet_ntop(AF_INET, &max, maxstring, ADDR_LEN);
if (ntohl(target.s_addr) >= ntohl(min.s_addr)
&& ntohl(target.s_addr) <= ntohl(max.s_addr))
{
Expand Down

0 comments on commit 73abec3

Please sign in to comment.