]> andersk Git - openssh.git/blobdiff - session.c
- dtucker@cvs.openbsd.org 2004/07/17 05:31:41
[openssh.git] / session.c
index cf2098931a93e49f863344c821b9ec41145172f4..99b84394ef7946ee88acb932b9ed6fdd45c9e0d8 100644 (file)
--- a/session.c
+++ b/session.c
@@ -33,7 +33,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.177 2004/06/30 08:36:59 djm Exp $");
+RCSID("$OpenBSD: session.c,v 1.179 2004/07/17 05:31:41 dtucker Exp $");
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -196,12 +196,11 @@ auth_input_request_forwarding(struct passwd * pw)
 static void
 display_loginmsg(void)
 {
-       if (buffer_len(&loginmsg) > 0) {
-               buffer_append(&loginmsg, "\0", 1);
-               printf("%s\n", (char *)buffer_ptr(&loginmsg));
-               buffer_clear(&loginmsg);
-       }
-       fflush(stdout);
+        if (buffer_len(&loginmsg) > 0) {
+                buffer_append(&loginmsg, "\0", 1);
+                printf("%s", (char *)buffer_ptr(&loginmsg));
+                buffer_clear(&loginmsg);
+        }
 }
 
 void
@@ -676,14 +675,19 @@ do_exec(Session *s, const char *command)
                do_exec_no_pty(s, command);
 
        original_command = NULL;
-}
 
+       /*
+        * Clear loginmsg: it's the child's responsibility to display
+        * it to the user, otherwise multiple sessions may accumulate
+        * multiple copies of the login messages.
+        */
+       buffer_clear(&loginmsg);
+}
 
 /* administrative, login(1)-like work */
 void
 do_login(Session *s, const char *command)
 {
-       char *time_string;
        socklen_t fromlen;
        struct sockaddr_storage from;
        struct passwd * pw = s->pw;
@@ -728,19 +732,6 @@ do_login(Session *s, const char *command)
 
        display_loginmsg();
 
-#ifndef NO_SSH_LASTLOG
-       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(s->hostname, "") == 0)
-                       printf("Last login: %s\r\n", time_string);
-               else
-                       printf("Last login: %s from %s\r\n", time_string,
-                           s->hostname);
-       }
-#endif /* NO_SSH_LASTLOG */
-
        do_motd();
 }
 
@@ -1001,7 +992,7 @@ do_setup_env(Session *s, const char *shell)
        if (!options.use_login) {
                /* Set basic environment. */
                for (i = 0; i < s->num_env; i++)
-                       child_set_env(&env, &envsize, s->env[i].name, 
+                       child_set_env(&env, &envsize, s->env[i].name,
                            s->env[i].val);
 
                child_set_env(&env, &envsize, "USER", pw->pw_name);
@@ -1318,9 +1309,10 @@ do_setusercontext(struct passwd *pw)
 static void
 do_pwchange(Session *s)
 {
+       fflush(NULL);
        fprintf(stderr, "WARNING: Your password has expired.\n");
        if (s->ttyfd != -1) {
-               fprintf(stderr,
+               fprintf(stderr,
                    "You must change your password now and login again!\n");
                execl(_PATH_PASSWD_PROG, "passwd", (char *)NULL);
                perror("passwd");
@@ -1431,6 +1423,13 @@ do_child(Session *s, const char *command)
 #else /* HAVE_OSF_SIA */
                do_nologin(pw);
                do_setusercontext(pw);
+               /*
+                * PAM session modules in do_setusercontext may have
+                * generated messages, so if this in an interactive
+                * login then display them too.
+                */
+               if (command == NULL)
+                       display_loginmsg();
 #endif /* HAVE_OSF_SIA */
        }
 
@@ -1696,12 +1695,6 @@ 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);
 
This page took 0.055249 seconds and 4 git commands to generate.