diff options
author | Pauli <pauli@openssl.org> | 2021-06-10 16:58:12 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-06-15 18:26:47 +1000 |
commit | a1fb5eb920fb156eda474f0e59d268316b6c893d (patch) | |
tree | 953573eb02ca107a7fe30b806fa9e0fce9b21c8e /apps | |
parent | c696f4bfc303d9b43a3167f48b3661972495211c (diff) |
apps: move global libctx and property query into their own file
The header has been split out so the functions should be as well.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15687)
Diffstat (limited to 'apps')
-rw-r--r-- | apps/include/app_libctx.h | 2 | ||||
-rw-r--r-- | apps/lib/app_libctx.c | 48 | ||||
-rw-r--r-- | apps/lib/apps.c | 43 | ||||
-rw-r--r-- | apps/lib/build.info | 2 |
4 files changed, 53 insertions, 42 deletions
diff --git a/apps/include/app_libctx.h b/apps/include/app_libctx.h index 61b143b7db..17c0afc713 100644 --- a/apps/include/app_libctx.h +++ b/apps/include/app_libctx.h @@ -10,6 +10,8 @@ #ifndef OSSL_APPS_LIBCTX_H # define OSSL_APPS_LIBCTX_H +# include <openssl/types.h> + OSSL_LIB_CTX *app_create_libctx(void); OSSL_LIB_CTX *app_get0_libctx(void); int app_set_propq(const char *arg); diff --git a/apps/lib/app_libctx.c b/apps/lib/app_libctx.c new file mode 100644 index 0000000000..4b9ec40e85 --- /dev/null +++ b/apps/lib/app_libctx.c @@ -0,0 +1,48 @@ +/* + * Copyright 1995-2021 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 "app_libctx.h" +#include "apps.h" + +static OSSL_LIB_CTX *app_libctx = NULL; +static const char *app_propq = NULL; + +int app_set_propq(const char *arg) +{ + app_propq = arg; + return 1; +} + +const char *app_get0_propq(void) +{ + return app_propq; +} + +OSSL_LIB_CTX *app_get0_libctx(void) +{ + return app_libctx; +} + +OSSL_LIB_CTX *app_create_libctx(void) +{ + /* + * Load the NULL provider into the default library context and create a + * library context which will then be used for any OPT_PROV options. + */ + if (app_libctx == NULL) { + if (!app_provider_load(NULL, "null")) { + opt_printf_stderr( "Failed to create null provider\n"); + return NULL; + } + app_libctx = OSSL_LIB_CTX_new(); + } + if (app_libctx == NULL) + opt_printf_stderr("Failed to create library context\n"); + return app_libctx; +} + diff --git a/apps/lib/apps.c b/apps/lib/apps.c index 79fe4f8409..dfbc3ec522 100644 --- a/apps/lib/apps.c +++ b/apps/lib/apps.c @@ -69,8 +69,6 @@ typedef struct { unsigned long mask; } NAME_EX_TBL; -static OSSL_LIB_CTX *app_libctx = NULL; - static int set_table_opts(unsigned long *flags, const char *arg, const NAME_EX_TBL * in_tbl); static int set_multi_opts(unsigned long *flags, const char *arg, @@ -336,50 +334,13 @@ static char *app_get_pass(const char *arg, int keepbio) return OPENSSL_strdup(tpass); } -OSSL_LIB_CTX *app_get0_libctx(void) -{ - return app_libctx; -} - -static const char *app_propq = NULL; - -int app_set_propq(const char *arg) -{ - app_propq = arg; - return 1; -} - -const char *app_get0_propq(void) -{ - return app_propq; -} - -OSSL_LIB_CTX *app_create_libctx(void) -{ - /* - * Load the NULL provider into the default library context and create a - * library context which will then be used for any OPT_PROV options. - */ - if (app_libctx == NULL) { - - if (!app_provider_load(NULL, "null")) { - BIO_puts(bio_err, "Failed to create null provider\n"); - return NULL; - } - app_libctx = OSSL_LIB_CTX_new(); - } - if (app_libctx == NULL) - BIO_puts(bio_err, "Failed to create library context\n"); - return app_libctx; -} - CONF *app_load_config_bio(BIO *in, const char *filename) { long errorline = -1; CONF *conf; int i; - conf = NCONF_new_ex(app_libctx, NULL); + conf = NCONF_new_ex(app_get0_libctx(), NULL); i = NCONF_load_bio(conf, in, &errorline); if (i > 0) return conf; @@ -422,7 +383,7 @@ CONF *app_load_config_internal(const char *filename, int quiet) BIO_free(in); } else { /* Return empty config if filename is empty string. */ - conf = NCONF_new_ex(app_libctx, NULL); + conf = NCONF_new_ex(app_get0_libctx(), NULL); } return conf; } diff --git a/apps/lib/build.info b/apps/lib/build.info index 340ce29b09..923ef5d92b 100644 --- a/apps/lib/build.info +++ b/apps/lib/build.info @@ -10,7 +10,7 @@ ENDIF # Source for libapps $LIBAPPSSRC=apps.c apps_ui.c opt.c fmt.c s_cb.c s_socket.c app_rand.c \ columns.c app_params.c names.c app_provider.c app_x509.c http_server.c \ - engine.c engine_loader.c + engine.c engine_loader.c app_libctx.c IF[{- !$disabled{apps} -}] LIBS{noinst}=../libapps.a |