blob: 3ef01f076a8c322e6deb9b124359a99532c41086 [file] [log] [blame]
Rich Salz846e33c2016-05-17 14:18:30 -04001/*
Matt Caswell6738bf12018-02-13 12:51:29 +00002 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00003 *
Rich Salz846e33c2016-05-17 14:18:30 -04004 * 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. Engelschalld02b48c1998-12-21 10:52:47 +00008 */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include "apps.h"
Richard Levittedab2cd62018-01-31 11:13:10 +010014#include "progs.h"
Bodo Möllerec577821999-04-23 22:13:45 +000015#include <openssl/bio.h>
Bodo Möllerec577821999-04-23 22:13:45 +000016#include <openssl/err.h>
17#include <openssl/ssl.h>
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000018
Rich Salz7e1b7482015-04-24 15:26:15 -040019typedef enum OPTION_choice {
Rich Salz412c8502016-08-03 15:15:20 -040020 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP
Rich Salz7e1b7482015-04-24 15:26:15 -040021} OPTION_CHOICE;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000022
FdaSilvaYY44c83eb2016-03-13 14:07:50 +010023const OPTIONS errstr_options[] = {
Rich Salz7e1b7482015-04-24 15:26:15 -040024 {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 Salz7e1b7482015-04-24 15:26:15 -040027 {NULL}
28};
Ralf S. Engelschall667ac4e2000-02-11 09:47:18 +000029
Rich Salz7e1b7482015-04-24 15:26:15 -040030int errstr_main(int argc, char **argv)
Matt Caswell0f113f32015-01-22 03:40:55 +000031{
Rich Salz7e1b7482015-04-24 15:26:15 -040032 OPTION_CHOICE o;
33 char buf[256], *prog;
34 int ret = 1;
Matt Caswell0f113f32015-01-22 03:40:55 +000035 unsigned long l;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000036
Rich Salz7e1b7482015-04-24 15:26:15 -040037 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 Caswell0f113f32015-01-22 03:40:55 +000048 }
Matt Caswell0f113f32015-01-22 03:40:55 +000049 }
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000050
Rich Salz7e1b7482015-04-24 15:26:15 -040051 ret = 0;
52 for (argv = opt_rest(); *argv; argv++) {
Paul Yang22342122017-06-13 01:24:02 +080053 if (sscanf(*argv, "%lx", &l) == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +000054 ret++;
Paul Yang22342122017-06-13 01:24:02 +080055 } else {
Matt Caswell302f7582016-02-10 15:16:06 +000056 /* 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 Salzcbe29642017-12-07 13:39:34 -050061 ERR_error_string_n(l, buf, sizeof(buf));
Rich Salz7e1b7482015-04-24 15:26:15 -040062 BIO_printf(bio_out, "%s\n", buf);
Matt Caswell0f113f32015-01-22 03:40:55 +000063 }
64 }
Rich Salz7e1b7482015-04-24 15:26:15 -040065 end:
KaoruToda26a7d932017-10-17 23:04:09 +090066 return ret;
Matt Caswell0f113f32015-01-22 03:40:55 +000067}