Rich Salz | 846e33c | 2016-05-17 14:18:30 -0400 | [diff] [blame] | 1 | /* |
Matt Caswell | 6738bf1 | 2018-02-13 12:51:29 +0000 | [diff] [blame] | 2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 3 | * |
Rich Salz | 846e33c | 2016-05-17 14:18:30 -0400 | [diff] [blame] | 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 |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include "apps.h" |
Richard Levitte | dab2cd6 | 2018-01-31 11:13:10 +0100 | [diff] [blame] | 14 | #include "progs.h" |
Bodo Möller | ec57782 | 1999-04-23 22:13:45 +0000 | [diff] [blame] | 15 | #include <openssl/bio.h> |
Bodo Möller | ec57782 | 1999-04-23 22:13:45 +0000 | [diff] [blame] | 16 | #include <openssl/err.h> |
| 17 | #include <openssl/ssl.h> |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 18 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 19 | typedef enum OPTION_choice { |
Rich Salz | 412c850 | 2016-08-03 15:15:20 -0400 | [diff] [blame] | 20 | OPT_ERR = -1, OPT_EOF = 0, OPT_HELP |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 21 | } OPTION_CHOICE; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 22 | |
FdaSilvaYY | 44c83eb | 2016-03-13 14:07:50 +0100 | [diff] [blame] | 23 | const OPTIONS errstr_options[] = { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 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"}, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 27 | {NULL} |
| 28 | }; |
Ralf S. Engelschall | 667ac4e | 2000-02-11 09:47:18 +0000 | [diff] [blame] | 29 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 30 | int errstr_main(int argc, char **argv) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 31 | { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 32 | OPTION_CHOICE o; |
| 33 | char buf[256], *prog; |
| 34 | int ret = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 35 | unsigned long l; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 36 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 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; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 48 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 49 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 50 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 51 | ret = 0; |
| 52 | for (argv = opt_rest(); *argv; argv++) { |
Paul Yang | 2234212 | 2017-06-13 01:24:02 +0800 | [diff] [blame] | 53 | if (sscanf(*argv, "%lx", &l) == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 54 | ret++; |
Paul Yang | 2234212 | 2017-06-13 01:24:02 +0800 | [diff] [blame] | 55 | } else { |
Matt Caswell | 302f758 | 2016-02-10 15:16:06 +0000 | [diff] [blame] | 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); |
Rich Salz | cbe2964 | 2017-12-07 13:39:34 -0500 | [diff] [blame] | 61 | ERR_error_string_n(l, buf, sizeof(buf)); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 62 | BIO_printf(bio_out, "%s\n", buf); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 65 | end: |
KaoruToda | 26a7d93 | 2017-10-17 23:04:09 +0900 | [diff] [blame] | 66 | return ret; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 67 | } |