summaryrefslogtreecommitdiff
path: root/loginrec.c
diff options
context:
space:
mode:
Diffstat (limited to 'loginrec.c')
-rw-r--r--loginrec.c67
1 files changed, 55 insertions, 12 deletions
diff --git a/loginrec.c b/loginrec.c
index 02c3106a3..6697ca7b0 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.44 2002/09/26 00:38:49 tim Exp $"); 166RCSID("$Id: loginrec.c,v 1.47 2003/03/10 00:23:07 djm Exp $");
167 167
168#ifdef HAVE_UTIL_H 168#ifdef HAVE_UTIL_H
169# include <util.h> 169# include <util.h>
@@ -609,6 +609,9 @@ void
609construct_utmp(struct logininfo *li, 609construct_utmp(struct logininfo *li,
610 struct utmp *ut) 610 struct utmp *ut)
611{ 611{
612# ifdef HAVE_ADDR_V6_IN_UTMP
613 struct sockaddr_in6 *sa6;
614# endif
612 memset(ut, '\0', sizeof(*ut)); 615 memset(ut, '\0', sizeof(*ut));
613 616
614 /* First fill out fields used for both logins and logouts */ 617 /* First fill out fields used for both logins and logouts */
@@ -661,6 +664,19 @@ construct_utmp(struct logininfo *li,
661 if (li->hostaddr.sa.sa_family == AF_INET) 664 if (li->hostaddr.sa.sa_family == AF_INET)
662 ut->ut_addr = li->hostaddr.sa_in.sin_addr.s_addr; 665 ut->ut_addr = li->hostaddr.sa_in.sin_addr.s_addr;
663# endif 666# endif
667# ifdef HAVE_ADDR_V6_IN_UTMP
668 /* this is just a 128-bit IPv6 address */
669 if (li->hostaddr.sa.sa_family == AF_INET6) {
670 sa6 = ((struct sockaddr_in6 *)&li->hostaddr.sa);
671 memcpy(ut->ut_addr_v6, sa6->sin6_addr.s6_addr, 16);
672 if (IN6_IS_ADDR_V4MAPPED(&sa6->sin6_addr)) {
673 ut->ut_addr_v6[0] = ut->ut_addr_v6[3];
674 ut->ut_addr_v6[1] = 0;
675 ut->ut_addr_v6[2] = 0;
676 ut->ut_addr_v6[3] = 0;
677 }
678 }
679# endif
664} 680}
665#endif /* USE_UTMP || USE_WTMP || USE_LOGIN */ 681#endif /* USE_UTMP || USE_WTMP || USE_LOGIN */
666 682
@@ -689,6 +705,9 @@ set_utmpx_time(struct logininfo *li, struct utmpx *utx)
689void 705void
690construct_utmpx(struct logininfo *li, struct utmpx *utx) 706construct_utmpx(struct logininfo *li, struct utmpx *utx)
691{ 707{
708# ifdef HAVE_ADDR_V6_IN_UTMP
709 struct sockaddr_in6 *sa6;
710# endif
692 memset(utx, '\0', sizeof(*utx)); 711 memset(utx, '\0', sizeof(*utx));
693# ifdef HAVE_ID_IN_UTMPX 712# ifdef HAVE_ID_IN_UTMPX
694 line_abbrevname(utx->ut_id, li->line, sizeof(utx->ut_id)); 713 line_abbrevname(utx->ut_id, li->line, sizeof(utx->ut_id));
@@ -725,6 +744,19 @@ construct_utmpx(struct logininfo *li, struct utmpx *utx)
725 if (li->hostaddr.sa.sa_family == AF_INET) 744 if (li->hostaddr.sa.sa_family == AF_INET)
726 utx->ut_addr = li->hostaddr.sa_in.sin_addr.s_addr; 745 utx->ut_addr = li->hostaddr.sa_in.sin_addr.s_addr;
727# endif 746# endif
747# ifdef HAVE_ADDR_V6_IN_UTMP
748 /* this is just a 128-bit IPv6 address */
749 if (li->hostaddr.sa.sa_family == AF_INET6) {
750 sa6 = ((struct sockaddr_in6 *)&li->hostaddr.sa);
751 memcpy(ut->ut_addr_v6, sa6->sin6_addr.s6_addr, 16);
752 if (IN6_IS_ADDR_V4MAPPED(&sa6->sin6_addr)) {
753 ut->ut_addr_v6[0] = ut->ut_addr_v6[3];
754 ut->ut_addr_v6[1] = 0;
755 ut->ut_addr_v6[2] = 0;
756 ut->ut_addr_v6[3] = 0;
757 }
758 }
759# endif
728# ifdef HAVE_SYSLEN_IN_UTMPX 760# ifdef HAVE_SYSLEN_IN_UTMPX
729 /* ut_syslen is the length of the utx_host string */ 761 /* ut_syslen is the length of the utx_host string */
730 utx->ut_syslen = MIN(strlen(li->hostname), sizeof(utx->ut_host)); 762 utx->ut_syslen = MIN(strlen(li->hostname), sizeof(utx->ut_host));
@@ -1313,6 +1345,7 @@ syslogin_perform_login(struct logininfo *li)
1313 } 1345 }
1314 construct_utmp(li, ut); 1346 construct_utmp(li, ut);
1315 login(ut); 1347 login(ut);
1348 free(ut);
1316 1349
1317 return 1; 1350 return 1;
1318} 1351}
@@ -1490,22 +1523,32 @@ int
1490lastlog_get_entry(struct logininfo *li) 1523lastlog_get_entry(struct logininfo *li)
1491{ 1524{
1492 struct lastlog last; 1525 struct lastlog last;
1493 int fd; 1526 int fd, ret;
1494 1527
1495 if (!lastlog_openseek(li, &fd, O_RDONLY)) 1528 if (!lastlog_openseek(li, &fd, O_RDONLY))
1496 return 0; 1529 return (0);
1497
1498 if (atomicio(read, fd, &last, sizeof(last)) != sizeof(last)) {
1499 close(fd);
1500 log("lastlog_get_entry: Error reading from %s: %s",
1501 LASTLOG_FILE, strerror(errno));
1502 return 0;
1503 }
1504 1530
1531 ret = atomicio(read, fd, &last, sizeof(last));
1505 close(fd); 1532 close(fd);
1506 1533
1507 lastlog_populate_entry(li, &last); 1534 switch (ret) {
1535 case 0:
1536 memset(&last, '\0', sizeof(last));
1537 /* FALLTHRU */
1538 case sizeof(last):
1539 lastlog_populate_entry(li, &last);
1540 return (1);
1541 case -1:
1542 error("%s: Error reading from %s: %s", __func__,
1543 LASTLOG_FILE, strerror(errno));
1544 return (0);
1545 default:
1546 error("%s: Error reading from %s: Expecting %d, got %d",
1547 __func__, LASTLOG_FILE, sizeof(last), ret);
1548 return (0);
1549 }
1508 1550
1509 return 1; 1551 /* NOTREACHED */
1552 return (0);
1510} 1553}
1511#endif /* USE_LASTLOG */ 1554#endif /* USE_LASTLOG */