summaryrefslogtreecommitdiff
path: root/sshlogin.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2004-07-17 17:05:14 +1000
committerDarren Tucker <dtucker@zip.com.au>2004-07-17 17:05:14 +1000
commit0999174755bbc5b50d65bfa95e0b322ffd12337c (patch)
treea0153a329222f784d98f8554ecd8d1d98bce23bd /sshlogin.c
parent3ca45082017f0fcaf01b0bf781ae33cf1cc57e27 (diff)
- dtucker@cvs.openbsd.org 2004/07/17 05:31:41
[monitor.c monitor_wrap.c session.c session.h sshd.c sshlogin.c] Move "Last logged in at.." message generation to the monitor, right before recording the new login. Fixes missing lastlog message when /var/log/lastlog is not world-readable and incorrect datestamp when multiple sessions are used (bz #463); much assistance & ok markus@
Diffstat (limited to 'sshlogin.c')
-rw-r--r--sshlogin.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/sshlogin.c b/sshlogin.c
index 75446f9eb..41817ec96 100644
--- a/sshlogin.c
+++ b/sshlogin.c
@@ -39,9 +39,15 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: sshlogin.c,v 1.9 2004/07/03 05:11:33 dtucker Exp $"); 42RCSID("$OpenBSD: sshlogin.c,v 1.10 2004/07/17 05:31:41 dtucker Exp $");
43 43
44#include "loginrec.h" 44#include "loginrec.h"
45#include "log.h"
46#include "buffer.h"
47#include "servconf.h"
48
49extern Buffer loginmsg;
50extern ServerOptions options;
45 51
46/* 52/*
47 * Returns the time when the user last logged in. Returns 0 if the 53 * Returns the time when the user last logged in. Returns 0 if the
@@ -60,6 +66,38 @@ get_last_login_time(uid_t uid, const char *logname,
60} 66}
61 67
62/* 68/*
69 * Generate and store last login message. This must be done before
70 * login_login() is called and lastlog is updated.
71 */
72void
73store_lastlog_message(const char *user, uid_t uid)
74{
75 char *time_string, hostname[MAXHOSTNAMELEN] = "", buf[512];
76 time_t last_login_time;
77
78#ifndef NO_SSH_LASTLOG
79 if (!options.print_lastlog)
80 return;
81
82 last_login_time = get_last_login_time(uid, user, hostname,
83 sizeof(hostname));
84
85 if (last_login_time != 0) {
86 time_string = ctime(&last_login_time);
87 if (strchr(time_string, '\n'))
88 *strchr(time_string, '\n') = '\0';
89 if (strcmp(hostname, "") == 0)
90 snprintf(buf, sizeof(buf), "Last login: %s\r\n",
91 time_string);
92 else
93 snprintf(buf, sizeof(buf), "Last login: %s from %s\r\n",
94 time_string, hostname);
95 buffer_append(&loginmsg, buf, strlen(buf));
96 }
97#endif /* NO_SSH_LASTLOG */
98}
99
100/*
63 * Records that the user has logged in. I wish these parts of operating 101 * Records that the user has logged in. I wish these parts of operating
64 * systems were more standardized. 102 * systems were more standardized.
65 */ 103 */
@@ -69,6 +107,9 @@ record_login(pid_t pid, const char *tty, const char *user, uid_t uid,
69{ 107{
70 struct logininfo *li; 108 struct logininfo *li;
71 109
110 /* save previous login details before writing new */
111 store_lastlog_message(user, uid);
112
72 li = login_alloc_entry(pid, user, host, tty); 113 li = login_alloc_entry(pid, user, host, tty);
73 login_set_addr(li, addr, addrlen); 114 login_set_addr(li, addr, addrlen);
74 login_login(li); 115 login_login(li);