From 9c75b2d93169686b865c2ac49843e43050f8f96a Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Tue, 19 Feb 2002 23:25:18 +0000 Subject: [PATCH] Use default openssl.cnf if config filename set to NULL and openssl_conf if appname NULL. --- CHANGES | 4 ++++ apps/apps.c | 20 ++++++++++++++++++++ crypto/conf/conf_mall.c | 16 ++-------------- crypto/conf/conf_mod.c | 16 +++++++++++++++- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index bfb5562920..10c31f5d84 100644 --- a/CHANGES +++ b/CHANGES @@ -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(). diff --git a/apps/apps.c b/apps/apps.c index 7864e792e3..cb04ede33e 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -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; + } diff --git a/crypto/conf/conf_mall.c b/crypto/conf/conf_mall.c index e7b4bdb65e..c1bab7df3a 100644 --- a/crypto/conf/conf_mall.c +++ b/crypto/conf/conf_mall.c @@ -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(); diff --git a/crypto/conf/conf_mod.c b/crypto/conf/conf_mod.c index b922f01ba7..7e88cfb625 100644 --- a/crypto/conf/conf_mod.c +++ b/crypto/conf/conf_mod.c @@ -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; -- 2.25.1