xref: /openssl/apps/version.c (revision 7ed6de99)
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     const char *tmp;
60 
61     prog = opt_init(argc, argv, version_options);
62     while ((o = opt_next()) != OPT_EOF) {
63         switch (o) {
64         case OPT_EOF:
65         case OPT_ERR:
66 opthelp:
67             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
68             goto end;
69         case OPT_HELP:
70             opt_help(version_options);
71             ret = 0;
72             goto end;
73         case OPT_B:
74             dirty = date = 1;
75             break;
76         case OPT_D:
77             dirty = dir = 1;
78             break;
79         case OPT_E:
80             dirty = engdir = 1;
81             break;
82         case OPT_M:
83             dirty = moddir = 1;
84             break;
85         case OPT_F:
86             dirty = cflags = 1;
87             break;
88         case OPT_O:
89             dirty = options = 1;
90             break;
91         case OPT_P:
92             dirty = platform = 1;
93             break;
94         case OPT_R:
95             dirty = seed = 1;
96             break;
97         case OPT_V:
98             dirty = version = 1;
99             break;
100         case OPT_C:
101             dirty = cpuinfo = 1;
102             break;
103 #if defined(_WIN32)
104         case OPT_W:
105             dirty = windows = 1;
106             break;
107 #endif
108         case OPT_A:
109             seed = options = cflags = version = date = platform
110                 = dir = engdir = moddir = cpuinfo
111                 = 1;
112             break;
113         }
114     }
115 
116     /* No extra arguments. */
117     if (!opt_check_rest_arg(NULL))
118         goto opthelp;
119 
120     if (!dirty)
121         version = 1;
122 
123     if (version)
124         printf("%s (Library: %s)\n",
125                OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
126     if (date)
127         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
128     if (platform)
129         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
130     if (options) {
131         printf("options: ");
132         printf(" %s", BN_options());
133         printf("\n");
134     }
135     if (cflags)
136         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
137     if (dir) {
138         tmp = OpenSSL_version(OPENSSL_DIR);
139         printf("OPENSSLDIR: %s\n", tmp == NULL ? "Undefined" : tmp);
140     }
141     if (engdir) {
142         tmp = OpenSSL_version(OPENSSL_ENGINES_DIR);
143         printf("ENGINESDIR: %s\n", tmp == NULL ? "Undefined" : tmp);
144     }
145     if (moddir) {
146         tmp = OpenSSL_version(OPENSSL_MODULES_DIR);
147         printf("MODULESDIR: %s\n", tmp == NULL ? "Undefined" : tmp);
148     }
149     if (seed) {
150         const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
151         printf("Seeding source: %s\n", src ? src : "N/A");
152     }
153     if (cpuinfo)
154         printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
155 #if defined(_WIN32)
156     if (windows)
157         printf("OSSL_WINCTX: %s\n", OpenSSL_version(OPENSSL_WINCTX));
158 #endif
159     ret = 0;
160  end:
161     return ret;
162 }
163 
164 
165 #if defined(__TANDEM) && defined(OPENSSL_VPROC)
166 /*
167  * Define a VPROC function for the openssl program.
168  * This is used by platform version identification tools.
169  * Do not inline this procedure or make it static.
170  */
171 # define OPENSSL_VPROC_STRING_(x)    x##_OPENSSL
172 # define OPENSSL_VPROC_STRING(x)     OPENSSL_VPROC_STRING_(x)
173 # define OPENSSL_VPROC_FUNC          OPENSSL_VPROC_STRING(OPENSSL_VPROC)
OPENSSL_VPROC_FUNC(void)174 void OPENSSL_VPROC_FUNC(void) {}
175 #endif
176