]> andersk Git - openssh.git/blobdiff - session.c
- djm@cvs.openbsd.org 2006/07/06 10:47:05
[openssh.git] / session.c
index 2bf9044048b6b97d324353f9aebcc16107ff94ff..899c3a16b47435ece14a452224857948154a7bc4 100644 (file)
--- a/session.c
+++ b/session.c
@@ -1,3 +1,4 @@
+/* $OpenBSD: session.c,v 1.205 2006/07/06 10:47:05 djm Exp $ */
 /*
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  *                    All rights reserved
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.191 2005/12/24 02:27:41 djm Exp $");
+
+#include <sys/types.h>
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#include <sys/wait.h>
+#include <sys/un.h>
+
+#include <grp.h>
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif
+#include <signal.h>
+#include <arpa/inet.h>
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -175,7 +189,7 @@ auth_input_request_forwarding(struct passwd * pw)
        sunaddr.sun_family = AF_UNIX;
        strlcpy(sunaddr.sun_path, auth_sock_name, sizeof(sunaddr.sun_path));
 
-       if (bind(sock, (struct sockaddr *) & sunaddr, sizeof(sunaddr)) < 0)
+       if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) < 0)
                packet_disconnect("bind: %.100s", strerror(errno));
 
        /* Restore the privileged uid. */
@@ -632,7 +646,7 @@ do_pre_login(Session *s)
        fromlen = sizeof(from);
        if (packet_connection_is_on_socket()) {
                if (getpeername(packet_get_connection_in(),
-                   (struct sockaddr *) & from, &fromlen) < 0) {
+                   (struct sockaddr *)&from, &fromlen) < 0) {
                        debug("getpeername: %.100s", strerror(errno));
                        cleanup_exit(255);
                }
@@ -826,7 +840,7 @@ child_set_env(char ***envp, u_int *envsizep, const char *name,
                        if (envsize >= 1000)
                                fatal("child_set_env: too many env vars");
                        envsize += 50;
-                       env = (*envp) = xrealloc(env, envsize * sizeof(char *));
+                       env = (*envp) = xrealloc(env, envsize, sizeof(char *));
                        *envsizep = envsize;
                }
                /* Need to set the NULL pointer at end of array beyond the new slot. */
@@ -972,7 +986,7 @@ do_setup_env(Session *s, const char *shell)
 
        /* Initialize the environment. */
        envsize = 100;
-       env = xmalloc(envsize * sizeof(char *));
+       env = xcalloc(envsize, sizeof(char *));
        env[0] = NULL;
 
 #ifdef HAVE_CYGWIN
@@ -1340,6 +1354,10 @@ do_setusercontext(struct passwd *pw)
 #endif
        if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid)
                fatal("Failed to set uids to %u.", (u_int) pw->pw_uid);
+
+#ifdef WITH_SELINUX
+       ssh_selinux_setup_exec_context(pw->pw_name);
+#endif
 }
 
 static void
@@ -1823,7 +1841,7 @@ session_subsystem_req(Session *s)
        struct stat st;
        u_int len;
        int success = 0;
-       char *cmd, *subsys = packet_get_string(&len);
+       char *prog, *cmd, *subsys = packet_get_string(&len);
        u_int i;
 
        packet_check_eom();
@@ -1831,9 +1849,10 @@ session_subsystem_req(Session *s)
 
        for (i = 0; i < options.num_subsystems; i++) {
                if (strcmp(subsys, options.subsystem_name[i]) == 0) {
-                       cmd = options.subsystem_command[i];
-                       if (stat(cmd, &st) < 0) {
-                               error("subsystem: cannot stat %s: %s", cmd,
+                       prog = options.subsystem_command[i];
+                       cmd = options.subsystem_args[i];
+                       if (stat(prog, &st) < 0) {
+                               error("subsystem: cannot stat %s: %s", prog,
                                    strerror(errno));
                                break;
                        }
@@ -1930,8 +1949,8 @@ session_env_req(Session *s)
        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 = xrealloc(s->env, s->num_env + 1,
+                           sizeof(*s->env));
                        s->env[s->num_env].name = name;
                        s->env[s->num_env].val = val;
                        s->num_env++;
@@ -2176,11 +2195,10 @@ session_exit_message(Session *s, int status)
 
        /* disconnect channel */
        debug("session_exit_message: release channel %d", s->chanid);
-       s->pid = 0;
 
        /*
         * Adjust cleanup callback attachment to send close messages when
-        * the channel gets EOF. The session will be then be closed 
+        * the channel gets EOF. The session will be then be closed
         * by session_close_by_channel when the childs close their fds.
         */
        channel_register_cleanup(c->self, session_close_by_channel, 1);
@@ -2238,6 +2256,7 @@ session_close_by_pid(pid_t pid, int status)
                session_exit_message(s, status);
        if (s->ttyfd != -1)
                session_pty_cleanup(s);
+       s->pid = 0;
 }
 
 /*
This page took 0.035016 seconds and 4 git commands to generate.