Use default openssl.cnf if config filename set to NULL and

openssl_conf if appname NULL.
This commit is contained in:
Dr. Stephen Henson 2002-02-19 23:25:18 +00:00
parent 54d11e6057
commit 9c75b2d931
4 changed files with 41 additions and 15 deletions

View File

@ -13,6 +13,10 @@
*) applies to 0.9.6a/0.9.6b/0.9.6c and 0.9.7
+) applies to 0.9.7 only
+) Move default behaviour to CONF_modules_load_file(). Is appname is NULL
use "openssl_conf" if filename is NULL use default openssl config file.
[Steve Henson]
+) Add an argument to OPENSSL_config() to allow the use of an alternative
config section name. Add a new flag to tolerate a missing config file
and move code to CONF_modules_load_file().

View File

@ -1314,3 +1314,23 @@ ENGINE *setup_engine(BIO *err, const char *engine, int debug)
}
return e;
}
int load_config(char *filename, BIO *err)
{
unsigned long flags;
if (filename)
flags = 0;
else
flags = CONF_MFLAGS_IGNORE_MISSING_FILE;
if (CONF_modules_load_file(filename, NULL, flags) <= 0)
{
if (err)
{
BIO_printf(err, "Error loading config file\n");
ERR_print_errors(err);
}
return 0;
}
return 1;
}

View File

@ -83,26 +83,14 @@ static int openssl_configured = 0;
void OPENSSL_config(const char *config_name)
{
int err_exit = 0;
char *file;
if (openssl_configured)
return;
OPENSSL_load_builtin_modules();
file = CONF_get1_default_config_file();
if (!file)
return;
if (config_name == NULL)
config_name = "openssl_conf";
ERR_clear_error();
if (CONF_modules_load_file(file, config_name,
CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0)
err_exit = 1;
OPENSSL_free(file);
if (err_exit)
if (CONF_modules_load_file(NULL, NULL,
CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0)
{
BIO *bio_err;
ERR_load_crypto_strings();

View File

@ -163,13 +163,25 @@ int CONF_modules_load(const CONF *cnf, const char *appname,
int CONF_modules_load_file(const char *filename, const char *appname,
unsigned long flags)
{
char *file;
CONF *conf = NULL;
int ret = 0;
conf = NCONF_new(NULL);
if (!conf)
goto err;
if (NCONF_load(conf, filename, NULL) <= 0)
if (filename == NULL)
{
file = CONF_get1_default_config_file();
if (!file)
goto err;
}
else
file = (char *)filename;
if (appname == NULL)
appname = "openssl_conf";
if (NCONF_load(conf, file, NULL) <= 0)
{
if ((flags & CONF_MFLAGS_IGNORE_MISSING_FILE) &&
(ERR_GET_REASON(ERR_peek_last_error()) == CONF_R_NO_SUCH_FILE))
@ -183,6 +195,8 @@ int CONF_modules_load_file(const char *filename, const char *appname,
ret = CONF_modules_load(conf, appname, flags);
err:
if (filename == NULL)
OPENSSL_free(file);
NCONF_free(conf);
return ret;