If hostname > UT_HOSTSIZE, use its numerical address instead to keep

valid utmp and wtmp entries
This commit is contained in:
Andrey A. Chernov 1996-06-17 14:59:07 +00:00
parent 2fcdb74d96
commit 333468bac7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=16433

View File

@ -37,10 +37,13 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <time.h>
#include <netdb.h>
#include <utmp.h>
#include <unistd.h>
#include <stdio.h>
@ -61,6 +64,18 @@ logwtmp(line, name, host)
struct utmp ut;
struct stat buf;
if (strlen(host) > UT_HOSTSIZE) {
struct hostent *hp = gethostbyname(host);
if (hp != NULL) {
struct in_addr in;
memmove(&in, hp->h_addr, sizeof(in));
host = inet_ntoa(in);
} else
host = "invalid hostname";
}
if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
return;
if (fstat(fd, &buf) == 0) {