]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
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 | |
8 | */ | |
9 | ||
10 | #include <stdio.h> | |
11 | #include <stdlib.h> | |
12 | #include <string.h> | |
13 | #include "apps.h" | |
14 | #include <openssl/bio.h> | |
15 | #include <openssl/err.h> | |
16 | #include <openssl/ssl.h> | |
17 | ||
18 | typedef enum OPTION_choice { | |
19 | OPT_ERR = -1, OPT_EOF = 0, OPT_HELP | |
20 | } OPTION_CHOICE; | |
21 | ||
22 | const OPTIONS errstr_options[] = { | |
23 | {OPT_HELP_STR, 1, '-', "Usage: %s [options] errnum...\n"}, | |
24 | {OPT_HELP_STR, 1, '-', " errnum Error number\n"}, | |
25 | {"help", OPT_HELP, '-', "Display this summary"}, | |
26 | {NULL} | |
27 | }; | |
28 | ||
29 | int errstr_main(int argc, char **argv) | |
30 | { | |
31 | OPTION_CHOICE o; | |
32 | char buf[256], *prog; | |
33 | int ret = 1; | |
34 | unsigned long l; | |
35 | ||
36 | prog = opt_init(argc, argv, errstr_options); | |
37 | while ((o = opt_next()) != OPT_EOF) { | |
38 | switch (o) { | |
39 | case OPT_EOF: | |
40 | case OPT_ERR: | |
41 | BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); | |
42 | goto end; | |
43 | case OPT_HELP: | |
44 | opt_help(errstr_options); | |
45 | ret = 0; | |
46 | goto end; | |
47 | } | |
48 | } | |
49 | ||
50 | ret = 0; | |
51 | for (argv = opt_rest(); *argv; argv++) { | |
52 | if (sscanf(*argv, "%lx", &l) == 0) { | |
53 | ret++; | |
54 | } else { | |
55 | /* We're not really an SSL application so this won't auto-init, but | |
56 | * we're still interested in SSL error strings | |
57 | */ | |
58 | OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS | |
59 | | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); | |
60 | ERR_error_string_n(l, buf, sizeof(buf)); | |
61 | BIO_printf(bio_out, "%s\n", buf); | |
62 | } | |
63 | } | |
64 | end: | |
65 | return ret; | |
66 | } |