info.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2019-2021 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_COMMON,
  14. OPT_CONFIGDIR, OPT_ENGINESDIR, OPT_MODULESDIR, OPT_DSOEXT, OPT_DIRNAMESEP,
  15. OPT_LISTSEP, OPT_SEEDS, OPT_CPUSETTINGS
  16. } OPTION_CHOICE;
  17. const OPTIONS info_options[] = {
  18. OPT_SECTION("General"),
  19. {"help", OPT_HELP, '-', "Display this summary"},
  20. OPT_SECTION("Output"),
  21. {"configdir", OPT_CONFIGDIR, '-', "Default configuration file directory"},
  22. {"enginesdir", OPT_ENGINESDIR, '-', "Default engine module directory"},
  23. {"modulesdir", OPT_MODULESDIR, '-',
  24. "Default module directory (other than engine modules)"},
  25. {"dsoext", OPT_DSOEXT, '-', "Configured extension for modules"},
  26. {"dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator"},
  27. {"listsep", OPT_LISTSEP, '-', "List separator character"},
  28. {"seeds", OPT_SEEDS, '-', "Seed sources"},
  29. {"cpusettings", OPT_CPUSETTINGS, '-', "CPU settings info"},
  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. case OPT_SEEDS:
  73. type = OPENSSL_INFO_SEED_SOURCE;
  74. dirty++;
  75. break;
  76. case OPT_CPUSETTINGS:
  77. type = OPENSSL_INFO_CPU_SETTINGS;
  78. dirty++;
  79. break;
  80. }
  81. }
  82. if (!opt_check_rest_arg(NULL))
  83. goto opthelp;
  84. if (dirty > 1) {
  85. BIO_printf(bio_err, "%s: Only one item allowed\n", prog);
  86. goto opthelp;
  87. }
  88. if (dirty == 0) {
  89. BIO_printf(bio_err, "%s: No items chosen\n", prog);
  90. goto opthelp;
  91. }
  92. BIO_printf(bio_out, "%s\n", OPENSSL_info(type));
  93. ret = 0;
  94. end:
  95. return ret;
  96. }