]> andersk Git - openssh.git/commitdiff
- (djm) OpenBSD CVS Sync
authordjm <djm>
Thu, 17 Jun 2004 15:17:29 +0000 (15:17 +0000)
committerdjm <djm>
Thu, 17 Jun 2004 15:17:29 +0000 (15:17 +0000)
   - djm@cvs.openbsd.org 2004/06/17 14:52:48
     [clientloop.c clientloop.h ssh.c]
     support environment passing over shared connections; ok markus@

ChangeLog
clientloop.c
clientloop.h
ssh.c

index 24a0f58596cb6339125a1678e701472b74fde192..f08d4f82224d412eac35f95abb2778ada0164d19 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+20040618
+ - (djm) OpenBSD CVS Sync
+   - djm@cvs.openbsd.org 2004/06/17 14:52:48
+     [clientloop.c clientloop.h ssh.c]
+     support environment passing over shared connections; ok markus@
+
 20040617
  - (dtucker) [regress/scp.sh] diff -N is not portable (but needed for some
    platforms), so test if diff understands it.  Pointed out by tim@, ok djm@
index 6b849a91a68d59f3b38d82af70d4d939b40d3570..eb320033130c22fccebdca0b19a60314008059ec 100644 (file)
@@ -59,7 +59,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: clientloop.c,v 1.125 2004/06/15 05:45:04 djm Exp $");
+RCSID("$OpenBSD: clientloop.c,v 1.126 2004/06/17 14:52:48 djm Exp $");
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -143,6 +143,7 @@ struct confirm_ctx {
        Buffer cmd;
        char *term;
        struct termios tio;
+       char **env;
 };
 
 /*XXX*/
@@ -538,6 +539,7 @@ client_extra_session2_setup(int id, void *arg)
 {
        struct confirm_ctx *cctx = arg;
        Channel *c;
+       int i;
        
        if (cctx == NULL)
                fatal("%s: cctx == NULL", __func__);
@@ -545,13 +547,18 @@ client_extra_session2_setup(int id, void *arg)
                fatal("%s: no channel for id %d", __func__, id);
 
        client_session2_setup(id, cctx->want_tty, cctx->want_subsys, 
-           cctx->term, &cctx->tio, c->rfd, &cctx->cmd, 
+           cctx->term, &cctx->tio, c->rfd, &cctx->cmd, cctx->env,
            client_subsystem_reply);
        
        c->confirm_ctx = NULL;
        buffer_free(&cctx->cmd);
-       free(cctx->term);
-       free(cctx);
+       xfree(cctx->term);
+       if (cctx->env != NULL) {
+               for (i = 0; cctx->env[i] != NULL; i++)
+                       xfree(cctx->env[i]);
+               xfree(cctx->env);
+       }                       
+       xfree(cctx);
 }
 
 static void
@@ -559,12 +566,12 @@ client_process_control(fd_set * readset)
 {
        Buffer m;
        Channel *c;
-       int client_fd, new_fd[3], ver;
+       int client_fd, new_fd[3], ver, i;
        socklen_t addrlen;
        struct sockaddr_storage addr;
        struct confirm_ctx *cctx;
        char *cmd;
-       u_int len;
+       u_int len, env_len;
        uid_t euid;
        gid_t egid;
 
@@ -631,6 +638,16 @@ client_process_control(fd_set * readset)
        buffer_init(&cctx->cmd);
        buffer_append(&cctx->cmd, cmd, strlen(cmd));
 
+       env_len = buffer_get_int(&m);
+       env_len = MIN(env_len, 4096);
+       debug3("%s: receiving %d env vars", __func__, env_len);
+       if (env_len != 0) {
+               cctx->env = xmalloc(sizeof(*cctx->env) * (env_len + 1));
+               for (i = 0; i < env_len; i++)
+                       cctx->env[i] = buffer_get_string(&m, &len);
+               cctx->env[i] = NULL;
+       }
+
        debug2("%s: accepted tty %d, subsys %d, cmd %s", __func__,
            cctx->want_tty, cctx->want_subsys, cmd);
 
@@ -1626,7 +1643,7 @@ client_input_global_request(int type, u_int32_t seq, void *ctxt)
 
 void
 client_session2_setup(int id, int want_tty, int want_subsystem, 
-    const char *term, struct termios *tiop, int in_fd, Buffer *cmd, 
+    const char *term, struct termios *tiop, int in_fd, Buffer *cmd, char **env,
     dispatch_fn *subsys_repl)
 {
        int len;
@@ -1654,15 +1671,14 @@ client_session2_setup(int id, int want_tty, int want_subsystem,
        }
 
        /* Transfer any environment variables from client to server */
-       if (options.num_send_env != 0) {
+       if (options.num_send_env != 0 && env != NULL) {
                int i, j, matched;
-               extern char **environ;
                char *name, *val;
 
                debug("Sending environment.");
-               for (i = 0; environ && environ[i] != NULL; i++) {
+               for (i = 0; env[i] != NULL; i++) {
                        /* Split */
-                       name = xstrdup(environ[i]);
+                       name = xstrdup(env[i]);
                        if ((val = strchr(name, '=')) == NULL) {
                                free(name);
                                continue;
index f1e13ac3a93cf2ed3b9fcc3cba65fae3ae849e6e..c34d6674dac989d50923ba6e94f2e7880f019ea1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: clientloop.h,v 1.9 2004/06/13 15:03:02 djm Exp $      */
+/*     $OpenBSD: clientloop.h,v 1.10 2004/06/17 14:52:48 djm Exp $     */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -39,4 +39,4 @@
 int     client_loop(int, int, int);
 void    client_global_request_reply_fwd(int, u_int32_t, void *);
 void    client_session2_setup(int, int, int, const char *, struct termios *, 
-           int, Buffer *, dispatch_fn *);
+           int, Buffer *, char **, dispatch_fn *);
diff --git a/ssh.c b/ssh.c
index 4badd2961d30810237e434dfcd97946ef0a2b663..9b434b93ecc0ef042591ce77f44555727b4682ac 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -40,7 +40,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh.c,v 1.214 2004/06/13 15:03:02 djm Exp $");
+RCSID("$OpenBSD: ssh.c,v 1.215 2004/06/17 14:52:48 djm Exp $");
 
 #include <openssl/evp.h>
 #include <openssl/err.h>
@@ -1080,6 +1080,8 @@ ssh_control_listener(void)
 static void
 ssh_session2_setup(int id, void *arg)
 {
+       extern char **environ;
+
        int interactive = tty_flag;
        if (options.forward_x11 && getenv("DISPLAY") != NULL) {
                char *proto, *data;
@@ -1100,7 +1102,7 @@ ssh_session2_setup(int id, void *arg)
        }
 
        client_session2_setup(id, tty_flag, subsystem_flag, getenv("TERM"),
-           NULL, fileno(stdin), &command, &ssh_subsystem_reply);
+           NULL, fileno(stdin), &command, environ, &ssh_subsystem_reply);
 
        packet_set_interactive(interactive);
 }
@@ -1230,9 +1232,10 @@ static void
 control_client(const char *path)
 {
        struct sockaddr_un addr;
-       int r, sock, exitval, addr_len;
+       int i, r, sock, exitval, addr_len;
        Buffer m;
        char *cp;
+       extern char **environ;
        
        memset(&addr, '\0', sizeof(addr));
        addr.sun_family = AF_UNIX;
@@ -1265,8 +1268,6 @@ control_client(const char *path)
                fatal("%s: wrong version", __func__);
        control_server_pid = buffer_get_int(&m);
 
-       /* XXX: env passing */
-
        buffer_clear(&m);
        buffer_put_int(&m, tty_flag);
        buffer_put_int(&m, subsystem_flag);
@@ -1275,6 +1276,13 @@ control_client(const char *path)
        buffer_append(&command, "\0", 1);
        buffer_put_cstring(&m, buffer_ptr(&command));
 
+       /* Pass environment */
+       for (i = 0; environ != NULL && environ[i] != NULL; i++)
+               ;
+       buffer_put_int(&m, i);
+       for (i = 0; environ != NULL && environ[i] != NULL; i++)
+               buffer_put_cstring(&m, environ[i]);
+
        if (ssh_msg_send(sock, /* version */0, &m) == -1)
                fatal("%s: msg_send", __func__);
 
This page took 0.068783 seconds and 5 git commands to generate.