diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2004-06-17 14:52:49 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2004-06-17 14:52:49 +0000 |
commit | 9549b87bfd5c610614fd577c47478687fd11e10c (patch) | |
tree | e74c70d57c2fa49f60ab650aa1a106cddcdc1dab | |
parent | 822e0910aad8c0f29044e60212354d5cbcf7ae1d (diff) |
support environment passing over shared connections; ok markus@
-rw-r--r-- | usr.bin/ssh/clientloop.c | 38 | ||||
-rw-r--r-- | usr.bin/ssh/clientloop.h | 4 | ||||
-rw-r--r-- | usr.bin/ssh/ssh.c | 18 |
3 files changed, 42 insertions, 18 deletions
diff --git a/usr.bin/ssh/clientloop.c b/usr.bin/ssh/clientloop.c index 6b849a91a68..eb320033130 100644 --- a/usr.bin/ssh/clientloop.c +++ b/usr.bin/ssh/clientloop.c @@ -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; diff --git a/usr.bin/ssh/clientloop.h b/usr.bin/ssh/clientloop.h index f1e13ac3a93..c34d6674dac 100644 --- a/usr.bin/ssh/clientloop.h +++ b/usr.bin/ssh/clientloop.h @@ -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/usr.bin/ssh/ssh.c b/usr.bin/ssh/ssh.c index 44d1ad1a6a0..7a1376bf425 100644 --- a/usr.bin/ssh/ssh.c +++ b/usr.bin/ssh/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> @@ -1064,6 +1064,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; @@ -1084,7 +1086,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); } @@ -1214,9 +1216,10 @@ static void control_client(const char *path) { struct sockaddr_un addr; - int r, sock, exitval; + int i, r, sock, exitval; Buffer m; char *cp; + extern char **environ; memset(&addr, '\0', sizeof(addr)); addr.sun_family = AF_UNIX; @@ -1249,8 +1252,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); @@ -1259,6 +1260,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__); |