summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/sshlogin.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/sshlogin.c')
-rw-r--r--crypto/openssh/sshlogin.c88
1 files changed, 28 insertions, 60 deletions
diff --git a/crypto/openssh/sshlogin.c b/crypto/openssh/sshlogin.c
index c6e2ad4..78c51ab 100644
--- a/crypto/openssh/sshlogin.c
+++ b/crypto/openssh/sshlogin.c
@@ -41,10 +41,7 @@
#include "includes.h"
RCSID("$OpenBSD: sshlogin.c,v 1.3 2001/12/19 07:18:56 deraadt Exp $");
-#include <util.h>
-#include <utmp.h>
-#include "sshlogin.h"
-#include "log.h"
+#include "loginrec.h"
/*
* Returns the time when the user last logged in. Returns 0 if the
@@ -56,27 +53,11 @@ u_long
get_last_login_time(uid_t uid, const char *logname,
char *buf, u_int bufsize)
{
- struct lastlog ll;
- char *lastlog;
- int fd;
+ struct logininfo li;
- lastlog = _PATH_LASTLOG;
- buf[0] = '\0';
-
- fd = open(lastlog, O_RDONLY);
- if (fd < 0)
- return 0;
- lseek(fd, (off_t) ((long) uid * sizeof(ll)), SEEK_SET);
- if (read(fd, &ll, sizeof(ll)) != sizeof(ll)) {
- close(fd);
- return 0;
- }
- close(fd);
- if (bufsize > sizeof(ll.ll_host) + 1)
- bufsize = sizeof(ll.ll_host) + 1;
- strncpy(buf, ll.ll_host, bufsize - 1);
- buf[bufsize - 1] = 0;
- return ll.ll_time;
+ login_get_lastlog(&li, uid);
+ strlcpy(buf, li.hostname, bufsize);
+ return li.tv_sec;
}
/*
@@ -88,49 +69,36 @@ void
record_login(pid_t pid, const char *ttyname, const char *user, uid_t uid,
const char *host, struct sockaddr * addr)
{
- int fd;
- struct lastlog ll;
- char *lastlog;
- struct utmp u;
-
- /* Construct an utmp/wtmp entry. */
- memset(&u, 0, sizeof(u));
- strncpy(u.ut_line, ttyname + 5, sizeof(u.ut_line));
- u.ut_time = time(NULL);
- strncpy(u.ut_name, user, sizeof(u.ut_name));
- strncpy(u.ut_host, host, sizeof(u.ut_host));
+ struct logininfo *li;
- login(&u);
- lastlog = _PATH_LASTLOG;
+ li = login_alloc_entry(pid, user, host, ttyname);
+ login_set_addr(li, addr, sizeof(struct sockaddr));
+ login_login(li);
+ login_free_entry(li);
+}
- /* Update lastlog unless actually recording a logout. */
- if (strcmp(user, "") != 0) {
- /*
- * It is safer to bzero the lastlog structure first because
- * some systems might have some extra fields in it (e.g. SGI)
- */
- memset(&ll, 0, sizeof(ll));
+#ifdef LOGIN_NEEDS_UTMPX
+void
+record_utmp_only(pid_t pid, const char *ttyname, const char *user,
+ const char *host, struct sockaddr * addr)
+{
+ struct logininfo *li;
- /* Update lastlog. */
- ll.ll_time = time(NULL);
- strncpy(ll.ll_line, ttyname + 5, sizeof(ll.ll_line));
- strncpy(ll.ll_host, host, sizeof(ll.ll_host));
- fd = open(lastlog, O_RDWR);
- if (fd >= 0) {
- lseek(fd, (off_t) ((long) uid * sizeof(ll)), SEEK_SET);
- if (write(fd, &ll, sizeof(ll)) != sizeof(ll))
- log("Could not write %.100s: %.100s", lastlog, strerror(errno));
- close(fd);
- }
- }
+ li = login_alloc_entry(pid, user, host, ttyname);
+ login_set_addr(li, addr, sizeof(struct sockaddr));
+ login_utmp_only(li);
+ login_free_entry(li);
}
+#endif
/* Records that the user has logged out. */
void
-record_logout(pid_t pid, const char *ttyname)
+record_logout(pid_t pid, const char *ttyname, const char *user)
{
- const char *line = ttyname + 5; /* /dev/ttyq8 -> ttyq8 */
- if (logout(line))
- logwtmp(line, "", "");
+ struct logininfo *li;
+
+ li = login_alloc_entry(pid, user, NULL, ttyname);
+ login_logout(li);
+ login_free_entry(li);
}
OpenPOWER on IntegriCloud