bugzilla-daemon at mindrot.org
2002-Jan-30 22:24 UTC
[Bug 87] New: Last logon that gets reported upon login is the current login time
http://bugzilla.mindrot.org/show_bug.cgi?id=87 Summary: Last logon that gets reported upon login is the current login time Product: Portable OpenSSH Version: 3.0.2p1 Platform: UltraSparc OS/Version: Solaris Status: NEW Severity: normal Priority: P2 Component: sshd AssignedTo: openssh-unix-dev at mindrot.org ReportedBy: wknox at mitre.org The last login time that gets reported with a Solaris PAM enabled build of OpenSSH 3.0.2p1 is the login time of the current session. Examining the mail archive, this was reported by Benn Oshrin on 10/12/2001, and he sent in a patch that moved the do_pam_session call into the do_login function in session.c. I can't find any discussion about why that patch did not get applied, but it hasn't, so I propose, instead of moving the do_pam_session call, to move the call to get_last_login_time into do_exec_pty and pass the resultant information to do_login. This has the unfortunate result of getting information that you may never use, but it seems that the portable release does have a few things in it explicit for one system or another, so this may be viable. The definition of do_login could be changed and the call could be made in do_exec_pty only on Solaris using PAM (using a #ifdef PAM_SUN_CODEBASE), but that seemed overly complicated to me. Any comments, anyone? Patch is below. --- session.c~ Sat Dec 1 18:37:08 2001 +++ session.c Tue Jan 29 16:14:25 2002 @@ -128,7 +128,7 @@ void do_exec_pty(Session *, const char *); void do_exec_no_pty(Session *, const char *); void do_exec(Session *, const char *); -void do_login(Session *, const char *); +void do_login(Session *, const char *, const time_t, const char *); #ifdef LOGIN_NEEDS_UTMPX static void do_pre_login(Session *s); #endif @@ -548,11 +548,17 @@ { int fdout, ptyfd, ttyfd, ptymaster; pid_t pid; + char hostname[MAXHOSTNAMELEN]; + time_t last_login_time; if (s == NULL) fatal("do_exec_pty: no session"); ptyfd = s->ptyfd; ttyfd = s->ttyfd; + /* Get the time and hostname when the user last logged in. */ + hostname[0] = '\0'; + last_login_time = get_last_login_time(s->pw->pw_uid, s->pw->pw_name, + hostname, sizeof(hostname)); #if defined(USE_PAM) do_pam_session(s->pw->pw_name, s->tty); @@ -584,7 +590,7 @@ /* record login, etc. similar to login(1) */ #ifndef HAVE_OSF_SIA if (!(options.use_login && command == NULL)) - do_login(s, command); + do_login(s, command, last_login_time, hostname); # ifdef LOGIN_NEEDS_UTMPX else do_pre_login(s); @@ -682,13 +688,11 @@ /* administrative, login(1)-like work */ void -do_login(Session *s, const char *command) +do_login(Session *s, const char *command, const time_t found_last_login_time, const char *last_host) { 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(); @@ -706,13 +710,6 @@ } } - /* 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. */ record_login(pid, s->tty, pw->pw_name, pw->pw_uid, get_remote_name_or_ip(utmp_len, options.reverse_mapping_check), @@ -741,14 +738,14 @@ printf("%s\n", aixloginmsg); #endif /* WITH_AIXAUTHENTICATE */ - if (options.print_lastlog && last_login_time != 0) { - time_string = ctime(&last_login_time); + if (options.print_lastlog && found_last_login_time != 0) { + time_string = ctime(&found_last_login_time); if (strchr(time_string, '\n')) *strchr(time_string, '\n') = 0; - if (strcmp(hostname, "") == 0) + if (strcmp(last_host, "") == 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, last_host); } do_motd(); @@ -1866,7 +1863,7 @@ /* Record that the user has logged out. */ if (s->pid != 0) - record_logout(s->pid, s->tty); + record_logout(s->pid, s->tty, s->pw->pw_name); /* Release the pseudo-tty. */ pty_release(s->tty); ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee.