version.c 4.4 KB
Newer Older
R
Rich Salz 已提交
1
/*
M
Matt Caswell 已提交
2
 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
R
Rich Salz 已提交
5 6 7
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
8
 */
9 10 11 12 13

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "apps.h"
14
#include "progs.h"
15 16
#include <openssl/evp.h>
#include <openssl/crypto.h>
17
#include <openssl/bn.h>
18 19 20 21 22 23 24
#ifndef OPENSSL_NO_MD2
# include <openssl/md2.h>
#endif
#ifndef OPENSSL_NO_RC4
# include <openssl/rc4.h>
#endif
#ifndef OPENSSL_NO_DES
25
# include <openssl/des.h>
26 27 28 29 30 31 32
#endif
#ifndef OPENSSL_NO_IDEA
# include <openssl/idea.h>
#endif
#ifndef OPENSSL_NO_BF
# include <openssl/blowfish.h>
#endif
33

34 35
typedef enum OPTION_choice {
    OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
36
    OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
37
} OPTION_CHOICE;
38

F
FdaSilvaYY 已提交
39
const OPTIONS version_options[] = {
R
Rich Salz 已提交
40
    OPT_SECTION("General"),
41
    {"help", OPT_HELP, '-', "Display this summary"},
R
Rich Salz 已提交
42 43

    OPT_SECTION("Output"),
44 45 46
    {"a", OPT_A, '-', "Show all data"},
    {"b", OPT_B, '-', "Show build date"},
    {"d", OPT_D, '-', "Show configuration directory"},
D
typo  
Dr. Stephen Henson 已提交
47
    {"e", OPT_E, '-', "Show engines directory"},
48
    {"m", OPT_M, '-', "Show modules directory"},
49 50 51
    {"f", OPT_F, '-', "Show compiler flags used"},
    {"o", OPT_O, '-', "Show some internal datatype options"},
    {"p", OPT_P, '-', "Show target build platform"},
R
Rich Salz 已提交
52
    {"r", OPT_R, '-', "Show random seeding options"},
53
    {"v", OPT_V, '-', "Show library version"},
54
    {"c", OPT_C, '-', "Show CPU settings info"},
55 56
    {NULL}
};
57

58
int version_main(int argc, char **argv)
59
{
R
Rich Salz 已提交
60
    int ret = 1, dirty = 0, seed = 0;
61
    int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
62
    int engdir = 0, moddir = 0, cpuinfo = 0;
63 64
    char *prog;
    OPTION_CHOICE o;
65

66 67 68 69 70
    prog = opt_init(argc, argv, version_options);
    while ((o = opt_next()) != OPT_EOF) {
        switch (o) {
        case OPT_EOF:
        case OPT_ERR:
71
opthelp:
72
            BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
73
            goto end;
74 75 76 77 78 79 80 81 82 83
        case OPT_HELP:
            opt_help(version_options);
            ret = 0;
            goto end;
        case OPT_B:
            dirty = date = 1;
            break;
        case OPT_D:
            dirty = dir = 1;
            break;
84 85 86
        case OPT_E:
            dirty = engdir = 1;
            break;
87 88 89
        case OPT_M:
            dirty = moddir = 1;
            break;
90 91 92 93 94 95 96 97 98
        case OPT_F:
            dirty = cflags = 1;
            break;
        case OPT_O:
            dirty = options = 1;
            break;
        case OPT_P:
            dirty = platform = 1;
            break;
R
Rich Salz 已提交
99 100 101
        case OPT_R:
            dirty = seed = 1;
            break;
102 103 104
        case OPT_V:
            dirty = version = 1;
            break;
105 106 107
        case OPT_C:
            dirty = cpuinfo = 1;
            break;
108
        case OPT_A:
109
            seed = options = cflags = version = date = platform
110
                = dir = engdir = moddir = cpuinfo
111
                = 1;
112
            break;
113 114
        }
    }
115 116 117 118
    if (opt_num_rest() != 0) {
        BIO_printf(bio_err, "Extra parameters given.\n");
        goto opthelp;
    }
119 120
    if (!dirty)
        version = 1;
121

122 123 124
    if (version)
        printf("%s (Library: %s)\n",
               OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
125
    if (date)
R
Rich Salz 已提交
126
        printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
127
    if (platform)
R
Rich Salz 已提交
128
        printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
129
    if (options) {
130 131
        printf("options: ");
        printf(" %s", BN_options());
132
#ifndef OPENSSL_NO_MD2
133
        printf(" %s", MD2_options());
134
#endif
135
#ifndef OPENSSL_NO_RC4
136
        printf(" %s", RC4_options());
137
#endif
138
#ifndef OPENSSL_NO_DES
139
        printf(" %s", DES_options());
140
#endif
141
#ifndef OPENSSL_NO_IDEA
142
        printf(" %s", IDEA_options());
143
#endif
144 145 146
        printf("\n");
    }
    if (cflags)
R
Rich Salz 已提交
147
        printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
148
    if (dir)
R
Rich Salz 已提交
149
        printf("%s\n", OpenSSL_version(OPENSSL_DIR));
150 151
    if (engdir)
        printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
152 153
    if (moddir)
        printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
154 155 156 157 158 159
    if (seed) {
        const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
        printf("Seeding source: %s\n", src ? src : "N/A");
    }
    if (cpuinfo)
        printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
160
    ret = 0;
161
 end:
K
KaoruToda 已提交
162
    return ret;
163
}