summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Friedl <markus@cvs.openbsd.org>2002-03-29 18:59:33 +0000
committerMarkus Friedl <markus@cvs.openbsd.org>2002-03-29 18:59:33 +0000
commita81e7457370e7d3a6592d62d908d42f4178a13fb (patch)
treeba01d3c1ef2ae8d8ea47429a1bac8f29cc7e45dd
parent76c631cf6595321a876682958bd2559e4dcab871 (diff)
retrieve last login time before the pty is allocated, store per session
-rw-r--r--usr.bin/ssh/session.c26
-rw-r--r--usr.bin/ssh/session.h5
2 files changed, 16 insertions, 15 deletions
diff --git a/usr.bin/ssh/session.c b/usr.bin/ssh/session.c
index b4d4fa026d0..b8536561176 100644
--- a/usr.bin/ssh/session.c
+++ b/usr.bin/ssh/session.c
@@ -33,7 +33,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.133 2002/03/28 15:34:51 markus Exp $");
+RCSID("$OpenBSD: session.c,v 1.134 2002/03/29 18:59:31 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -543,10 +543,8 @@ void
do_login(Session *s, const char *command)
{
char *time_string;
- char hostname[MAXHOSTNAMELEN];
socklen_t fromlen;
struct sockaddr_storage from;
- time_t last_login_time;
struct passwd * pw = s->pw;
pid_t pid = getpid();
@@ -564,13 +562,6 @@ do_login(Session *s, const char *command)
}
}
- /* Get the time and hostname when the user last logged in. */
- if (options.print_lastlog) {
- hostname[0] = '\0';
- last_login_time = get_last_login_time(pw->pw_uid, pw->pw_name,
- hostname, sizeof(hostname));
- }
-
/* Record that there was a login on that tty from the remote host. */
if (!use_privsep)
record_login(pid, s->tty, pw->pw_name, pw->pw_uid,
@@ -581,14 +572,15 @@ do_login(Session *s, const char *command)
if (check_quietlogin(s, command))
return;
- if (options.print_lastlog && last_login_time != 0) {
- time_string = ctime(&last_login_time);
+ if (options.print_lastlog && s->last_login_time != 0) {
+ time_string = ctime(&s->last_login_time);
if (strchr(time_string, '\n'))
*strchr(time_string, '\n') = 0;
- if (strcmp(hostname, "") == 0)
+ if (strcmp(s->hostname, "") == 0)
printf("Last login: %s\r\n", time_string);
else
- printf("Last login: %s from %s\r\n", time_string, hostname);
+ printf("Last login: %s from %s\r\n", time_string,
+ s->hostname);
}
do_motd();
@@ -1255,6 +1247,12 @@ session_pty_req(Session *s)
packet_disconnect("Protocol error: you already have a pty.");
return 0;
}
+ /* Get the time and hostname when the user last logged in. */
+ if (options.print_lastlog) {
+ s->hostname[0] = '\0';
+ s->last_login_time = get_last_login_time(s->pw->pw_uid,
+ s->pw->pw_name, s->hostname, sizeof(s->hostname));
+ }
s->term = packet_get_string(&len);
diff --git a/usr.bin/ssh/session.h b/usr.bin/ssh/session.h
index fad3abe1ca2..2a7e4b224fd 100644
--- a/usr.bin/ssh/session.h
+++ b/usr.bin/ssh/session.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.h,v 1.16 2002/03/19 10:35:39 markus Exp $ */
+/* $OpenBSD: session.h,v 1.17 2002/03/29 18:59:32 markus Exp $ */
/*
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
@@ -39,6 +39,9 @@ struct Session {
int ptyfd, ttyfd, ptymaster;
int row, col, xpixel, ypixel;
char tty[TTYSZ];
+ /* last login */
+ char hostname[MAXHOSTNAMELEN];
+ time_t last_login_time;
/* X11 */
int display_number;
char *display;