diff options
Diffstat (limited to 'clientloop.c')
-rw-r--r-- | clientloop.c | 38 |
1 files changed, 27 insertions, 11 deletions
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" |
62 | RCSID("$OpenBSD: clientloop.c,v 1.125 2004/06/15 05:45:04 djm Exp $"); | 62 | RCSID("$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 | ||
557 | static void | 564 | static 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 | ||
1627 | void | 1644 | void |
1628 | client_session2_setup(int id, int want_tty, int want_subsystem, | 1645 | client_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; |