The unified diff between revisions [22bbe895..] and [b02ba662..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'cli-runopts.c'

#
#
# patch "cli-runopts.c"
#  from [1f8cf84cdb17a77e4c71c1b8fa01aa00fb728948]
#    to [b02f7082ddf80d835eeaebf3526a52b146bfa983]
#
============================================================
--- cli-runopts.c	1f8cf84cdb17a77e4c71c1b8fa01aa00fb728948
+++ cli-runopts.c	b02f7082ddf80d835eeaebf3526a52b146bfa983
@@ -33,13 +33,16 @@ static void printhelp();
 cli_runopts cli_opts; /* GLOBAL */

 static void printhelp();
-static void parsehostname(char* userhostarg);
+static void parsehostname(const char* orighostarg);
 #ifdef ENABLE_CLI_PUBKEY_AUTH
 static void loadidentityfile(const char* filename);
 #endif
 #ifdef ENABLE_CLI_ANYTCPFWD
-static void addforward(char* str, struct TCPFwdList** fwdlist);
+static void addforward(const char* str, struct TCPFwdList** fwdlist);
 #endif
+#ifdef ENABLE_CLI_NETCAT
+static void add_netcat(const char *str);
+#endif

 static void printhelp() {

@@ -65,6 +68,9 @@ static void printhelp() {
 #endif
 					"-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"
 					"-K <keepalive>  (0 is never, default %d)\n"
+#ifdef ENABLE_CLI_NETCAT
+					"-B <endhost:endport> Netcat-alike bouncing\n"
+#endif
 #ifdef DEBUG_TRACE
 					"-v    verbose\n"
 #endif
@@ -87,6 +93,9 @@ void cli_getopts(int argc, char ** argv)
 #ifdef ENABLE_CLI_REMOTETCPFWD
 	int nextisremote = 0;
 #endif
+#ifdef ENABLE_CLI_NETCAT
+	int nextisnetcat = 0;
+#endif
 	char* dummy = NULL; /* Not used for anything real */

 	char* recv_window_arg = NULL;
@@ -144,6 +153,14 @@ void cli_getopts(int argc, char ** argv)
 			continue;
 		}
 #endif
+#ifdef ENABLE_CLI_NETCAT
+		if (nextisnetcat) {
+			TRACE(("nextisnetcat true"))
+			add_netcat(argv[i]);
+			nextisnetcat = 0;
+			continue;
+		}
+#endif
 		if (next) {
 			/* The previous flag set a value to assign */
 			*next = argv[i];
@@ -199,6 +216,11 @@ void cli_getopts(int argc, char ** argv)
 					nextisremote = 1;
 					break;
 #endif
+#ifdef ENABLE_CLI_NETCAT
+				case 'B':
+					nextisnetcat = 1;
+					break;
+#endif
 				case 'l':
 					next = &cli_opts.username;
 					break;
@@ -351,15 +373,13 @@ static void loadidentityfile(const char*
 #endif


-/* Parses a [user@]hostname argument. userhostarg is the argv[i] corresponding
- * - note that it will be modified */
-static void parsehostname(char* orighostarg) {
+/* Parses a [user@]hostname argument. orighostarg is the argv[i] corresponding */
+static void parsehostname(const char* orighostarg) {

 	uid_t uid;
 	struct passwd *pw = NULL;
 	char *userhostarg = NULL;

-	/* We probably don't want to be editing argvs */
 	userhostarg = m_strdup(orighostarg);

 	cli_opts.remotehost = strchr(userhostarg, '@');
@@ -389,10 +409,48 @@ static void parsehostname(char* orighost
 	}
 }

+#ifdef ENABLE_CLI_NETCAT
+static void add_netcat(const char* origstr) {
+	char *portstr = NULL;
+
+	char * str = m_strdup(origstr);
+
+	portstr = strchr(str, ':');
+	if (portstr == NULL) {
+		TRACE(("No netcat port"))
+		goto fail;
+	}
+	*portstr = '\0';
+	portstr++;
+
+	if (strchr(portstr, ':')) {
+		TRACE(("Multiple netcat colons"))
+		goto fail;
+	}
+
+	cli_opts.netcat_port = strtoul(portstr, NULL, 10);
+	if (errno != 0) {
+		TRACE(("bad netcat port"))
+		goto fail;
+	}
+
+	if (cli_opts.netcat_port > 65535) {
+		TRACE(("too large netcat port"))
+		goto fail;
+	}
+
+	cli_opts.netcat_host = str;
+	return;
+
+fail:
+	dropbear_exit("Bad netcat endpoint '%s'", origstr);
+}
+#endif
+
 #ifdef ENABLE_CLI_ANYTCPFWD
 /* Turn a "listenport:remoteaddr:remoteport" string into into a forwarding
  * set, and add it to the forwarding list */
-static void addforward(char* origstr, struct TCPFwdList** fwdlist) {
+static void addforward(const char* origstr, struct TCPFwdList** fwdlist) {

 	char * listenport = NULL;
 	char * connectport = NULL;
@@ -428,13 +486,13 @@ static void addforward(char* origstr, st

 	/* Now we check the ports - note that the port ints are unsigned,
 	 * the check later only checks for >= MAX_PORT */
-	newfwd->listenport = strtol(listenport, NULL, 10);
+	newfwd->listenport = strtoul(listenport, NULL, 10);
 	if (errno != 0) {
 		TRACE(("bad listenport strtol"))
 		goto fail;
 	}

-	newfwd->connectport = strtol(connectport, NULL, 10);
+	newfwd->connectport = strtoul(connectport, NULL, 10);
 	if (errno != 0) {
 		TRACE(("bad connectport strtol"))
 		goto fail;