version.c 4.6 KB

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