- Allow specifying a port with host/port.

- Rearrange multihop hostname parsing

--HG--
extra : convert_revision : 0594a6cbca9edc235c325e02dc927060c4324741
This commit is contained in:
Matt Johnston 2008-09-18 16:01:59 +00:00
parent bece6ddcc2
commit d981ff2c8d

View File

@ -33,7 +33,8 @@
cli_runopts cli_opts; /* GLOBAL */ cli_runopts cli_opts; /* GLOBAL */
static void printhelp(); static void printhelp();
static void parsehostname(const char* orighostarg, const char* argv0); static void parse_hostname(const char* orighostarg);
static void parse_multihop_hostname(const char* orighostarg, const char* argv0);
static void fill_own_user(); static void fill_own_user();
#ifdef ENABLE_CLI_PUBKEY_AUTH #ifdef ENABLE_CLI_PUBKEY_AUTH
static void loadidentityfile(const char* filename); static void loadidentityfile(const char* filename);
@ -48,7 +49,7 @@ static void add_netcat(const char *str);
static void printhelp() { static void printhelp() {
fprintf(stderr, "Dropbear client v%s\n" fprintf(stderr, "Dropbear client v%s\n"
"Usage: %s [options] [user@]host [command]\n" "Usage: %s [options] [user@]host[/port] [command]\n"
"Options are:\n" "Options are:\n"
"-p <remoteport>\n" "-p <remoteport>\n"
"-l <username>\n" "-l <username>\n"
@ -290,9 +291,11 @@ void cli_getopts(int argc, char ** argv) {
/* Either the hostname or commands */ /* Either the hostname or commands */
if (cli_opts.remotehost == NULL) { if (cli_opts.remotehost == NULL) {
#ifdef ENABLE_CLI_MULTIHOP
parsehostname(argv[i], argv[0]); parse_multihop_hostname(argv[i], argv[0]);
#else
parse_hostname(argv[i]);
#endif
} else { } else {
/* this is part of the commands to send - after this we /* this is part of the commands to send - after this we
@ -393,7 +396,8 @@ static void loadidentityfile(const char* filename) {
#ifdef ENABLE_CLI_MULTIHOP #ifdef ENABLE_CLI_MULTIHOP
/* Sets up 'onion-forwarding' connections. /* Sets up 'onion-forwarding' connections. This will spawn
* a separate dbclient process for each hop.
* As an example, if the cmdline is * As an example, if the cmdline is
* dbclient wrt,madako,canyons * dbclient wrt,madako,canyons
* then we want to run: * then we want to run:
@ -401,8 +405,10 @@ static void loadidentityfile(const char* filename) {
* and then the inner dbclient will recursively run: * and then the inner dbclient will recursively run:
* dbclient -J "dbclient -B madako:22 wrt" madako * dbclient -J "dbclient -B madako:22 wrt" madako
* etc for as many hosts as we want. * etc for as many hosts as we want.
*
* Ports for hosts can be specified as host/port.
*/ */
static void parsehostname(const char* orighostarg, const char* argv0) { static void parse_multihop_hostname(const char* orighostarg, const char* argv0) {
char *userhostarg = NULL; char *userhostarg = NULL;
char *last_hop = NULL;; char *last_hop = NULL;;
char *remainder = NULL; char *remainder = NULL;
@ -420,24 +426,7 @@ static void parsehostname(const char* orighostarg, const char* argv0) {
userhostarg = last_hop; userhostarg = last_hop;
} }
cli_opts.remotehost = strchr(userhostarg, '@'); parse_hostname(userhostarg);
if (cli_opts.remotehost == NULL) {
/* no username portion, the cli-auth.c code can figure the
* local user's name */
cli_opts.remotehost = userhostarg;
} else {
cli_opts.remotehost[0] = '\0'; /* Split the user/host */
cli_opts.remotehost++;
cli_opts.username = userhostarg;
}
if (cli_opts.username == NULL) {
cli_opts.username = m_strdup(cli_opts.own_user);
}
if (cli_opts.remotehost[0] == '\0') {
dropbear_exit("Bad hostname");
}
if (last_hop) { if (last_hop) {
/* Set up the proxycmd */ /* Set up the proxycmd */
@ -454,15 +443,14 @@ static void parsehostname(const char* orighostarg, const char* argv0) {
cli_opts.proxycmd = m_malloc(cmd_len); cli_opts.proxycmd = m_malloc(cmd_len);
snprintf(cli_opts.proxycmd, cmd_len, "%s -B %s:%s %s", snprintf(cli_opts.proxycmd, cmd_len, "%s -B %s:%s %s",
argv0, cli_opts.remotehost, cli_opts.remoteport, remainder); argv0, cli_opts.remotehost, cli_opts.remoteport, remainder);
dropbear_log(LOG_INFO, "proxycmd: '%s'", cli_opts.proxycmd);
} }
} }
#endif /* !ENABLE_CLI_MULTIHOP */
#else /* !ENABLE_CLI_MULTIHOP */ /* Parses a [user@]hostname[/port] argument. */
static void parse_hostname(const char* orighostarg) {
/* Parses a [user@]hostname argument. orighostarg is the argv[i] corresponding */
static void parsehostname(const char* orighostarg, const char* argv0) {
char *userhostarg = NULL; char *userhostarg = NULL;
char *port = NULL;
userhostarg = m_strdup(orighostarg); userhostarg = m_strdup(orighostarg);
@ -481,13 +469,17 @@ static void parsehostname(const char* orighostarg, const char* argv0) {
cli_opts.username = m_strdup(cli_opts.own_user); cli_opts.username = m_strdup(cli_opts.own_user);
} }
port = strchr(cli_opts.remotehost, '/');
if (port) {
*port = '\0';
cli_opts.remoteport = port+1;
}
if (cli_opts.remotehost[0] == '\0') { if (cli_opts.remotehost[0] == '\0') {
dropbear_exit("Bad hostname"); dropbear_exit("Bad hostname");
} }
} }
#endif /* !ENABLE_CLI_MULTIHOP */
#ifdef ENABLE_CLI_NETCAT #ifdef ENABLE_CLI_NETCAT
static void add_netcat(const char* origstr) { static void add_netcat(const char* origstr) {
char *portstr = NULL; char *portstr = NULL;