]> git.ipfire.org Git - thirdparty/openssl.git/blob - apps/version.c
Update copyright year
[thirdparty/openssl.git] / apps / version.c
1 /*
2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (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 #ifndef OPENSSL_NO_MD2
19 # include <openssl/md2.h>
20 #endif
21 #ifndef OPENSSL_NO_RC4
22 # include <openssl/rc4.h>
23 #endif
24 #ifndef OPENSSL_NO_DES
25 # include <openssl/des.h>
26 #endif
27 #ifndef OPENSSL_NO_IDEA
28 # include <openssl/idea.h>
29 #endif
30 #ifndef OPENSSL_NO_BF
31 # include <openssl/blowfish.h>
32 #endif
33
34 typedef enum OPTION_choice {
35 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
36 OPT_B, OPT_D, OPT_E, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
37 } OPTION_CHOICE;
38
39 const OPTIONS version_options[] = {
40 {"help", OPT_HELP, '-', "Display this summary"},
41 {"a", OPT_A, '-', "Show all data"},
42 {"b", OPT_B, '-', "Show build date"},
43 {"d", OPT_D, '-', "Show configuration directory"},
44 {"e", OPT_E, '-', "Show engines directory"},
45 {"f", OPT_F, '-', "Show compiler flags used"},
46 {"o", OPT_O, '-', "Show some internal datatype options"},
47 {"p", OPT_P, '-', "Show target build platform"},
48 {"r", OPT_R, '-', "Show random seeding options"},
49 {"v", OPT_V, '-', "Show library version"},
50 {NULL}
51 };
52
53 #if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
54 static void printlist(const char *prefix, const char **dev)
55 {
56 printf("%s (", prefix);
57 for ( ; *dev != NULL; dev++)
58 printf(" \"%s\"", *dev);
59 printf(" )");
60 }
61 #endif
62
63 int version_main(int argc, char **argv)
64 {
65 int ret = 1, dirty = 0, seed = 0;
66 int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
67 int engdir = 0;
68 char *prog;
69 OPTION_CHOICE o;
70
71 prog = opt_init(argc, argv, version_options);
72 while ((o = opt_next()) != OPT_EOF) {
73 switch (o) {
74 case OPT_EOF:
75 case OPT_ERR:
76 opthelp:
77 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
78 goto end;
79 case OPT_HELP:
80 opt_help(version_options);
81 ret = 0;
82 goto end;
83 case OPT_B:
84 dirty = date = 1;
85 break;
86 case OPT_D:
87 dirty = dir = 1;
88 break;
89 case OPT_E:
90 dirty = engdir = 1;
91 break;
92 case OPT_F:
93 dirty = cflags = 1;
94 break;
95 case OPT_O:
96 dirty = options = 1;
97 break;
98 case OPT_P:
99 dirty = platform = 1;
100 break;
101 case OPT_R:
102 dirty = seed = 1;
103 break;
104 case OPT_V:
105 dirty = version = 1;
106 break;
107 case OPT_A:
108 seed = cflags = version = date = platform = dir = engdir = 1;
109 break;
110 }
111 }
112 if (opt_num_rest() != 0) {
113 BIO_printf(bio_err, "Extra parameters given.\n");
114 goto opthelp;
115 }
116 if (!dirty)
117 version = 1;
118
119 if (version) {
120 if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
121 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
122 else
123 printf("%s (Library: %s)\n",
124 OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
125 }
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 #ifndef OPENSSL_NO_MD2
134 printf("%s ", MD2_options());
135 #endif
136 #ifndef OPENSSL_NO_RC4
137 printf("%s ", RC4_options());
138 #endif
139 #ifndef OPENSSL_NO_DES
140 printf("%s ", DES_options());
141 #endif
142 #ifndef OPENSSL_NO_IDEA
143 printf("%s ", IDEA_options());
144 #endif
145 #ifndef OPENSSL_NO_BF
146 printf("%s ", BF_options());
147 #endif
148 printf("\n");
149 }
150 if (cflags)
151 printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
152 if (dir)
153 printf("%s\n", OpenSSL_version(OPENSSL_DIR));
154 if (engdir)
155 printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
156 if (seed) {
157 printf("Seeding source:");
158 #ifdef OPENSSL_RAND_SEED_RTDSC
159 printf(" rtdsc");
160 #endif
161 #ifdef OPENSSL_RAND_SEED_RDCPU
162 printf(" rdrand ( rdseed rdrand )");
163 #endif
164 #ifdef OPENSSL_RAND_SEED_LIBRANDOM
165 printf(" C-library-random");
166 #endif
167 #ifdef OPENSSL_RAND_SEED_GETRANDOM
168 printf(" getrandom-syscall");
169 #endif
170 #ifdef OPENSSL_RAND_SEED_DEVRANDOM
171 {
172 static const char *dev[] = { DEVRANDOM, NULL };
173 printlist(" random-device", dev);
174 }
175 #endif
176 #ifdef OPENSSL_RAND_SEED_EGD
177 {
178 static const char *dev[] = { DEVRANDOM_EGD, NULL };
179 printlist(" EGD", dev);
180 }
181 #endif
182 #ifdef OPENSSL_RAND_SEED_NONE
183 printf(" none");
184 #endif
185 #ifdef OPENSSL_RAND_SEED_OS
186 printf(" os-specific");
187 #endif
188 printf("\n");
189 }
190 ret = 0;
191 end:
192 return ret;
193 }