version.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright 1995-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 <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "apps.h"
  13. #include "progs.h"
  14. #include <openssl/evp.h>
  15. #include <openssl/crypto.h>
  16. #include <openssl/bn.h>
  17. typedef enum OPTION_choice {
  18. OPT_COMMON,
  19. OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
  20. } OPTION_CHOICE;
  21. const OPTIONS version_options[] = {
  22. OPT_SECTION("General"),
  23. {"help", OPT_HELP, '-', "Display this summary"},
  24. OPT_SECTION("Output"),
  25. {"a", OPT_A, '-', "Show all data"},
  26. {"b", OPT_B, '-', "Show build date"},
  27. {"d", OPT_D, '-', "Show configuration directory"},
  28. {"e", OPT_E, '-', "Show engines directory"},
  29. {"m", OPT_M, '-', "Show modules directory"},
  30. {"f", OPT_F, '-', "Show compiler flags used"},
  31. {"o", OPT_O, '-', "Show some internal datatype options"},
  32. {"p", OPT_P, '-', "Show target build platform"},
  33. {"r", OPT_R, '-', "Show random seeding options"},
  34. {"v", OPT_V, '-', "Show library version"},
  35. {"c", OPT_C, '-', "Show CPU settings info"},
  36. {NULL}
  37. };
  38. int version_main(int argc, char **argv)
  39. {
  40. int ret = 1, dirty = 0, seed = 0;
  41. int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
  42. int engdir = 0, moddir = 0, cpuinfo = 0;
  43. char *prog;
  44. OPTION_CHOICE o;
  45. prog = opt_init(argc, argv, version_options);
  46. while ((o = opt_next()) != OPT_EOF) {
  47. switch (o) {
  48. case OPT_EOF:
  49. case OPT_ERR:
  50. opthelp:
  51. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  52. goto end;
  53. case OPT_HELP:
  54. opt_help(version_options);
  55. ret = 0;
  56. goto end;
  57. case OPT_B:
  58. dirty = date = 1;
  59. break;
  60. case OPT_D:
  61. dirty = dir = 1;
  62. break;
  63. case OPT_E:
  64. dirty = engdir = 1;
  65. break;
  66. case OPT_M:
  67. dirty = moddir = 1;
  68. break;
  69. case OPT_F:
  70. dirty = cflags = 1;
  71. break;
  72. case OPT_O:
  73. dirty = options = 1;
  74. break;
  75. case OPT_P:
  76. dirty = platform = 1;
  77. break;
  78. case OPT_R:
  79. dirty = seed = 1;
  80. break;
  81. case OPT_V:
  82. dirty = version = 1;
  83. break;
  84. case OPT_C:
  85. dirty = cpuinfo = 1;
  86. break;
  87. case OPT_A:
  88. seed = options = cflags = version = date = platform
  89. = dir = engdir = moddir = cpuinfo
  90. = 1;
  91. break;
  92. }
  93. }
  94. /* No extra arguments. */
  95. if (!opt_check_rest_arg(NULL))
  96. goto opthelp;
  97. if (!dirty)
  98. version = 1;
  99. if (version)
  100. printf("%s (Library: %s)\n",
  101. OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
  102. if (date)
  103. printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
  104. if (platform)
  105. printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
  106. if (options) {
  107. printf("options: ");
  108. printf(" %s", BN_options());
  109. printf("\n");
  110. }
  111. if (cflags)
  112. printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
  113. if (dir)
  114. printf("%s\n", OpenSSL_version(OPENSSL_DIR));
  115. if (engdir)
  116. printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
  117. if (moddir)
  118. printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
  119. if (seed) {
  120. const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
  121. printf("Seeding source: %s\n", src ? src : "N/A");
  122. }
  123. if (cpuinfo)
  124. printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
  125. ret = 0;
  126. end:
  127. return ret;
  128. }
  129. #if defined(__TANDEM) && defined(OPENSSL_VPROC)
  130. /*
  131. * Define a VPROC function for the openssl program.
  132. * This is used by platform version identification tools.
  133. * Do not inline this procedure or make it static.
  134. */
  135. # define OPENSSL_VPROC_STRING_(x) x##_OPENSSL
  136. # define OPENSSL_VPROC_STRING(x) OPENSSL_VPROC_STRING_(x)
  137. # define OPENSSL_VPROC_FUNC OPENSSL_VPROC_STRING(OPENSSL_VPROC)
  138. void OPENSSL_VPROC_FUNC(void) {}
  139. #endif