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