Home | History | Annotate | Line # | Download | only in apps
      1  1.1.1.3  christos /*
      2  1.1.1.6  christos  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
      3      1.1  christos  *
      4  1.1.1.6  christos  * Licensed under the Apache License 2.0 (the "License").  You may not use
      5  1.1.1.3  christos  * this file except in compliance with the License.  You can obtain a copy
      6  1.1.1.3  christos  * in the file LICENSE in the source distribution or at
      7  1.1.1.3  christos  * https://www.openssl.org/source/license.html
      8      1.1  christos  */
      9      1.1  christos 
     10      1.1  christos #include <stdio.h>
     11      1.1  christos #include <stdlib.h>
     12      1.1  christos #include <string.h>
     13      1.1  christos #include "apps.h"
     14  1.1.1.5  christos #include "progs.h"
     15      1.1  christos #include <openssl/evp.h>
     16      1.1  christos #include <openssl/crypto.h>
     17      1.1  christos #include <openssl/bn.h>
     18      1.1  christos 
     19  1.1.1.3  christos typedef enum OPTION_choice {
     20  1.1.1.6  christos     OPT_COMMON,
     21  1.1.1.6  christos     OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
     22  1.1.1.3  christos } OPTION_CHOICE;
     23  1.1.1.3  christos 
     24  1.1.1.5  christos const OPTIONS version_options[] = {
     25  1.1.1.6  christos     OPT_SECTION("General"),
     26  1.1.1.3  christos     {"help", OPT_HELP, '-', "Display this summary"},
     27  1.1.1.6  christos 
     28  1.1.1.6  christos     OPT_SECTION("Output"),
     29  1.1.1.3  christos     {"a", OPT_A, '-', "Show all data"},
     30  1.1.1.3  christos     {"b", OPT_B, '-', "Show build date"},
     31  1.1.1.3  christos     {"d", OPT_D, '-', "Show configuration directory"},
     32  1.1.1.3  christos     {"e", OPT_E, '-', "Show engines directory"},
     33  1.1.1.6  christos     {"m", OPT_M, '-', "Show modules directory"},
     34  1.1.1.3  christos     {"f", OPT_F, '-', "Show compiler flags used"},
     35  1.1.1.3  christos     {"o", OPT_O, '-', "Show some internal datatype options"},
     36  1.1.1.3  christos     {"p", OPT_P, '-', "Show target build platform"},
     37  1.1.1.5  christos     {"r", OPT_R, '-', "Show random seeding options"},
     38  1.1.1.3  christos     {"v", OPT_V, '-', "Show library version"},
     39  1.1.1.6  christos     {"c", OPT_C, '-', "Show CPU settings info"},
     40  1.1.1.3  christos     {NULL}
     41  1.1.1.3  christos };
     42      1.1  christos 
     43  1.1.1.3  christos int version_main(int argc, char **argv)
     44  1.1.1.2       spz {
     45  1.1.1.5  christos     int ret = 1, dirty = 0, seed = 0;
     46  1.1.1.2       spz     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
     47  1.1.1.6  christos     int engdir = 0, moddir = 0, cpuinfo = 0;
     48  1.1.1.3  christos     char *prog;
     49  1.1.1.3  christos     OPTION_CHOICE o;
     50  1.1.1.3  christos 
     51  1.1.1.3  christos     prog = opt_init(argc, argv, version_options);
     52  1.1.1.3  christos     while ((o = opt_next()) != OPT_EOF) {
     53  1.1.1.3  christos         switch (o) {
     54  1.1.1.3  christos         case OPT_EOF:
     55  1.1.1.3  christos         case OPT_ERR:
     56  1.1.1.4  christos opthelp:
     57  1.1.1.3  christos             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
     58  1.1.1.2       spz             goto end;
     59  1.1.1.3  christos         case OPT_HELP:
     60  1.1.1.3  christos             opt_help(version_options);
     61  1.1.1.3  christos             ret = 0;
     62  1.1.1.3  christos             goto end;
     63  1.1.1.3  christos         case OPT_B:
     64  1.1.1.3  christos             dirty = date = 1;
     65  1.1.1.3  christos             break;
     66  1.1.1.3  christos         case OPT_D:
     67  1.1.1.3  christos             dirty = dir = 1;
     68  1.1.1.3  christos             break;
     69  1.1.1.3  christos         case OPT_E:
     70  1.1.1.3  christos             dirty = engdir = 1;
     71  1.1.1.3  christos             break;
     72  1.1.1.6  christos         case OPT_M:
     73  1.1.1.6  christos             dirty = moddir = 1;
     74  1.1.1.6  christos             break;
     75  1.1.1.3  christos         case OPT_F:
     76  1.1.1.3  christos             dirty = cflags = 1;
     77  1.1.1.3  christos             break;
     78  1.1.1.3  christos         case OPT_O:
     79  1.1.1.3  christos             dirty = options = 1;
     80  1.1.1.3  christos             break;
     81  1.1.1.3  christos         case OPT_P:
     82  1.1.1.3  christos             dirty = platform = 1;
     83  1.1.1.3  christos             break;
     84  1.1.1.5  christos         case OPT_R:
     85  1.1.1.5  christos             dirty = seed = 1;
     86  1.1.1.5  christos             break;
     87  1.1.1.3  christos         case OPT_V:
     88  1.1.1.3  christos             dirty = version = 1;
     89  1.1.1.3  christos             break;
     90  1.1.1.6  christos         case OPT_C:
     91  1.1.1.6  christos             dirty = cpuinfo = 1;
     92  1.1.1.6  christos             break;
     93  1.1.1.3  christos         case OPT_A:
     94  1.1.1.6  christos             seed = options = cflags = version = date = platform
     95  1.1.1.6  christos                 = dir = engdir = moddir = cpuinfo
     96  1.1.1.5  christos                 = 1;
     97  1.1.1.3  christos             break;
     98  1.1.1.2       spz         }
     99  1.1.1.2       spz     }
    100  1.1.1.6  christos 
    101  1.1.1.6  christos     /* No extra arguments. */
    102  1.1.1.6  christos     argc = opt_num_rest();
    103  1.1.1.6  christos     if (argc != 0)
    104  1.1.1.4  christos         goto opthelp;
    105  1.1.1.6  christos 
    106  1.1.1.3  christos     if (!dirty)
    107  1.1.1.3  christos         version = 1;
    108  1.1.1.2       spz 
    109  1.1.1.6  christos     if (version)
    110  1.1.1.6  christos         printf("%s (Library: %s)\n",
    111  1.1.1.6  christos                OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
    112  1.1.1.2       spz     if (date)
    113  1.1.1.3  christos         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
    114  1.1.1.2       spz     if (platform)
    115  1.1.1.3  christos         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
    116  1.1.1.2       spz     if (options) {
    117  1.1.1.6  christos         printf("options: ");
    118  1.1.1.6  christos         printf(" %s", BN_options());
    119  1.1.1.2       spz         printf("\n");
    120  1.1.1.2       spz     }
    121  1.1.1.2       spz     if (cflags)
    122  1.1.1.3  christos         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
    123  1.1.1.2       spz     if (dir)
    124  1.1.1.3  christos         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
    125  1.1.1.3  christos     if (engdir)
    126  1.1.1.3  christos         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
    127  1.1.1.6  christos     if (moddir)
    128  1.1.1.6  christos         printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
    129  1.1.1.5  christos     if (seed) {
    130  1.1.1.6  christos         const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
    131  1.1.1.6  christos         printf("Seeding source: %s\n", src ? src : "N/A");
    132  1.1.1.5  christos     }
    133  1.1.1.6  christos     if (cpuinfo)
    134  1.1.1.6  christos         printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
    135  1.1.1.3  christos     ret = 0;
    136  1.1.1.2       spz  end:
    137  1.1.1.5  christos     return ret;
    138  1.1.1.2       spz }
    139  1.1.1.6  christos 
    140  1.1.1.6  christos 
    141  1.1.1.6  christos #if defined(__TANDEM) && defined(OPENSSL_VPROC)
    142  1.1.1.6  christos /*
    143  1.1.1.6  christos  * Define a VPROC function for the openssl program.
    144  1.1.1.6  christos  * This is used by platform version identification tools.
    145  1.1.1.6  christos  * Do not inline this procedure or make it static.
    146  1.1.1.6  christos  */
    147  1.1.1.6  christos # define OPENSSL_VPROC_STRING_(x)    x##_OPENSSL
    148  1.1.1.6  christos # define OPENSSL_VPROC_STRING(x)     OPENSSL_VPROC_STRING_(x)
    149  1.1.1.6  christos # define OPENSSL_VPROC_FUNC          OPENSSL_VPROC_STRING(OPENSSL_VPROC)
    150  1.1.1.6  christos void OPENSSL_VPROC_FUNC(void) {}
    151  1.1.1.6  christos #endif
    152