From 8e19999a00e0aa19ff3b81c775b4a1b5970d3f48 Mon Sep 17 00:00:00 2001 From: dtucker Date: Fri, 9 Apr 2010 08:13:27 +0000 Subject: - (dtucker) [configure.ac defines.h loginrec.c logintest.c] Bug #1732: enable utmpx support on FreeBSD where possible. Patch from Ed Schouten, ok djm@ --- loginrec.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'loginrec.c') 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. -- cgit v1.2.1