From 97526c738c4cd08d52cb022605460e34b2f0b80f Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 15 Nov 2002 22:42:00 +0000 Subject: utmp.ut_time and lastlog.ll_time are explicitly int32_t rather than time_t. Deal with the possibility that time_t != int32_t. This boils down to this sort of thing: - time(&ut.ut_time); + ut.ut_time = time(NULL); and similar for ctime(3) etc. I've kept it minimal for the stuff that may need to be portable (or 3rd party code), but used Matt's time32 stuff for cases where that isn't as much of a concern. Approved by: re (jhb) --- lib/libpam/modules/pam_lastlog/pam_lastlog.c | 10 ++++++---- usr.bin/who/who.c | 8 +++++--- usr.sbin/ppp/physical.c | 2 +- usr.sbin/pppd/auth.c | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/libpam/modules/pam_lastlog/pam_lastlog.c b/lib/libpam/modules/pam_lastlog/pam_lastlog.c index f33d0a6..66f61d3 100644 --- a/lib/libpam/modules/pam_lastlog/pam_lastlog.c +++ b/lib/libpam/modules/pam_lastlog/pam_lastlog.c @@ -71,6 +71,7 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, struct passwd *pwd; struct utmp utmp; struct lastlog ll; + time_t t; const char *rhost, *user, *tty; off_t llpos; int fd, pam_err; @@ -109,13 +110,14 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, goto file_err; if ((flags & PAM_SILENT) == 0) { if (read(fd, &ll, sizeof ll) == sizeof ll && ll.ll_time != 0) { + t = ll.ll_time; if (*ll.ll_host != '\0') pam_info(pamh, "Last login: %.*s from %.*s", - 24 - 5, ctime(&ll.ll_time), + 24 - 5, ctime(&t), (int)sizeof(ll.ll_host), ll.ll_host); else pam_info(pamh, "Last login: %.*s on %.*s", - 24 - 5, ctime(&ll.ll_time), + 24 - 5, ctime(&t), (int)sizeof(ll.ll_line), ll.ll_line); } if (lseek(fd, llpos, L_SET) != llpos) @@ -123,7 +125,7 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, } bzero(&ll, sizeof(ll)); - time(&ll.ll_time); + ll.ll_time = time(NULL); /* note: does not need to be NUL-terminated */ strncpy(ll.ll_line, tty, sizeof(ll.ll_line)); @@ -140,7 +142,7 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, * Record session in utmp(5) and wtmp(5). */ bzero(&utmp, sizeof(utmp)); - time(&utmp.ut_time); + utmp.ut_time = time(NULL); /* note: does not need to be NUL-terminated */ strncpy(utmp.ut_name, user, sizeof(utmp.ut_name)); if (rhost != NULL) diff --git a/usr.bin/who/who.c b/usr.bin/who/who.c index 000cc21..23c7608 100644 --- a/usr.bin/who/who.c +++ b/usr.bin/who/who.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -160,7 +161,7 @@ row(struct utmp *ut) { char buf[80], tty[sizeof(_PATH_DEV) + UT_LINESIZE]; struct stat sb; - time_t idle; + time_t idle, t; static int d_first = -1; struct tm *tm; char state; @@ -184,7 +185,8 @@ row(struct utmp *ut) if (Tflag) printf("%c ", state); printf("%-*.*s ", UT_LINESIZE, UT_LINESIZE, ut->ut_line); - tm = localtime(&ut->ut_time); + t = _time32_to_time(ut->ut_time); + tm = localtime(&t); strftime(buf, sizeof(buf), d_first ? "%e %b %R" : "%b %e %R", tm); printf("%-*s ", 12, buf); if (uflag) { @@ -265,7 +267,7 @@ whoami(FILE *fp) name = "?"; strncpy(ut.ut_name, name, UT_NAMESIZE); strncpy(ut.ut_line, tty, UT_LINESIZE); - time(&ut.ut_time); + ut.ut_time = _time_to_time32(time(NULL)); row(&ut); } diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c index 29ea189..bff1198 100644 --- a/usr.sbin/ppp/physical.c +++ b/usr.sbin/ppp/physical.c @@ -916,7 +916,7 @@ physical_Login(struct physical *p, const char *name) char *colon; memset(&ut, 0, sizeof ut); - time(&ut.ut_time); + ut.ut_time = time(NULL); strncpy(ut.ut_name, name, sizeof ut.ut_name); if (p->handler && (p->handler->type == TCP_DEVICE || p->handler->type == UDP_DEVICE)) { diff --git a/usr.sbin/pppd/auth.c b/usr.sbin/pppd/auth.c index b2d43f8..6d2d737 100644 --- a/usr.sbin/pppd/auth.c +++ b/usr.sbin/pppd/auth.c @@ -995,7 +995,7 @@ plogin(user, passwd, msg, msglen) #endif memset((void *)&utmp, 0, sizeof(utmp)); - (void)time(&utmp.ut_time); + utmp.ut_time = time(NULL); (void)strncpy(utmp.ut_name, user, sizeof(utmp.ut_name)); (void)strncpy(utmp.ut_host, ":PPP", sizeof(utmp.ut_host)); (void)strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line)); -- cgit v1.1