Make sure that the 'config' variable is correctly defined and declared
[openssl.git] / apps / openssl.c
index f65096a68be712102227174d23dd43b15244c4ff..d0937156766773662dac7bc667c8b1e15719842e 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <string.h>
 #include <stdlib.h>
 #define OPENSSL_C /* tells apps.h to use complete apps_startup() */
+#include "apps.h"
 #include <openssl/bio.h>
 #include <openssl/crypto.h>
 #include <openssl/lhash.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
 #include <openssl/ssl.h>
+#include <openssl/engine.h>
 #define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */
-#include "apps.h"
 #include "progs.h"
 #include "s_apps.h"
 #include <openssl/err.h>
@@ -138,11 +139,11 @@ static unsigned long MS_CALLBACK hash(const void *a_void);
 static int MS_CALLBACK cmp(const void *a_void,const void *b_void);
 static LHASH *prog_init(void );
 static int do_cmd(LHASH *prog,int argc,char *argv[]);
-LHASH *config=NULL;
 char *default_config_file=NULL;
 
 /* Make sure there is only one when MONOLITH is defined */
 #ifdef MONOLITH
+CONF *config=NULL;
 BIO *bio_err=NULL;
 #endif
 
@@ -214,8 +215,8 @@ static void lock_dbg_cb(int mode, int type, const char *file, int line)
 int main(int Argc, char *Argv[])
        {
        ARGS arg;
-#define PROG_NAME_SIZE 16
-       char pname[PROG_NAME_SIZE];
+#define PROG_NAME_SIZE 39
+       char pname[PROG_NAME_SIZE+1];
        FUNCTION f,*fp;
        MS_STATIC char *prompt,buf[1024],config_name[256];
        int n,i,ret=0;
@@ -227,12 +228,17 @@ int main(int Argc, char *Argv[])
        arg.data=NULL;
        arg.count=0;
 
-       if (getenv("OPENSSL_DEBUG_MEMORY") != NULL)
+       if (getenv("OPENSSL_DEBUG_MEMORY") != NULL) /* if not defined, use compiled-in library defaults */
                {
                if (!(0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))
                        {
                        CRYPTO_malloc_debug_init();
-                       CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
+                       CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+                       }
+               else
+                       {
+                       /* OPENSSL_DEBUG_MEMORY=off */
+                       CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
                        }
                }
        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
@@ -250,9 +256,6 @@ 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);
 
-       ERR_load_crypto_strings();
-       ENGINE_load_builtin_engines();
-
        /* Lets load up our environment a little */
        p=getenv("OPENSSL_CONF");
        if (p == NULL)
@@ -269,8 +272,14 @@ int main(int Argc, char *Argv[])
 
        default_config_file=p;
 
-       config=CONF_load(config,p,&errline);
-       if (config == NULL) ERR_clear_error();
+       config=NCONF_new(NULL);
+       i=NCONF_load(config,p,&errline);
+       if (i == 0)
+               {
+               NCONF_free(config);
+               config = NULL;
+               ERR_clear_error();
+               }
 
        prog=prog_init();
 
@@ -339,16 +348,14 @@ int main(int Argc, char *Argv[])
 end:
        if (config != NULL)
                {
-               CONF_free(config);
+               NCONF_free(config);
                config=NULL;
                }
        if (prog != NULL) lh_free(prog);
        if (arg.data != NULL) OPENSSL_free(arg.data);
-       ERR_remove_state(0);
 
-       EVP_cleanup();
-       ERR_free_strings();
-       
+       apps_shutdown();
+
        CRYPTO_mem_leaks(bio_err);
        if (bio_err != NULL)
                {