dbmulti.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /* definitions are cleanest if we just put them here */
  26. int dropbear_main(int argc, char ** argv);
  27. int cli_main(int argc, char ** argv);
  28. int dropbearkey_main(int argc, char ** argv);
  29. int dropbearconvert_main(int argc, char ** argv);
  30. int scp_main(int argc, char ** argv);
  31. static int runprog(const char *progname, int argc, char ** argv, int *match) {
  32. *match = DROPBEAR_SUCCESS;
  33. #ifdef DBMULTI_dropbear
  34. if (strcmp(progname, "dropbear") == 0) {
  35. return dropbear_main(argc, argv);
  36. }
  37. #endif
  38. #ifdef DBMULTI_dbclient
  39. if (strcmp(progname, "dbclient") == 0
  40. || strcmp(progname, "ssh") == 0) {
  41. return cli_main(argc, argv);
  42. }
  43. #endif
  44. #ifdef DBMULTI_dropbearkey
  45. if (strcmp(progname, "dropbearkey") == 0) {
  46. return dropbearkey_main(argc, argv);
  47. }
  48. #endif
  49. #ifdef DBMULTI_dropbearconvert
  50. if (strcmp(progname, "dropbearconvert") == 0) {
  51. return dropbearconvert_main(argc, argv);
  52. }
  53. #endif
  54. #ifdef DBMULTI_scp
  55. if (strcmp(progname, "scp") == 0) {
  56. return scp_main(argc, argv);
  57. }
  58. #endif
  59. *match = DROPBEAR_FAILURE;
  60. return 1;
  61. }
  62. int main(int argc, char ** argv) {
  63. int i;
  64. for (i = 0; i < 2; i++) {
  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(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. }