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