use of -D at EscapeChar command line

Cody A Raspen cody-ssh at raspen.org
Wed May 19 06:43:50 EST 2004


Greetings,

Here's a small patch to allow adding dynamic port forwards during a 
session using the ~C command line. Local and remote port forwards are 
already supported in a similar manner, but we thought this would be useful 
as well -- hope it finds its way to the official distribution.

Best,
Cody Raspen
John Mishanski

-------------- next part --------------
diff -aur openssh-3.8.1p1-orig/clientloop.c openssh-3.8.1p1/clientloop.c
--- openssh-3.8.1p1-orig/clientloop.c	2003-12-17 00:33:11.000000000 -0500
+++ openssh-3.8.1p1/clientloop.c	2004-05-18 16:12:57.000000000 -0400
@@ -508,6 +508,7 @@
 	u_short fwd_port, fwd_host_port;
 	char buf[1024], sfwd_port[6], sfwd_host_port[6];
 	int local = 0;
+	int socks = 0;
 
 	leave_raw_mode();
 	handler = signal(SIGINT, SIG_IGN);
@@ -518,12 +519,18 @@
 		s++;
 	if (*s == 0)
 		goto out;
-	if (strlen(s) < 2 || s[0] != '-' || !(s[1] == 'L' || s[1] == 'R')) {
+	if (strlen(s) < 2 || s[0] != '-' || !(s[1] == 'L' || s[1] == 'R' || s[1] == 'D')) {
 		logit("Invalid command.");
 		goto out;
 	}
 	if (s[1] == 'L')
 		local = 1;
+
+	if (s[1] == 'D') {
+		socks = 1;
+		local = 1;
+	}
+	
 	if (!local && !compat20) {
 		logit("Not supported for SSH protocol version 1.");
 		goto out;
@@ -532,27 +539,47 @@
 	while (*s && isspace(*s))
 		s++;
 
-	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) {
-		logit("Bad forwarding specification.");
-		goto out;
-	}
-	if ((fwd_port = a2port(sfwd_port)) == 0 ||
-	    (fwd_host_port = a2port(sfwd_host_port)) == 0) {
-		logit("Bad forwarding port(s).");
-		goto out;
-	}
-	if (local) {
-		if (channel_setup_local_fwd_listener(fwd_port, buf,
-		    fwd_host_port, options.gateway_ports) < 0) {
+	if (socks){
+		if ( (sscanf(s, "%5[0-9]", sfwd_port)) != 1) {
+			logit("Bad forwarding port.");
+			goto out;
+		}
+		
+		fwd_port = a2port(sfwd_port);
+		if (channel_setup_local_fwd_listener(fwd_port, "socks",
+			0, options.gateway_ports) < 0) {
 			logit("Port forwarding failed.");
 			goto out;
 		}
-	} else
-		channel_request_remote_forwarding(fwd_port, buf,
-		    fwd_host_port);
+		
+	} else {
+		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) {
+			
+			logit("Bad forwarding specification.");
+			goto out;
+		}
+		
+		if ((fwd_port = a2port(sfwd_port)) == 0 ||
+			(fwd_host_port = a2port(sfwd_host_port)) == 0) {
+			logit("Bad forwarding port(s).");
+			goto out;
+		}
+		
+		if (local) {
+			if (channel_setup_local_fwd_listener(fwd_port, buf,
+			fwd_host_port, options.gateway_ports) < 0) {
+				logit("Port forwarding failed.");
+				goto out;
+			}
+		} else
+			channel_request_remote_forwarding(fwd_port, buf,
+			fwd_host_port);
+		
+	}
+
 	logit("Forwarding port.");
 out:
 	signal(SIGINT, handler);


More information about the openssh-unix-dev mailing list