]> andersk Git - gssapi-openssh.git/blobdiff - openssh/session.c
Merge from OPENSSH_3_8_1P1_GSSAPI_20040713 to OPENSSH_3_9P1_GSSAPI_20040818.
[gssapi-openssh.git] / openssh / session.c
index f8c6e944f128867a90a3227648f6bf3c5b5cdee7..5d6e104035d7eb4d6b943e144d7fefbadc13c440 100644 (file)
@@ -33,7 +33,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.172 2004/01/30 09:48:57 markus Exp $");
+RCSID("$OpenBSD: session.c,v 1.180 2004/07/28 09:40:29 markus Exp $");
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -42,7 +42,7 @@ RCSID("$OpenBSD: session.c,v 1.172 2004/01/30 09:48:57 markus Exp $");
 #include "sshpty.h"
 #include "packet.h"
 #include "buffer.h"
-#include "mpaux.h"
+#include "match.h"
 #include "uidswap.h"
 #include "compat.h"
 #include "channels.h"
@@ -201,12 +201,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
@@ -285,7 +284,7 @@ do_authenticated1(Authctxt *authctxt)
                        compression_level = packet_get_int();
                        packet_check_eom();
                        if (compression_level < 1 || compression_level > 9) {
-                               packet_send_debug("Received illegal compression level %d.",
+                               packet_send_debug("Received invalid compression level %d.",
                                    compression_level);
                                break;
                        }
@@ -501,7 +500,11 @@ do_exec_no_pty(Session *s, const char *command)
        close(perr[1]);
 
        if (compat20) {
-               session_set_fds(s, pin[1], pout[0], s->is_subsystem ? -1 : perr[0]);
+               if (s->is_subsystem) {
+                       close(perr[0]);
+                       perr[0] = -1;
+               }
+               session_set_fds(s, pin[1], pout[0], perr[0]);
        } else {
                /* Enter the interactive session. */
                server_loop(pid, pin[1], pout[0], perr[0]);
@@ -712,14 +715,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;
@@ -764,19 +772,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();
 }
 
@@ -1147,6 +1142,10 @@ 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,
+                           s->env[i].val);
+
                child_set_env(&env, &envsize, "USER", pw->pw_name);
                child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
 #ifdef _AIX
@@ -1482,9 +1481,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");
@@ -1607,6 +1607,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 */
        }
 
@@ -1907,12 +1914,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);
 
@@ -2039,9 +2040,8 @@ session_exec_req(Session *s)
 static int
 session_break_req(Session *s)
 {
-       u_int break_length;
 
-       break_length = packet_get_int();        /* ignored */
+       packet_get_int();       /* ignored */
        packet_check_eom();
 
        if (s->ttyfd == -1 ||
@@ -2050,6 +2050,41 @@ session_break_req(Session *s)
        return 1;
 }
 
+static int
+session_env_req(Session *s)
+{
+       char *name, *val;
+       u_int name_len, val_len, i;
+
+       name = packet_get_string(&name_len);
+       val = packet_get_string(&val_len);
+       packet_check_eom();
+
+       /* Don't set too many environment variables */
+       if (s->num_env > 128) {
+               debug2("Ignoring env request %s: too many env vars", name);
+               goto fail;
+       }
+
+       for (i = 0; i < options.num_accept_env; i++) {
+               if (match_pattern(name, options.accept_env[i])) {
+                       debug2("Setting env %d: %s=%s", s->num_env, name, val);
+                       s->env = xrealloc(s->env, sizeof(*s->env) *
+                           (s->num_env + 1));
+                       s->env[s->num_env].name = name;
+                       s->env[s->num_env].val = val;
+                       s->num_env++;
+                       return (1);
+               }
+       }
+       debug2("Ignoring env request %s: disallowed name", name);
+
+ fail:
+       xfree(name);
+       xfree(val);
+       return (0);
+}
+
 static int
 session_auth_agent_req(Session *s)
 {
@@ -2097,13 +2132,16 @@ session_input_channel_req(Channel *c, const char *rtype)
                        success = session_auth_agent_req(s);
                } else if (strcmp(rtype, "subsystem") == 0) {
                        success = session_subsystem_req(s);
-               } else if (strcmp(rtype, "break") == 0) {
-                       success = session_break_req(s);
+               } else if (strcmp(rtype, "env") == 0) {
+                       success = session_env_req(s);
                }
        }
        if (strcmp(rtype, "window-change") == 0) {
                success = session_window_change_req(s);
+       } else if (strcmp(rtype, "break") == 0) {
+               success = session_break_req(s);
        }
+
        return success;
 }
 
@@ -2236,6 +2274,8 @@ session_exit_message(Session *s, int status)
 void
 session_close(Session *s)
 {
+       int i;
+
        debug("session_close: session %d pid %ld", s->self, (long)s->pid);
        if (s->ttyfd != -1)
                session_pty_cleanup(s);
@@ -2250,6 +2290,12 @@ session_close(Session *s)
        if (s->auth_proto)
                xfree(s->auth_proto);
        s->used = 0;
+       for (i = 0; i < s->num_env; i++) {
+               xfree(s->env[i].name);
+               xfree(s->env[i].val);
+       }
+       if (s->env != NULL)
+               xfree(s->env);
        session_proctitle(s);
 }
 
This page took 1.035708 seconds and 4 git commands to generate.