Update copyright year
[openssl.git] / apps / version.c
1 /*
2  * Copyright 1995-2020 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_ERR = -1, OPT_EOF = 0, OPT_HELP,
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     if (opt_num_rest() != 0) {
101         BIO_printf(bio_err, "Extra parameters given.\n");
102         goto opthelp;
103     }
104     if (!dirty)
105         version = 1;
106
107     if (version)
108         printf("%s (Library: %s)\n",
109                OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
110     if (date)
111         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
112     if (platform)
113         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
114     if (options) {
115         printf("options: ");
116         printf(" %s", BN_options());
117         printf("\n");
118     }
119     if (cflags)
120         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
121     if (dir)
122         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
123     if (engdir)
124         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
125     if (moddir)
126         printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
127     if (seed) {
128         const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
129         printf("Seeding source: %s\n", src ? src : "N/A");
130     }
131     if (cpuinfo)
132         printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
133     ret = 0;
134  end:
135     return ret;
136 }