summaryrefslogtreecommitdiff
path: root/loginrec.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2003-01-07 16:46:58 +1100
committerDamien Miller <djm@mindrot.org>2003-01-07 16:46:58 +1100
commit7df881d20e85ecbd389311cea999162a945774e1 (patch)
tree3e6547e9d35c679f1a2d2687ad0f2f9a75edfcf9 /loginrec.c
parent64004b5566282ceb395674e0c4aaa89e04b3847d (diff)
- (djm) Bug #110: bogus error messages in lastlog_get_entry(). Fix based
on one by peak@argo.troja.mff.cuni.cz
Diffstat (limited to 'loginrec.c')
-rw-r--r--loginrec.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/loginrec.c b/loginrec.c
index a0d14dbdf..0a5fefad3 100644
--- a/loginrec.c
+++ b/loginrec.c
@@ -163,7 +163,7 @@
163#include "log.h" 163#include "log.h"
164#include "atomicio.h" 164#include "atomicio.h"
165 165
166RCSID("$Id: loginrec.c,v 1.45 2003/01/03 03:42:28 djm Exp $"); 166RCSID("$Id: loginrec.c,v 1.46 2003/01/07 05:46:58 djm Exp $");
167 167
168#ifdef HAVE_UTIL_H 168#ifdef HAVE_UTIL_H
169# include <util.h> 169# include <util.h>
@@ -1522,22 +1522,32 @@ int
1522lastlog_get_entry(struct logininfo *li) 1522lastlog_get_entry(struct logininfo *li)
1523{ 1523{
1524 struct lastlog last; 1524 struct lastlog last;
1525 int fd; 1525 int fd, ret;
1526 1526
1527 if (!lastlog_openseek(li, &fd, O_RDONLY)) 1527 if (!lastlog_openseek(li, &fd, O_RDONLY))
1528 return 0; 1528 return (0);
1529
1530 if (atomicio(read, fd, &last, sizeof(last)) != sizeof(last)) {
1531 close(fd);
1532 log("lastlog_get_entry: Error reading from %s: %s",
1533 LASTLOG_FILE, strerror(errno));
1534 return 0;
1535 }
1536 1529
1530 ret = atomicio(read, fd, &last, sizeof(last));
1537 close(fd); 1531 close(fd);
1538 1532
1539 lastlog_populate_entry(li, &last); 1533 switch (ret) {
1534 case 0:
1535 memset(&last, '\0', sizeof(last));
1536 /* FALLTHRU */
1537 case sizeof(last):
1538 lastlog_populate_entry(li, &last);
1539 return (1);
1540 case -1:
1541 error("%s: Error reading from %s: %s", __func__,
1542 LASTLOG_FILE, strerror(errno));
1543 return (0);
1544 default:
1545 error("%s: Error reading from %s: Expecting %d, got %d",
1546 __func__, LASTLOG_FILE, sizeof(last), ret);
1547 return (0);
1548 }
1540 1549
1541 return 1; 1550 /* NOTREACHED */
1551 return (0);
1542} 1552}
1543#endif /* USE_LASTLOG */ 1553#endif /* USE_LASTLOG */