xref: /netbsd-src/crypto/external/bsd/openssl/dist/apps/version.c (revision b0d1725196a7921d003d2c66a14f186abda4176b)
1c7da899bSchristos /*
2*b0d17251Schristos  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
3a89c9211Schristos  *
4*b0d17251Schristos  * Licensed under the Apache License 2.0 (the "License").  You may not use
5c7da899bSchristos  * this file except in compliance with the License.  You can obtain a copy
6c7da899bSchristos  * in the file LICENSE in the source distribution or at
7c7da899bSchristos  * https://www.openssl.org/source/license.html
8a89c9211Schristos  */
9a89c9211Schristos 
10a89c9211Schristos #include <stdio.h>
11a89c9211Schristos #include <stdlib.h>
12a89c9211Schristos #include <string.h>
13a89c9211Schristos #include "apps.h"
1413d40330Schristos #include "progs.h"
15a89c9211Schristos #include <openssl/evp.h>
16a89c9211Schristos #include <openssl/crypto.h>
17a89c9211Schristos #include <openssl/bn.h>
18a89c9211Schristos 
19c7da899bSchristos typedef enum OPTION_choice {
20*b0d17251Schristos     OPT_COMMON,
21*b0d17251Schristos     OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
22c7da899bSchristos } OPTION_CHOICE;
23a89c9211Schristos 
2413d40330Schristos const OPTIONS version_options[] = {
25*b0d17251Schristos     OPT_SECTION("General"),
26c7da899bSchristos     {"help", OPT_HELP, '-', "Display this summary"},
27*b0d17251Schristos 
28*b0d17251Schristos     OPT_SECTION("Output"),
29c7da899bSchristos     {"a", OPT_A, '-', "Show all data"},
30c7da899bSchristos     {"b", OPT_B, '-', "Show build date"},
31c7da899bSchristos     {"d", OPT_D, '-', "Show configuration directory"},
32c7da899bSchristos     {"e", OPT_E, '-', "Show engines directory"},
33*b0d17251Schristos     {"m", OPT_M, '-', "Show modules directory"},
34c7da899bSchristos     {"f", OPT_F, '-', "Show compiler flags used"},
35c7da899bSchristos     {"o", OPT_O, '-', "Show some internal datatype options"},
36c7da899bSchristos     {"p", OPT_P, '-', "Show target build platform"},
3713d40330Schristos     {"r", OPT_R, '-', "Show random seeding options"},
38c7da899bSchristos     {"v", OPT_V, '-', "Show library version"},
39*b0d17251Schristos     {"c", OPT_C, '-', "Show CPU settings info"},
40c7da899bSchristos     {NULL}
41c7da899bSchristos };
42a89c9211Schristos 
version_main(int argc,char ** argv)43c7da899bSchristos int version_main(int argc, char **argv)
44a89c9211Schristos {
4513d40330Schristos     int ret = 1, dirty = 0, seed = 0;
46a89c9211Schristos     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
47*b0d17251Schristos     int engdir = 0, moddir = 0, cpuinfo = 0;
48c7da899bSchristos     char *prog;
49c7da899bSchristos     OPTION_CHOICE o;
50a89c9211Schristos 
51c7da899bSchristos     prog = opt_init(argc, argv, version_options);
52c7da899bSchristos     while ((o = opt_next()) != OPT_EOF) {
53c7da899bSchristos         switch (o) {
54c7da899bSchristos         case OPT_EOF:
55c7da899bSchristos         case OPT_ERR:
5653060421Schristos opthelp:
57c7da899bSchristos             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
58a89c9211Schristos             goto end;
59c7da899bSchristos         case OPT_HELP:
60c7da899bSchristos             opt_help(version_options);
61c7da899bSchristos             ret = 0;
62c7da899bSchristos             goto end;
63c7da899bSchristos         case OPT_B:
64c7da899bSchristos             dirty = date = 1;
65c7da899bSchristos             break;
66c7da899bSchristos         case OPT_D:
67c7da899bSchristos             dirty = dir = 1;
68c7da899bSchristos             break;
69c7da899bSchristos         case OPT_E:
70c7da899bSchristos             dirty = engdir = 1;
71c7da899bSchristos             break;
72*b0d17251Schristos         case OPT_M:
73*b0d17251Schristos             dirty = moddir = 1;
74*b0d17251Schristos             break;
75c7da899bSchristos         case OPT_F:
76c7da899bSchristos             dirty = cflags = 1;
77c7da899bSchristos             break;
78c7da899bSchristos         case OPT_O:
79c7da899bSchristos             dirty = options = 1;
80c7da899bSchristos             break;
81c7da899bSchristos         case OPT_P:
82c7da899bSchristos             dirty = platform = 1;
83c7da899bSchristos             break;
8413d40330Schristos         case OPT_R:
8513d40330Schristos             dirty = seed = 1;
8613d40330Schristos             break;
87c7da899bSchristos         case OPT_V:
88c7da899bSchristos             dirty = version = 1;
89c7da899bSchristos             break;
90*b0d17251Schristos         case OPT_C:
91*b0d17251Schristos             dirty = cpuinfo = 1;
92*b0d17251Schristos             break;
93c7da899bSchristos         case OPT_A:
94*b0d17251Schristos             seed = options = cflags = version = date = platform
95*b0d17251Schristos                 = dir = engdir = moddir = cpuinfo
9613d40330Schristos                 = 1;
97c7da899bSchristos             break;
98a89c9211Schristos         }
99a89c9211Schristos     }
100*b0d17251Schristos 
101*b0d17251Schristos     /* No extra arguments. */
102*b0d17251Schristos     argc = opt_num_rest();
103*b0d17251Schristos     if (argc != 0)
10453060421Schristos         goto opthelp;
105*b0d17251Schristos 
106c7da899bSchristos     if (!dirty)
107c7da899bSchristos         version = 1;
108a89c9211Schristos 
109*b0d17251Schristos     if (version)
110a89c9211Schristos         printf("%s (Library: %s)\n",
111c7da899bSchristos                OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
112635165faSspz     if (date)
113c7da899bSchristos         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
114635165faSspz     if (platform)
115c7da899bSchristos         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
116635165faSspz     if (options) {
117a89c9211Schristos         printf("options: ");
118a89c9211Schristos         printf(" %s", BN_options());
119a89c9211Schristos         printf("\n");
120a89c9211Schristos     }
121635165faSspz     if (cflags)
122c7da899bSchristos         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
123635165faSspz     if (dir)
124c7da899bSchristos         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
125c7da899bSchristos     if (engdir)
126c7da899bSchristos         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
127*b0d17251Schristos     if (moddir)
128*b0d17251Schristos         printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
12913d40330Schristos     if (seed) {
130*b0d17251Schristos         const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
131*b0d17251Schristos         printf("Seeding source: %s\n", src ? src : "N/A");
13213d40330Schristos     }
133*b0d17251Schristos     if (cpuinfo)
134*b0d17251Schristos         printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
135c7da899bSchristos     ret = 0;
136a89c9211Schristos  end:
13713d40330Schristos     return ret;
138a89c9211Schristos }
139*b0d17251Schristos 
140*b0d17251Schristos 
141*b0d17251Schristos #if defined(__TANDEM) && defined(OPENSSL_VPROC)
142*b0d17251Schristos /*
143*b0d17251Schristos  * Define a VPROC function for the openssl program.
144*b0d17251Schristos  * This is used by platform version identification tools.
145*b0d17251Schristos  * Do not inline this procedure or make it static.
146*b0d17251Schristos  */
147*b0d17251Schristos # define OPENSSL_VPROC_STRING_(x)    x##_OPENSSL
148*b0d17251Schristos # define OPENSSL_VPROC_STRING(x)     OPENSSL_VPROC_STRING_(x)
149*b0d17251Schristos # define OPENSSL_VPROC_FUNC          OPENSSL_VPROC_STRING(OPENSSL_VPROC)
OPENSSL_VPROC_FUNC(void)150*b0d17251Schristos void OPENSSL_VPROC_FUNC(void) {}
151*b0d17251Schristos #endif
152