diff options
author | Matt Johnston <matt@ucc.asn.au> | 2016-03-10 21:35:23 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2016-03-10 21:35:23 +0800 |
commit | d77b8db8aae43b1722a1d6da08617c67852a75e9 (patch) | |
tree | 6c82da3c6e893668db3df7450a37dc6cee2f60e0 | |
parent | 5155707216f0aafb9146e39220d1007159fe4f88 (diff) | |
download | dropbear-d77b8db8aae43b1722a1d6da08617c67852a75e9.tar.gz |
allow specifying dropbearmulti command as an argument
-rw-r--r-- | dbmulti.c | 30 |
1 files changed, 22 insertions, 8 deletions
@@ -26,17 +26,13 @@ /* definitions are cleanest if we just put them here */ int dropbear_main(int argc, char ** argv); +int cli_main(int argc, char ** argv); int dropbearkey_main(int argc, char ** argv); int dropbearconvert_main(int argc, char ** argv); int scp_main(int argc, char ** argv); -int main(int argc, char ** argv) { - - char * progname; - - if (argc > 0) { - /* figure which form we're being called as */ - progname = basename(argv[0]); +static int runprog(const char *progname, int argc, char ** argv, int *match) { + *match = DROPBEAR_SUCCESS; #ifdef DBMULTI_dropbear if (strcmp(progname, "dropbear") == 0) { @@ -64,10 +60,28 @@ int main(int argc, char ** argv) { return scp_main(argc, argv); } #endif + *match = DROPBEAR_FAILURE; + return 1; +} + +int main(int argc, char ** argv) { + int i; + for (i = 0; i < 2; i++) { + /* Try symlink first, then try as an argument eg "dropbearmulti dbclient host ..." */ + if (argc > i) { + int match, res; + /* figure which form we're being called as */ + const char* progname = basename(argv[i]); + res = runprog(progname, argc-i, &argv[i], &match); + if (match == DROPBEAR_SUCCESS) { + return res; + } + } } fprintf(stderr, "Dropbear SSH multi-purpose v%s\n" - "Make a symlink pointing at this binary with one of the following names:\n" + "Make a symlink pointing at this binary with one of the\n" + "following names or run 'dropbearmulti <command>'.\n" #ifdef DBMULTI_dropbear "'dropbear' - the Dropbear server\n" #endif |