- if (errstr)
- {
- /* we cannot use bio_err here */
- fprintf(stderr, "openssl (lock_dbg_cb): %s (mode=%d, type=%d) at %s:%d\n",
- errstr, mode, type, file, line);
- }
- }
-
-
-int main(int Argc, char *_Argv[])
- {
- ARGS arg;
-#define PROG_NAME_SIZE 39
- char pname[PROG_NAME_SIZE+1];
- FUNCTION f,*fp;
- MS_STATIC const char *prompt;
- MS_STATIC char buf[1024];
- char *to_free=NULL;
- int n,i,ret=0;
- int argc;
- char **argv,*p;
- LHASH_OF(FUNCTION) *prog=NULL;
- long errline;
-
-#if defined( OPENSSL_SYS_VMS) && !defined( VMS_TRUST_ARGV)
- /* 2011-03-08 SMS.
- * "HP C V7.3-009 on OpenVMS Alpha V8.3" with 64-bit
- * pointers (at least) may not NULL-terminate argv[]
- * as expected. If necessary, use a (properly)
- * NULL-terminated duplicate of argv[].
- */
- /* 2011-03-20 RL.
- * Additionally, when the argument vector is full of
- * 32-bit pointers and we have a 64-bit pointer size
- * everywhere else, we need to make a copy of it using
- * 64-bit pointers. Hence the odd conditinal.
- */
- char **Argv = NULL;
- int free_Argv = 0;
-
- if (_Argv[ Argc] != NULL
-# if defined(__INITIAL_POINTER_SIZE)
- || sizeof(_Argv) < (__INITIAL_POINTER_SIZE / 8)
-# endif
- )
- {
- int i;
- Argv = OPENSSL_malloc( (Argc+ 1)* sizeof( char *));
- if (Argv == NULL)
- { ret = -1; goto end; }
- for(i = 0; i < Argc; i++)
- Argv[i] = _Argv[i];
- Argv[ Argc] = NULL;
- free_Argv = 1;
- }
- else
- {
- /* 2011-03-20 RL.
- * If we didn't copy the argument vector, then simply
- * assign our variable. This will never happen when
- * the argument vector pointer size was smaller than
- * the initial pointer size, so even if the case might
- * look unsafe, it isn't, it's just there to shut the
- * compiler up.
- */
- Argv = (char **)_Argv;
- }
-#else
- char **Argv = _Argv;
-#endif
-
- arg.data=NULL;
- arg.count=0;
-
- 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 (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_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);
-
-#if 0
- if (getenv("OPENSSL_DEBUG_LOCKING") != NULL)
-#endif
- {
- CRYPTO_set_locking_callback(lock_dbg_cb);
- }
-
- apps_startup();
-
- /* Lets load up our environment a little */
- p=getenv("OPENSSL_CONF");
- if (p == NULL)
- p=getenv("SSLEAY_CONF");
- if (p == NULL)
- p=to_free=make_config_name();
-
- default_config_file=p;
-
- config=NCONF_new(NULL);
- i=NCONF_load(config,p,&errline);
- if (i == 0)
- {
- if (ERR_GET_REASON(ERR_peek_last_error())
- == CONF_R_NO_SUCH_FILE)
- {
- BIO_printf(bio_err,
- "WARNING: can't open config file: %s\n",p);
- ERR_clear_error();
- NCONF_free(config);
- config = NULL;
- }
- else
- {
- ERR_print_errors(bio_err);
- NCONF_free(config);
- exit(1);
- }
- }
-
- prog=prog_init();
-
- /* first check the program name */
- program_name(Argv[0],pname,sizeof pname);
-
- f.name=pname;
- fp=lh_FUNCTION_retrieve(prog,&f);
- if (fp != NULL)
- {
- Argv[0]=pname;
- ret=fp->func(Argc,Argv);
- goto end;
- }
-
- /* ok, now check that there are not arguments, if there are,
- * run with them, shifting the ssleay off the front */
- if (Argc != 1)
- {
- Argc--;
- Argv++;
- ret=do_cmd(prog,Argc,Argv);
- if (ret < 0) ret=0;
- goto end;
- }
-
- /* ok, lets enter the old 'OpenSSL>' mode */
-
- for (;;)
- {
- ret=0;
- p=buf;
- n=sizeof buf;
- i=0;
- for (;;)
- {
- p[0]='\0';
- if (i++)
- prompt=">";
- else prompt="OpenSSL> ";
- fputs(prompt,stdout);
- fflush(stdout);
- if (!fgets(p,n,stdin))
- goto end;
- if (p[0] == '\0') goto end;
- i=strlen(p);
- if (i <= 1) break;
- if (p[i-2] != '\\') break;
- i-=2;
- p+=i;
- n-=i;
- }
- if (!chopup_args(&arg,buf,&argc,&argv)) break;
-
- ret=do_cmd(prog,argc,argv);
- if (ret < 0)
- {
- ret=0;
- goto end;
- }
- if (ret != 0)
- BIO_printf(bio_err,"error in %s\n",argv[0]);
- (void)BIO_flush(bio_err);
- }
- BIO_printf(bio_err,"bad exit\n");
- ret=1;
-end:
- if (to_free)
- OPENSSL_free(to_free);
- if (config != NULL)
- {
- NCONF_free(config);
- config=NULL;
- }
- if (prog != NULL) lh_FUNCTION_free(prog);
- if (arg.data != NULL) OPENSSL_free(arg.data);
-
- apps_shutdown();
-
- CRYPTO_mem_leaks(bio_err);
- if (bio_err != NULL)
- {
- BIO_free(bio_err);
- bio_err=NULL;
- }
-#if defined( OPENSSL_SYS_VMS) && !defined( VMS_TRUST_ARGV)
- /* Free any duplicate Argv[] storage. */
- if (free_Argv)
- {
- OPENSSL_free(Argv);
- }
-#endif
- OPENSSL_EXIT(ret);
- }
-
-#define LIST_STANDARD_COMMANDS "list-standard-commands"
-#define LIST_MESSAGE_DIGEST_COMMANDS "list-message-digest-commands"
-#define LIST_MESSAGE_DIGEST_ALGORITHMS "list-message-digest-algorithms"
-#define LIST_CIPHER_COMMANDS "list-cipher-commands"
-#define LIST_CIPHER_ALGORITHMS "list-cipher-algorithms"
-#define LIST_PUBLIC_KEY_ALGORITHMS "list-public-key-algorithms"