freebsd-dev/crypto/openssl/apps/errstr.c

68 lines
1.8 KiB
C
Raw Normal View History

2018-09-13 19:18:07 +00:00
/*
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
*
2018-09-13 19:18:07 +00:00
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "apps.h"
2018-09-13 19:18:07 +00:00
#include "progs.h"
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
2018-09-13 19:18:07 +00:00
typedef enum OPTION_choice {
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP
} OPTION_CHOICE;
2018-09-13 19:18:07 +00:00
const OPTIONS errstr_options[] = {
{OPT_HELP_STR, 1, '-', "Usage: %s [options] errnum...\n"},
{OPT_HELP_STR, 1, '-', " errnum Error number\n"},
{"help", OPT_HELP, '-', "Display this summary"},
{NULL}
};
2000-04-13 06:33:22 +00:00
2018-09-13 19:18:07 +00:00
int errstr_main(int argc, char **argv)
2015-03-20 15:28:40 +00:00
{
2018-09-13 19:18:07 +00:00
OPTION_CHOICE o;
char buf[256], *prog;
int ret = 1;
2015-03-20 15:28:40 +00:00
unsigned long l;
2018-09-13 19:18:07 +00:00
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;
2015-03-20 15:28:40 +00:00
}
}
2018-09-13 19:18:07 +00:00
ret = 0;
for (argv = opt_rest(); *argv; argv++) {
if (sscanf(*argv, "%lx", &l) == 0) {
2015-03-20 15:28:40 +00:00
ret++;
2018-09-13 19:18:07 +00:00
} 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);
2015-03-20 15:28:40 +00:00
}
}
2018-09-13 19:18:07 +00:00
end:
return ret;
2015-03-20 15:28:40 +00:00
}