From: Todd C. Miller Date: Wed, 10 Aug 1994 23:21:47 +0000 (+0000) Subject: added load_ip_addrs() to load the ip_addrs global var X-Git-Tag: SUDO_1_3_1~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49673e12cb89c238cc2b9561182f4f98cc2906c8;p=sudo added load_ip_addrs() to load the ip_addrs global var --- diff --git a/sudo.c b/sudo.c index 3bccbcf94..25c5a4ac1 100644 --- a/sudo.c +++ b/sudo.c @@ -76,6 +76,8 @@ static char rcsid[] = "$Id$"; #endif /* HAVE_MALLOC_H */ #include #include +#include +#include #include #ifdef _AIX #include @@ -114,6 +116,7 @@ char *cmnd; char *user; char *epasswd; char host[MAXHOSTNAMELEN + 1]; +struct in_addr *ip_addrs; char cwd[MAXPATHLEN + 1]; uid_t uid = -2; @@ -283,10 +286,12 @@ static void load_globals() inform_user(GLOBAL_NO_HOSTNAME); #ifdef FQDN } else { - if ((h_ent = gethostbyname(host)) == NULL) + if ((h_ent = gethostbyname(host)) == NULL) { log_error(GLOBAL_HOST_UNREGISTERED); - else + } else { strcpy(host, h_ent -> h_name); + load_ip_addrs(h_ent); + } } #else } @@ -554,3 +559,43 @@ static void load_cmnd() exit(1); } } + + + +/********************************************************************** + * + * load_ip_addrs() + * + * This function sets the ip_addrs global variable + */ + +void load_ip_addrs(h_ent) + struct hostent *h_ent; +{ + char **addr; /* to walk addr list in h_ent */ + int i; /* counter */ + + /* set h_ent if not already set */ + if (h_ent == NULL && (h_ent = gethostbyname(host)) == NULL) { + log_error(GLOBAL_HOST_UNREGISTERED); + + return; + } + + /* malloc space for ip_addrs array */ + for (addr = h_ent -> h_addr_list, i = 0; *addr; addr++, i++) + ; + if (i) { + ip_addrs = malloc(sizeof(struct in_addr) * (i)); + if (ip_addrs == NULL) { + perror("malloc"); + (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); + exit(1); + } + } + + /* copy ip addrs to ip_addrs array */ + for (addr = h_ent -> h_addr_list, i = 0; *addr; addr++, i++) + (void) memcpy(&ip_addrs[i], *addr, h_ent -> h_length); + ip_addrs[i].s_addr = 0; +}