about summary refs log tree commit diff
path: root/inet
diff options
context:
space:
mode:
Diffstat (limited to 'inet')
-rw-r--r--inet/rcmd.c76
-rw-r--r--inet/rexec.c27
2 files changed, 82 insertions, 21 deletions
diff --git a/inet/rcmd.c b/inet/rcmd.c
index 3fc8adc742..2631523a22 100644
--- a/inet/rcmd.c
+++ b/inet/rcmd.c
@@ -42,6 +42,7 @@ static char sccsid[] = "@(#)rcmd.c	8.3 (Berkeley) 3/26/94";
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#include <alloca.h>
 #include <signal.h>
 #include <fcntl.h>
 #include <netdb.h>
@@ -63,20 +64,35 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
 	const char *locuser, *remuser, *cmd;
 	int *fd2p;
 {
-	struct hostent *hp;
+	struct hostent hostbuf, *hp;
+	size_t hstbuflen;
+	char *tmphstbuf;
 	struct sockaddr_in sin, from;
 	fd_set reads;
 	int32_t oldmask;
 	pid_t pid;
 	int s, lport, timo;
 	char c;
+	int herr;
 
 	pid = getpid();
-	hp = gethostbyname(*ahost);
-	if (hp == NULL) {
-		herror(*ahost);
-		return (-1);
-	}
+
+	hstbuflen = 1024;
+	tmphstbuf = __alloca (hstbuflen);
+	while (__gethostbyname_r (*ahost, &hostbuf, tmphstbuf, hstbuflen,
+				  &hp, &herr) < 0)
+	  if (herr != NETDB_INTERNAL || errno != ERANGE)
+	    {
+	      herror(*ahost);
+	      return -1;
+	    }
+	  else
+	    {
+	      /* Enlarge the buffer.  */
+	      hstbuflen *= 2;
+	      tmphstbuf = __alloca (hstbuflen);
+	    }
+
 	*ahost = hp->h_name;
 	oldmask = sigblock(sigmask(SIGURG));
 	for (timo = 1, lport = IPPORT_RESERVED - 1;;) {
@@ -244,12 +260,27 @@ ruserok(rhost, superuser, ruser, luser)
 	const char *rhost, *ruser, *luser;
 	int superuser;
 {
-	struct hostent *hp;
+	struct hostent hostbuf, *hp;
+	size_t buflen;
+	char *buffer;
 	u_int32_t addr;
 	char **ap;
+	int herr;
+
+	buflen = 1024;
+	buffer = __alloca (buflen);
+
+	while (__gethostbyname_r (rhost, &hostbuf, buffer, buflen, &hp, &herr)
+	       < 0)
+	  if (herr != NETDB_INTERNAL || errno != ERANGE)
+	    return -1;
+	  else
+	    {
+	      /* Enlarge the buffer.  */
+	      buflen *= 2;
+	      buffer = __alloca (buflen);
+	    }
 
-	if ((hp = gethostbyname(rhost)) == NULL)
-		return (-1);
 	for (ap = hp->h_addr_list; *ap; ++ap) {
 		bcopy(*ap, &addr, sizeof(addr));
 		if (iruserok(addr, superuser, ruser, luser) == 0)
@@ -275,7 +306,7 @@ iruserok(raddr, superuser, ruser, luser)
 {
 	register char *cp;
 	struct stat sbuf;
-	struct passwd *pwd;
+	struct passwd pwdbuf, *pwd;
 	FILE *hostf;
 	uid_t uid;
 	int first;
@@ -293,10 +324,12 @@ again:
 	if (first == 1 && (__check_rhosts_file || superuser)) {
 		char *pbuf;
 		size_t dirlen;
+		size_t buflen = __sysconf (_SC_GETPW_R_SIZE_MAX);
+		char buffer = __alloca (buflen);
 
 		first = 0;
-		if ((pwd = getpwnam(luser)) == NULL)
-			return (-1);
+		if (getpwnam_r (luser, &pwdbuf, buffer, buflen, &pwd) < 0)
+			return -1;
 
 		dirlen = strlen (pwd->pw_dir);
 		pbuf = alloca (dirlen + sizeof "/.rhosts");
@@ -395,17 +428,30 @@ __icheckhost(raddr, lhost)
 	u_int32_t raddr;
 	register char *lhost;
 {
-	register struct hostent *hp;
+	register struct hostent hostbuf, *hp;
+	size_t buflen;
+	char *buffer;
 	register u_int32_t laddr;
 	register char **pp;
+	int herr;
 
 	/* Try for raw ip address first. */
 	if (isdigit(*lhost) && (int32_t)(laddr = inet_addr(lhost)) != -1)
 		return (raddr == laddr);
 
 	/* Better be a hostname. */
-	if ((hp = gethostbyname(lhost)) == NULL)
-		return (0);
+	buflen = 1024;
+	buffer = __alloca (buflen);
+	while (__gethostbyname_r (lhost, &hostbuf, buffer, buflen, &hp, &herr)
+	       < 0)
+	  if (herr != NETDB_INTERNAL || errno != ERANGE)
+	    return 0;
+	  else
+	    {
+	      /* Enlarge the buffer.  */
+	      buflen *= 2;
+	      buflen = __alloca (buflen);
+	    }
 
 	/* Spin through ip addresses. */
 	for (pp = hp->h_addr_list; *pp; ++pp)
diff --git a/inet/rexec.c b/inet/rexec.c
index f4772475fd..d91949de3c 100644
--- a/inet/rexec.c
+++ b/inet/rexec.c
@@ -40,6 +40,7 @@ static char sccsid[] = "@(#)rexec.c	8.1 (Berkeley) 6/4/93";
 
 #include <netinet/in.h>
 
+#include <alloca.h>
 #include <stdio.h>
 #include <netdb.h>
 #include <errno.h>
@@ -56,16 +57,30 @@ rexec(ahost, rport, name, pass, cmd, fd2p)
 	int *fd2p;
 {
 	struct sockaddr_in sin, sin2, from;
-	struct hostent *hp;
+	struct hostent hostbuf, *hp;
+	size_t hstbuflen;
+	char *hsttmpbuf;
 	u_short port;
 	int s, timo = 1, s3;
 	char c;
+	int herr;
+
+	hstbuflen = 1024;
+	hsttmpbuf = __alloca (hstbuflen);
+	while (__gethostbyname_r (*ahost, &hostbuf, hsttmpbuf, hstbuflen,
+				  &hp, &herr) < 0)
+	  if (herr != NETDB_INTERNAL || errno != ERANGE)
+	    {
+	      herror(*ahost);
+	      return -1;
+	    }
+	  else
+	    {
+	      /* Enlarge the buffer.  */
+	      hstbuflen *= 2;
+	      hsttmpbuf = __alloca (hstbuflen);
+	    }
 
-	hp = gethostbyname(*ahost);
-	if (hp == 0) {
-		herror(*ahost);
-		return (-1);
-	}
 	*ahost = hp->h_name;
 	ruserpass(hp->h_name, &name, &pass);
 retry: