2
0

info.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/crypto.h>
  10. #include "apps.h"
  11. #include "progs.h"
  12. typedef enum OPTION_choice {
  13. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
  14. OPT_CONFIGDIR, OPT_ENGINESDIR, OPT_MODULESDIR, OPT_DSOEXT, OPT_DIRNAMESEP,
  15. OPT_LISTSEP
  16. } OPTION_CHOICE;
  17. const OPTIONS info_options[] = {
  18. {"help", OPT_HELP, '-', "Display this summary"},
  19. {"configdir", OPT_CONFIGDIR, '-', "Default configuration file directory"},
  20. {"c", OPT_CONFIGDIR, '-', "Default configuration file directory"},
  21. {"enginesdir", OPT_ENGINESDIR, '-', "Default engine module directory"},
  22. {"e", OPT_ENGINESDIR, '-', "Default engine module directory"},
  23. {"modulesdir", OPT_ENGINESDIR, '-',
  24. "Default module directory (other than engine modules)"},
  25. {"m", OPT_ENGINESDIR, '-',
  26. "Default module directory (other than engine modules)"},
  27. {"dsoext", OPT_DSOEXT, '-', "Configured extension for modules"},
  28. {"dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator"},
  29. {"listsep", OPT_LISTSEP, '-', "List separator character"},
  30. {NULL}
  31. };
  32. int info_main(int argc, char **argv)
  33. {
  34. int ret = 1, dirty = 0, type = 0;
  35. char *prog;
  36. OPTION_CHOICE o;
  37. prog = opt_init(argc, argv, info_options);
  38. while ((o = opt_next()) != OPT_EOF) {
  39. switch (o) {
  40. default:
  41. opthelp:
  42. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  43. goto end;
  44. case OPT_HELP:
  45. opt_help(info_options);
  46. ret = 0;
  47. goto end;
  48. case OPT_CONFIGDIR:
  49. type = OPENSSL_INFO_CONFIG_DIR;
  50. dirty++;
  51. break;
  52. case OPT_ENGINESDIR:
  53. type = OPENSSL_INFO_ENGINES_DIR;
  54. dirty++;
  55. break;
  56. case OPT_MODULESDIR:
  57. type = OPENSSL_INFO_MODULES_DIR;
  58. dirty++;
  59. break;
  60. case OPT_DSOEXT:
  61. type = OPENSSL_INFO_DSO_EXTENSION;
  62. dirty++;
  63. break;
  64. case OPT_DIRNAMESEP:
  65. type = OPENSSL_INFO_DIR_FILENAME_SEPARATOR;
  66. dirty++;
  67. break;
  68. case OPT_LISTSEP:
  69. type = OPENSSL_INFO_LIST_SEPARATOR;
  70. dirty++;
  71. break;
  72. }
  73. }
  74. if (opt_num_rest() != 0) {
  75. BIO_printf(bio_err, "%s: Extra parameters given.\n", prog);
  76. goto opthelp;
  77. }
  78. if (dirty > 1) {
  79. BIO_printf(bio_err, "%s: Only one item allowed\n", prog);
  80. goto opthelp;
  81. }
  82. if (dirty == 0) {
  83. BIO_printf(bio_err, "%s: No items chosen\n", prog);
  84. goto opthelp;
  85. }
  86. BIO_printf(bio_out, "%s\n", OPENSSL_info(type));
  87. ret = 0;
  88. end:
  89. return ret;
  90. }