summaryrefslogtreecommitdiff
path: root/login.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-12-21 11:18:08 +1100
committerDamien Miller <djm@mindrot.org>1999-12-21 11:18:08 +1100
commit76112de73437ac3db04b45d4b7a9d1f1b74f83fd (patch)
treecbfb21a6bd6acc7c3a478b5c186ee49e0b0f9fbb /login.c
parent368cf64d5c7cee6eb85d9240ea04ccf43273b5fc (diff)
- Integration of large HPUX patch from Andre Lucas
<andre.lucas@dial.pipex.com>. 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
Diffstat (limited to 'login.c')
-rw-r--r--login.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/login.c b/login.c
index e506d24ee..552117ca4 100644
--- a/login.c
+++ b/login.c
@@ -18,7 +18,7 @@
18 */ 18 */
19 19
20#include "includes.h" 20#include "includes.h"
21RCSID("$Id: login.c,v 1.7 1999/12/20 22:51:36 damien Exp $"); 21RCSID("$Id: login.c,v 1.8 1999/12/21 00:18:08 damien Exp $");
22 22
23#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) 23#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
24# include <utmpx.h> 24# include <utmpx.h>
@@ -53,6 +53,7 @@ unsigned long
53get_last_login_time(uid_t uid, const char *logname, 53get_last_login_time(uid_t uid, const char *logname,
54 char *buf, unsigned int bufsize) 54 char *buf, unsigned int bufsize)
55{ 55{
56#if defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG)
56 struct lastlog ll; 57 struct lastlog ll;
57 char *lastlog; 58 char *lastlog;
58 int fd; 59 int fd;
@@ -74,6 +75,45 @@ get_last_login_time(uid_t uid, const char *logname,
74 strncpy(buf, ll.ll_host, bufsize - 1); 75 strncpy(buf, ll.ll_host, bufsize - 1);
75 buf[bufsize - 1] = 0; 76 buf[bufsize - 1] = 0;
76 return ll.ll_time; 77 return ll.ll_time;
78
79#else /* defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) */
80 /* Look in wtmp for the last login */
81 struct utmp wt;
82 char *wt_file = _PATH_WTMP;
83 int fd1;
84 unsigned long t = 0;
85
86 if ( (fd1 = open(wt_file, O_RDONLY)) < 0 ) {
87 error("Couldn't open %.100s to find last login time.", wt_file);
88 return 0;
89 }
90
91 /* seek to last record of file */
92 lseek(fd1, (off_t)(0-sizeof(struct utmp)), SEEK_END);
93
94 /* loop through wtmp for our last user login record */
95 do {
96 if (read(fd1, &wt, sizeof(wt)) != sizeof(wt)) {
97 close(fd1);
98 return 0;
99 }
100
101 if ( wt.ut_type == USER_PROCESS) {
102 if ( !strncmp(logname, wt.ut_user, 8) ) {
103 t = (unsigned long) wt.ut_time;
104 if (bufsize > sizeof(wt.ut_host) + 1)
105 bufsize = sizeof(wt.ut_host) + 1;
106 strncpy(buf, wt.ut_host, bufsize - 1);
107 buf[bufsize - 1] = 0;
108 }
109 }
110
111 if (lseek(fd1, (off_t)(0-2*sizeof(struct utmp)), SEEK_CUR) == -1)
112 break;
113 } while (t == 0);
114
115 return t;
116#endif /* defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) */
77} 117}
78 118
79/* 119/*
@@ -85,9 +125,10 @@ void
85record_login(int pid, const char *ttyname, const char *user, uid_t uid, 125record_login(int pid, const char *ttyname, const char *user, uid_t uid,
86 const char *host, struct sockaddr_in * addr) 126 const char *host, struct sockaddr_in * addr)
87{ 127{
88 int fd; 128#if defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG)
89 struct lastlog ll; 129 struct lastlog ll;
90 char *lastlog; 130 char *lastlog;
131#endif /* defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) */
91 struct UTMP_STR u; 132 struct UTMP_STR u;
92 const char *utmp, *wtmp; 133 const char *utmp, *wtmp;
93 134
@@ -110,10 +151,13 @@ record_login(int pid, const char *ttyname, const char *user, uid_t uid,
110 wtmp = _PATH_WTMP; 151 wtmp = _PATH_WTMP;
111 152
112 login(&u); 153 login(&u);
154
155#ifdef defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG)
113 lastlog = _PATH_LASTLOG; 156 lastlog = _PATH_LASTLOG;
114 157
115 /* Update lastlog unless actually recording a logout. */ 158 /* Update lastlog unless actually recording a logout. */
116 if (strcmp(user, "") != 0) { 159 if (strcmp(user, "") != 0) {
160 int fd;
117 /* 161 /*
118 * It is safer to bzero the lastlog structure first because 162 * It is safer to bzero the lastlog structure first because
119 * some systems might have some extra fields in it (e.g. SGI) 163 * 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,
132 close(fd); 176 close(fd);
133 } 177 }
134 } 178 }
179#endif /* defined(HAVE_LASTLOG_H) && !defined(DISABLE_LASTLOG) */
135} 180}
136 181
137/* Records that the user has logged out. */ 182/* Records that the user has logged out. */