comparison dbmulti.c @ 1235:11f645c3715b

allow specifying dropbearmulti command as an argument
author Matt Johnston <matt@ucc.asn.au>
date Thu, 10 Mar 2016 21:35:23 +0800
parents af4ef98b8591
children 0dcc5b0d93fa
comparison
equal deleted inserted replaced
1234:32cdbbe4b67e 1235:11f645c3715b
24 24
25 #include "includes.h" 25 #include "includes.h"
26 26
27 /* definitions are cleanest if we just put them here */ 27 /* definitions are cleanest if we just put them here */
28 int dropbear_main(int argc, char ** argv); 28 int dropbear_main(int argc, char ** argv);
29 int cli_main(int argc, char ** argv);
29 int dropbearkey_main(int argc, char ** argv); 30 int dropbearkey_main(int argc, char ** argv);
30 int dropbearconvert_main(int argc, char ** argv); 31 int dropbearconvert_main(int argc, char ** argv);
31 int scp_main(int argc, char ** argv); 32 int scp_main(int argc, char ** argv);
32 33
33 int main(int argc, char ** argv) { 34 static int runprog(const char *progname, int argc, char ** argv, int *match) {
34 35 *match = DROPBEAR_SUCCESS;
35 char * progname;
36
37 if (argc > 0) {
38 /* figure which form we're being called as */
39 progname = basename(argv[0]);
40 36
41 #ifdef DBMULTI_dropbear 37 #ifdef DBMULTI_dropbear
42 if (strcmp(progname, "dropbear") == 0) { 38 if (strcmp(progname, "dropbear") == 0) {
43 return dropbear_main(argc, argv); 39 return dropbear_main(argc, argv);
44 } 40 }
62 #ifdef DBMULTI_scp 58 #ifdef DBMULTI_scp
63 if (strcmp(progname, "scp") == 0) { 59 if (strcmp(progname, "scp") == 0) {
64 return scp_main(argc, argv); 60 return scp_main(argc, argv);
65 } 61 }
66 #endif 62 #endif
63 *match = DROPBEAR_FAILURE;
64 return 1;
65 }
66
67 int main(int argc, char ** argv) {
68 int i;
69 for (i = 0; i < 2; i++) {
70 /* Try symlink first, then try as an argument eg "dropbearmulti dbclient host ..." */
71 if (argc > i) {
72 int match, res;
73 /* figure which form we're being called as */
74 const char* progname = basename(argv[i]);
75 res = runprog(progname, argc-i, &argv[i], &match);
76 if (match == DROPBEAR_SUCCESS) {
77 return res;
78 }
79 }
67 } 80 }
68 81
69 fprintf(stderr, "Dropbear SSH multi-purpose v%s\n" 82 fprintf(stderr, "Dropbear SSH multi-purpose v%s\n"
70 "Make a symlink pointing at this binary with one of the following names:\n" 83 "Make a symlink pointing at this binary with one of the\n"
84 "following names or run 'dropbearmulti <command>'.\n"
71 #ifdef DBMULTI_dropbear 85 #ifdef DBMULTI_dropbear
72 "'dropbear' - the Dropbear server\n" 86 "'dropbear' - the Dropbear server\n"
73 #endif 87 #endif
74 #ifdef DBMULTI_dbclient 88 #ifdef DBMULTI_dbclient
75 "'dbclient' or 'ssh' - the Dropbear client\n" 89 "'dbclient' or 'ssh' - the Dropbear client\n"