Fix grammar in srp_verifier.txt
[openssl.git] / apps / version.c
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     if (!opt_check_rest_arg(NULL))
103         goto opthelp;
104
105     if (!dirty)
106         version = 1;
107
108     if (version)
109         printf("%s (Library: %s)\n",
110                OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
111     if (date)
112         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
113     if (platform)
114         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
115     if (options) {
116         printf("options: ");
117         printf(" %s", BN_options());
118         printf("\n");
119     }
120     if (cflags)
121         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
122     if (dir)
123         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
124     if (engdir)
125         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
126     if (moddir)
127         printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
128     if (seed) {
129         const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
130         printf("Seeding source: %s\n", src ? src : "N/A");
131     }
132     if (cpuinfo)
133         printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
134     ret = 0;
135  end:
136     return ret;
137 }
138
139
140 #if defined(__TANDEM) && defined(OPENSSL_VPROC)
141 /*
142  * Define a VPROC function for the openssl program.
143  * This is used by platform version identification tools.
144  * Do not inline this procedure or make it static.
145  */
146 # define OPENSSL_VPROC_STRING_(x)    x##_OPENSSL
147 # define OPENSSL_VPROC_STRING(x)     OPENSSL_VPROC_STRING_(x)
148 # define OPENSSL_VPROC_FUNC          OPENSSL_VPROC_STRING(OPENSSL_VPROC)
149 void OPENSSL_VPROC_FUNC(void) {}
150 #endif