]> andersk Git - openssh.git/blobdiff - session.c
- stevesk@cvs.openbsd.org 2002/12/04 04:36:47
[openssh.git] / session.c
index 38388d43af96b4685b70e1013ef162d6e9ca27a8..ac1561756f5e498ce1be652cf792a4d3a8e105aa 100644 (file)
--- a/session.c
+++ b/session.c
@@ -33,7 +33,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.144 2002/07/19 15:43:33 markus Exp $");
+RCSID("$OpenBSD: session.c,v 1.151 2002/12/04 04:36:47 stevesk Exp $");
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -210,13 +210,6 @@ do_authenticated(Authctxt *authctxt)
                close(startup_pipe);
                startup_pipe = -1;
        }
-#ifdef WITH_AIXAUTHENTICATE
-       /* We don't have a pty yet, so just label the line as "ssh" */
-       if (loginsuccess(authctxt->user,
-           get_canonical_hostname(options.verify_reverse_mapping),
-           "ssh", &aixloginmsg) < 0)
-               aixloginmsg = NULL;
-#endif /* WITH_AIXAUTHENTICATE */
 
        /* setup the channel layer */
        if (!no_port_forwarding_flag && options.allow_tcp_forwarding)
@@ -519,10 +512,17 @@ do_exec_no_pty(Session *s, const char *command)
                        perror("dup2 stderr");
 #endif /* USE_PIPES */
 
+#ifdef _UNICOS
+               cray_init_job(s->pw); /* set up cray jid and tmpdir */
+#endif
+
                /* Do processing for the child (exec command etc). */
                do_child(s, command);
                /* NOTREACHED */
        }
+#ifdef _UNICOS
+       signal(WJSIGNAL, cray_job_termination_handler);
+#endif /* _UNICOS */
 #ifdef HAVE_CYGWIN
        if (is_winnt)
                cygwin_set_impersonation_token(INVALID_HANDLE_VALUE);
@@ -610,8 +610,12 @@ do_exec_pty(Session *s, const char *command)
 
                /* record login, etc. similar to login(1) */
 #ifndef HAVE_OSF_SIA
-               if (!(options.use_login && command == NULL))
+               if (!(options.use_login && command == NULL)) {
+#ifdef _UNICOS
+                       cray_init_job(s->pw); /* set up cray jid and tmpdir */
+#endif /* _UNICOS */
                        do_login(s, command);
+               }
 # ifdef LOGIN_NEEDS_UTMPX
                else
                        do_pre_login(s);
@@ -622,6 +626,9 @@ do_exec_pty(Session *s, const char *command)
                do_child(s, command);
                /* NOTREACHED */
        }
+#ifdef _UNICOS
+       signal(WJSIGNAL, cray_job_termination_handler);
+#endif /* _UNICOS */
 #ifdef HAVE_CYGWIN
        if (is_winnt)
                cygwin_set_impersonation_token(INVALID_HANDLE_VALUE);
@@ -671,8 +678,8 @@ do_pre_login(Session *s)
         * the address be 0.0.0.0.
         */
        memset(&from, 0, sizeof(from));
+       fromlen = sizeof(from);
        if (packet_connection_is_on_socket()) {
-               fromlen = sizeof(from);
                if (getpeername(packet_get_connection_in(),
                    (struct sockaddr *) & from, &fromlen) < 0) {
                        debug("getpeername: %.100s", strerror(errno));
@@ -737,7 +744,7 @@ do_login(Session *s, const char *command)
                record_login(pid, s->tty, pw->pw_name, pw->pw_uid,
                    get_remote_name_or_ip(utmp_len,
                    options.verify_reverse_mapping),
-                   (struct sockaddr *)&from);
+                   (struct sockaddr *)&from, fromlen);
 
 #ifdef USE_PAM
        /*
@@ -762,6 +769,7 @@ do_login(Session *s, const char *command)
                printf("%s\n", aixloginmsg);
 #endif /* WITH_AIXAUTHENTICATE */
 
+#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'))
@@ -772,6 +780,7 @@ do_login(Session *s, const char *command)
                        printf("Last login: %s from %s\r\n", time_string,
                            s->hostname);
        }
+#endif /* NO_SSH_LASTLOG */
 
        do_motd();
 }
@@ -962,8 +971,10 @@ do_setup_env(Session *s, const char *shell)
                child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
                child_set_env(&env, &envsize, "HOME", pw->pw_dir);
 #ifdef HAVE_LOGIN_CAP
-               (void) setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH);
-               child_set_env(&env, &envsize, "PATH", getenv("PATH"));
+               if (setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH) < 0)
+                       child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
+               else
+                       child_set_env(&env, &envsize, "PATH", getenv("PATH"));
 #else /* HAVE_LOGIN_CAP */
 # ifndef HAVE_CYGWIN
                /*
@@ -1009,10 +1020,16 @@ do_setup_env(Session *s, const char *shell)
                }
        }
 
+       /* SSH_CLIENT deprecated */
        snprintf(buf, sizeof buf, "%.50s %d %d",
            get_remote_ipaddr(), get_remote_port(), get_local_port());
        child_set_env(&env, &envsize, "SSH_CLIENT", buf);
 
+       snprintf(buf, sizeof buf, "%.50s %d %.50s %d",
+           get_remote_ipaddr(), get_remote_port(),
+           get_local_ipaddr(packet_get_connection_in()), get_local_port());
+       child_set_env(&env, &envsize, "SSH_CONNECTION", buf);
+
        if (s->ttyfd != -1)
                child_set_env(&env, &envsize, "SSH_TTY", s->tty);
        if (s->term)
@@ -1023,6 +1040,11 @@ do_setup_env(Session *s, const char *shell)
                child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND",
                    original_command);
 
+#ifdef _UNICOS
+       if (cray_tmpdir[0] != '\0')
+               child_set_env(&env, &envsize, "TMPDIR", cray_tmpdir);
+#endif /* _UNICOS */
+
 #ifdef _AIX
        {
                char *cp;
@@ -1063,9 +1085,9 @@ do_setup_env(Session *s, const char *shell)
                    auth_sock_name);
 
        /* read $HOME/.ssh/environment. */
-       if (!options.use_login) {
+       if (options.permit_user_env && !options.use_login) {
                snprintf(buf, sizeof buf, "%.200s/.ssh/environment",
-                   pw->pw_dir);
+                   strcmp(pw->pw_dir, "/") ? pw->pw_dir : "");
                read_environment_file(&env, &envsize, buf);
        }
        if (debug_flag) {
@@ -1124,8 +1146,10 @@ do_rc_files(Session *s, const char *shell)
                /* Add authority data to .Xauthority if appropriate. */
                if (debug_flag) {
                        fprintf(stderr,
-                           "Running %.500s add "
-                           "%.100s %.100s %.100s\n",
+                           "Running %.500s remove %.100s\n",
+                           options.xauth_location, s->auth_display);
+                       fprintf(stderr,
+                           "%.500s add %.100s %.100s %.100s\n",
                            options.xauth_location, s->auth_display,
                            s->auth_proto, s->auth_data);
                }
@@ -1133,6 +1157,8 @@ do_rc_files(Session *s, const char *shell)
                    options.xauth_location);
                f = popen(cmd, "w");
                if (f) {
+                       fprintf(f, "remove %s\n",
+                           s->auth_display);
                        fprintf(f, "add %s %s %s\n",
                            s->auth_display, s->auth_proto,
                            s->auth_data);
@@ -1160,6 +1186,8 @@ do_nologin(struct passwd *pw)
 #endif
        if (f) {
                /* /etc/nologin exists.  Print its contents and exit. */
+               log("User %.100s not allowed because %s exists",
+                   pw->pw_name, _PATH_NOLOGIN);
                while (fgets(buf, sizeof(buf), f))
                        fputs(buf, stderr);
                fclose(f);
@@ -1272,6 +1300,10 @@ do_child(Session *s, const char *command)
        if (options.use_login && command != NULL)
                options.use_login = 0;
 
+#ifdef _UNICOS
+       cray_setup(pw->pw_uid, pw->pw_name, command);
+#endif /* _UNICOS */
+
        /*
         * Login(1) does this as well, and it needs uid 0 for the "-h"
         * switch, so we let login(1) to this for us.
@@ -1807,6 +1839,27 @@ session_pty_cleanup(void *session)
        PRIVSEP(session_pty_cleanup2(session));
 }
 
+static char *
+sig2name(int sig)
+{
+#define SSH_SIG(x) if (sig == SIG ## x) return #x
+       SSH_SIG(ABRT);
+       SSH_SIG(ALRM);
+       SSH_SIG(FPE);
+       SSH_SIG(HUP);
+       SSH_SIG(ILL);
+       SSH_SIG(INT);
+       SSH_SIG(KILL);
+       SSH_SIG(PIPE);
+       SSH_SIG(QUIT);
+       SSH_SIG(SEGV);
+       SSH_SIG(TERM);
+       SSH_SIG(USR1);
+       SSH_SIG(USR2);
+#undef SSH_SIG
+       return "SIG@openssh.com";
+}
+
 static void
 session_exit_message(Session *s, int status)
 {
@@ -1824,7 +1877,7 @@ session_exit_message(Session *s, int status)
                packet_send();
        } else if (WIFSIGNALED(status)) {
                channel_request_start(s->chanid, "exit-signal", 0);
-               packet_put_int(WTERMSIG(status));
+               packet_put_cstring(sig2name(WTERMSIG(status)));
 #ifdef WCOREDUMP
                packet_put_char(WCOREDUMP(status));
 #else /* WCOREDUMP */
This page took 0.04891 seconds and 4 git commands to generate.