err.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. #ifndef HEADER_ERR_H
  10. # define HEADER_ERR_H
  11. # include <openssl/e_os2.h>
  12. # ifndef OPENSSL_NO_STDIO
  13. # include <stdio.h>
  14. # include <stdlib.h>
  15. # endif
  16. # include <openssl/ossl_typ.h>
  17. # include <openssl/bio.h>
  18. # include <openssl/lhash.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. # ifndef OPENSSL_NO_ERR
  23. # define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e)
  24. # else
  25. # define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0)
  26. # endif
  27. # include <errno.h>
  28. # define ERR_TXT_MALLOCED 0x01
  29. # define ERR_TXT_STRING 0x02
  30. # define ERR_FLAG_MARK 0x01
  31. # define ERR_NUM_ERRORS 16
  32. typedef struct err_state_st {
  33. int err_flags[ERR_NUM_ERRORS];
  34. unsigned long err_buffer[ERR_NUM_ERRORS];
  35. char *err_data[ERR_NUM_ERRORS];
  36. int err_data_flags[ERR_NUM_ERRORS];
  37. const char *err_file[ERR_NUM_ERRORS];
  38. int err_line[ERR_NUM_ERRORS];
  39. int top, bottom;
  40. } ERR_STATE;
  41. /* library */
  42. # define ERR_LIB_NONE 1
  43. # define ERR_LIB_SYS 2
  44. # define ERR_LIB_BN 3
  45. # define ERR_LIB_RSA 4
  46. # define ERR_LIB_DH 5
  47. # define ERR_LIB_EVP 6
  48. # define ERR_LIB_BUF 7
  49. # define ERR_LIB_OBJ 8
  50. # define ERR_LIB_PEM 9
  51. # define ERR_LIB_DSA 10
  52. # define ERR_LIB_X509 11
  53. /* #define ERR_LIB_METH 12 */
  54. # define ERR_LIB_ASN1 13
  55. # define ERR_LIB_CONF 14
  56. # define ERR_LIB_CRYPTO 15
  57. # define ERR_LIB_EC 16
  58. # define ERR_LIB_SSL 20
  59. /* #define ERR_LIB_SSL23 21 */
  60. /* #define ERR_LIB_SSL2 22 */
  61. /* #define ERR_LIB_SSL3 23 */
  62. /* #define ERR_LIB_RSAREF 30 */
  63. /* #define ERR_LIB_PROXY 31 */
  64. # define ERR_LIB_BIO 32
  65. # define ERR_LIB_PKCS7 33
  66. # define ERR_LIB_X509V3 34
  67. # define ERR_LIB_PKCS12 35
  68. # define ERR_LIB_RAND 36
  69. # define ERR_LIB_DSO 37
  70. # define ERR_LIB_ENGINE 38
  71. # define ERR_LIB_OCSP 39
  72. # define ERR_LIB_UI 40
  73. # define ERR_LIB_COMP 41
  74. # define ERR_LIB_ECDSA 42
  75. # define ERR_LIB_ECDH 43
  76. # define ERR_LIB_OSSL_STORE 44
  77. # define ERR_LIB_FIPS 45
  78. # define ERR_LIB_CMS 46
  79. # define ERR_LIB_TS 47
  80. # define ERR_LIB_HMAC 48
  81. /* # define ERR_LIB_JPAKE 49 */
  82. # define ERR_LIB_CT 50
  83. # define ERR_LIB_ASYNC 51
  84. # define ERR_LIB_KDF 52
  85. # define ERR_LIB_USER 128
  86. # define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  87. # define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  88. # define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  89. # define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  90. # define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  91. # define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  92. # define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  93. # define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  94. # define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  95. # define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  96. # define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  97. # define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  98. # define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  99. # define ECerr(f,r) ERR_PUT_error(ERR_LIB_EC,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  100. # define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  101. # define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  102. # define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  103. # define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  104. # define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  105. # define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  106. # define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  107. # define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  108. # define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  109. # define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  110. # define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  111. # define ECDSAerr(f,r) ERR_PUT_error(ERR_LIB_ECDSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  112. # define ECDHerr(f,r) ERR_PUT_error(ERR_LIB_ECDH,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  113. # define OSSL_STOREerr(f,r) ERR_PUT_error(ERR_LIB_OSSL_STORE,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  114. # define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  115. # define CMSerr(f,r) ERR_PUT_error(ERR_LIB_CMS,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  116. # define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  117. # define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  118. # define CTerr(f,r) ERR_PUT_error(ERR_LIB_CT,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  119. # define ASYNCerr(f,r) ERR_PUT_error(ERR_LIB_ASYNC,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  120. # define KDFerr(f,r) ERR_PUT_error(ERR_LIB_KDF,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  121. # define OSSL_STOREerr(f,r) ERR_PUT_error(ERR_LIB_OSSL_STORE,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
  122. # define ERR_PACK(l,f,r) ( \
  123. (((unsigned int)(l) & 0x0FF) << 24L) | \
  124. (((unsigned int)(f) & 0xFFF) << 12L) | \
  125. (((unsigned int)(r) & 0xFFF) ) )
  126. # define ERR_GET_LIB(l) (int)(((l) >> 24L) & 0x0FFL)
  127. # define ERR_GET_FUNC(l) (int)(((l) >> 12L) & 0xFFFL)
  128. # define ERR_GET_REASON(l) (int)( (l) & 0xFFFL)
  129. # define ERR_FATAL_ERROR(l) (int)( (l) & ERR_R_FATAL)
  130. /* OS functions */
  131. # define SYS_F_FOPEN 1
  132. # define SYS_F_CONNECT 2
  133. # define SYS_F_GETSERVBYNAME 3
  134. # define SYS_F_SOCKET 4
  135. # define SYS_F_IOCTLSOCKET 5
  136. # define SYS_F_BIND 6
  137. # define SYS_F_LISTEN 7
  138. # define SYS_F_ACCEPT 8
  139. # define SYS_F_WSASTARTUP 9/* Winsock stuff */
  140. # define SYS_F_OPENDIR 10
  141. # define SYS_F_FREAD 11
  142. # define SYS_F_GETADDRINFO 12
  143. # define SYS_F_GETNAMEINFO 13
  144. # define SYS_F_SETSOCKOPT 14
  145. # define SYS_F_GETSOCKOPT 15
  146. # define SYS_F_GETSOCKNAME 16
  147. # define SYS_F_GETHOSTBYNAME 17
  148. # define SYS_F_FFLUSH 18
  149. # define SYS_F_OPEN 19
  150. # define SYS_F_CLOSE 20
  151. # define SYS_F_IOCTL 21
  152. # define SYS_F_STAT 22
  153. # define SYS_F_FCNTL 23
  154. /* reasons */
  155. # define ERR_R_SYS_LIB ERR_LIB_SYS/* 2 */
  156. # define ERR_R_BN_LIB ERR_LIB_BN/* 3 */
  157. # define ERR_R_RSA_LIB ERR_LIB_RSA/* 4 */
  158. # define ERR_R_DH_LIB ERR_LIB_DH/* 5 */
  159. # define ERR_R_EVP_LIB ERR_LIB_EVP/* 6 */
  160. # define ERR_R_BUF_LIB ERR_LIB_BUF/* 7 */
  161. # define ERR_R_OBJ_LIB ERR_LIB_OBJ/* 8 */
  162. # define ERR_R_PEM_LIB ERR_LIB_PEM/* 9 */
  163. # define ERR_R_DSA_LIB ERR_LIB_DSA/* 10 */
  164. # define ERR_R_X509_LIB ERR_LIB_X509/* 11 */
  165. # define ERR_R_ASN1_LIB ERR_LIB_ASN1/* 13 */
  166. # define ERR_R_EC_LIB ERR_LIB_EC/* 16 */
  167. # define ERR_R_BIO_LIB ERR_LIB_BIO/* 32 */
  168. # define ERR_R_PKCS7_LIB ERR_LIB_PKCS7/* 33 */
  169. # define ERR_R_X509V3_LIB ERR_LIB_X509V3/* 34 */
  170. # define ERR_R_ENGINE_LIB ERR_LIB_ENGINE/* 38 */
  171. # define ERR_R_UI_LIB ERR_LIB_UI/* 40 */
  172. # define ERR_R_ECDSA_LIB ERR_LIB_ECDSA/* 42 */
  173. # define ERR_R_OSSL_STORE_LIB ERR_LIB_OSSL_STORE/* 44 */
  174. # define ERR_R_NESTED_ASN1_ERROR 58
  175. # define ERR_R_MISSING_ASN1_EOS 63
  176. /* fatal error */
  177. # define ERR_R_FATAL 64
  178. # define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
  179. # define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
  180. # define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
  181. # define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL)
  182. # define ERR_R_DISABLED (5|ERR_R_FATAL)
  183. # define ERR_R_INIT_FAIL (6|ERR_R_FATAL)
  184. # define ERR_R_PASSED_INVALID_ARGUMENT (7)
  185. # define ERR_R_OPERATION_FAIL (8|ERR_R_FATAL)
  186. /*
  187. * 99 is the maximum possible ERR_R_... code, higher values are reserved for
  188. * the individual libraries
  189. */
  190. typedef struct ERR_string_data_st {
  191. unsigned long error;
  192. const char *string;
  193. } ERR_STRING_DATA;
  194. DEFINE_LHASH_OF(ERR_STRING_DATA);
  195. void ERR_put_error(int lib, int func, int reason, const char *file, int line);
  196. void ERR_set_error_data(char *data, int flags);
  197. unsigned long ERR_get_error(void);
  198. unsigned long ERR_get_error_line(const char **file, int *line);
  199. unsigned long ERR_get_error_line_data(const char **file, int *line,
  200. const char **data, int *flags);
  201. unsigned long ERR_peek_error(void);
  202. unsigned long ERR_peek_error_line(const char **file, int *line);
  203. unsigned long ERR_peek_error_line_data(const char **file, int *line,
  204. const char **data, int *flags);
  205. unsigned long ERR_peek_last_error(void);
  206. unsigned long ERR_peek_last_error_line(const char **file, int *line);
  207. unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
  208. const char **data, int *flags);
  209. void ERR_clear_error(void);
  210. char *ERR_error_string(unsigned long e, char *buf);
  211. void ERR_error_string_n(unsigned long e, char *buf, size_t len);
  212. const char *ERR_lib_error_string(unsigned long e);
  213. const char *ERR_func_error_string(unsigned long e);
  214. const char *ERR_reason_error_string(unsigned long e);
  215. void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
  216. void *u);
  217. # ifndef OPENSSL_NO_STDIO
  218. void ERR_print_errors_fp(FILE *fp);
  219. # endif
  220. void ERR_print_errors(BIO *bp);
  221. void ERR_add_error_data(int num, ...);
  222. void ERR_add_error_vdata(int num, va_list args);
  223. int ERR_load_strings(int lib, ERR_STRING_DATA *str);
  224. int ERR_load_strings_const(const ERR_STRING_DATA *str);
  225. int ERR_unload_strings(int lib, ERR_STRING_DATA *str);
  226. int ERR_load_ERR_strings(void);
  227. #if OPENSSL_API_COMPAT < 0x10100000L
  228. # define ERR_load_crypto_strings() \
  229. OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL)
  230. # define ERR_free_strings() while(0) continue
  231. #endif
  232. DEPRECATEDIN_1_1_0(void ERR_remove_thread_state(void *))
  233. DEPRECATEDIN_1_0_0(void ERR_remove_state(unsigned long pid))
  234. ERR_STATE *ERR_get_state(void);
  235. int ERR_get_next_error_library(void);
  236. int ERR_set_mark(void);
  237. int ERR_pop_to_mark(void);
  238. int ERR_clear_last_mark(void);
  239. #ifdef __cplusplus
  240. }
  241. #endif
  242. #endif