]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/version.c
Fix an s_server arbitrary file read issue on Windows
[thirdparty/openssl.git] / apps / version.c
CommitLineData
846e33c7 1/*
6738bf14 2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
a661b653 3 *
846e33c7
RS
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
a661b653 8 */
d02b48c6
RE
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include "apps.h"
dab2cd68 14#include "progs.h"
ec577822
BM
15#include <openssl/evp.h>
16#include <openssl/crypto.h>
f0eae953 17#include <openssl/bn.h>
4f94d1a8
BM
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
125cc35b 25# include <openssl/des.h>
4f94d1a8
BM
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
d02b48c6 33
7e1b7485
RS
34typedef enum OPTION_choice {
35 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
8389ec4b 36 OPT_B, OPT_D, OPT_E, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
7e1b7485 37} OPTION_CHOICE;
d02b48c6 38
44c83ebd 39const OPTIONS version_options[] = {
7e1b7485
RS
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"},
01a2ade0 44 {"e", OPT_E, '-', "Show engines directory"},
7e1b7485
RS
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"},
8389ec4b 48 {"r", OPT_R, '-', "Show random seeding options"},
7e1b7485
RS
49 {"v", OPT_V, '-', "Show library version"},
50 {NULL}
51};
667ac4ec 52
b35ef026
RS
53#if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
54static 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
7e1b7485 63int version_main(int argc, char **argv)
0f113f3e 64{
8389ec4b 65 int ret = 1, dirty = 0, seed = 0;
0f113f3e 66 int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
e09621ff 67 int engdir = 0;
7e1b7485
RS
68 char *prog;
69 OPTION_CHOICE o;
d02b48c6 70
7e1b7485
RS
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:
c27363f5 76opthelp:
7e1b7485 77 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
0f113f3e 78 goto end;
7e1b7485
RS
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;
e09621ff
RL
89 case OPT_E:
90 dirty = engdir = 1;
91 break;
7e1b7485
RS
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;
8389ec4b
RS
101 case OPT_R:
102 dirty = seed = 1;
103 break;
7e1b7485
RS
104 case OPT_V:
105 dirty = version = 1;
106 break;
107 case OPT_A:
b971b05e
RL
108 seed = options = cflags = version = date = platform = dir = engdir
109 = 1;
7e1b7485 110 break;
0f113f3e
MC
111 }
112 }
c27363f5
RS
113 if (opt_num_rest() != 0) {
114 BIO_printf(bio_err, "Extra parameters given.\n");
115 goto opthelp;
116 }
7e1b7485
RS
117 if (!dirty)
118 version = 1;
d02b48c6 119
0f113f3e 120 if (version) {
2234212c 121 if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
b0700d2c 122 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2234212c 123 else
0f113f3e 124 printf("%s (Library: %s)\n",
b0700d2c 125 OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
0f113f3e
MC
126 }
127 if (date)
b0700d2c 128 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
0f113f3e 129 if (platform)
b0700d2c 130 printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
0f113f3e
MC
131 if (options) {
132 printf("options: ");
133 printf("%s ", BN_options());
cf1b7d96 134#ifndef OPENSSL_NO_MD2
0f113f3e 135 printf("%s ", MD2_options());
d02b48c6 136#endif
cf1b7d96 137#ifndef OPENSSL_NO_RC4
0f113f3e 138 printf("%s ", RC4_options());
d02b48c6 139#endif
cf1b7d96 140#ifndef OPENSSL_NO_DES
0f113f3e 141 printf("%s ", DES_options());
d02b48c6 142#endif
cf1b7d96 143#ifndef OPENSSL_NO_IDEA
9021a5df 144 printf("%s ", IDEA_options());
d02b48c6 145#endif
cf1b7d96 146#ifndef OPENSSL_NO_BF
0f113f3e 147 printf("%s ", BF_options());
d02b48c6 148#endif
0f113f3e
MC
149 printf("\n");
150 }
151 if (cflags)
b0700d2c 152 printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
0f113f3e 153 if (dir)
b0700d2c 154 printf("%s\n", OpenSSL_version(OPENSSL_DIR));
e09621ff
RL
155 if (engdir)
156 printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
8389ec4b
RS
157 if (seed) {
158 printf("Seeding source:");
159#ifdef OPENSSL_RAND_SEED_RTDSC
160 printf(" rtdsc");
161#endif
162#ifdef OPENSSL_RAND_SEED_RDCPU
b35ef026 163 printf(" rdrand ( rdseed rdrand )");
8389ec4b
RS
164#endif
165#ifdef OPENSSL_RAND_SEED_LIBRANDOM
166 printf(" C-library-random");
167#endif
168#ifdef OPENSSL_RAND_SEED_GETRANDOM
169 printf(" getrandom-syscall");
170#endif
171#ifdef OPENSSL_RAND_SEED_DEVRANDOM
b35ef026
RS
172 {
173 static const char *dev[] = { DEVRANDOM, NULL };
174 printlist(" random-device", dev);
175 }
8389ec4b
RS
176#endif
177#ifdef OPENSSL_RAND_SEED_EGD
b35ef026
RS
178 {
179 static const char *dev[] = { DEVRANDOM_EGD, NULL };
180 printlist(" EGD", dev);
181 }
8389ec4b
RS
182#endif
183#ifdef OPENSSL_RAND_SEED_NONE
184 printf(" none");
185#endif
186#ifdef OPENSSL_RAND_SEED_OS
187 printf(" os-specific");
188#endif
189 printf("\n");
190 }
7e1b7485 191 ret = 0;
0f113f3e 192 end:
26a7d938 193 return ret;
0f113f3e 194}