summaryrefslogtreecommitdiffstats
path: root/usr.bin/login/login.c
diff options
context:
space:
mode:
authorshin <shin@FreeBSD.org>2000-02-19 15:57:52 +0000
committershin <shin@FreeBSD.org>2000-02-19 15:57:52 +0000
commit64995770850f2ea869f74413a0bebc17df9a6db4 (patch)
treef1f4f8b1c1e550bdf70d7e3c2da6f6fbb18fa35b /usr.bin/login/login.c
parent009cea468daf0b0dd19fd1dc00bcf62e4c28ffd5 (diff)
downloadFreeBSD-src-64995770850f2ea869f74413a0bebc17df9a6db4.zip
FreeBSD-src-64995770850f2ea869f74413a0bebc17df9a6db4.tar.gz
Added IPv6 name resolving support for utmp logging.
Approved by: jkh
Diffstat (limited to 'usr.bin/login/login.c')
-rw-r--r--usr.bin/login/login.c57
1 files changed, 42 insertions, 15 deletions
diff --git a/usr.bin/login/login.c b/usr.bin/login/login.c
index 7b7cc97..5d1c7fb 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);
}
OpenPOWER on IntegriCloud