Patch to allow local port forwarding from an existing connection

Markus Friedl markus at openbsd.org
Sat Sep 22 01:53:58 EST 2001


i thought about read_passphrase:


Index: clientloop.c
===================================================================
RCS file: /home/markus/cvs/ssh/clientloop.c,v
retrieving revision 1.82
diff -u -r1.82 clientloop.c
--- clientloop.c	2001/09/17 20:52:47	1.82
+++ clientloop.c	2001/09/21 11:56:04
@@ -81,6 +81,7 @@
 #include "atomicio.h"
 #include "sshtty.h"
 #include "misc.h"
+#include "readpass.h"
 
 /* import options */
 extern Options options;
@@ -467,6 +468,68 @@
 	}
 }
 
+static void
+process_cmdline(Buffer *xbin, Buffer *xbout, Buffer *xberr)
+{
+	u_short fwd_port, fwd_host_port;
+	char buf[1024], sfwd_port[6], sfwd_host_port[6];
+	char *s, *cmd;
+	int n, local = 0;
+
+	leave_raw_mode();
+
+	cmd = s = read_passphrase("\r\n> ", RP_ECHO);
+	if (s == NULL)
+		goto out;
+	while (*s && isspace(*s))
+		s++;
+	if (*s == 0)
+		goto out;
+	if (strlen(s) < 2 || s[0] != '-' || !(s[1] == 'L' || s[1] == 'R')) {
+		log("Invalid command");
+		goto out;
+	}
+	if (s[1] == 'L') {
+		local = 1;
+	}
+	if (!local && !compat20) {
+		log("Not supported for SSH protocol version 1");
+		goto out;
+	}
+	s += 2;
+	while (*s && isspace(*s))
+		s++;
+	if (*s == 0)
+		goto out;
+	if (sscanf(s, "%5[0-9]:%255[^:]:%5[0-9]", sfwd_port, buf, sfwd_host_port)
+	    != 3 &&
+	    sscanf(s, "%5[0-9]/%255[^/]/%5[0-9]", sfwd_port, buf, sfwd_host_port)
+	    != 3) {
+		log("Bad forwarding specification");
+		goto out;
+	}
+	if ((fwd_port = a2port(sfwd_port)) == 0 ||
+	    (fwd_host_port = a2port(sfwd_host_port)) == 0) {
+		log("Bad forwarding port(s)");
+		goto out;
+	}
+	if (local) {
+		n = channel_request_local_forwarding(fwd_port, buf,
+		    fwd_host_port, options.gateway_ports);
+		if (n <= 0) {
+			log("Port forwarding failed");
+			goto out;
+		}
+	} else {
+		channel_request_remote_forwarding(fwd_port, buf, fwd_host_port);
+	}
+	log("Forwarding port");
+out:
+	enter_raw_mode();
+	if (cmd)
+		xfree(cmd);
+}
+
 /* process the characters one by one */
 static int
 process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len)
@@ -585,6 +648,10 @@
 				s = channel_open_message();
 				buffer_append(berr, s, strlen(s));
 				xfree(s);
+				continue;
+
+			case 'c':
+				process_cmdline(bin, bout, berr);
 				continue;
 
 			default:



More information about the openssh-unix-dev mailing list