route information
Darren Tucker
dtucker at zip.com.au
Mon Jan 21 13:39:30 EST 2008
On Mon, Jan 21, 2008 at 03:01:50AM +0100, Peter Stuge wrote:
> On Mon, Jan 21, 2008 at 12:02:43PM +1100, Darren Tucker wrote:
> > I have a hack that adds "portforward from stdin/out" which is
> > useful for this kind of thing as it does not require netcat on the
> > intermediate host (eg "ssh -N -L stdio:$target:$port $bouncehost").
> > The syntax is ugly but it works.
>
> What does the patch look like?
Something like this. It doesn't seem to shut down the channel cleanly
(which doesn't matter in this case) but other than that it seems to
work.
Index: channels.c
===================================================================
RCS file: /cvs/openssh/channels.c,v
retrieving revision 1.255
diff -u -p -r1.255 channels.c
--- channels.c 28 Dec 2007 15:43:51 -0000 1.255
+++ channels.c 21 Jan 2008 02:37:17 -0000
@@ -1240,8 +1240,16 @@ port_open_helper(Channel *c, char *rtype
{
int direct;
char buf[1024];
- char *remote_ipaddr = get_peer_ipaddr(c->sock);
- int remote_port = get_peer_port(c->sock);
+ char *remote_ipaddr;
+ int remote_port;
+
+ if (strcmp(c->ctype, "stdio-forward") == 0) {
+ remote_ipaddr = xstrdup("STDIO");
+ remote_port = 0;
+ } else {
+ remote_ipaddr = get_peer_ipaddr(c->sock);
+ remote_port = get_peer_port(c->sock);
+ }
direct = (strcmp(rtype, "direct-tcpip") == 0);
@@ -2341,6 +2349,29 @@ channel_set_af(int af)
}
static int
+channel_setup_stdio_fwd(const char *host_to_connect, u_short port_to_connect)
+{
+ Channel *c;
+ int in, out;
+
+ in = dup(STDIN_FILENO);
+ out = dup(STDOUT_FILENO);
+ if (in < 0 || out < 0)
+ fatal("channel_setup_stdio_fwd: dup() in/out failed");
+
+ c = channel_new("stdio-forward", SSH_CHANNEL_OPENING, in, out,
+ -1, CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT,
+ 0, "stdio-forward", 1);
+
+ strlcpy(c->path, host_to_connect, sizeof(c->path));
+ c->host_port = port_to_connect;
+ c->listening_port = 0;
+
+ port_open_helper(c, "direct-tcpip");
+ return 1;
+}
+
+static int
channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_port,
const char *host_to_connect, u_short port_to_connect, int gateway_ports)
{
@@ -2362,6 +2393,11 @@ channel_setup_fwd_listener(int type, con
error("Forward host name too long.");
return 0;
}
+
+ /* check for STDIO special case */
+ if (listen_port == 0)
+ return channel_setup_stdio_fwd(host_to_connect,
+ port_to_connect);
/*
* Determine whether or not a port forward listens to loopback,
Index: readconf.c
===================================================================
RCS file: /cvs/openssh/readconf.c,v
retrieving revision 1.141
diff -u -p -r1.141 readconf.c
--- readconf.c 1 Jan 2008 09:32:26 -0000 1.141
+++ readconf.c 21 Jan 2008 02:37:17 -0000
@@ -240,7 +240,8 @@ add_local_forward(Options *options, cons
Forward *fwd;
#ifndef NO_IPPORT_RESERVED_CONCEPT
extern uid_t original_real_uid;
- if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0)
+ if (newfwd->listen_port > 0 && newfwd->listen_port < IPPORT_RESERVED &&
+ original_real_uid != 0)
fatal("Privileged ports can only be forwarded by root.");
#endif
if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
@@ -1217,7 +1218,7 @@ fill_default_options(Options * options)
int
parse_forward(Forward *fwd, const char *fwdspec)
{
- int i;
+ int i, stdio_fwd = 0;
char *p, *cp, *fwdarg[4];
memset(fwd, '\0', sizeof(*fwd));
@@ -1239,7 +1240,10 @@ parse_forward(Forward *fwd, const char *
switch (i) {
case 3:
fwd->listen_host = NULL;
- fwd->listen_port = a2port(fwdarg[0]);
+ if (strcmp(fwdarg[0], "stdio") == 0)
+ stdio_fwd = 1;
+ else
+ fwd->listen_port = a2port(fwdarg[0]);
fwd->connect_host = xstrdup(cleanhostname(fwdarg[1]));
fwd->connect_port = a2port(fwdarg[2]);
break;
@@ -1256,7 +1260,7 @@ parse_forward(Forward *fwd, const char *
xfree(p);
- if (fwd->listen_port == 0 || fwd->connect_port == 0)
+ if ((!stdio_fwd && fwd->listen_port == 0) || fwd->connect_port == 0)
goto fail_free;
if (fwd->connect_host != NULL &&
--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69
Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.
More information about the openssh-unix-dev
mailing list