summaryrefslogtreecommitdiff
path: root/login.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-01-02 11:45:33 +1100
committerDamien Miller <djm@mindrot.org>2000-01-02 11:45:33 +1100
commit6b85a7ffa6aefa75be7b19fc08a99d3971e02412 (patch)
treea1e49bce1c5be172c1ecf82dc7b4874470f19e42 /login.c
parent7cfd3e6fb631a59e28e3f6876d663fae4e63002d (diff)
- Added support for directory-based lastlogs
- Really fix typedefs, patch from Ben Taylor <bent@clark.net> - Prevent multiple inclusion of config.h and defines.h. Suggested by Andre Lucas <andre.lucas@dial.pipex.com>
Diffstat (limited to 'login.c')
-rw-r--r--login.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/login.c b/login.c
index 3dd208aa8..7adc4f22c 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.16 1999/12/30 22:42:24 damien Exp $"); 21RCSID("$Id: login.c,v 1.17 2000/01/02 00:45:33 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>
@@ -57,14 +57,24 @@ get_last_login_time(uid_t uid, const char *logname,
57 struct lastlog ll; 57 struct lastlog ll;
58 char *lastlog; 58 char *lastlog;
59 int fd; 59 int fd;
60#ifdef LASTLOG_IS_DIR
61 char buf[1024];
62#endif /* LASTLOG_IS_DIR */
60 63
61 lastlog = _PATH_LASTLOG; 64 lastlog = _PATH_LASTLOG;
62 buf[0] = '\0'; 65 buf[0] = '\0';
63 66
67#ifdef LASTLOG_IS_DIR
64 fd = open(lastlog, O_RDONLY); 68 fd = open(lastlog, O_RDONLY);
65 if (fd < 0) 69 if (fd < 0)
66 return 0; 70 return 0;
67 lseek(fd, (off_t) ((long) uid * sizeof(ll)), SEEK_SET); 71 lseek(fd, (off_t) ((long) uid * sizeof(ll)), SEEK_SET);
72#else /* LASTLOG_IS_DIR */
73 snprintf(buf, sizeof(buf), "%s/%s", lastlog, logname);
74 fd = open(buf, O_RDONLY);
75 if (fd < 0)
76 return 0;
77#endif /* LASTLOG_IS_DIR */
68 if (read(fd, &ll, sizeof(ll)) != sizeof(ll)) { 78 if (read(fd, &ll, sizeof(ll)) != sizeof(ll)) {
69 close(fd); 79 close(fd);
70 return 0; 80 return 0;
@@ -132,6 +142,9 @@ record_login(int pid, const char *ttyname, const char *user, uid_t uid,
132#if defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) 142#if defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG)
133 struct lastlog ll; 143 struct lastlog ll;
134 char *lastlog; 144 char *lastlog;
145#ifdef LASTLOG_IS_DIR
146 char buf[1024];
147#endif /* LASTLOG_IS_DIR */
135#endif /* defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) */ 148#endif /* defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) */
136 struct utmp u; 149 struct utmp u;
137#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) 150#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
@@ -207,9 +220,15 @@ record_login(int pid, const char *ttyname, const char *user, uid_t uid,
207 ll.ll_time = time(NULL); 220 ll.ll_time = time(NULL);
208 strncpy(ll.ll_line, ttyname + 5, sizeof(ll.ll_line)); 221 strncpy(ll.ll_line, ttyname + 5, sizeof(ll.ll_line));
209 strncpy(ll.ll_host, host, sizeof(ll.ll_host)); 222 strncpy(ll.ll_host, host, sizeof(ll.ll_host));
223#ifdef LASTLOG_IS_DIR
224 snprintf(buf, sizeof(buf), "%s/%s", lastlog, logname);
225 fd = open(buf, O_RDWR);
226 if (fd >= 0) {
227#else /* LASTLOG_IS_DIR */
210 fd = open(lastlog, O_RDWR); 228 fd = open(lastlog, O_RDWR);
211 if (fd >= 0) { 229 if (fd >= 0) {
212 lseek(fd, (off_t) ((long) uid * sizeof(ll)), SEEK_SET); 230 lseek(fd, (off_t) ((long) uid * sizeof(ll)), SEEK_SET);
231#endif /* LASTLOG_IS_DIR */
213 if (write(fd, &ll, sizeof(ll)) != sizeof(ll)) 232 if (write(fd, &ll, sizeof(ll)) != sizeof(ll))
214 log("Could not write %.100s: %.100s", lastlog, strerror(errno)); 233 log("Could not write %.100s: %.100s", lastlog, strerror(errno));
215 close(fd); 234 close(fd);