mirror of https://github.com/openssl/openssl
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)
This commit is contained in:
parent
c696f4bfc3
commit
a1fb5eb920
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue