Config code updates.

CONF_modules_unload() now calls CONF_modules_finish()
automatically.

Default use of section openssl_conf moved to
CONF_modules_load()

Load config file in several openssl utilities.

Most utilities now load modules from the config file,
though in a few (such as version) this isn't done
because it couldn't be used for anything.

In the case of ca and req the config file used is
the same as the utility itself: that is the -config
command line option can be used to specify an
alternative file.
This commit is contained in:
Dr. Stephen Henson 2002-02-22 13:58:15 +00:00
parent 7c2831ac90
commit 0cd8572b2d
31 changed files with 105 additions and 5 deletions

14
CHANGES
View File

@ -13,7 +13,19 @@
*) 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
+) Config modules support in openssl utility.
Most commands now load modules from the config file,
though in a few (such as version) this isn't done
because it couldn't be used for anything.
In the case of ca and req the config file used is
the same as the utility itself: that is the -config
command line option can be used to specify an
alternative file.
[Steve Henson]
+) Move default behaviour from OPENSSL_config(). If appname is NULL
use "openssl_conf" if filename is NULL use default openssl config file.
[Steve Henson]

View File

@ -196,7 +196,8 @@ extern BIO *bio_err;
# define apps_shutdown() \
do { destroy_ui_method(); EVP_cleanup(); \
ENGINE_cleanup(); CRYPTO_cleanup_all_ex_data(); \
ERR_remove_state(0); ERR_free_strings(); } while(0)
ERR_remove_state(0); ERR_free_strings(); \
CONF_modules_unload(1); } while(0)
#endif
typedef struct args_st
@ -244,6 +245,8 @@ STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath);
ENGINE *setup_engine(BIO *err, const char *engine, int debug);
int load_config(BIO *err, CONF *cnf);
/* Functions defined in ca.c and also used in ocsp.c */
int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
ASN1_GENERALIZEDTIME **pinvtm, char *str);

View File

@ -103,6 +103,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
prog=argv[0];
argc--;
argv++;

View File

@ -590,6 +590,9 @@ bad:
goto err;
}
if (!load_config(bio_err, conf))
goto err;
/* Lets get the config section we are using */
if (section == NULL)
{

View File

@ -120,6 +120,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
if (bio_out == NULL)
if ((bio_out=BIO_new(BIO_s_file())) != NULL)
{

View File

@ -112,6 +112,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
/* first check the program name */
program_name(argv[0],pname,PROG_NAME_SIZE);

View File

@ -100,6 +100,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
engine=NULL;
infile=NULL;
outfile=NULL;

View File

@ -166,6 +166,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
infile=NULL;
outfile=NULL;
informat=FORMAT_PEM;

View File

@ -109,6 +109,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
engine=NULL;
infile=NULL;
outfile=NULL;

View File

@ -106,6 +106,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
infile=NULL;
outfile=NULL;
informat=FORMAT_PEM;

View File

@ -127,6 +127,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
/* first check the program name */
program_name(argv[0],pname,PROG_NAME_SIZE);
if (strcmp(pname,"base64") == 0)

View File

@ -356,6 +356,9 @@ int MAIN(int argc, char **argv)
if (bio_err == NULL)
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
if (!load_config(bio_err, NULL))
goto end;
bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);
#ifdef OPENSSL_SYS_VMS
{

View File

@ -96,6 +96,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
argv++;
argc--;
for (;;)

View File

@ -93,6 +93,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
argv++;
argc--;
for (;;)

View File

@ -99,6 +99,9 @@ int MAIN(int argc, char **argv)
if (bio_err == NULL)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto err;
if ((out=BIO_new(BIO_s_file())) == NULL)
{
BIO_printf(bio_err,"unable to create BIO for output\n");

View File

@ -145,6 +145,9 @@ int MAIN(int argc, char **argv)
int nmin = 0, ndays = -1;
if (bio_err == NULL) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
if (!load_config(bio_err, NULL))
goto end;
SSL_load_error_strings();
args = argv + 1;
reqnames = sk_new_null();

View File

@ -79,6 +79,9 @@ int MAIN(int argc, char **argv)
if (bio_err == NULL)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto err;
out = BIO_new(BIO_s_file());
if (out == NULL)
goto err;

View File

@ -127,6 +127,9 @@ int MAIN(int argc, char **argv)
enc = EVP_des_ede3_cbc();
if (bio_err == NULL ) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
if (!load_config(bio_err, NULL))
goto end;
args = argv + 1;

View File

@ -90,6 +90,9 @@ int MAIN(int argc, char **argv)
if (bio_err == NULL) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
if (!load_config(bio_err, NULL))
goto end;
informat=FORMAT_PEM;
outformat=FORMAT_PEM;
@ -347,6 +350,7 @@ int MAIN(int argc, char **argv)
return (1);
}
end:
EVP_PKEY_free(pkey);
BIO_free_all(out);
BIO_free(in);

View File

@ -92,6 +92,9 @@ int MAIN(int argc, char **argv)
if ((bio_err = BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto err;
badopt = 0;
i = 0;
while (!badopt && argv[++i] != NULL)

View File

@ -503,6 +503,8 @@ bad:
if (req_conf != NULL)
{
if (!load_config(bio_err, req_conf))
goto end;
p=NCONF_get_string(req_conf,NULL,"oid_file");
if (p == NULL)
ERR_clear_error();

View File

@ -113,6 +113,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
infile=NULL;
outfile=NULL;
informat=FORMAT_PEM;

View File

@ -104,6 +104,9 @@ int MAIN(int argc, char **argv)
argv++;
if(!bio_err) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
if (!load_config(bio_err, NULL))
goto end;
ERR_load_crypto_strings();
OpenSSL_add_all_algorithms();
pad = RSA_PKCS1_PADDING;

View File

@ -271,6 +271,9 @@ int MAIN(int argc, char **argv)
if (bio_err == NULL)
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
if (!load_config(bio_err, NULL))
goto end;
if ( ((cbuf=OPENSSL_malloc(BUFSIZZ)) == NULL) ||
((sbuf=OPENSSL_malloc(BUFSIZZ)) == NULL) ||
((mbuf=OPENSSL_malloc(BUFSIZZ)) == NULL))

View File

@ -504,6 +504,9 @@ int MAIN(int argc, char *argv[])
if (bio_err == NULL)
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
if (!load_config(bio_err, NULL))
goto end;
verify_depth=0;
#ifdef FIONBIO
s_nbio=0;

View File

@ -109,6 +109,9 @@ int MAIN(int argc, char **argv)
args = argv + 1;
ret = 1;
if (!load_config(bio_err, NULL))
goto end;
while (!badarg && *args && *args[0] == '-') {
if (!strcmp (*args, "-encrypt")) operation = SMIME_ENCRYPT;
else if (!strcmp (*args, "-decrypt")) operation = SMIME_DECRYPT;

View File

@ -515,6 +515,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
#ifndef OPENSSL_NO_RSA
memset(rsa_key,0,sizeof(rsa_key));
for (i=0; i<RSA_NUM; i++)

View File

@ -98,6 +98,9 @@ int MAIN(int argc, char **argv)
if (!bio_err) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
if (!load_config(bio_err, NULL))
goto end;
prog=argv[0];
argc--;
argv++;

View File

@ -100,6 +100,9 @@ int MAIN(int argc, char **argv)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
argc--;
argv++;
for (;;)

View File

@ -191,6 +191,9 @@ int MAIN(int argc, char **argv)
if (bio_err == NULL)
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
if (!load_config(bio_err, NULL))
goto end;
STDout=BIO_new_fp(stdout,BIO_NOCLOSE);
#ifdef OPENSSL_SYS_VMS
{

View File

@ -130,9 +130,11 @@ int CONF_modules_load(const CONF *cnf, const char *appname,
int ret, i;
if (!cnf || !appname)
if (!cnf)
return 1;
if (appname == NULL)
appname = "openssl_conf";
vsection = NCONF_get_string(cnf, NULL, appname);
@ -178,8 +180,6 @@ int CONF_modules_load_file(const char *filename, const char *appname,
}
else
file = (char *)filename;
if (appname == NULL)
appname = "openssl_conf";
if (NCONF_load(conf, file, NULL) <= 0)
{
@ -422,6 +422,7 @@ void CONF_modules_unload(int all)
{
int i;
CONF_MODULE *md;
CONF_modules_finish();
/* unload modules in reverse order */
for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--)
{