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,
17 OPT_ENGINESDIR,
18 OPT_MODULESDIR,
19 OPT_DSOEXT,
20 OPT_DIRNAMESEP,
21 OPT_LISTSEP,
22 OPT_SEEDS,
23 OPT_CPUSETTINGS,
24 OPT_WINDOWSCONTEXT
25 } OPTION_CHOICE;
26
27 const OPTIONS info_options[] = {
28
29 OPT_SECTION("General"),
30 { "help", OPT_HELP, '-', "Display this summary" },
31
32 OPT_SECTION("Output"),
33 { "configdir", OPT_CONFIGDIR, '-', "Default configuration file directory" },
34 { "enginesdir", OPT_ENGINESDIR, '-', "Default engine module directory" },
35 { "modulesdir", OPT_MODULESDIR, '-',
36 "Default module directory (other than engine modules)" },
37 { "dsoext", OPT_DSOEXT, '-', "Configured extension for modules" },
38 { "dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator" },
39 { "listsep", OPT_LISTSEP, '-', "List separator character" },
40 { "seeds", OPT_SEEDS, '-', "Seed sources" },
41 { "cpusettings", OPT_CPUSETTINGS, '-', "CPU settings info" },
42 { "windowscontext", OPT_WINDOWSCONTEXT, '-', "Windows install context" },
43 { NULL }
44 };
45
info_main(int argc,char ** argv)46 int info_main(int argc, char **argv)
47 {
48 int ret = 1, dirty = 0, type = 0;
49 char *prog;
50 OPTION_CHOICE o;
51 const char *typedata;
52
53 prog = opt_init(argc, argv, info_options);
54 while ((o = opt_next()) != OPT_EOF) {
55 switch (o) {
56 default:
57 opthelp:
58 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
59 goto end;
60 case OPT_HELP:
61 opt_help(info_options);
62 ret = 0;
63 goto end;
64 case OPT_CONFIGDIR:
65 type = OPENSSL_INFO_CONFIG_DIR;
66 dirty++;
67 break;
68 case OPT_ENGINESDIR:
69 type = OPENSSL_INFO_ENGINES_DIR;
70 dirty++;
71 break;
72 case OPT_MODULESDIR:
73 type = OPENSSL_INFO_MODULES_DIR;
74 dirty++;
75 break;
76 case OPT_DSOEXT:
77 type = OPENSSL_INFO_DSO_EXTENSION;
78 dirty++;
79 break;
80 case OPT_DIRNAMESEP:
81 type = OPENSSL_INFO_DIR_FILENAME_SEPARATOR;
82 dirty++;
83 break;
84 case OPT_LISTSEP:
85 type = OPENSSL_INFO_LIST_SEPARATOR;
86 dirty++;
87 break;
88 case OPT_SEEDS:
89 type = OPENSSL_INFO_SEED_SOURCE;
90 dirty++;
91 break;
92 case OPT_CPUSETTINGS:
93 type = OPENSSL_INFO_CPU_SETTINGS;
94 dirty++;
95 break;
96 case OPT_WINDOWSCONTEXT:
97 type = OPENSSL_INFO_WINDOWS_CONTEXT;
98 dirty++;
99 break;
100 }
101 }
102 if (!opt_check_rest_arg(NULL))
103 goto opthelp;
104 if (dirty > 1) {
105 BIO_printf(bio_err, "%s: Only one item allowed\n", prog);
106 goto opthelp;
107 }
108 if (dirty == 0) {
109 BIO_printf(bio_err, "%s: No items chosen\n", prog);
110 goto opthelp;
111 }
112
113 typedata = OPENSSL_info(type);
114 BIO_printf(bio_out, "%s\n", typedata == NULL ? "Undefined" : typedata);
115 ret = 0;
116 end:
117 return ret;
118 }
119