-- | ``We've all heard that a million monkeys banging on | Damien Miller - | a million typewriters will eventually reproduce the | <djm at mindrot.org> | works of Shakespeare. Now, thanks to the Internet, / | we know this is not true.'' - Robert Wilensky UCB / http://www.mindrot.org ---------- Forwarded message ---------- Date: Tue, 14 Nov 2000 16:33:18 +0100 From: System Administrator <sysadmin at chrysler.kbs.twi.tudelft.nl> To: openssh at openssh.com Subject: 2.3.0p1, Solaris 7 and last login Hi, I'm having a problem with sshd showing the wrong last login entry, that is, it shows the current login. I didn't notice it until recently, but it seems that it has been there since version 2.2.0p1. Some (more or less) useful stats here. I'm reporting the bug against: Version: portable OpenSSH 2.3.0p1 OS: Solaris 7 for Sparc w/ many recent recommended/security patches. Additional kernel module for /dev/[u]random support (from Andreas Maier, version 0.4) Configure command: ./configure --with-ipv4-default \ --with-ssl-dir=/usr/local/openssl-0.9.6 --with-random=/dev/urandom \ --prefix=/usr/local/openssh --sysconfdir=/etc/openssh \ --localstatedir=/var/run OpenSSL version: 0.9.6 Compiler: gcc 2.95.2 I've been looking around in the mailing list archive, and it seems that a problem with similar symptoms was fixed in 2.3.0p1, but unfortunately, this does not fix the problem for me. The fix in question was the removal of an erroneous call to write_login() which happened before getting the last login details. However, I found out that the call to do_pam_session(), which happens before the get_last_login_time() call, also writes a last login entry in my case. I made a workaround for the problem, but I'm sure it is not the way to do it. One good reason is that my patch does not take the result of do_login() into account and always prints the last login message. My patch is included in an attachment. Hope that I've been any help, Boi Ps. did I mention that in general, OpenSSH rocks? :) -- UNIX System Administrator - Boi Sletterink Phone: +31-15-278 2504 -------------- next part -------------- *** session.c.orig Sat Oct 28 05:19:58 2000 --- session.c Tue Nov 14 16:04:21 2000 *************** *** 590,600 **** --- 590,616 ---- int fdout, ptyfd, ttyfd, ptymaster; pid_t pid; + #define BOIS_DIRTY_PATCH + #ifdef BOIS_DIRTY_PATCH + char hostname[MAXHOSTNAMELEN]; + time_t last_login_time; + struct passwd * pw = s->pw; + char *time_string; + #endif + if (s == NULL) fatal("do_exec_pty: no session"); ptyfd = s->ptyfd; ttyfd = s->ttyfd; + #ifdef BOIS_DIRTY_PATCH + /* Get the time and hostname when the user last logged in. */ + hostname[0] = '\0'; + last_login_time = get_last_login_time(pw->pw_uid, pw->pw_name, + hostname, sizeof(hostname)); + #endif + + #ifdef USE_PAM do_pam_session(pw->pw_name, s->tty); do_pam_setcred(); *************** *** 628,634 **** --- 644,667 ---- /* record login, etc. similar to login(1) */ if (!(options.use_login && command == NULL)) + { + #ifdef BOIS_DIRTY_PATCH + if (last_login_time != 0) { + time_string = ctime(&last_login_time); + if (strchr(time_string, '\n')) + *strchr(time_string, '\n') = 0; + if (strcmp(hostname, "") == 0) + printf("Last login: %s\r\n", time_string); + else + printf("Last login: %s from %s\r\n", time_string, hostname); + } + else + { + printf("Never logged in before.\n"); + } + #endif do_login(s, command); + } /* Do common processing for the child, such as execing the command. */ do_child(command, pw, s->term, s->display, s->auth_proto, *************** *** 711,720 **** --- 744,755 ---- } } + #ifndef BOIS_DIRTY_PATCH /* Get the time and hostname when the user last logged in. */ hostname[0] = '\0'; last_login_time = get_last_login_time(pw->pw_uid, pw->pw_name, hostname, sizeof(hostname)); + #endif /* Record that there was a login on that tty from the remote host. */ record_login(pid, s->tty, pw->pw_name, pw->pw_uid, *************** *** 751,756 **** --- 786,792 ---- printf("%s\n", aixloginmsg); #endif /* WITH_AIXAUTHENTICATE */ + #ifndef BOIS_DIRTY_PATCH if (last_login_time != 0) { time_string = ctime(&last_login_time); if (strchr(time_string, '\n')) *************** *** 760,765 **** --- 796,803 ---- else printf("Last login: %s from %s\r\n", time_string, hostname); } + #endif + if (options.print_motd) { #ifdef HAVE_LOGIN_CAP f = fopen(login_getcapstr(lc, "welcome", "/etc/motd",