Config code updates.
authorDr. Stephen Henson <steve@openssl.org>
Fri, 22 Feb 2002 13:58:15 +0000 (13:58 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 22 Feb 2002 13:58:15 +0000 (13:58 +0000)
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.

31 files changed:
CHANGES
apps/apps.h
apps/asn1pars.c
apps/ca.c
apps/crl.c
apps/dgst.c
apps/dh.c
apps/dhparam.c
apps/dsa.c
apps/dsaparam.c
apps/enc.c
apps/engine.c
apps/gendh.c
apps/gendsa.c
apps/genrsa.c
apps/ocsp.c
apps/passwd.c
apps/pkcs12.c
apps/pkcs8.c
apps/rand.c
apps/req.c
apps/rsa.c
apps/rsautl.c
apps/s_client.c
apps/s_server.c
apps/smime.c
apps/speed.c
apps/spkac.c
apps/verify.c
apps/x509.c
crypto/conf/conf_mod.c

diff --git a/CHANGES b/CHANGES
index 10c31f5d844f329c94144cfeff7b8d3476dd05d0..3829e4339b5463d26fa15a5b21948d0bea30e1f8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
          *) 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]
 
index db75538a03317f5928ed6451c4b6c9cb0abac371..aad2862123f438060dab0c36db23f710b34365c0 100644 (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);
index 4918bcb1c0654d5a90de194a8e91db7ac5f0f8ac..0e6167d2d44c237be0aa653b36bc23de75379460 100644 (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++;
index d009ebd624456c9037a5ecbc96be850a304f9c52..94820bff5b914b570f52149945d76da1e3217ea6 100644 (file)
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -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)
                {
index 5ea59d0169aabbdd047b366474d774eceb1c9618..f25b1877b59ed9caf3ce62808d4d6748bbd01bc1 100644 (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)
                        {
index 7989a1dcd38604c16864f5c1d420a5c1b733c6ea..c3e37be41fa159d4a28d388ffdb606a3495cde9a 100644 (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);
 
index dc854264f0bddcb40e012373ef0e0480485521e9..27c3dc8df22cdc8e86d5d8a80ccaaace72bff20d 100644 (file)
--- a/apps/dh.c
+++ b/apps/dh.c
@@ -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;
index e55d0ce0cbbcc8a268c2f9bb86e24b2d0a5db8e4..f1664a59b7acc9f7f558980734f7208fe8bafe41 100644 (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;
index 9d10a7c8608bf4868fc066a6539d0ee15ffcf98b..9da1a41645b78f493d78d24bb5c23410c9959617 100644 (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;
index 84a5ac6286ac129ca99f51e91c5db66c9a130c67..d54c77d93e56fbae0df005f26a78ce438192134f 100644 (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;
index a8b33874b0a068dccf535ebd3b77e74780319f45..d01060f226b8cdd6fafff346e1416cddd330b1b5 100644 (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)
index f71076b13b0f203af2d868d117e0770c4bebceec..734ecb3e5db0a4581bc5e495d7057f8785536041 100644 (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
        {
index 83cbff912007705bc469a81b58c9f7f1766ca341..f2542960bf28be2bb311a750fba474bd2490eb7d 100644 (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 (;;)
index ebee7f0269550df5f055a14b417c5bbd4b4b6f5d..1e1e9f3e4c4e672b439873ebc91db05613d12cef 100644 (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 (;;)
index 5a58235e0c6b97d2e349f2a6619bd1c62a8c3976..515bd7c9017135667781a2c8cc4ba3ae2ba84d16 100644 (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");
index 66460391fbfd0badd2bdb66f061e1c6c6b25d43c..c87edbc44b6f7abcd17eaa5450da574909319f01 100644 (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();
index d3fa228bdb4149f035a9eeda26e9ef779dcf449e..2023b76f5bf39a0bff01f6338b7413fbb7aaa59d 100644 (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;
index a42421803412261963a954820b6db6f7a1b23448..6a23b64f5e1c947547860453e5861950f5fe974f 100644 (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;
 
 
index c0becce9033776af57798a59529eb74cb8ba23ea..ea8c04dffa1281fc14b302460b4e6fb853788be4 100644 (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);
index 68622165eb890b551e5c5e13081ad3754f0f3477..f51f5bec3560d487c38d6e6fc45b2d51b56accda 100644 (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)
index c406b6444c0f64e4e64db12f3ca19bc1d5b58b7c..2ec2864005a0be2df4f8a0aebba704dad3a04d49 100644 (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();
index 6cadcb21747ad5a899bb024eeb231cc1bf08a30b..60a33815276443949c23f32cf9b0d9ffe6213a09 100644 (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;
index e079dc87f8fd8bbb0a302fdfafb1e9ce45126083..9b02e6782e01bc657fad82d95f8be43381ab60a9 100644 (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;
index 15a63cc9e6a8029daa9048a817fa8fe48afe7b08..9c0dbc2bf6f86a4814d2695569abbac79047c1ed 100644 (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))
index 618cb8d638e782bd198566b9f84032825ba26c3c..78d90fad55d8344df59433ed7118296cd3152a61 100644 (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;
index 731f9dd5d043cf392fa984d35d438bc840ec70f4..cd750e32b7cb9d157719f787fdad9e6f6dffc58e 100644 (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;
index 5e536680255cf7ada3d1cd892ba035273853c7b3..1c2b4eeda297b5c97dc88452e7d92a24eb4e5e94 100644 (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++)
index fa5dc248c88734b2addc97d2a27421125cd072f5..049a37963c2b6511f2251456cfca43f1e6223466 100644 (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++;
index 255bf5ad280fe58b0d661db382f9862b161656f0..215ef84fc75f5347e3ee530328f3fc9fedec8bf8 100644 (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 (;;)
index b2ea09d52fbfb48f099d028cdb2f98fee7698583..88386d613690b579c563e811cff65b7d6da12708 100644 (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
        {
index 7e88cfb62506c986e11d1bf75cb79089215bed63..459a2d7df191383578ed0f6c239d5ac947754ad0 100644 (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--)
                {