OPENSSL_info(): add the item OPENSSL_INFO_SEED_SOURCE and use it
[openssl.git] / apps / info.c
1 /*
2  * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (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 <openssl/crypto.h>
11 #include "apps.h"
12 #include "progs.h"
13
14 typedef enum OPTION_choice {
15     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
16     OPT_CONFIGDIR, OPT_ENGINESDIR, OPT_MODULESDIR, OPT_DSOEXT, OPT_DIRNAMESEP,
17     OPT_LISTSEP, OPT_SEEDS
18 } OPTION_CHOICE;
19
20 const OPTIONS info_options[] = {
21     {"help", OPT_HELP, '-', "Display this summary"},
22     {"configdir", OPT_CONFIGDIR, '-', "Default configuration file directory"},
23     {"c", OPT_CONFIGDIR, '-', "Default configuration file directory"},
24     {"enginesdir", OPT_ENGINESDIR, '-', "Default engine module directory"},
25     {"e", OPT_ENGINESDIR, '-', "Default engine module directory"},
26     {"modulesdir", OPT_ENGINESDIR, '-',
27      "Default module directory (other than engine modules)"},
28     {"m", OPT_ENGINESDIR, '-',
29      "Default module directory (other than engine modules)"},
30     {"dsoext", OPT_DSOEXT, '-', "Configured extension for modules"},
31     {"dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator"},
32     {"listsep", OPT_LISTSEP, '-', "List separator character"},
33     {"seeds", OPT_SEEDS, '-', "Seed sources"},
34     {NULL}
35 };
36
37 int info_main(int argc, char **argv)
38 {
39     int ret = 1, dirty = 0, type = 0;
40     char *prog;
41     OPTION_CHOICE o;
42
43     prog = opt_init(argc, argv, info_options);
44     while ((o = opt_next()) != OPT_EOF) {
45         switch (o) {
46         default:
47 opthelp:
48             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
49             goto end;
50         case OPT_HELP:
51             opt_help(info_options);
52             ret = 0;
53             goto end;
54         case OPT_CONFIGDIR:
55             type = OPENSSL_INFO_CONFIG_DIR;
56             dirty++;
57             break;
58         case OPT_ENGINESDIR:
59             type = OPENSSL_INFO_ENGINES_DIR;
60             dirty++;
61             break;
62         case OPT_MODULESDIR:
63             type = OPENSSL_INFO_MODULES_DIR;
64             dirty++;
65             break;
66         case OPT_DSOEXT:
67             type = OPENSSL_INFO_DSO_EXTENSION;
68             dirty++;
69             break;
70         case OPT_DIRNAMESEP:
71             type = OPENSSL_INFO_DIR_FILENAME_SEPARATOR;
72             dirty++;
73             break;
74         case OPT_LISTSEP:
75             type = OPENSSL_INFO_LIST_SEPARATOR;
76             dirty++;
77             break;
78         case OPT_SEEDS:
79             type = OPENSSL_INFO_SEED_SOURCE;
80             dirty++;
81             break;
82         }
83     }
84     if (opt_num_rest() != 0) {
85         BIO_printf(bio_err, "%s: Extra parameters given.\n", prog);
86         goto opthelp;
87     }
88     if (dirty > 1) {
89         BIO_printf(bio_err, "%s: Only one item allowed\n", prog);
90         goto opthelp;
91     }
92     if (dirty == 0) {
93         BIO_printf(bio_err, "%s: No items chosen\n", prog);
94         goto opthelp;
95     }
96
97     BIO_printf(bio_out, "%s\n", OPENSSL_info(type));
98     ret = 0;
99  end:
100     return ret;
101 }