Add -ciphers flag to enc command
[openssl.git] / apps / errstr.c
1 /*
2  * Copyright 1995-2016 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/lhash.h>
16 #include <openssl/err.h>
17 #include <openssl/ssl.h>
18
19 typedef enum OPTION_choice {
20     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
21     OPT_STATS
22 } OPTION_CHOICE;
23
24 OPTIONS errstr_options[] = {
25     {OPT_HELP_STR, 1, '-', "Usage: %s [options] errnum...\n"},
26     {OPT_HELP_STR, 1, '-', "  errnum  Error number\n"},
27     {"help", OPT_HELP, '-', "Display this summary"},
28     {"stats", OPT_STATS, '-',
29      "Print internal hashtable statistics (long!)"},
30     {NULL}
31 };
32
33 int errstr_main(int argc, char **argv)
34 {
35     OPTION_CHOICE o;
36     char buf[256], *prog;
37     int ret = 1;
38     unsigned long l;
39
40     prog = opt_init(argc, argv, errstr_options);
41     while ((o = opt_next()) != OPT_EOF) {
42         switch (o) {
43         case OPT_EOF:
44         case OPT_ERR:
45             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
46             goto end;
47         case OPT_HELP:
48             opt_help(errstr_options);
49             ret = 0;
50             goto end;
51         case OPT_STATS:
52             lh_ERR_STRING_DATA_node_stats_bio(ERR_get_string_table(),
53                                               bio_out);
54             lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(), bio_out);
55             lh_ERR_STRING_DATA_node_usage_stats_bio(ERR_get_string_table(),
56                                                     bio_out);
57             ret = 0;
58             goto end;
59         }
60     }
61
62     ret = 0;
63     for (argv = opt_rest(); *argv; argv++) {
64         if (sscanf(*argv, "%lx", &l) == 0)
65             ret++;
66         else {
67             /* We're not really an SSL application so this won't auto-init, but
68              * we're still interested in SSL error strings
69              */
70             OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS
71                              | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
72             ERR_error_string_n(l, buf, sizeof buf);
73             BIO_printf(bio_out, "%s\n", buf);
74         }
75     }
76  end:
77     return (ret);
78 }