Subject: [PATCH 1/2] Proxy over localhost, attempt II.

From: "Steffen (Daode) Nurpmeso" <[email-masked]>
Date: Thu, 20 Feb 2014 10:35:15 +0100

---
 cli-main.c    | 6 ++++--
 cli-runopts.c | 6 ++++++
 dbclient.1    | 6 ++++++
 runopts.h     | 1 +
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/cli-main.c b/cli-main.c
index 713cb09..bf75fd8 100644
--- a/cli-main.c
+++ b/cli-main.c
@@ -86,8 +86,10 @@ int main(int argc, char ** argv) {
 	} else
 #endif
 	{
-		progress = connect_remote(cli_opts.remotehost, cli_opts.remoteport, 
-			cli_connected, &ses, cli_opts.bind_address, cli_opts.bind_port);
+		progress = connect_remote((cli_opts.proxy_over_localhost
+				? "localhost" : cli_opts.remotehost),
+				cli_opts.remoteport, cli_connected, &ses,
+				cli_opts.bind_address, cli_opts.bind_port);
 		sock_in = sock_out = -1;
 	}
 
diff --git a/cli-runopts.c b/cli-runopts.c
index abcfc9f..26d1f22 100644
--- a/cli-runopts.c
+++ b/cli-runopts.c
@@ -57,6 +57,7 @@ static void printhelp() {
 					"Usage: %s [options] [user@]host[/port] [command]\n"
 #endif
 					"-p <remoteport>\n"
+					"-Y <port> Connect to localhost:port, authenticate as [user@]host\n"
 					"-l <username>\n"
 					"-t    Allocate a pty\n"
 					"-T    Don't allocate a pty\n"
@@ -213,6 +214,9 @@ void cli_getopts(int argc, char ** argv) {
 					}
 					cli_opts.always_accept_key = 1;
 					break;
+				case 'Y': /* "local-remoteport" */
+					cli_opts.proxy_over_localhost = 1;
+					/* FALLTRHU */
 				case 'p': /* remoteport */
 					next = &cli_opts.remoteport;
 					break;
@@ -681,6 +685,8 @@ static void parse_hostname(const char* orighostarg) {
 		port = strchr(cli_opts.remotehost, '/');
 	}
 	if (port) {
+		if (cli_opts.proxy_over_localhost)
+			dropbear_exit("-Y mutually exclusive with ^port");
 		*port = '\0';
 		cli_opts.remoteport = port+1;
 	}
diff --git a/dbclient.1 b/dbclient.1
index 1516e7c..6375895 100644
--- a/dbclient.1
+++ b/dbclient.1
@@ -4,6 +4,7 @@ dbclient \- lightweight SSH client
 .SH SYNOPSIS
 .B dbclient
 [\fIflag arguments\fR] [\-p
+.I port\fR] [\-Y
 .I port\fR] [\-i
 .I id\fR] [\-L
 .I l\fR:\fIh\fR:\fIp\fR] [\-R
@@ -35,6 +36,11 @@ Connect to
 on the remote host. Alternatively a port can be specified as hostname^port.
 Default is 22.
 .TP
+.B \-Y \fIport
+Connect to
+.I port
+on localhost, but use the given hostname for key comparison purposes.
+.TP
 .B \-i \fIidfile
 Identity file.
 Read the identity key from file
diff --git a/runopts.h b/runopts.h
index 3123383..cb00350 100644
--- a/runopts.h
+++ b/runopts.h
@@ -145,6 +145,7 @@ typedef struct cli_runopts {
 	int wantpty;
 	int always_accept_key;
 	int no_hostkey_check;
+	int proxy_over_localhost;
 	int no_cmd;
 	int backgrounded;
 	int is_subsystem;
-- 
2.16.2

---

From: "Steffen (Daode) Nurpmeso" <[email-masked]>
Date: Wed, 19 Feb 2014 20:54:05 +0100

---
 scp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/scp.c b/scp.c
index 742ae00..7a5c293 100644
--- a/scp.c
+++ b/scp.c
@@ -326,7 +326,7 @@ main(int argc, char **argv)
 	addargs(&args, "%s", ssh_program);
 
 	fflag = tflag = 0;
-	while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q1246S:o:F:")) != -1)
+	while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:Y:q1246S:o:F:")) != -1)
 		switch (ch) {
 		/* User-visible flags. */
 		case '1':
@@ -345,6 +345,9 @@ main(int argc, char **argv)
 		case 'P':
 			addargs(&args, "-p%s", optarg);
 			break;
+		case 'Y':
+			addargs(&args, "-Y%s", optarg);
+			break;
 		case 'B':
 			fprintf(stderr, "Note: -B option is disabled in this version of scp");
 			break;
@@ -1145,7 +1148,7 @@ usage(void)
 {
 	(void) fprintf(stderr,
 	    "usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]\n"
-	    "           [-l limit] [-P port] [-S program]\n"
+	    "           [-l limit] [-P port] [-Y port] [-S program]\n"
 	    "           [[user@]host1:]file1 [...] [[user@]host2:]file2\n");
 	exit(1);
 }
-- 
2.16.2