xref: /openssl/apps/info.c (revision 7ed6de99)
1 /*
2  * Copyright 2019-2024 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_COMMON,
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 
22     OPT_SECTION("General"),
23     {"help", OPT_HELP, '-', "Display this summary"},
24 
25     OPT_SECTION("Output"),
26     {"configdir", OPT_CONFIGDIR, '-', "Default configuration file directory"},
27     {"enginesdir", OPT_ENGINESDIR, '-', "Default engine module directory"},
28     {"modulesdir", OPT_MODULESDIR, '-',
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     {"cpusettings", OPT_CPUSETTINGS, '-', "CPU settings info"},
35     {NULL}
36 };
37 
info_main(int argc,char ** argv)38 int info_main(int argc, char **argv)
39 {
40     int ret = 1, dirty = 0, type = 0;
41     char *prog;
42     OPTION_CHOICE o;
43     const char *typedata;
44 
45     prog = opt_init(argc, argv, info_options);
46     while ((o = opt_next()) != OPT_EOF) {
47         switch (o) {
48         default:
49 opthelp:
50             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
51             goto end;
52         case OPT_HELP:
53             opt_help(info_options);
54             ret = 0;
55             goto end;
56         case OPT_CONFIGDIR:
57             type = OPENSSL_INFO_CONFIG_DIR;
58             dirty++;
59             break;
60         case OPT_ENGINESDIR:
61             type = OPENSSL_INFO_ENGINES_DIR;
62             dirty++;
63             break;
64         case OPT_MODULESDIR:
65             type = OPENSSL_INFO_MODULES_DIR;
66             dirty++;
67             break;
68         case OPT_DSOEXT:
69             type = OPENSSL_INFO_DSO_EXTENSION;
70             dirty++;
71             break;
72         case OPT_DIRNAMESEP:
73             type = OPENSSL_INFO_DIR_FILENAME_SEPARATOR;
74             dirty++;
75             break;
76         case OPT_LISTSEP:
77             type = OPENSSL_INFO_LIST_SEPARATOR;
78             dirty++;
79             break;
80         case OPT_SEEDS:
81             type = OPENSSL_INFO_SEED_SOURCE;
82             dirty++;
83             break;
84         case OPT_CPUSETTINGS:
85             type = OPENSSL_INFO_CPU_SETTINGS;
86             dirty++;
87             break;
88         }
89     }
90     if (!opt_check_rest_arg(NULL))
91         goto opthelp;
92     if (dirty > 1) {
93         BIO_printf(bio_err, "%s: Only one item allowed\n", prog);
94         goto opthelp;
95     }
96     if (dirty == 0) {
97         BIO_printf(bio_err, "%s: No items chosen\n", prog);
98         goto opthelp;
99     }
100 
101     typedata = OPENSSL_info(type);
102     BIO_printf(bio_out, "%s\n", typedata == NULL ? "Undefined" : typedata);
103     ret = 0;
104  end:
105     return ret;
106 }
107