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, OPT_WINDOWSCONTEXT 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 {"windowscontext", OPT_WINDOWSCONTEXT, '-', "Windows install context"}, 36 {NULL} 37 }; 38 39 int info_main(int argc, char **argv) 40 { 41 int ret = 1, dirty = 0, type = 0; 42 char *prog; 43 OPTION_CHOICE o; 44 const char *typedata; 45 46 prog = opt_init(argc, argv, info_options); 47 while ((o = opt_next()) != OPT_EOF) { 48 switch (o) { 49 default: 50 opthelp: 51 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); 52 goto end; 53 case OPT_HELP: 54 opt_help(info_options); 55 ret = 0; 56 goto end; 57 case OPT_CONFIGDIR: 58 type = OPENSSL_INFO_CONFIG_DIR; 59 dirty++; 60 break; 61 case OPT_ENGINESDIR: 62 type = OPENSSL_INFO_ENGINES_DIR; 63 dirty++; 64 break; 65 case OPT_MODULESDIR: 66 type = OPENSSL_INFO_MODULES_DIR; 67 dirty++; 68 break; 69 case OPT_DSOEXT: 70 type = OPENSSL_INFO_DSO_EXTENSION; 71 dirty++; 72 break; 73 case OPT_DIRNAMESEP: 74 type = OPENSSL_INFO_DIR_FILENAME_SEPARATOR; 75 dirty++; 76 break; 77 case OPT_LISTSEP: 78 type = OPENSSL_INFO_LIST_SEPARATOR; 79 dirty++; 80 break; 81 case OPT_SEEDS: 82 type = OPENSSL_INFO_SEED_SOURCE; 83 dirty++; 84 break; 85 case OPT_CPUSETTINGS: 86 type = OPENSSL_INFO_CPU_SETTINGS; 87 dirty++; 88 break; 89 case OPT_WINDOWSCONTEXT: 90 type = OPENSSL_INFO_WINDOWS_CONTEXT; 91 dirty++; 92 break; 93 } 94 } 95 if (!opt_check_rest_arg(NULL)) 96 goto opthelp; 97 if (dirty > 1) { 98 BIO_printf(bio_err, "%s: Only one item allowed\n", prog); 99 goto opthelp; 100 } 101 if (dirty == 0) { 102 BIO_printf(bio_err, "%s: No items chosen\n", prog); 103 goto opthelp; 104 } 105 106 typedata = OPENSSL_info(type); 107 BIO_printf(bio_out, "%s\n", typedata == NULL ? "Undefined" : typedata); 108 ret = 0; 109 end: 110 return ret; 111 } 112