summaryrefslogtreecommitdiff
path: root/loginrec.c
diff options
context:
space:
mode:
authordtucker <dtucker>2010-04-09 08:13:27 +0000
committerdtucker <dtucker>2010-04-09 08:13:27 +0000
commit8e19999a00e0aa19ff3b81c775b4a1b5970d3f48 (patch)
treeb1a427f8c405200f3e74f3aea18a5bd43b7b0e4d /loginrec.c
parent4c0be02c618677f27ae405a5f70d8699d6b82502 (diff)
downloadopenssh-8e19999a00e0aa19ff3b81c775b4a1b5970d3f48.tar.gz
- (dtucker) [configure.ac defines.h loginrec.c logintest.c] Bug #1732: enable
utmpx support on FreeBSD where possible. Patch from Ed Schouten, ok djm@
Diffstat (limited to 'loginrec.c')
-rw-r--r--loginrec.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/loginrec.c b/loginrec.c
index bca95970..6f655cb1 100644
--- a/loginrec.c
+++ b/loginrec.c
@@ -207,6 +207,7 @@ int syslogin_write_entry(struct logininfo *li);
int getlast_entry(struct logininfo *li);
int lastlog_get_entry(struct logininfo *li);
+int utmpx_get_entry(struct logininfo *li);
int wtmp_get_entry(struct logininfo *li);
int wtmpx_get_entry(struct logininfo *li);
@@ -508,6 +509,10 @@ getlast_entry(struct logininfo *li)
#ifdef USE_LASTLOG
return(lastlog_get_entry(li));
#else /* !USE_LASTLOG */
+#if defined(USE_UTMPX) && defined(HAVE_SETUTXDB) && \
+ defined(UTXDB_LASTLOGIN) && defined(HAVE_GETUTXUSER)
+ return (utmpx_get_entry(li));
+#endif
#if defined(DISABLE_LASTLOG)
/* On some systems we shouldn't even try to obtain last login
@@ -1608,6 +1613,32 @@ lastlog_get_entry(struct logininfo *li)
#endif /* HAVE_GETLASTLOGXBYNAME */
#endif /* USE_LASTLOG */
+#if defined(USE_UTMPX) && defined(HAVE_SETUTXDB) && \
+ defined(UTXDB_LASTLOGIN) && defined(HAVE_GETUTXUSER)
+int
+utmpx_get_entry(struct logininfo *li)
+{
+ struct utmpx *utx;
+
+ if (setutxdb(UTXDB_LASTLOGIN, NULL) != 0)
+ return (0);
+ utx = getutxuser(li->username);
+ if (utx == NULL) {
+ endutxent();
+ return (0);
+ }
+
+ line_fullname(li->line, utx->ut_line,
+ MIN_SIZEOF(li->line, utx->ut_line));
+ strlcpy(li->hostname, utx->ut_host,
+ MIN_SIZEOF(li->hostname, utx->ut_host));
+ li->tv_sec = utx->ut_tv.tv_sec;
+ li->tv_usec = utx->ut_tv.tv_usec;
+ endutxent();
+ return (1);
+}
+#endif /* USE_UTMPX && HAVE_SETUTXDB && UTXDB_LASTLOGIN && HAVE_GETUTXUSER */
+
#ifdef USE_BTMP
/*
* Logs failed login attempts in _PATH_BTMP if that exists.