diff options
author | Konstantin Tokarev <ktokarev@smartlabs.tv> | 2015-11-30 20:36:15 +0300 |
---|---|---|
committer | Konstantin Tokarev <ktokarev@smartlabs.tv> | 2015-11-30 20:36:15 +0300 |
commit | 1b69d6d6582c75a6a667d7b2513c5dce3f5504f4 (patch) | |
tree | 938356f3618d96e79f3205ae3c83f011e5a20cd7 | |
parent | f64a50f31995dc12bba316f3649e3e5f6ee64f90 (diff) |
Added OpenSSH-like -o command line option to dbclient.
Like in OpenSSH, whitespaces are ignored, key and value may be separated
by one '=' character.
For now only yes/no flag parsing is implemented.
-rw-r--r-- | cli-runopts.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/cli-runopts.c b/cli-runopts.c index e8cb313..ea178c7 100644 --- a/cli-runopts.c +++ b/cli-runopts.c @@ -46,6 +46,7 @@ static void addforward(const char* str, m_list *fwdlist); #ifdef ENABLE_CLI_NETCAT static void add_netcat(const char *str); #endif +static void add_extendedopt(const char *str); static void printhelp() { @@ -64,6 +65,7 @@ static void printhelp() { "-y Always accept remote host key if unknown\n" "-y -y Don't perform any remote host key checking (caution)\n" "-s Request a subsystem (use by external sftp)\n" + "-o option Set option in OpenSSH-like format ('-o help' to list options)\n" #ifdef ENABLE_CLI_PUBKEY_AUTH "-i <identityfile> (multiple allowed, default %s)\n" #endif @@ -106,6 +108,7 @@ void cli_getopts(int argc, char ** argv) { unsigned int i, j; char ** next = 0; enum { + OPT_EXTENDED_OPTIONS, #ifdef ENABLE_CLI_PUBKEY_AUTH OPT_AUTHKEY, #endif @@ -224,6 +227,9 @@ void cli_getopts(int argc, char ** argv) { case 's': cli_opts.is_subsystem = 1; break; + case 'o': + opt = OPT_EXTENDED_OPTIONS; + break; #ifdef ENABLE_CLI_LOCALTCPFWD case 'L': opt = OPT_LOCALTCPFWD; @@ -301,7 +307,6 @@ void cli_getopts(int argc, char ** argv) { print_version(); exit(EXIT_SUCCESS); break; - case 'o': case 'b': next = &dummy; default: @@ -321,6 +326,11 @@ void cli_getopts(int argc, char ** argv) { dropbear_exit("Missing argument"); } + if (opt == OPT_EXTENDED_OPTIONS) { + TRACE(("opt extended")) + add_extendedopt(&argv[i][j]); + } + else #ifdef ENABLE_CLI_PUBKEY_AUTH if (opt == OPT_AUTHKEY) { TRACE(("opt authkey")) @@ -806,3 +816,47 @@ badport: dropbear_exit("Bad TCP port in '%s'", origstr); } #endif + +static int match_extendedopt(const char** strptr, const char *optname) { + int seen_eq = 0; + int optlen = strlen(optname); + const char *str = *strptr; + + while (isspace(*str)) + ++str; + + if (strncasecmp(str, optname, optlen) != 0) + return DROPBEAR_FAILURE; + + str += optlen; + + while (isspace(*str) || (!seen_eq && *str == '=')) { + if (*str == '=') + seen_eq = 1; + ++str; + } + + *strptr = str; + return DROPBEAR_SUCCESS; +} + +static int parse_flag_value(const char *value) +{ + if (strcmp(value, "yes") == 0 || strcmp(value, "true") == 0) + return 1; + else if (strcmp(value, "no") == 0 || strcmp(value, "false") == 0) + return 0; + + dropbear_exit("Bad yes/no argument '%s'", value); +} + +static void add_extendedopt(const char* origstr) { + const char *optstr = origstr; + + if (strcmp(origstr, "help") == 0) { + dropbear_log(LOG_INFO, "No options available\n"); + exit(EXIT_SUCCESS); + } + + dropbear_exit("Bad configuration option '%s'", origstr); +} |