2
0

version.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 1995-2020 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_ERR = -1, OPT_EOF = 0, OPT_HELP,
  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. argc = opt_num_rest();
  96. if (argc != 0)
  97. goto opthelp;
  98. if (!dirty)
  99. version = 1;
  100. if (version)
  101. printf("%s (Library: %s)\n",
  102. OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
  103. if (date)
  104. printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
  105. if (platform)
  106. printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
  107. if (options) {
  108. printf("options: ");
  109. printf(" %s", BN_options());
  110. printf("\n");
  111. }
  112. if (cflags)
  113. printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
  114. if (dir)
  115. printf("%s\n", OpenSSL_version(OPENSSL_DIR));
  116. if (engdir)
  117. printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
  118. if (moddir)
  119. printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
  120. if (seed) {
  121. const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
  122. printf("Seeding source: %s\n", src ? src : "N/A");
  123. }
  124. if (cpuinfo)
  125. printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
  126. ret = 0;
  127. end:
  128. return ret;
  129. }
  130. #if defined(__TANDEM) && defined(OPENSSL_VPROC)
  131. /*
  132. * Define a VPROC function for the openssl program.
  133. * This is used by platform version identification tools.
  134. * Do not inline this procedure or make it static.
  135. */
  136. # define OPENSSL_VPROC_STRING_(x) x##_OPENSSL
  137. # define OPENSSL_VPROC_STRING(x) OPENSSL_VPROC_STRING_(x)
  138. # define OPENSSL_VPROC_FUNC OPENSSL_VPROC_STRING(OPENSSL_VPROC)
  139. void OPENSSL_VPROC_FUNC(void) {}
  140. #endif