]>
Commit | Line | Data |
---|---|---|
846e33c7 | 1 | /* |
6738bf14 | 2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. |
a661b653 | 3 | * |
dffa7520 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
846e33c7 RS |
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 |
34 | typedef enum OPTION_choice { |
35 | OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, | |
363e941e | 36 | OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C |
7e1b7485 | 37 | } OPTION_CHOICE; |
d02b48c6 | 38 | |
44c83ebd | 39 | const OPTIONS version_options[] = { |
5388f986 | 40 | OPT_SECTION("General"), |
7e1b7485 | 41 | {"help", OPT_HELP, '-', "Display this summary"}, |
5388f986 RS |
42 | |
43 | OPT_SECTION("Output"), | |
7e1b7485 RS |
44 | {"a", OPT_A, '-', "Show all data"}, |
45 | {"b", OPT_B, '-', "Show build date"}, | |
46 | {"d", OPT_D, '-', "Show configuration directory"}, | |
01a2ade0 | 47 | {"e", OPT_E, '-', "Show engines directory"}, |
47ca8338 | 48 | {"m", OPT_M, '-', "Show modules directory"}, |
7e1b7485 RS |
49 | {"f", OPT_F, '-', "Show compiler flags used"}, |
50 | {"o", OPT_O, '-', "Show some internal datatype options"}, | |
51 | {"p", OPT_P, '-', "Show target build platform"}, | |
8389ec4b | 52 | {"r", OPT_R, '-', "Show random seeding options"}, |
7e1b7485 | 53 | {"v", OPT_V, '-', "Show library version"}, |
363e941e | 54 | {"c", OPT_C, '-', "Show CPU settings info"}, |
7e1b7485 RS |
55 | {NULL} |
56 | }; | |
667ac4ec | 57 | |
7e1b7485 | 58 | int version_main(int argc, char **argv) |
0f113f3e | 59 | { |
8389ec4b | 60 | int ret = 1, dirty = 0, seed = 0; |
0f113f3e | 61 | int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0; |
363e941e | 62 | int engdir = 0, moddir = 0, cpuinfo = 0; |
7e1b7485 RS |
63 | char *prog; |
64 | OPTION_CHOICE o; | |
d02b48c6 | 65 | |
7e1b7485 RS |
66 | prog = opt_init(argc, argv, version_options); |
67 | while ((o = opt_next()) != OPT_EOF) { | |
68 | switch (o) { | |
69 | case OPT_EOF: | |
70 | case OPT_ERR: | |
c27363f5 | 71 | opthelp: |
7e1b7485 | 72 | BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); |
0f113f3e | 73 | goto end; |
7e1b7485 RS |
74 | case OPT_HELP: |
75 | opt_help(version_options); | |
76 | ret = 0; | |
77 | goto end; | |
78 | case OPT_B: | |
79 | dirty = date = 1; | |
80 | break; | |
81 | case OPT_D: | |
82 | dirty = dir = 1; | |
83 | break; | |
e09621ff RL |
84 | case OPT_E: |
85 | dirty = engdir = 1; | |
86 | break; | |
47ca8338 RL |
87 | case OPT_M: |
88 | dirty = moddir = 1; | |
89 | break; | |
7e1b7485 RS |
90 | case OPT_F: |
91 | dirty = cflags = 1; | |
92 | break; | |
93 | case OPT_O: | |
94 | dirty = options = 1; | |
95 | break; | |
96 | case OPT_P: | |
97 | dirty = platform = 1; | |
98 | break; | |
8389ec4b RS |
99 | case OPT_R: |
100 | dirty = seed = 1; | |
101 | break; | |
7e1b7485 RS |
102 | case OPT_V: |
103 | dirty = version = 1; | |
104 | break; | |
363e941e BE |
105 | case OPT_C: |
106 | dirty = cpuinfo = 1; | |
107 | break; | |
7e1b7485 | 108 | case OPT_A: |
47ca8338 | 109 | seed = options = cflags = version = date = platform |
363e941e | 110 | = dir = engdir = moddir = cpuinfo |
b971b05e | 111 | = 1; |
7e1b7485 | 112 | break; |
0f113f3e MC |
113 | } |
114 | } | |
c27363f5 RS |
115 | if (opt_num_rest() != 0) { |
116 | BIO_printf(bio_err, "Extra parameters given.\n"); | |
117 | goto opthelp; | |
118 | } | |
7e1b7485 RS |
119 | if (!dirty) |
120 | version = 1; | |
d02b48c6 | 121 | |
1dea43c3 P |
122 | if (version) |
123 | printf("%s (Library: %s)\n", | |
124 | OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION)); | |
0f113f3e | 125 | if (date) |
b0700d2c | 126 | printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON)); |
0f113f3e | 127 | if (platform) |
b0700d2c | 128 | printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM)); |
0f113f3e | 129 | if (options) { |
bddf965d P |
130 | printf("options: "); |
131 | printf(" %s", BN_options()); | |
cf1b7d96 | 132 | #ifndef OPENSSL_NO_MD2 |
bddf965d | 133 | printf(" %s", MD2_options()); |
d02b48c6 | 134 | #endif |
cf1b7d96 | 135 | #ifndef OPENSSL_NO_RC4 |
bddf965d | 136 | printf(" %s", RC4_options()); |
d02b48c6 | 137 | #endif |
cf1b7d96 | 138 | #ifndef OPENSSL_NO_DES |
bddf965d | 139 | printf(" %s", DES_options()); |
d02b48c6 | 140 | #endif |
cf1b7d96 | 141 | #ifndef OPENSSL_NO_IDEA |
bddf965d | 142 | printf(" %s", IDEA_options()); |
d02b48c6 | 143 | #endif |
cf1b7d96 | 144 | #ifndef OPENSSL_NO_BF |
bddf965d | 145 | printf(" %s", BF_options()); |
d02b48c6 | 146 | #endif |
0f113f3e MC |
147 | printf("\n"); |
148 | } | |
149 | if (cflags) | |
b0700d2c | 150 | printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS)); |
0f113f3e | 151 | if (dir) |
b0700d2c | 152 | printf("%s\n", OpenSSL_version(OPENSSL_DIR)); |
e09621ff RL |
153 | if (engdir) |
154 | printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR)); | |
47ca8338 RL |
155 | if (moddir) |
156 | printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR)); | |
363e941e BE |
157 | if (seed) { |
158 | const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE); | |
159 | printf("Seeding source: %s\n", src ? src : "N/A"); | |
160 | } | |
161 | if (cpuinfo) | |
162 | printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO)); | |
7e1b7485 | 163 | ret = 0; |
0f113f3e | 164 | end: |
26a7d938 | 165 | return ret; |
0f113f3e | 166 | } |