From 76112de73437ac3db04b45d4b7a9d1f1b74f83fd Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Tue, 21 Dec 1999 11:18:08 +1100 Subject: - Integration of large HPUX patch from Andre Lucas . Integrating it had a few other benefits: - Ability to disable shadow passwords at configure time - Ability to disable lastlog support at configure time - Support for IP address in $DISPLAY --- login.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'login.c') diff --git a/login.c b/login.c index e506d24e..552117ca 100644 --- a/login.c +++ b/login.c @@ -18,7 +18,7 @@ */ #include "includes.h" -RCSID("$Id: login.c,v 1.7 1999/12/20 22:51:36 damien Exp $"); +RCSID("$Id: login.c,v 1.8 1999/12/21 00:18:08 damien Exp $"); #if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) # include @@ -53,6 +53,7 @@ unsigned long get_last_login_time(uid_t uid, const char *logname, char *buf, unsigned int bufsize) { +#if defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) struct lastlog ll; char *lastlog; int fd; @@ -74,6 +75,45 @@ get_last_login_time(uid_t uid, const char *logname, strncpy(buf, ll.ll_host, bufsize - 1); buf[bufsize - 1] = 0; return ll.ll_time; + +#else /* defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) */ + /* Look in wtmp for the last login */ + struct utmp wt; + char *wt_file = _PATH_WTMP; + int fd1; + unsigned long t = 0; + + if ( (fd1 = open(wt_file, O_RDONLY)) < 0 ) { + error("Couldn't open %.100s to find last login time.", wt_file); + return 0; + } + + /* seek to last record of file */ + lseek(fd1, (off_t)(0-sizeof(struct utmp)), SEEK_END); + + /* loop through wtmp for our last user login record */ + do { + if (read(fd1, &wt, sizeof(wt)) != sizeof(wt)) { + close(fd1); + return 0; + } + + if ( wt.ut_type == USER_PROCESS) { + if ( !strncmp(logname, wt.ut_user, 8) ) { + t = (unsigned long) wt.ut_time; + if (bufsize > sizeof(wt.ut_host) + 1) + bufsize = sizeof(wt.ut_host) + 1; + strncpy(buf, wt.ut_host, bufsize - 1); + buf[bufsize - 1] = 0; + } + } + + if (lseek(fd1, (off_t)(0-2*sizeof(struct utmp)), SEEK_CUR) == -1) + break; + } while (t == 0); + + return t; +#endif /* defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) */ } /* @@ -85,9 +125,10 @@ void record_login(int pid, const char *ttyname, const char *user, uid_t uid, const char *host, struct sockaddr_in * addr) { - int fd; +#if defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) struct lastlog ll; char *lastlog; +#endif /* defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) */ struct UTMP_STR u; const char *utmp, *wtmp; @@ -110,10 +151,13 @@ record_login(int pid, const char *ttyname, const char *user, uid_t uid, wtmp = _PATH_WTMP; login(&u); + +#ifdef defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) lastlog = _PATH_LASTLOG; /* Update lastlog unless actually recording a logout. */ if (strcmp(user, "") != 0) { + int fd; /* * It is safer to bzero the lastlog structure first because * some systems might have some extra fields in it (e.g. SGI) @@ -132,6 +176,7 @@ record_login(int pid, const char *ttyname, const char *user, uid_t uid, close(fd); } } +#endif /* defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) */ } /* Records that the user has logged out. */ -- cgit v1.2.3