dbmulti.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Dropbear SSH
  3. *
  4. * Copyright (c) 2002,2003 Matt Johnston
  5. * All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE. */
  24. #include "includes.h"
  25. #include "dbutil.h"
  26. static int runprog(const char *multipath,
  27. const char *progname, int argc, char ** argv, int *match) {
  28. *match = DROPBEAR_SUCCESS;
  29. #ifdef DBMULTI_dropbear
  30. if (strcmp(progname, "dropbear") == 0) {
  31. return dropbear_main(argc, argv, multipath);
  32. }
  33. #endif
  34. #ifdef DBMULTI_dbclient
  35. if (strcmp(progname, "dbclient") == 0
  36. || strcmp(progname, "ssh") == 0) {
  37. return cli_main(argc, argv);
  38. }
  39. #endif
  40. #ifdef DBMULTI_dropbearkey
  41. if (strcmp(progname, "dropbearkey") == 0) {
  42. return dropbearkey_main(argc, argv);
  43. }
  44. #endif
  45. #ifdef DBMULTI_dropbearconvert
  46. if (strcmp(progname, "dropbearconvert") == 0) {
  47. return dropbearconvert_main(argc, argv);
  48. }
  49. #endif
  50. #ifdef DBMULTI_scp
  51. if (strcmp(progname, "scp") == 0) {
  52. return scp_main(argc, argv);
  53. }
  54. #endif
  55. *match = DROPBEAR_FAILURE;
  56. return 1;
  57. }
  58. int main(int argc, char ** argv) {
  59. int i;
  60. for (i = 0; i < 2; i++) {
  61. const char* multipath = NULL;
  62. if (i == 1) {
  63. multipath = argv[0];
  64. }
  65. /* Try symlink first, then try as an argument eg "dropbearmulti dbclient host ..." */
  66. if (argc > i) {
  67. int match, res;
  68. /* figure which form we're being called as */
  69. const char* progname = basename(argv[i]);
  70. res = runprog(multipath, progname, argc-i, &argv[i], &match);
  71. if (match == DROPBEAR_SUCCESS) {
  72. return res;
  73. }
  74. }
  75. }
  76. fprintf(stderr, "Dropbear SSH multi-purpose v%s\n"
  77. "Make a symlink pointing at this binary with one of the\n"
  78. "following names or run 'dropbearmulti <command>'.\n"
  79. #ifdef DBMULTI_dropbear
  80. "'dropbear' - the Dropbear server\n"
  81. #endif
  82. #ifdef DBMULTI_dbclient
  83. "'dbclient' or 'ssh' - the Dropbear client\n"
  84. #endif
  85. #ifdef DBMULTI_dropbearkey
  86. "'dropbearkey' - the key generator\n"
  87. #endif
  88. #ifdef DBMULTI_dropbearconvert
  89. "'dropbearconvert' - the key converter\n"
  90. #endif
  91. #ifdef DBMULTI_scp
  92. "'scp' - secure copy\n"
  93. #endif
  94. ,
  95. DROPBEAR_VERSION);
  96. exit(1);
  97. }