summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2002-01-28 14:50:07 +0000
committerume <ume@FreeBSD.org>2002-01-28 14:50:07 +0000
commitfd850072e807af92d7bbe6e9788ad1512ed52986 (patch)
treeaa7213688f02bef0d0c01d25e97a7a80d151d4af /libexec
parentcffbd574038c24c23c6860649b06bd6be1262445 (diff)
downloadFreeBSD-src-fd850072e807af92d7bbe6e9788ad1512ed52986.zip
FreeBSD-src-fd850072e807af92d7bbe6e9788ad1512ed52986.tar.gz
Log wtmp according to an address family properly.
Reported by: matusita Reviewed by: matusita MFC after: 1 week
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ftpd/extern.h5
-rw-r--r--libexec/ftpd/ftpd.c6
-rw-r--r--libexec/ftpd/logwtmp.c30
3 files changed, 16 insertions, 25 deletions
diff --git a/libexec/ftpd/extern.h b/libexec/ftpd/extern.h
index 9e0562e..3a881db 100644
--- a/libexec/ftpd/extern.h
+++ b/libexec/ftpd/extern.h
@@ -34,13 +34,16 @@
* $FreeBSD$
*/
+#include <sys/types.h>
+#include <sys/socket.h>
+
void blkfree __P((char **));
char **copyblk __P((char **));
void cwd __P((char *));
void delete __P((char *));
void dologout __P((int));
void fatalerror __P((char *));
-void ftpd_logwtmp __P((char *, char *, char *));
+void ftpd_logwtmp __P((char *, char *, struct sockaddr *addr));
int ftpd_pclose __P((FILE *));
FILE *ftpd_popen __P((char *, char *));
char *getline __P((char *, int, FILE *));
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c
index 287436a..90cd030 100644
--- a/libexec/ftpd/ftpd.c
+++ b/libexec/ftpd/ftpd.c
@@ -1057,7 +1057,7 @@ end_login()
(void) seteuid((uid_t)0);
if (logged_in)
- ftpd_logwtmp(ttyline, "", "");
+ ftpd_logwtmp(ttyline, "", NULL);
pw = NULL;
#ifdef LOGIN_CAP
setusercontext(NULL, getpwuid(0), (uid_t)0,
@@ -1339,7 +1339,7 @@ skip:
#endif
/* open wtmp before chroot */
- ftpd_logwtmp(ttyline, pw->pw_name, remotehost);
+ ftpd_logwtmp(ttyline, pw->pw_name, (struct sockaddr *)&his_addr);
logged_in = 1;
if (guest && stats && statfd < 0)
@@ -2377,7 +2377,7 @@ dologout(status)
if (logged_in) {
(void) seteuid((uid_t)0);
- ftpd_logwtmp(ttyline, "", "");
+ ftpd_logwtmp(ttyline, "", NULL);
}
/* beware of flushing buffers after a SIGPIPE */
_exit(status);
diff --git a/libexec/ftpd/logwtmp.c b/libexec/ftpd/logwtmp.c
index 2ac57d1..185d92d 100644
--- a/libexec/ftpd/logwtmp.c
+++ b/libexec/ftpd/logwtmp.c
@@ -52,6 +52,7 @@ static const char rcsid[] =
#include <unistd.h>
#include <stdio.h>
#include <string.h>
+#include <libutil.h>
#include "extern.h"
static int fd = -1;
@@ -62,31 +63,18 @@ static int fd = -1;
* after login, but before logout).
*/
void
-ftpd_logwtmp(line, name, host)
- char *line, *name, *host;
+ftpd_logwtmp(line, name, addr)
+ char *line, *name;
+ struct sockaddr *addr;
{
struct utmp ut;
struct stat buf;
+ char host[UT_HOSTSIZE];
- if (strlen(host) > UT_HOSTSIZE) {
- struct addrinfo hints, *res;
- int error;
- static char hostbuf[BUFSIZ];
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- error = getaddrinfo(host, NULL, &hints, &res);
- if (error)
- host = "invalid hostname";
- else {
- getnameinfo(res->ai_addr, res->ai_addrlen,
- hostbuf, sizeof(hostbuf), NULL, 0,
- NI_NUMERICHOST);
- host = hostbuf;
- if (strlen(host) > UT_HOSTSIZE)
- host[UT_HOSTSIZE] = '\0';
- }
- }
+ if (addr == NULL)
+ host[0] = '\0';
+ else
+ realhostname_sa(host, sizeof(host), addr, addr->sa_len);
if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
return;
OpenPOWER on IntegriCloud