diff options
author | Richard Levitte <levitte@openssl.org> | 2019-04-09 14:39:54 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-04-23 15:51:39 +0200 |
commit | 0109e030db9207a47e195b4c3a3b13e9017f0ed2 (patch) | |
tree | 835826a1f94de53d09cb15c8752ce428ffdd0b46 /crypto | |
parent | 47ca8338358b01ef429a3801ce6173f7a0791674 (diff) |
Add a way for the application to get OpenSSL configuration data
OpenSSL_version(OPENSSL_DIR) gives you a nicely formatted string for
display, but if all you really want is the directory itself, you were
forced to parsed the string.
This introduces a new function to get diverse configuration data from
the library, OPENSSL_info(). This works the same way as
OpenSSL_version(), but has its own series of types, currently
including:
OPENSSL_INFO_CONFIG_DIR returns OPENSSLDIR
OPENSSL_INFO_ENGINES_DIR returns ENGINESDIR
OPENSSL_INFO_MODULES_DIR returns MODULESDIR
OPENSSL_INFO_DSO_EXTENSION returns DSO_EXTENSION
OPENSSL_INFO_DIR_FILENAME_SEPARATOR returns directory/filename separator
OPENSSL_INFO_LIST_SEPARATOR returns list separator
For scripting purposes, this also adds the command 'openssl info'.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8709)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/build.info | 2 | ||||
-rw-r--r-- | crypto/info.c | 44 |
2 files changed, 45 insertions, 1 deletions
diff --git a/crypto/build.info b/crypto/build.info index 77dcffb906..30dcf8c91e 100644 --- a/crypto/build.info +++ b/crypto/build.info @@ -14,7 +14,7 @@ SOURCE[../libcrypto]=provider_core.c provider_predefined.c provider_conf.c \ # Central utilities SOURCE[../libcrypto]=\ - cryptlib.c mem.c mem_dbg.c cversion.c ex_data.c cpt_err.c \ + cryptlib.c mem.c mem_dbg.c cversion.c info.c ex_data.c cpt_err.c \ ebcdic.c uid.c o_time.c o_str.c o_dir.c o_fopen.c ctype.c \ threads_pthread.c threads_win.c threads_none.c getenv.c \ o_init.c o_fips.c mem_sec.c init.c context.c sparse_array.c \ diff --git a/crypto/info.c b/crypto/info.c new file mode 100644 index 0000000000..5a929ddd03 --- /dev/null +++ b/crypto/info.c @@ -0,0 +1,44 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <stddef.h> +#include <openssl/crypto.h> +#include "internal/dso_conf.h" +#include "e_os.h" + +const char *OPENSSL_info(int t) +{ + switch (t) { + case OPENSSL_INFO_CONFIG_DIR: + return OPENSSLDIR; + case OPENSSL_INFO_ENGINES_DIR: + return ENGINESDIR; + case OPENSSL_INFO_MODULES_DIR: + return MODULESDIR; + case OPENSSL_INFO_DSO_EXTENSION: + return DSO_EXTENSION; + case OPENSSL_INFO_DIR_FILENAME_SEPARATOR: +#if defined(_WIN32) + return "\\"; +#elif defined(__VMS) + return ""; +#else /* Assume POSIX */ + return "/"; +#endif + case OPENSSL_INFO_LIST_SEPARATOR: + { + static const char list_sep[] = { LIST_SEPARATOR_CHAR, '\0' }; + return list_sep; + } + default: + break; + } + /* Not an error */ + return NULL; +} |