From 570a43b84e5c486897474eef3a132adc3dc9c8d3 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 6 Apr 2013 11:24:24 -0400 Subject: [PATCH] Check for setutxent(). Fixes crash on OpenWRT (ar71xx). --- configure.ac | 2 +- src/modules/login.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 8ecc26b..07e84b7 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]) + strerror strsep getgrent setutxent]) AC_CHECK_FUNC([__progname]) # Test for struct passwd members. diff --git a/src/modules/login.c b/src/modules/login.c index 40fa72d..6909650 100644 --- a/src/modules/login.c +++ b/src/modules/login.c @@ -238,7 +238,7 @@ again: continue; /* - * The current user owns this file (process id). + * The current user owns this file (process id). */ if (st.st_uid == uid) { #ifdef __sun__ @@ -278,7 +278,7 @@ again: #endif /* - * Skip duplicate pids. + * Skip duplicate pids. */ for (i = 0; i < pid_index; i++) { if (pids[i] == pid) @@ -439,7 +439,7 @@ static char *lastlogin(const struct passwd *pw, char *tf) 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[0] || !isalnum(last.ll_host[0])) ? !isdigit(last.ll_line[3]) ? "!" : "-" : last.ll_host, !last.ll_time ? "!" : stamp(last.ll_time, tf)); return buf; @@ -452,7 +452,7 @@ static char *lastlogin(const struct passwd *pw, char *tf) static UTMP **get_utmp(const char *user) { UTMP **logins = NULL; -#ifdef HAVE_UTMPX_H +#if defined HAVE_UTMPX_H && defined (HAVE_SETUTXENT) UTMP *u; #else UTMP u; @@ -472,7 +472,7 @@ static UTMP **get_utmp(const char *user) login_count = 0; -#ifdef HAVE_UTMPX_H +#if defined HAVE_UTMPX_H && defined (HAVE_SETUTXENT) setutxent(); while ((u = getutxent()) != NULL) { @@ -501,7 +501,7 @@ static UTMP **get_utmp(const char *user) return NULL; } -#ifdef HAVE_UTMPX_H +#if defined HAVE_UTMPX_H && defined (HAVE_SETUTXENT) #ifdef __NetBSD__ memcpy(logins[login_count]->ut_name, u->ut_name, UTX_NAMESIZE); logins[login_count]->ut_name[UTX_NAMESIZE-1] = 0; -- 2.11.4.GIT