Skip to content

Commit

Permalink
cli-runopts.c: support more options
Browse files Browse the repository at this point in the history
The dbclient has flags that have equivalent opts:

 -b to -o BindAddress
 -i to -o IdentityFile
 -A to -o ForwardAgent
 -K to -o ServerAliveInterval
 -J is same as -o ProxyCommand

Note: in the  OpenSSH "-K Enables GSSAPI‐based authentication".
For interoperability use the -o ServerAliveInterval.

Note: in the OpenSSH the -J is same a -o ProxyJump.
For interoperability use the -o ProxyCommand.
  • Loading branch information
stokito committed Dec 24, 2023
1 parent 99ea64b commit ea40869
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
59 changes: 50 additions & 9 deletions src/cli-runopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ void cli_getopts(int argc, char ** argv) {
unsigned int cmdlen;

char* recv_window_arg = NULL;
char* keepalive_arg = NULL;
char* idle_timeout_arg = NULL;
char *host_arg = NULL;
char *bind_arg = NULL;
char c;

/* see printhelp() for options */
Expand Down Expand Up @@ -171,8 +169,10 @@ void cli_getopts(int argc, char ** argv) {
#if DROPBEAR_CLI_PROXYCMD
cli_opts.proxycmd = NULL;
#endif
cli_opts.bind_arg = NULL;
cli_opts.bind_address = NULL;
cli_opts.bind_port = NULL;
cli_opts.keepalive_arg = NULL;
#ifndef DISABLE_ZLIB
opts.compress_mode = DROPBEAR_COMPRESS_ON;
#endif
Expand Down Expand Up @@ -283,7 +283,7 @@ void cli_getopts(int argc, char ** argv) {
next = &recv_window_arg;
break;
case 'K':
next = &keepalive_arg;
next = (char**)&cli_opts.keepalive_arg;
break;
case 'I':
next = &idle_timeout_arg;
Expand Down Expand Up @@ -324,7 +324,7 @@ void cli_getopts(int argc, char ** argv) {
exit(EXIT_SUCCESS);
break;
case 'b':
next = &bind_arg;
next = (char**)&cli_opts.bind_arg;
break;
case 'z':
opts.disable_ip_tos = 1;
Expand Down Expand Up @@ -434,8 +434,8 @@ void cli_getopts(int argc, char ** argv) {
cli_opts.remoteport = "22";
}

if (bind_arg) {
if (split_address_port(bind_arg,
if (cli_opts.bind_arg) {
if (split_address_port(cli_opts.bind_arg,
&cli_opts.bind_address, &cli_opts.bind_port)
== DROPBEAR_FAILURE) {
dropbear_exit("Bad -b argument");
Expand All @@ -460,10 +460,10 @@ void cli_getopts(int argc, char ** argv) {
if (recv_window_arg) {
parse_recv_window(recv_window_arg);
}
if (keepalive_arg) {
if (cli_opts.keepalive_arg) {
unsigned int val;
if (m_str_to_uint(keepalive_arg, &val) == DROPBEAR_FAILURE) {
dropbear_exit("Bad keepalive '%s'", keepalive_arg);
if (m_str_to_uint(cli_opts.keepalive_arg, &val) == DROPBEAR_FAILURE) {
dropbear_exit("Bad keepalive '%s'", cli_opts.keepalive_arg);
}
opts.keepalive_secs = val;
}
Expand Down Expand Up @@ -892,8 +892,18 @@ static void add_extendedopt(const char* origstr) {
"\tDisableTrivialAuth\n"
#if DROPBEAR_CLI_ANYTCPFWD
"\tExitOnForwardFailure\n"
#endif
#if DROPBEAR_CLI_AGENTFWD
"\tForwardAgent\n"
#endif
#if DROPBEAR_CLI_PUBKEY_AUTH
"\tIdentityFile\n"
#endif
"\tPort\n"
#if DROPBEAR_CLI_PROXYCMD
"\tProxyCommand\n"
#endif
"\tServerAliveInterval\n"
"\tStrictHostKeyChecking\n"
#ifndef DISABLE_SYSLOG
"\tUseSyslog\n"
Expand All @@ -902,6 +912,11 @@ static void add_extendedopt(const char* origstr) {
exit(EXIT_SUCCESS);
}

if (match_extendedopt(&optstr, "BindAddress") == DROPBEAR_SUCCESS) {
cli_opts.bind_arg = optstr;
return;
}

if (match_extendedopt(&optstr, "DisableTrivialAuth") == DROPBEAR_SUCCESS) {
cli_opts.disable_trivial_auth = parse_flag_value(optstr);
return;
Expand All @@ -914,11 +929,37 @@ static void add_extendedopt(const char* origstr) {
}
#endif

#if DROPBEAR_CLI_AGENTFWD
if (match_extendedopt(&optstr, "ForwardAgent") == DROPBEAR_SUCCESS) {
cli_opts.agent_fwd = parse_flag_value(optstr);
return;
}
#endif

#if DROPBEAR_CLI_PUBKEY_AUTH
if (match_extendedopt(&optstr, "IdentityFile") == DROPBEAR_SUCCESS) {
loadidentityfile(optstr, 1);
return;
}
#endif

if (match_extendedopt(&optstr, "Port") == DROPBEAR_SUCCESS) {
cli_opts.remoteport = optstr;
return;
}

#if DROPBEAR_CLI_PROXYCMD
if (match_extendedopt(&optstr, "ProxyCommand") == DROPBEAR_SUCCESS) {
cli_opts.proxycmd = (char*)optstr;
return;
}
#endif

if (match_extendedopt(&optstr, "ServerAliveInterval") == DROPBEAR_SUCCESS) {
cli_opts.keepalive_arg = optstr;
return;
}

if (match_extendedopt(&optstr, "StrictHostKeyChecking") == DROPBEAR_SUCCESS) {
if (strcmp(optstr, "accept-new") == 0) {
cli_opts.always_accept_key = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/runopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ typedef struct cli_runopts {
#if DROPBEAR_CLI_PROXYCMD
char *proxycmd;
#endif
const char *bind_arg;
char *bind_address;
char *bind_port;
const char *keepalive_arg;
} cli_runopts;

extern cli_runopts cli_opts;
Expand Down

0 comments on commit ea40869

Please sign in to comment.