示例#1
0
int
errstr_main(int argc, char **argv)
{
	unsigned long ulval;
	char *ularg, *ep;
	int argsused, i;
	char buf[256];
	int ret = 0;

	if (single_execution) {
		if (pledge("stdio rpath", NULL) == -1) {
			perror("pledge");
			exit(1);
		}
	}

	memset(&errstr_config, 0, sizeof(errstr_config));

	if (options_parse(argc, argv, errstr_options, NULL, &argsused) != 0) {
		errstr_usage();
		return (1);
	}

	if (errstr_config.stats) {
		BIO *out;

		if ((out = BIO_new_fp(stdout, BIO_NOCLOSE)) == NULL) {
			fprintf(stderr, "Out of memory");
			return (1);
		}

		lh_ERR_STRING_DATA_node_stats_bio(ERR_get_string_table(), out);
		lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(), out);
		lh_ERR_STRING_DATA_node_usage_stats_bio(
			    ERR_get_string_table(), out);

		BIO_free_all(out);
	}

	for (i = argsused; i < argc; i++) {
		errno = 0;
		ularg = argv[i];
		ulval = strtoul(ularg, &ep, 16);
		if (strchr(ularg, '-') != NULL ||
		    (ularg[0] == '\0' || *ep != '\0') ||
		    (errno == ERANGE && ulval == ULONG_MAX)) {
			printf("%s: bad error code\n", ularg);
			ret++;
			continue;
		}

		ERR_error_string_n(ulval, buf, sizeof(buf));
		printf("%s\n", buf);
	}

	return (ret);
}
示例#2
0
int MAIN(int argc, char **argv)
	{
	int i,ret=0;
	char buf[256];
	unsigned long l;

	apps_startup();

	if (bio_err == NULL)
		if ((bio_err=BIO_new(BIO_s_file())) != NULL)
			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);

	SSL_load_error_strings();

	if ((argc > 1) && (strcmp(argv[1],"-stats") == 0))
		{
		BIO *out=NULL;

		out=BIO_new(BIO_s_file());
		if ((out != NULL) && BIO_set_fp(out,stdout,BIO_NOCLOSE))
			{
#ifdef OPENSSL_SYS_VMS
			{
			BIO *tmpbio = BIO_new(BIO_f_linebuffer());
			out = BIO_push(tmpbio, out);
			}
#endif
			lh_ERR_STRING_DATA_node_stats_bio(
						  ERR_get_string_table(), out);
			lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(),
						     out);
			lh_ERR_STRING_DATA_node_usage_stats_bio(
						    ERR_get_string_table(),out);
			}
		if (out != NULL) BIO_free_all(out);
		argc--;
		argv++;
		}

	for (i=1; i<argc; i++)
		{
		if (sscanf(argv[i],"%lx",&l))
			{
			ERR_error_string_n(l, buf, sizeof buf);
			printf("%s\n",buf);
			}
		else
			{
			printf("%s: bad error code\n",argv[i]);
			printf("usage: errstr [-stats] <errno> ...\n");
			ret++;
			}
		}
	apps_shutdown();
	OPENSSL_EXIT(ret);
	}
示例#3
0
int errstr_main(int argc, char **argv)
{
    OPTION_CHOICE o;
    char buf[256], *prog;
    int ret = 1;
    unsigned long l;

    prog = opt_init(argc, argv, errstr_options);
    while ((o = opt_next()) != OPT_EOF) {
        switch (o) {
        case OPT_EOF:
        case OPT_ERR:
            BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
            goto end;
        case OPT_HELP:
            opt_help(errstr_options);
            ret = 0;
            goto end;
        case OPT_STATS:
            lh_ERR_STRING_DATA_node_stats_bio(ERR_get_string_table(),
                                              bio_out);
            lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(), bio_out);
            lh_ERR_STRING_DATA_node_usage_stats_bio(ERR_get_string_table(),
                                                    bio_out);
            ret = 0;
            goto end;
        }
    }

    ret = 0;
    for (argv = opt_rest(); *argv; argv++) {
        if (sscanf(*argv, "%lx", &l) == 0)
            ret++;
        else {
            /* We're not really an SSL application so this won't auto-init, but
             * we're still interested in SSL error strings
             */
            OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS
                             | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
            ERR_error_string_n(l, buf, sizeof buf);
            BIO_printf(bio_out, "%s\n", buf);
        }
    }
end:
    return (ret);
}