jpayne@69: /* jpayne@69: * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. jpayne@69: * jpayne@69: * Licensed under the OpenSSL license (the "License"). You may not use jpayne@69: * this file except in compliance with the License. You can obtain a copy jpayne@69: * in the file LICENSE in the source distribution or at jpayne@69: * https://www.openssl.org/source/license.html jpayne@69: */ jpayne@69: jpayne@69: #ifndef HEADER_ERR_H jpayne@69: # define HEADER_ERR_H jpayne@69: jpayne@69: # include jpayne@69: jpayne@69: # ifndef OPENSSL_NO_STDIO jpayne@69: # include jpayne@69: # include jpayne@69: # endif jpayne@69: jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: # ifndef OPENSSL_NO_ERR jpayne@69: # define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e) jpayne@69: # else jpayne@69: # define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0) jpayne@69: # endif jpayne@69: jpayne@69: # include jpayne@69: jpayne@69: # define ERR_TXT_MALLOCED 0x01 jpayne@69: # define ERR_TXT_STRING 0x02 jpayne@69: jpayne@69: # define ERR_FLAG_MARK 0x01 jpayne@69: # define ERR_FLAG_CLEAR 0x02 jpayne@69: jpayne@69: # define ERR_NUM_ERRORS 16 jpayne@69: typedef struct err_state_st { jpayne@69: int err_flags[ERR_NUM_ERRORS]; jpayne@69: unsigned long err_buffer[ERR_NUM_ERRORS]; jpayne@69: char *err_data[ERR_NUM_ERRORS]; jpayne@69: int err_data_flags[ERR_NUM_ERRORS]; jpayne@69: const char *err_file[ERR_NUM_ERRORS]; jpayne@69: int err_line[ERR_NUM_ERRORS]; jpayne@69: int top, bottom; jpayne@69: } ERR_STATE; jpayne@69: jpayne@69: /* library */ jpayne@69: # define ERR_LIB_NONE 1 jpayne@69: # define ERR_LIB_SYS 2 jpayne@69: # define ERR_LIB_BN 3 jpayne@69: # define ERR_LIB_RSA 4 jpayne@69: # define ERR_LIB_DH 5 jpayne@69: # define ERR_LIB_EVP 6 jpayne@69: # define ERR_LIB_BUF 7 jpayne@69: # define ERR_LIB_OBJ 8 jpayne@69: # define ERR_LIB_PEM 9 jpayne@69: # define ERR_LIB_DSA 10 jpayne@69: # define ERR_LIB_X509 11 jpayne@69: /* #define ERR_LIB_METH 12 */ jpayne@69: # define ERR_LIB_ASN1 13 jpayne@69: # define ERR_LIB_CONF 14 jpayne@69: # define ERR_LIB_CRYPTO 15 jpayne@69: # define ERR_LIB_EC 16 jpayne@69: # define ERR_LIB_SSL 20 jpayne@69: /* #define ERR_LIB_SSL23 21 */ jpayne@69: /* #define ERR_LIB_SSL2 22 */ jpayne@69: /* #define ERR_LIB_SSL3 23 */ jpayne@69: /* #define ERR_LIB_RSAREF 30 */ jpayne@69: /* #define ERR_LIB_PROXY 31 */ jpayne@69: # define ERR_LIB_BIO 32 jpayne@69: # define ERR_LIB_PKCS7 33 jpayne@69: # define ERR_LIB_X509V3 34 jpayne@69: # define ERR_LIB_PKCS12 35 jpayne@69: # define ERR_LIB_RAND 36 jpayne@69: # define ERR_LIB_DSO 37 jpayne@69: # define ERR_LIB_ENGINE 38 jpayne@69: # define ERR_LIB_OCSP 39 jpayne@69: # define ERR_LIB_UI 40 jpayne@69: # define ERR_LIB_COMP 41 jpayne@69: # define ERR_LIB_ECDSA 42 jpayne@69: # define ERR_LIB_ECDH 43 jpayne@69: # define ERR_LIB_OSSL_STORE 44 jpayne@69: # define ERR_LIB_FIPS 45 jpayne@69: # define ERR_LIB_CMS 46 jpayne@69: # define ERR_LIB_TS 47 jpayne@69: # define ERR_LIB_HMAC 48 jpayne@69: /* # define ERR_LIB_JPAKE 49 */ jpayne@69: # define ERR_LIB_CT 50 jpayne@69: # define ERR_LIB_ASYNC 51 jpayne@69: # define ERR_LIB_KDF 52 jpayne@69: # define ERR_LIB_SM2 53 jpayne@69: jpayne@69: # define ERR_LIB_USER 128 jpayne@69: jpayne@69: # define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define ECerr(f,r) ERR_PUT_error(ERR_LIB_EC,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define ECDSAerr(f,r) ERR_PUT_error(ERR_LIB_ECDSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define ECDHerr(f,r) ERR_PUT_error(ERR_LIB_ECDH,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define OSSL_STOREerr(f,r) ERR_PUT_error(ERR_LIB_OSSL_STORE,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define CMSerr(f,r) ERR_PUT_error(ERR_LIB_CMS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define CTerr(f,r) ERR_PUT_error(ERR_LIB_CT,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define ASYNCerr(f,r) ERR_PUT_error(ERR_LIB_ASYNC,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define KDFerr(f,r) ERR_PUT_error(ERR_LIB_KDF,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: # define SM2err(f,r) ERR_PUT_error(ERR_LIB_SM2,(f),(r),OPENSSL_FILE,OPENSSL_LINE) jpayne@69: jpayne@69: # define ERR_PACK(l,f,r) ( \ jpayne@69: (((unsigned int)(l) & 0x0FF) << 24L) | \ jpayne@69: (((unsigned int)(f) & 0xFFF) << 12L) | \ jpayne@69: (((unsigned int)(r) & 0xFFF) ) ) jpayne@69: # define ERR_GET_LIB(l) (int)(((l) >> 24L) & 0x0FFL) jpayne@69: # define ERR_GET_FUNC(l) (int)(((l) >> 12L) & 0xFFFL) jpayne@69: # define ERR_GET_REASON(l) (int)( (l) & 0xFFFL) jpayne@69: # define ERR_FATAL_ERROR(l) (int)( (l) & ERR_R_FATAL) jpayne@69: jpayne@69: /* OS functions */ jpayne@69: # define SYS_F_FOPEN 1 jpayne@69: # define SYS_F_CONNECT 2 jpayne@69: # define SYS_F_GETSERVBYNAME 3 jpayne@69: # define SYS_F_SOCKET 4 jpayne@69: # define SYS_F_IOCTLSOCKET 5 jpayne@69: # define SYS_F_BIND 6 jpayne@69: # define SYS_F_LISTEN 7 jpayne@69: # define SYS_F_ACCEPT 8 jpayne@69: # define SYS_F_WSASTARTUP 9/* Winsock stuff */ jpayne@69: # define SYS_F_OPENDIR 10 jpayne@69: # define SYS_F_FREAD 11 jpayne@69: # define SYS_F_GETADDRINFO 12 jpayne@69: # define SYS_F_GETNAMEINFO 13 jpayne@69: # define SYS_F_SETSOCKOPT 14 jpayne@69: # define SYS_F_GETSOCKOPT 15 jpayne@69: # define SYS_F_GETSOCKNAME 16 jpayne@69: # define SYS_F_GETHOSTBYNAME 17 jpayne@69: # define SYS_F_FFLUSH 18 jpayne@69: # define SYS_F_OPEN 19 jpayne@69: # define SYS_F_CLOSE 20 jpayne@69: # define SYS_F_IOCTL 21 jpayne@69: # define SYS_F_STAT 22 jpayne@69: # define SYS_F_FCNTL 23 jpayne@69: # define SYS_F_FSTAT 24 jpayne@69: jpayne@69: /* reasons */ jpayne@69: # define ERR_R_SYS_LIB ERR_LIB_SYS/* 2 */ jpayne@69: # define ERR_R_BN_LIB ERR_LIB_BN/* 3 */ jpayne@69: # define ERR_R_RSA_LIB ERR_LIB_RSA/* 4 */ jpayne@69: # define ERR_R_DH_LIB ERR_LIB_DH/* 5 */ jpayne@69: # define ERR_R_EVP_LIB ERR_LIB_EVP/* 6 */ jpayne@69: # define ERR_R_BUF_LIB ERR_LIB_BUF/* 7 */ jpayne@69: # define ERR_R_OBJ_LIB ERR_LIB_OBJ/* 8 */ jpayne@69: # define ERR_R_PEM_LIB ERR_LIB_PEM/* 9 */ jpayne@69: # define ERR_R_DSA_LIB ERR_LIB_DSA/* 10 */ jpayne@69: # define ERR_R_X509_LIB ERR_LIB_X509/* 11 */ jpayne@69: # define ERR_R_ASN1_LIB ERR_LIB_ASN1/* 13 */ jpayne@69: # define ERR_R_EC_LIB ERR_LIB_EC/* 16 */ jpayne@69: # define ERR_R_BIO_LIB ERR_LIB_BIO/* 32 */ jpayne@69: # define ERR_R_PKCS7_LIB ERR_LIB_PKCS7/* 33 */ jpayne@69: # define ERR_R_X509V3_LIB ERR_LIB_X509V3/* 34 */ jpayne@69: # define ERR_R_ENGINE_LIB ERR_LIB_ENGINE/* 38 */ jpayne@69: # define ERR_R_UI_LIB ERR_LIB_UI/* 40 */ jpayne@69: # define ERR_R_ECDSA_LIB ERR_LIB_ECDSA/* 42 */ jpayne@69: # define ERR_R_OSSL_STORE_LIB ERR_LIB_OSSL_STORE/* 44 */ jpayne@69: jpayne@69: # define ERR_R_NESTED_ASN1_ERROR 58 jpayne@69: # define ERR_R_MISSING_ASN1_EOS 63 jpayne@69: jpayne@69: /* fatal error */ jpayne@69: # define ERR_R_FATAL 64 jpayne@69: # define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL) jpayne@69: # define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL) jpayne@69: # define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL) jpayne@69: # define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL) jpayne@69: # define ERR_R_DISABLED (5|ERR_R_FATAL) jpayne@69: # define ERR_R_INIT_FAIL (6|ERR_R_FATAL) jpayne@69: # define ERR_R_PASSED_INVALID_ARGUMENT (7) jpayne@69: # define ERR_R_OPERATION_FAIL (8|ERR_R_FATAL) jpayne@69: jpayne@69: /* jpayne@69: * 99 is the maximum possible ERR_R_... code, higher values are reserved for jpayne@69: * the individual libraries jpayne@69: */ jpayne@69: jpayne@69: typedef struct ERR_string_data_st { jpayne@69: unsigned long error; jpayne@69: const char *string; jpayne@69: } ERR_STRING_DATA; jpayne@69: jpayne@69: DEFINE_LHASH_OF(ERR_STRING_DATA); jpayne@69: jpayne@69: void ERR_put_error(int lib, int func, int reason, const char *file, int line); jpayne@69: void ERR_set_error_data(char *data, int flags); jpayne@69: jpayne@69: unsigned long ERR_get_error(void); jpayne@69: unsigned long ERR_get_error_line(const char **file, int *line); jpayne@69: unsigned long ERR_get_error_line_data(const char **file, int *line, jpayne@69: const char **data, int *flags); jpayne@69: unsigned long ERR_peek_error(void); jpayne@69: unsigned long ERR_peek_error_line(const char **file, int *line); jpayne@69: unsigned long ERR_peek_error_line_data(const char **file, int *line, jpayne@69: const char **data, int *flags); jpayne@69: unsigned long ERR_peek_last_error(void); jpayne@69: unsigned long ERR_peek_last_error_line(const char **file, int *line); jpayne@69: unsigned long ERR_peek_last_error_line_data(const char **file, int *line, jpayne@69: const char **data, int *flags); jpayne@69: void ERR_clear_error(void); jpayne@69: char *ERR_error_string(unsigned long e, char *buf); jpayne@69: void ERR_error_string_n(unsigned long e, char *buf, size_t len); jpayne@69: const char *ERR_lib_error_string(unsigned long e); jpayne@69: const char *ERR_func_error_string(unsigned long e); jpayne@69: const char *ERR_reason_error_string(unsigned long e); jpayne@69: void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), jpayne@69: void *u); jpayne@69: # ifndef OPENSSL_NO_STDIO jpayne@69: void ERR_print_errors_fp(FILE *fp); jpayne@69: # endif jpayne@69: void ERR_print_errors(BIO *bp); jpayne@69: void ERR_add_error_data(int num, ...); jpayne@69: void ERR_add_error_vdata(int num, va_list args); jpayne@69: int ERR_load_strings(int lib, ERR_STRING_DATA *str); jpayne@69: int ERR_load_strings_const(const ERR_STRING_DATA *str); jpayne@69: int ERR_unload_strings(int lib, ERR_STRING_DATA *str); jpayne@69: int ERR_load_ERR_strings(void); jpayne@69: jpayne@69: #if OPENSSL_API_COMPAT < 0x10100000L jpayne@69: # define ERR_load_crypto_strings() \ jpayne@69: OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL) jpayne@69: # define ERR_free_strings() while(0) continue jpayne@69: #endif jpayne@69: jpayne@69: DEPRECATEDIN_1_1_0(void ERR_remove_thread_state(void *)) jpayne@69: DEPRECATEDIN_1_0_0(void ERR_remove_state(unsigned long pid)) jpayne@69: ERR_STATE *ERR_get_state(void); jpayne@69: jpayne@69: int ERR_get_next_error_library(void); jpayne@69: jpayne@69: int ERR_set_mark(void); jpayne@69: int ERR_pop_to_mark(void); jpayne@69: int ERR_clear_last_mark(void); jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: #endif