3333cli_runopts cli_opts ; /* GLOBAL */
3434
3535static void printhelp ();
36- static void parsehostname (const char * orighostarg , const char * argv0 );
36+ static void parse_hostname (const char * orighostarg );
37+ static void parse_multihop_hostname (const char * orighostarg , const char * argv0 );
3738static void fill_own_user ();
3839#ifdef ENABLE_CLI_PUBKEY_AUTH
3940static void loadidentityfile (const char * filename );
@@ -48,7 +49,7 @@ static void add_netcat(const char *str);
4849static void printhelp () {
4950
5051 fprintf (stderr , "Dropbear client v%s\n"
51- "Usage: %s [options] [user@]host [command]\n"
52+ "Usage: %s [options] [user@]host[/port] [command]\n"
5253 "Options are:\n"
5354 "-p <remoteport>\n"
5455 "-l <username>\n"
@@ -290,9 +291,11 @@ void cli_getopts(int argc, char ** argv) {
290291 /* Either the hostname or commands */
291292
292293 if (cli_opts .remotehost == NULL ) {
293-
294- parsehostname (argv [i ], argv [0 ]);
295-
294+ #ifdef ENABLE_CLI_MULTIHOP
295+ parse_multihop_hostname (argv [i ], argv [0 ]);
296+ #else
297+ parse_hostname (argv [i ]);
298+ #endif
296299 } else {
297300
298301 /* this is part of the commands to send - after this we
@@ -393,16 +396,19 @@ static void loadidentityfile(const char* filename) {
393396
394397#ifdef ENABLE_CLI_MULTIHOP
395398
396- /* Sets up 'onion-forwarding' connections.
399+ /* Sets up 'onion-forwarding' connections. This will spawn
400+ * a separate dbclient process for each hop.
397401 * As an example, if the cmdline is
398402 * dbclient wrt,madako,canyons
399403 * then we want to run:
400404 * dbclient -J "dbclient -B canyons:22 wrt,madako" canyons
401405 * and then the inner dbclient will recursively run:
402406 * dbclient -J "dbclient -B madako:22 wrt" madako
403407 * etc for as many hosts as we want.
408+ *
409+ * Ports for hosts can be specified as host/port.
404410 */
405- static void parsehostname (const char * orighostarg , const char * argv0 ) {
411+ static void parse_multihop_hostname (const char * orighostarg , const char * argv0 ) {
406412 char * userhostarg = NULL ;
407413 char * last_hop = NULL ;;
408414 char * remainder = NULL ;
@@ -420,24 +426,7 @@ static void parsehostname(const char* orighostarg, const char* argv0) {
420426 userhostarg = last_hop ;
421427 }
422428
423- cli_opts .remotehost = strchr (userhostarg , '@' );
424- if (cli_opts .remotehost == NULL ) {
425- /* no username portion, the cli-auth.c code can figure the
426- * local user's name */
427- cli_opts .remotehost = userhostarg ;
428- } else {
429- cli_opts .remotehost [0 ] = '\0' ; /* Split the user/host */
430- cli_opts .remotehost ++ ;
431- cli_opts .username = userhostarg ;
432- }
433-
434- if (cli_opts .username == NULL ) {
435- cli_opts .username = m_strdup (cli_opts .own_user );
436- }
437-
438- if (cli_opts .remotehost [0 ] == '\0' ) {
439- dropbear_exit ("Bad hostname" );
440- }
429+ parse_hostname (userhostarg );
441430
442431 if (last_hop ) {
443432 /* Set up the proxycmd */
@@ -454,15 +443,14 @@ static void parsehostname(const char* orighostarg, const char* argv0) {
454443 cli_opts .proxycmd = m_malloc (cmd_len );
455444 snprintf (cli_opts .proxycmd , cmd_len , "%s -B %s:%s %s" ,
456445 argv0 , cli_opts .remotehost , cli_opts .remoteport , remainder );
457- dropbear_log (LOG_INFO , "proxycmd: '%s'" , cli_opts .proxycmd );
458446 }
459447}
448+ #endif /* !ENABLE_CLI_MULTIHOP */
460449
461- #else /* !ENABLE_CLI_MULTIHOP */
462-
463- /* Parses a [user@]hostname argument. orighostarg is the argv[i] corresponding */
464- static void parsehostname (const char * orighostarg , const char * argv0 ) {
450+ /* Parses a [user@]hostname[/port] argument. */
451+ static void parse_hostname (const char * orighostarg ) {
465452 char * userhostarg = NULL ;
453+ char * port = NULL ;
466454
467455 userhostarg = m_strdup (orighostarg );
468456
@@ -481,13 +469,17 @@ static void parsehostname(const char* orighostarg, const char* argv0) {
481469 cli_opts .username = m_strdup (cli_opts .own_user );
482470 }
483471
472+ port = strchr (cli_opts .remotehost , '/' );
473+ if (port ) {
474+ * port = '\0' ;
475+ cli_opts .remoteport = port + 1 ;
476+ }
477+
484478 if (cli_opts .remotehost [0 ] == '\0' ) {
485479 dropbear_exit ("Bad hostname" );
486480 }
487481}
488482
489- #endif /* !ENABLE_CLI_MULTIHOP */
490-
491483#ifdef ENABLE_CLI_NETCAT
492484static void add_netcat (const char * origstr ) {
493485 char * portstr = NULL ;
0 commit comments