diff options
| author | millert <> | 2016-05-28 15:46:00 +0000 |
|---|---|---|
| committer | millert <> | 2016-05-28 15:46:00 +0000 |
| commit | bc4d67dba56c497c4f04fd3fec21cce6bd9268ea (patch) | |
| tree | cb53508c8fe90a7f49156667cc5f1a3b4329be07 /src/lib/libc/net/rcmdsh.c | |
| parent | c229d5649abc30a96be97b04d692cbe3df3c1d75 (diff) | |
| download | openbsd-bc4d67dba56c497c4f04fd3fec21cce6bd9268ea.tar.gz openbsd-bc4d67dba56c497c4f04fd3fec21cce6bd9268ea.tar.bz2 openbsd-bc4d67dba56c497c4f04fd3fec21cce6bd9268ea.zip | |
Use getaddrinfo() instead of the non-standard gethostbyname2().
OK deraadt@ jca@ jung@ florian@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/net/rcmdsh.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/lib/libc/net/rcmdsh.c b/src/lib/libc/net/rcmdsh.c index 14275d414a..b9cbd6d5d1 100644 --- a/src/lib/libc/net/rcmdsh.c +++ b/src/lib/libc/net/rcmdsh.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: rcmdsh.c,v 1.18 2015/11/24 22:03:33 millert Exp $ */ | 1 | /* $OpenBSD: rcmdsh.c,v 1.19 2016/05/28 15:46:00 millert Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 2001, MagniComp | 4 | * Copyright (c) 2001, MagniComp |
| @@ -38,6 +38,7 @@ | |||
| 38 | #include <sys/wait.h> | 38 | #include <sys/wait.h> |
| 39 | #include <signal.h> | 39 | #include <signal.h> |
| 40 | #include <errno.h> | 40 | #include <errno.h> |
| 41 | #include <limits.h> | ||
| 41 | #include <netdb.h> | 42 | #include <netdb.h> |
| 42 | #include <stdio.h> | 43 | #include <stdio.h> |
| 43 | #include <stdlib.h> | 44 | #include <stdlib.h> |
| @@ -55,7 +56,8 @@ int | |||
| 55 | rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, | 56 | rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, |
| 56 | const char *cmd, char *rshprog) | 57 | const char *cmd, char *rshprog) |
| 57 | { | 58 | { |
| 58 | struct hostent *hp; | 59 | static char hbuf[HOST_NAME_MAX+1]; |
| 60 | struct addrinfo hint, *res; | ||
| 59 | int sp[2]; | 61 | int sp[2]; |
| 60 | pid_t cpid; | 62 | pid_t cpid; |
| 61 | char *p, pwbuf[_PW_BUF_LEN]; | 63 | char *p, pwbuf[_PW_BUF_LEN]; |
| @@ -74,9 +76,16 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, | |||
| 74 | 76 | ||
| 75 | /* Validate remote hostname. */ | 77 | /* Validate remote hostname. */ |
| 76 | if (strcmp(*ahost, "localhost") != 0) { | 78 | if (strcmp(*ahost, "localhost") != 0) { |
| 77 | if ((hp = gethostbyname2(*ahost, AF_INET)) || | 79 | memset(&hint, 0, sizeof(hint)); |
| 78 | (hp = gethostbyname2(*ahost, AF_INET6))) | 80 | hint.ai_family = PF_UNSPEC; |
| 79 | *ahost = hp->h_name; | 81 | hint.ai_flags = AI_CANONNAME; |
| 82 | if (getaddrinfo(*ahost, NULL, &hint, &res) == 0) { | ||
| 83 | if (res->ai_canonname) { | ||
| 84 | strlcpy(hbuf, res->ai_canonname, sizeof(hbuf)); | ||
| 85 | *ahost = hbuf; | ||
| 86 | } | ||
| 87 | freeaddrinfo(res); | ||
| 88 | } | ||
| 80 | } | 89 | } |
| 81 | 90 | ||
| 82 | /* Get a socketpair we'll use for stdin and stdout. */ | 91 | /* Get a socketpair we'll use for stdin and stdout. */ |
