[PATCH] add dropbearmulti arg1 support

hhm heehooman at gmail.com
Thu Apr 11 15:26:08 WST 2013


This patch adds support for calling dropbearmulti with a program name as
its *first* parameter.

This enables use of dropbearmulti without any symlinks. The following are
examples of where this can be useful:
1) on file systems which do not support symlinks (FAT for example)
2) for convenience; needing only one file

Enjoy

=============================
diff -u a/dbmulti.c b/dbmulti.c
--- a/dbmulti.c
+++ b/dbmulti.c
@@ -33,10 +33,33 @@
 int main(int argc, char ** argv) {

  char * progname;
+#ifdef DROPBEARMULTI_ARG1
+ int arg1;
+#endif

- if (argc > 0) {
- /* figure which form we're being called as */
- progname = basename(argv[0]);
+ if (argc > 0
+#ifdef DROPBEARMULTI_ARG1
+ || argc < 0
+#endif
+ ) {
+#ifdef DROPBEARMULTI_ARG1
+ if (argc > 0) {
+ arg1 = 0;
+#endif
+ /* figure which form we're being called as */
+ progname = basename(argv[0]);
+#ifdef DROPBEARMULTI_ARG1
+ } else {
+ char buf[64];
+ arg1 = -1;
+ progname = argv[1];
+ snprintf(buf, sizeof buf, "%s %s", argv[0], progname); /* this appears in
usages, maybe should just use original argv0 if needed by a sub-program */
+ argv[1] = buf; /* new argv[0] */
+ argv += 1;
+ argc = -argc; /* restore argc to pre-signaling state */
+ argc -= 1;
+ }
+#endif

 #ifdef DBMULTI_dropbear
  if (strcmp(progname, "dropbear") == 0) {
@@ -66,8 +89,19 @@
 #endif
  }

+#ifdef DROPBEARMULTI_ARG1
+ if (!arg1 && argc > 1) { /* matched none of the prognames, has args on
cmdline */
+ argc = -argc; /* negate argc as signal */
+ return main(argc, argv);
+ }
+#endif
+
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"
+#ifdef DROPBEARMULTI_ARG1
+ ", or pass a name to it as the first parameter,"
+#endif
+ " with one of the following names:\n"
 #ifdef DBMULTI_dropbear
  "'dropbear' - the Dropbear server\n"
 #endif
diff -u a/MULTI b/MULTI
--- a/MULTI
+++ b/MULTI
@@ -21,6 +21,12 @@

 ./dropbear <options here>

+Alternatively, call dropbearmulti with the name of an executable as its
first argument (if this option was chosen):
+
+./dropbearmulti dropbear <options here>
+./dropbearmulti dbclient <options here>
+etc
+
 "make install" doesn't currently work for multi-binary configuration,
though
 in most situations where it is being used, the target and build systems
will
 differ.
diff -u a/options.h b/options.h
--- a/options.h
+++ b/options.h
@@ -14,6 +14,11 @@
 #define DROPBEAR_DEFPORT "22"
 #endif

+#ifndef DROPBEARMULTI_ARG1
+/* Dropbearmulti program invocation via argv1 */
+#define DROPBEARMULTI_ARG1
+#endif
+
 #ifndef DROPBEAR_DEFADDRESS
 /* Listen on all interfaces */
 #define DROPBEAR_DEFADDRESS ""
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ucc.gu.uwa.edu.au/pipermail/dropbear/attachments/20130411/87ecb123/attachment.htm 


More information about the Dropbear mailing list