From 7df881d20e85ecbd389311cea999162a945774e1 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Tue, 7 Jan 2003 16:46:58 +1100 Subject: [PATCH] - (djm) Bug #110: bogus error messages in lastlog_get_entry(). Fix based on one by peak@argo.troja.mff.cuni.cz --- ChangeLog | 4 +++- loginrec.c | 34 ++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 28c340032..0ab9043a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ - (djm) Bug #26: Use local mkstemp() rather than glibc's silly one. Fixes Can't pass KRB4 TGT passing. Fix from: jan.iven@cern.ch - (djm) Fix Bug #442 for PAM case + - (djm) Bug #110: bogus error messages in lastlog_get_entry(). Fix based + on one by peak@argo.troja.mff.cuni.cz 20030103 - (djm) Bug #461: ssh-copy-id fails with no arguments. Patch from @@ -934,4 +936,4 @@ save auth method before monitor_reset_key_state(); bugzilla bug #284; ok provos@ -$Id: ChangeLog,v 1.2544 2003/01/07 05:15:20 djm Exp $ +$Id: ChangeLog,v 1.2545 2003/01/07 05:46:58 djm Exp $ diff --git a/loginrec.c b/loginrec.c index a0d14dbdf..0a5fefad3 100644 --- a/loginrec.c +++ b/loginrec.c @@ -163,7 +163,7 @@ #include "log.h" #include "atomicio.h" -RCSID("$Id: loginrec.c,v 1.45 2003/01/03 03:42:28 djm Exp $"); +RCSID("$Id: loginrec.c,v 1.46 2003/01/07 05:46:58 djm Exp $"); #ifdef HAVE_UTIL_H # include @@ -1522,22 +1522,32 @@ int lastlog_get_entry(struct logininfo *li) { struct lastlog last; - int fd; + int fd, ret; if (!lastlog_openseek(li, &fd, O_RDONLY)) - return 0; - - if (atomicio(read, fd, &last, sizeof(last)) != sizeof(last)) { - close(fd); - log("lastlog_get_entry: Error reading from %s: %s", - LASTLOG_FILE, strerror(errno)); - return 0; - } + return (0); + ret = atomicio(read, fd, &last, sizeof(last)); close(fd); - lastlog_populate_entry(li, &last); + switch (ret) { + case 0: + memset(&last, '\0', sizeof(last)); + /* FALLTHRU */ + case sizeof(last): + lastlog_populate_entry(li, &last); + return (1); + case -1: + error("%s: Error reading from %s: %s", __func__, + LASTLOG_FILE, strerror(errno)); + return (0); + default: + error("%s: Error reading from %s: Expecting %d, got %d", + __func__, LASTLOG_FILE, sizeof(last), ret); + return (0); + } - return 1; + /* NOTREACHED */ + return (0); } #endif /* USE_LASTLOG */