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