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