From 8fa8821470f2387252058c32f03ef85ef05d26b6 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 6 Apr 2013 13:38:59 -0400 Subject: [PATCH] Check for getlastlogx(). Recent NetBSD releases have this. --- configure.ac | 2 +- src/modules/login.c | 17 +++++++++++++++++ src/modules/login.h | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 07e84b7..9c99110 100644 --- a/configure.ac +++ b/configure.ac @@ -43,7 +43,7 @@ AC_FUNC_STAT AC_FUNC_STRFTIME AC_FUNC_MMAP AC_CHECK_FUNCS([memset getspnam munmap setpassent setgroupent strchr strdup \ - strerror strsep getgrent setutxent]) + strerror strsep getgrent setutxent getlastlogx]) AC_CHECK_FUNC([__progname]) # Test for struct passwd members. diff --git a/src/modules/login.c b/src/modules/login.c index 4a80394..3d744a6 100644 --- a/src/modules/login.c +++ b/src/modules/login.c @@ -381,6 +381,22 @@ static void last_strings(char *str) } /* Get the lastlog structure from the lastlog file. */ +#ifdef HAVE_GETLASTLOGX +static char *lastlogin(const struct passwd *pw, char *tf) +{ + struct lastlogx *last = getlastlogx(_PATH_LASTLOGX, pw->pw_uid, NULL); + static char buf[LINE_MAX]; + + if (!last) + return NULL; + + snprintf(buf, sizeof(buf), "%s,%s,%s", + !last->ll_line[0] ? "!" : last->ll_line, + (!last->ll_host[0] || !isalnum(last->ll_host[0])) ? "-" : last->ll_host, + stamp(last->ll_tv.tv_sec, tf)); + return buf; +} +#else #if __FreeBSD_version >= 900000 static char *lastlogin(const struct passwd *pw, char *tf) { @@ -458,6 +474,7 @@ static char *lastlogin(const struct passwd *pw, char *tf) return buf; } #endif +#endif /* This will return an array of utmp structures if a user is logged in, NULL * otherwise. We'll try to keep the utmp file descriptor open if possible to diff --git a/src/modules/login.h b/src/modules/login.h index dbab0a0..62fd20b 100644 --- a/src/modules/login.h +++ b/src/modules/login.h @@ -56,6 +56,11 @@ #define UT_HOSTSIZE 256 #define UT_LINESIZE 32 #define UT_NAMESIZE 32 +#ifndef UTX_NAMESIZE +#ifdef UTX_USERSIZE +#define UTX_NAMESIZE UTX_USERSIZE +#endif +#endif #endif typedef struct utmpx UTMP; #else -- 2.11.4.GIT