diff options
author | Yoshinobu Inoue <shin@FreeBSD.org> | 2000-02-19 15:57:52 +0000 |
---|---|---|
committer | Yoshinobu Inoue <shin@FreeBSD.org> | 2000-02-19 15:57:52 +0000 |
commit | 6d939e82e0d6b54be01c0c7323db0c4c0121a82b (patch) | |
tree | 0763d284c94c8ca92ac3a4a51c8e33d7e9ab8c18 /usr.bin/login | |
parent | 956ef11d6468248ad7263b69257602a9ce6bcaec (diff) | |
download | src-6d939e82e0d6b54be01c0c7323db0c4c0121a82b.tar.gz src-6d939e82e0d6b54be01c0c7323db0c4c0121a82b.zip |
Added IPv6 name resolving support for utmp logging.
Approved by: jkh
Notes
Notes:
svn path=/head/; revision=57339
Diffstat (limited to 'usr.bin/login')
-rw-r--r-- | usr.bin/login/login.c | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/usr.bin/login/login.c b/usr.bin/login/login.c index 7b7cc97b7d77..5d1c7fbd77f8 100644 --- a/usr.bin/login/login.c +++ b/usr.bin/login/login.c @@ -54,6 +54,7 @@ static const char rcsid[] = #include <sys/copyright.h> #include <sys/param.h> #include <sys/stat.h> +#include <sys/socket.h> #include <sys/time.h> #include <sys/resource.h> #include <sys/file.h> @@ -84,6 +85,11 @@ static const char rcsid[] = #include "pathnames.h" +/* wrapper for KAME-special getnameinfo() */ +#ifndef NI_WITHSCOPEID +#define NI_WITHSCOPEID 0 +#endif + void badlogin __P((char *)); void checknologin __P((void)); void dolastlog __P((int)); @@ -187,15 +193,27 @@ main(argc, argv) trimdomain(optarg, UT_HOSTSIZE); if (strlen(optarg) > UT_HOSTSIZE) { - struct hostent *hp = gethostbyname(optarg); - - if (hp != NULL) { - struct in_addr in; - - memmove(&in, hp->h_addr, sizeof(in)); - optarg = strdup(inet_ntoa(in)); + struct addrinfo hints, *res; + int ga_err; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + ga_err = getaddrinfo(optarg, NULL, &hints, + &res); + if (ga_err == 0) { + char hostbuf[MAXHOSTNAMELEN]; + + getnameinfo(res->ai_addr, + res->ai_addrlen, + hostbuf, + sizeof(hostbuf), NULL, 0, + NI_NUMERICHOST| + NI_WITHSCOPEID); + optarg = strdup(hostbuf); } else optarg = "invalid hostname"; + if (res != NULL) + freeaddrinfo(res); } hostname = optarg; break; @@ -408,15 +426,24 @@ main(argc, argv) if (lc != NULL) { if (hostname) { - struct hostent *hp = gethostbyname(full_hostname); - - if (hp == NULL) + struct addrinfo hints, *res; + int ga_err; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + ga_err = getaddrinfo(full_hostname, NULL, &hints, + &res); + if (ga_err == 0) { + char hostbuf[MAXHOSTNAMELEN]; + + getnameinfo(res->ai_addr, res->ai_addrlen, + hostbuf, sizeof(hostbuf), NULL, 0, + NI_NUMERICHOST|NI_WITHSCOPEID); + optarg = strdup(hostbuf); + } else optarg = NULL; - else { - struct in_addr in; - memmove(&in, hp->h_addr, sizeof(in)); - optarg = strdup(inet_ntoa(in)); - } + if (res != NULL) + freeaddrinfo(res); if (!auth_hostok(lc, full_hostname, optarg)) refused("Permission denied", "HOST", 1); } |