summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2004-06-18 01:17:29 +1000
committerDamien Miller <djm@mindrot.org>2004-06-18 01:17:29 +1000
commit3756dcee244f47c20a6590129d99e625169836c6 (patch)
tree4ac3b83e6a1bdc7a543e92bf1b66def8444af739
parenta9972e19e941f9f711103b50dd57f6bc0c1aad53 (diff)
- (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@
-rw-r--r--ChangeLog8
-rw-r--r--clientloop.c38
-rw-r--r--clientloop.h4
-rw-r--r--ssh.c18
4 files changed, 49 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 95b583e3c..ae4897e6d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
120040618
2 - (djm) OpenBSD CVS Sync
3 - djm@cvs.openbsd.org 2004/06/17 14:52:48
4 [clientloop.c clientloop.h ssh.c]
5 support environment passing over shared connections; ok markus@
6
120040617 720040617
2 - (dtucker) [regress/scp.sh] diff -N is not portable (but needed for some 8 - (dtucker) [regress/scp.sh] diff -N is not portable (but needed for some
3 platforms), so test if diff understands it. Pointed out by tim@, ok djm@ 9 platforms), so test if diff understands it. Pointed out by tim@, ok djm@
@@ -1270,4 +1276,4 @@
1270 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 1276 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
1271 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 1277 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
1272 1278
1273$Id: ChangeLog,v 1.3404 2004/06/17 07:01:21 dtucker Exp $ 1279$Id: ChangeLog,v 1.3405 2004/06/17 15:17:29 djm Exp $
diff --git a/clientloop.c b/clientloop.c
index 6b849a91a..eb3200331 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -59,7 +59,7 @@
59 */ 59 */
60 60
61#include "includes.h" 61#include "includes.h"
62RCSID("$OpenBSD: clientloop.c,v 1.125 2004/06/15 05:45:04 djm Exp $"); 62RCSID("$OpenBSD: clientloop.c,v 1.126 2004/06/17 14:52:48 djm Exp $");
63 63
64#include "ssh.h" 64#include "ssh.h"
65#include "ssh1.h" 65#include "ssh1.h"
@@ -143,6 +143,7 @@ struct confirm_ctx {
143 Buffer cmd; 143 Buffer cmd;
144 char *term; 144 char *term;
145 struct termios tio; 145 struct termios tio;
146 char **env;
146}; 147};
147 148
148/*XXX*/ 149/*XXX*/
@@ -538,6 +539,7 @@ client_extra_session2_setup(int id, void *arg)
538{ 539{
539 struct confirm_ctx *cctx = arg; 540 struct confirm_ctx *cctx = arg;
540 Channel *c; 541 Channel *c;
542 int i;
541 543
542 if (cctx == NULL) 544 if (cctx == NULL)
543 fatal("%s: cctx == NULL", __func__); 545 fatal("%s: cctx == NULL", __func__);
@@ -545,13 +547,18 @@ client_extra_session2_setup(int id, void *arg)
545 fatal("%s: no channel for id %d", __func__, id); 547 fatal("%s: no channel for id %d", __func__, id);
546 548
547 client_session2_setup(id, cctx->want_tty, cctx->want_subsys, 549 client_session2_setup(id, cctx->want_tty, cctx->want_subsys,
548 cctx->term, &cctx->tio, c->rfd, &cctx->cmd, 550 cctx->term, &cctx->tio, c->rfd, &cctx->cmd, cctx->env,
549 client_subsystem_reply); 551 client_subsystem_reply);
550 552
551 c->confirm_ctx = NULL; 553 c->confirm_ctx = NULL;
552 buffer_free(&cctx->cmd); 554 buffer_free(&cctx->cmd);
553 free(cctx->term); 555 xfree(cctx->term);
554 free(cctx); 556 if (cctx->env != NULL) {
557 for (i = 0; cctx->env[i] != NULL; i++)
558 xfree(cctx->env[i]);
559 xfree(cctx->env);
560 }
561 xfree(cctx);
555} 562}
556 563
557static void 564static void
@@ -559,12 +566,12 @@ client_process_control(fd_set * readset)
559{ 566{
560 Buffer m; 567 Buffer m;
561 Channel *c; 568 Channel *c;
562 int client_fd, new_fd[3], ver; 569 int client_fd, new_fd[3], ver, i;
563 socklen_t addrlen; 570 socklen_t addrlen;
564 struct sockaddr_storage addr; 571 struct sockaddr_storage addr;
565 struct confirm_ctx *cctx; 572 struct confirm_ctx *cctx;
566 char *cmd; 573 char *cmd;
567 u_int len; 574 u_int len, env_len;
568 uid_t euid; 575 uid_t euid;
569 gid_t egid; 576 gid_t egid;
570 577
@@ -631,6 +638,16 @@ client_process_control(fd_set * readset)
631 buffer_init(&cctx->cmd); 638 buffer_init(&cctx->cmd);
632 buffer_append(&cctx->cmd, cmd, strlen(cmd)); 639 buffer_append(&cctx->cmd, cmd, strlen(cmd));
633 640
641 env_len = buffer_get_int(&m);
642 env_len = MIN(env_len, 4096);
643 debug3("%s: receiving %d env vars", __func__, env_len);
644 if (env_len != 0) {
645 cctx->env = xmalloc(sizeof(*cctx->env) * (env_len + 1));
646 for (i = 0; i < env_len; i++)
647 cctx->env[i] = buffer_get_string(&m, &len);
648 cctx->env[i] = NULL;
649 }
650
634 debug2("%s: accepted tty %d, subsys %d, cmd %s", __func__, 651 debug2("%s: accepted tty %d, subsys %d, cmd %s", __func__,
635 cctx->want_tty, cctx->want_subsys, cmd); 652 cctx->want_tty, cctx->want_subsys, cmd);
636 653
@@ -1626,7 +1643,7 @@ client_input_global_request(int type, u_int32_t seq, void *ctxt)
1626 1643
1627void 1644void
1628client_session2_setup(int id, int want_tty, int want_subsystem, 1645client_session2_setup(int id, int want_tty, int want_subsystem,
1629 const char *term, struct termios *tiop, int in_fd, Buffer *cmd, 1646 const char *term, struct termios *tiop, int in_fd, Buffer *cmd, char **env,
1630 dispatch_fn *subsys_repl) 1647 dispatch_fn *subsys_repl)
1631{ 1648{
1632 int len; 1649 int len;
@@ -1654,15 +1671,14 @@ client_session2_setup(int id, int want_tty, int want_subsystem,
1654 } 1671 }
1655 1672
1656 /* Transfer any environment variables from client to server */ 1673 /* Transfer any environment variables from client to server */
1657 if (options.num_send_env != 0) { 1674 if (options.num_send_env != 0 && env != NULL) {
1658 int i, j, matched; 1675 int i, j, matched;
1659 extern char **environ;
1660 char *name, *val; 1676 char *name, *val;
1661 1677
1662 debug("Sending environment."); 1678 debug("Sending environment.");
1663 for (i = 0; environ && environ[i] != NULL; i++) { 1679 for (i = 0; env[i] != NULL; i++) {
1664 /* Split */ 1680 /* Split */
1665 name = xstrdup(environ[i]); 1681 name = xstrdup(env[i]);
1666 if ((val = strchr(name, '=')) == NULL) { 1682 if ((val = strchr(name, '=')) == NULL) {
1667 free(name); 1683 free(name);
1668 continue; 1684 continue;
diff --git a/clientloop.h b/clientloop.h
index f1e13ac3a..c34d6674d 100644
--- a/clientloop.h
+++ b/clientloop.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: clientloop.h,v 1.9 2004/06/13 15:03:02 djm Exp $ */ 1/* $OpenBSD: clientloop.h,v 1.10 2004/06/17 14:52:48 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -39,4 +39,4 @@
39int client_loop(int, int, int); 39int client_loop(int, int, int);
40void client_global_request_reply_fwd(int, u_int32_t, void *); 40void client_global_request_reply_fwd(int, u_int32_t, void *);
41void client_session2_setup(int, int, int, const char *, struct termios *, 41void client_session2_setup(int, int, int, const char *, struct termios *,
42 int, Buffer *, dispatch_fn *); 42 int, Buffer *, char **, dispatch_fn *);
diff --git a/ssh.c b/ssh.c
index 4badd2961..9b434b93e 100644
--- a/ssh.c
+++ b/ssh.c
@@ -40,7 +40,7 @@
40 */ 40 */
41 41
42#include "includes.h" 42#include "includes.h"
43RCSID("$OpenBSD: ssh.c,v 1.214 2004/06/13 15:03:02 djm Exp $"); 43RCSID("$OpenBSD: ssh.c,v 1.215 2004/06/17 14:52:48 djm Exp $");
44 44
45#include <openssl/evp.h> 45#include <openssl/evp.h>
46#include <openssl/err.h> 46#include <openssl/err.h>
@@ -1080,6 +1080,8 @@ ssh_control_listener(void)
1080static void 1080static void
1081ssh_session2_setup(int id, void *arg) 1081ssh_session2_setup(int id, void *arg)
1082{ 1082{
1083 extern char **environ;
1084
1083 int interactive = tty_flag; 1085 int interactive = tty_flag;
1084 if (options.forward_x11 && getenv("DISPLAY") != NULL) { 1086 if (options.forward_x11 && getenv("DISPLAY") != NULL) {
1085 char *proto, *data; 1087 char *proto, *data;
@@ -1100,7 +1102,7 @@ ssh_session2_setup(int id, void *arg)
1100 } 1102 }
1101 1103
1102 client_session2_setup(id, tty_flag, subsystem_flag, getenv("TERM"), 1104 client_session2_setup(id, tty_flag, subsystem_flag, getenv("TERM"),
1103 NULL, fileno(stdin), &command, &ssh_subsystem_reply); 1105 NULL, fileno(stdin), &command, environ, &ssh_subsystem_reply);
1104 1106
1105 packet_set_interactive(interactive); 1107 packet_set_interactive(interactive);
1106} 1108}
@@ -1230,9 +1232,10 @@ static void
1230control_client(const char *path) 1232control_client(const char *path)
1231{ 1233{
1232 struct sockaddr_un addr; 1234 struct sockaddr_un addr;
1233 int r, sock, exitval, addr_len; 1235 int i, r, sock, exitval, addr_len;
1234 Buffer m; 1236 Buffer m;
1235 char *cp; 1237 char *cp;
1238 extern char **environ;
1236 1239
1237 memset(&addr, '\0', sizeof(addr)); 1240 memset(&addr, '\0', sizeof(addr));
1238 addr.sun_family = AF_UNIX; 1241 addr.sun_family = AF_UNIX;
@@ -1265,8 +1268,6 @@ control_client(const char *path)
1265 fatal("%s: wrong version", __func__); 1268 fatal("%s: wrong version", __func__);
1266 control_server_pid = buffer_get_int(&m); 1269 control_server_pid = buffer_get_int(&m);
1267 1270
1268 /* XXX: env passing */
1269
1270 buffer_clear(&m); 1271 buffer_clear(&m);
1271 buffer_put_int(&m, tty_flag); 1272 buffer_put_int(&m, tty_flag);
1272 buffer_put_int(&m, subsystem_flag); 1273 buffer_put_int(&m, subsystem_flag);
@@ -1275,6 +1276,13 @@ control_client(const char *path)
1275 buffer_append(&command, "\0", 1); 1276 buffer_append(&command, "\0", 1);
1276 buffer_put_cstring(&m, buffer_ptr(&command)); 1277 buffer_put_cstring(&m, buffer_ptr(&command));
1277 1278
1279 /* Pass environment */
1280 for (i = 0; environ != NULL && environ[i] != NULL; i++)
1281 ;
1282 buffer_put_int(&m, i);
1283 for (i = 0; environ != NULL && environ[i] != NULL; i++)
1284 buffer_put_cstring(&m, environ[i]);
1285
1278 if (ssh_msg_send(sock, /* version */0, &m) == -1) 1286 if (ssh_msg_send(sock, /* version */0, &m) == -1)
1279 fatal("%s: msg_send", __func__); 1287 fatal("%s: msg_send", __func__);
1280 1288