]>
Commit | Line | Data |
---|---|---|
846e33c7 | 1 | /* |
2234212c | 2 | * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. |
d02b48c6 | 3 | * |
846e33c7 RS |
4 | * Licensed under the OpenSSL license (the "License"). You may not use |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
d02b48c6 RE |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
11 | #include <stdlib.h> | |
12 | #include <string.h> | |
13 | #include "apps.h" | |
ec577822 BM |
14 | #include <openssl/bio.h> |
15 | #include <openssl/lhash.h> | |
16 | #include <openssl/err.h> | |
17 | #include <openssl/ssl.h> | |
d02b48c6 | 18 | |
7e1b7485 | 19 | typedef enum OPTION_choice { |
412c8507 | 20 | OPT_ERR = -1, OPT_EOF = 0, OPT_HELP |
7e1b7485 | 21 | } OPTION_CHOICE; |
d02b48c6 | 22 | |
44c83ebd | 23 | const OPTIONS errstr_options[] = { |
7e1b7485 RS |
24 | {OPT_HELP_STR, 1, '-', "Usage: %s [options] errnum...\n"}, |
25 | {OPT_HELP_STR, 1, '-', " errnum Error number\n"}, | |
26 | {"help", OPT_HELP, '-', "Display this summary"}, | |
7e1b7485 RS |
27 | {NULL} |
28 | }; | |
667ac4ec | 29 | |
7e1b7485 | 30 | int errstr_main(int argc, char **argv) |
0f113f3e | 31 | { |
7e1b7485 RS |
32 | OPTION_CHOICE o; |
33 | char buf[256], *prog; | |
34 | int ret = 1; | |
0f113f3e | 35 | unsigned long l; |
d02b48c6 | 36 | |
7e1b7485 RS |
37 | prog = opt_init(argc, argv, errstr_options); |
38 | while ((o = opt_next()) != OPT_EOF) { | |
39 | switch (o) { | |
40 | case OPT_EOF: | |
41 | case OPT_ERR: | |
42 | BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); | |
43 | goto end; | |
44 | case OPT_HELP: | |
45 | opt_help(errstr_options); | |
46 | ret = 0; | |
47 | goto end; | |
0f113f3e | 48 | } |
0f113f3e | 49 | } |
d02b48c6 | 50 | |
7e1b7485 RS |
51 | ret = 0; |
52 | for (argv = opt_rest(); *argv; argv++) { | |
2234212c | 53 | if (sscanf(*argv, "%lx", &l) == 0) { |
0f113f3e | 54 | ret++; |
2234212c | 55 | } else { |
302f7588 MC |
56 | /* We're not really an SSL application so this won't auto-init, but |
57 | * we're still interested in SSL error strings | |
58 | */ | |
59 | OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS | |
60 | | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); | |
7e1b7485 RS |
61 | ERR_error_string_n(l, buf, sizeof buf); |
62 | BIO_printf(bio_out, "%s\n", buf); | |
0f113f3e MC |
63 | } |
64 | } | |
7e1b7485 RS |
65 | end: |
66 | return (ret); | |
0f113f3e | 67 | } |