155682Smarkm/* apps/errstr.c */
2178825Sdfr/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
355682Smarkm * All rights reserved.
455682Smarkm *
555682Smarkm * This package is an SSL implementation written
655682Smarkm * by Eric Young (eay@cryptsoft.com).
755682Smarkm * The implementation was written so as to conform with Netscapes SSL.
855682Smarkm *
955682Smarkm * This library is free for commercial and non-commercial use as long as
1055682Smarkm * the following conditions are aheared to.  The following conditions
1155682Smarkm * apply to all code found in this distribution, be it the RC4, RSA,
1255682Smarkm * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1355682Smarkm * included with this distribution is covered by the same copyright terms
1455682Smarkm * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1555682Smarkm *
1655682Smarkm * Copyright remains Eric Young's, and as such any Copyright notices in
1755682Smarkm * the code are not to be removed.
1855682Smarkm * If this package is used in a product, Eric Young should be given attribution
1955682Smarkm * as the author of the parts of the library used.
2055682Smarkm * This can be in the form of a textual message at program startup or
2155682Smarkm * in documentation (online or textual) provided with the package.
2255682Smarkm *
2355682Smarkm * Redistribution and use in source and binary forms, with or without
2455682Smarkm * modification, are permitted provided that the following conditions
2555682Smarkm * are met:
2655682Smarkm * 1. Redistributions of source code must retain the copyright
2755682Smarkm *    notice, this list of conditions and the following disclaimer.
2855682Smarkm * 2. Redistributions in binary form must reproduce the above copyright
2955682Smarkm *    notice, this list of conditions and the following disclaimer in the
3055682Smarkm *    documentation and/or other materials provided with the distribution.
3155682Smarkm * 3. All advertising materials mentioning features or use of this software
3255682Smarkm *    must display the following acknowledgement:
3355682Smarkm *    "This product includes cryptographic software written by
3455682Smarkm *     Eric Young (eay@cryptsoft.com)"
3555682Smarkm *    The word 'cryptographic' can be left out if the rouines from the library
36178825Sdfr *    being used are not cryptographic related :-).
3755682Smarkm * 4. If you include any Windows specific code (or a derivative thereof) from
38178825Sdfr *    the apps directory (application code) you must include an acknowledgement:
39178825Sdfr *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40178825Sdfr *
41178825Sdfr * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42178825Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43178825Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44178825Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45178825Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46178825Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47178825Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48178825Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49178825Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50178825Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5157419Smarkm * SUCH DAMAGE.
5257419Smarkm *
5357419Smarkm * The licence and distribution terms for any publically available version or
5457419Smarkm * derivative of this code cannot be changed.  i.e. this code cannot simply be
5555682Smarkm * copied and put under another distribution licence
5655682Smarkm * [including the GNU Public Licence.]
5755682Smarkm */
5855682Smarkm
5955682Smarkm#include <stdio.h>
6055682Smarkm#include <stdlib.h>
6157419Smarkm#include <string.h>
6257419Smarkm#include "apps.h"
6355682Smarkm#include <openssl/bio.h>
6455682Smarkm#include <openssl/lhash.h>
6555682Smarkm#include <openssl/err.h>
6657419Smarkm#include <openssl/ssl.h>
6757419Smarkm
6857419Smarkm#undef PROG
6957419Smarkm#define PROG	errstr_main
7055682Smarkm
71178825Sdfrint MAIN(int, char **);
72178825Sdfr
7355682Smarkmint MAIN(int argc, char **argv)
7455682Smarkm	{
7555682Smarkm	int i,ret=0;
7655682Smarkm	char buf[256];
7755682Smarkm	unsigned long l;
7855682Smarkm
7955682Smarkm	apps_startup();
8055682Smarkm
8155682Smarkm	if (bio_err == NULL)
8255682Smarkm		if ((bio_err=BIO_new(BIO_s_file())) != NULL)
8355682Smarkm			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
8455682Smarkm
8555682Smarkm	SSL_load_error_strings();
8655682Smarkm
8755682Smarkm	if ((argc > 1) && (strcmp(argv[1],"-stats") == 0))
8855682Smarkm		{
8955682Smarkm		BIO *out=NULL;
9057419Smarkm
9157419Smarkm		out=BIO_new(BIO_s_file());
9255682Smarkm		if ((out != NULL) && BIO_set_fp(out,stdout,BIO_NOCLOSE))
9355682Smarkm			{
9455682Smarkm#ifdef OPENSSL_SYS_VMS
9555682Smarkm			{
9655682Smarkm			BIO *tmpbio = BIO_new(BIO_f_linebuffer());
9755682Smarkm			out = BIO_push(tmpbio, out);
9857419Smarkm			}
9957419Smarkm#endif
10057419Smarkm			lh_ERR_STRING_DATA_node_stats_bio(
10157419Smarkm						  ERR_get_string_table(), out);
10257419Smarkm			lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(),
10355682Smarkm						     out);
104178825Sdfr			lh_ERR_STRING_DATA_node_usage_stats_bio(
105178825Sdfr						    ERR_get_string_table(),out);
10655682Smarkm			}
10755682Smarkm		if (out != NULL) BIO_free_all(out);
10855682Smarkm		argc--;
109178825Sdfr		argv++;
11055682Smarkm		}
11155682Smarkm
11257419Smarkm	for (i=1; i<argc; i++)
11357419Smarkm		{
11457419Smarkm		if (sscanf(argv[i],"%lx",&l))
11557419Smarkm			{
11657419Smarkm			ERR_error_string_n(l, buf, sizeof buf);
11755682Smarkm			printf("%s\n",buf);
118178825Sdfr			}
119178825Sdfr		else
12055682Smarkm			{
12155682Smarkm			printf("%s: bad error code\n",argv[i]);
12255682Smarkm			printf("usage: errstr [-stats] <errno> ...\n");
12355682Smarkm			ret++;
124178825Sdfr			}
12555682Smarkm		}
12655682Smarkm	apps_shutdown();
12755682Smarkm	OPENSSL_EXIT(ret);
12855682Smarkm	}
12955682Smarkm