From 8fad25550e7b3a1976f454da7963742a3573f46a Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sun, 24 Dec 2023 13:06:35 +0200 Subject: [PATCH] cli-runopts.c: support more options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dbclient has flags that have equivalent opts: -b to -o BindAddress -i to -o IdentityFile -A to -o ForwardAgent -K to -o ServerAliveInterval Note: that in OpenSSH "-K Enables GSSAPIā€based authentication". For interoperability use the -o ServerAliveInterval. --- src/cli-runopts.c | 49 ++++++++++++++++++++++++++++++++++++++--------- src/runopts.h | 2 ++ 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/cli-runopts.c b/src/cli-runopts.c index 3e89e78b8..af72704e2 100644 --- a/src/cli-runopts.c +++ b/src/cli-runopts.c @@ -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 */ @@ -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 @@ -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; @@ -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; @@ -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"); @@ -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; } @@ -892,8 +892,15 @@ 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" + "\tServerAliveInterval\n" "\tStrictHostKeyChecking\n" #ifndef DISABLE_SYSLOG "\tUseSyslog\n" @@ -902,6 +909,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; @@ -914,11 +926,30 @@ 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 (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.no_hostkey_check = 1; diff --git a/src/runopts.h b/src/runopts.h index 411691899..6a5ae5d3c 100644 --- a/src/runopts.h +++ b/src/runopts.h @@ -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;