Bugzilla – Attachment 2531 Details for
Bug 2336
Expose dynamic port for -R 0:... via environment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Expose remote port forwarding info for the executed command
0001-Set-environ-SSH_PORT_FORWARDING-for-the-command.patch (text/plain), 3.46 KB, created by
Sami Hartikainen
on 2015-01-26 21:45:52 AEDT
(
hide
)
Description:
Expose remote port forwarding info for the executed command
Filename:
MIME Type:
Creator:
Sami Hartikainen
Created:
2015-01-26 21:45:52 AEDT
Size:
3.46 KB
patch
obsolete
>From 76753c852a409cd26c9178928234d45cd44371b0 Mon Sep 17 00:00:00 2001 >From: Sami Hartikainen <sami.hartikainen@teleste.com> >Date: Mon, 22 Sep 2014 14:09:23 +0300 >Subject: [PATCH] Set environ SSH_PORT_FORWARDING for the command > >If (-R type) port forwarding options are specified prior to >executing the command, they are set in the command's environ >in the new SSH_PORT_FORWARDING variable. > >The format lists two values per one forwarding: > > SSH_PORT_FORWARDING=<listen_addr> <listen_port> > >Examples: > > SSH_PORT_FORWARDING=localhost 33228 localhost 33228 > SSH_PORT_FORWARDING=* 33228 * 33228 > SSH_PORT_FORWARDING=10.136.100.78 2600 > >The '*' indicates that all available interfaces are listened, while >'localhost' indicates that only the local loopback is listened. Two >listen_addr with the same port indicate that both IPv4 and 6 addresses >are listened. >--- > channels.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > channels.h | 5 +++++ > session.c | 5 +++++ > 3 files changed, 76 insertions(+) > >diff --git a/channels.c b/channels.c >index 3396758..617e3cf 100644 >--- a/channels.c >+++ b/channels.c >@@ -4264,3 +4264,69 @@ auth_request_forwarding(void) > packet_send(); > packet_write_wait(); > } >+ >+ >+/* -- forwarding info queries */ >+ >+int >+channel_rforwards_exist(void) >+{ >+ Channel *c; >+ u_int i; >+ >+ for (i = 0; i < channels_alloc; i++) { >+ c = channels[i]; >+ if (c == NULL) >+ continue; >+ switch (c->type) { >+ case SSH_CHANNEL_PORT_LISTENER: >+ case SSH_CHANNEL_RPORT_LISTENER: >+ case SSH_CHANNEL_UNIX_LISTENER: >+ case SSH_CHANNEL_RUNIX_LISTENER: >+ return 1; >+ default: >+ break; >+ } >+ } >+ >+ return 0; >+} >+ >+char * >+channel_rforwards_as_string(const struct ForwardOptions *fwd_opts) >+{ >+ Buffer buffer; >+ Channel *c; >+ char buf[1024], *cp; >+ u_int i; >+ >+ buffer_init(&buffer); >+ for (i = 0; i < channels_alloc; i++) { >+ c = channels[i]; >+ if (c == NULL) >+ continue; >+ switch (c->type) { >+ case SSH_CHANNEL_PORT_LISTENER: >+ case SSH_CHANNEL_RPORT_LISTENER: >+ case SSH_CHANNEL_UNIX_LISTENER: >+ case SSH_CHANNEL_RUNIX_LISTENER: >+ snprintf(buf, sizeof buf, >+ "%s %d ", >+ c->listening_addr != NULL ? >+ c->listening_addr : >+ (fwd_opts->gateway_ports == 3 ? "localhost" : >+ fwd_opts->gateway_ports == 2 ? >+ (c->path != NULL && *c->path != '\0' ? c->path : "*") : >+ fwd_opts->gateway_ports ? "*" : "localhost"), >+ c->listening_port); >+ buffer_append(&buffer, buf, strlen(buf)); >+ break; >+ default: >+ break; >+ } >+ } >+ buffer_append(&buffer, "\0", 1); >+ cp = xstrdup(buffer_ptr(&buffer)); >+ buffer_free(&buffer); >+ return cp; >+} >diff --git a/channels.h b/channels.h >index a000c98..effb397 100644 >--- a/channels.h >+++ b/channels.h >@@ -295,6 +295,11 @@ void deny_input_open(int, u_int32_t, void *); > > void auth_request_forwarding(void); > >+/* rforward info */ >+ >+int channel_rforwards_exist(void); >+char *channel_rforwards_as_string(const struct ForwardOptions *); >+ > /* channel close */ > > int chan_is_dead(Channel *, int); >diff --git a/session.c b/session.c >index 3e96557..48fd724 100644 >--- a/session.c >+++ b/session.c >@@ -1255,6 +1255,11 @@ do_setup_env(Session *s, const char *shell) > if (original_command) > child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND", > original_command); >+ if (channel_rforwards_exist()) { >+ char *const fwds = channel_rforwards_as_string(&options.fwd_opts); >+ child_set_env(&env, &envsize, "SSH_PORT_FORWARDING", fwds); >+ free(fwds); >+ } > > #ifdef _UNICOS > if (cray_tmpdir[0] != '\0') >-- >1.9.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 2336
: 2531