586917298d667c627a1da28674dab9670518e022
[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, OPT_CPUSETTINGS
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     {"enginesdir", OPT_ENGINESDIR, '-', "Default engine module directory"},
24     {"modulesdir", OPT_MODULESDIR, '-',
25      "Default module directory (other than engine modules)"},
26     {"dsoext", OPT_DSOEXT, '-', "Configured extension for modules"},
27     {"dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator"},
28     {"listsep", OPT_LISTSEP, '-', "List separator character"},
29     {"seeds", OPT_SEEDS, '-', "Seed sources"},
30     {"cpusettings", OPT_CPUSETTINGS, '-', "CPU settings info"},
31     {NULL}
32 };
33
34 int info_main(int argc, char **argv)
35 {
36     int ret = 1, dirty = 0, type = 0;
37     char *prog;
38     OPTION_CHOICE o;
39
40     prog = opt_init(argc, argv, info_options);
41     while ((o = opt_next()) != OPT_EOF) {
42         switch (o) {
43         default:
44 opthelp:
45             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
46             goto end;
47         case OPT_HELP:
48             opt_help(info_options);
49             ret = 0;
50             goto end;
51         case OPT_CONFIGDIR:
52             type = OPENSSL_INFO_CONFIG_DIR;
53             dirty++;
54             break;
55         case OPT_ENGINESDIR:
56             type = OPENSSL_INFO_ENGINES_DIR;
57             dirty++;
58             break;
59         case OPT_MODULESDIR:
60             type = OPENSSL_INFO_MODULES_DIR;
61             dirty++;
62             break;
63         case OPT_DSOEXT:
64             type = OPENSSL_INFO_DSO_EXTENSION;
65             dirty++;
66             break;
67         case OPT_DIRNAMESEP:
68             type = OPENSSL_INFO_DIR_FILENAME_SEPARATOR;
69             dirty++;
70             break;
71         case OPT_LISTSEP:
72             type = OPENSSL_INFO_LIST_SEPARATOR;
73             dirty++;
74             break;
75         case OPT_SEEDS:
76             type = OPENSSL_INFO_SEED_SOURCE;
77             dirty++;
78             break;
79         case OPT_CPUSETTINGS:
80             type = OPENSSL_INFO_CPU_SETTINGS;
81             dirty++;
82             break;
83         }
84     }
85     if (opt_num_rest() != 0) {
86         BIO_printf(bio_err, "%s: Extra parameters given.\n", prog);
87         goto opthelp;
88     }
89     if (dirty > 1) {
90         BIO_printf(bio_err, "%s: Only one item allowed\n", prog);
91         goto opthelp;
92     }
93     if (dirty == 0) {
94         BIO_printf(bio_err, "%s: No items chosen\n", prog);
95         goto opthelp;
96     }
97
98     BIO_printf(bio_out, "%s\n", OPENSSL_info(type));
99     ret = 0;
100  end:
101     return ret;
102 }