err.3 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. .\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .if !\nF .nr F 0
  58. .if \nF>0 \{\
  59. . de IX
  60. . tm Index:\\$1\t\\n%\t"\\$2"
  61. ..
  62. . if !\nF==2 \{\
  63. . nr % 0
  64. . nr F 2
  65. . \}
  66. .\}
  67. .\"
  68. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  69. .\" Fear. Run. Save yourself. No user-serviceable parts.
  70. . \" fudge factors for nroff and troff
  71. .if n \{\
  72. . ds #H 0
  73. . ds #V .8m
  74. . ds #F .3m
  75. . ds #[ \f1
  76. . ds #] \fP
  77. .\}
  78. .if t \{\
  79. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  80. . ds #V .6m
  81. . ds #F 0
  82. . ds #[ \&
  83. . ds #] \&
  84. .\}
  85. . \" simple accents for nroff and troff
  86. .if n \{\
  87. . ds ' \&
  88. . ds ` \&
  89. . ds ^ \&
  90. . ds , \&
  91. . ds ~ ~
  92. . ds /
  93. .\}
  94. .if t \{\
  95. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  96. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  97. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  98. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  99. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  100. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  101. .\}
  102. . \" troff and (daisy-wheel) nroff accents
  103. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  104. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  105. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  106. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  107. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  108. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  109. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  110. .ds ae a\h'-(\w'a'u*4/10)'e
  111. .ds Ae A\h'-(\w'A'u*4/10)'E
  112. . \" corrections for vroff
  113. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  114. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  115. . \" for low resolution devices (crt and lpr)
  116. .if \n(.H>23 .if \n(.V>19 \
  117. \{\
  118. . ds : e
  119. . ds 8 ss
  120. . ds o a
  121. . ds d- d\h'-1'\(ga
  122. . ds D- D\h'-1'\(hy
  123. . ds th \o'bp'
  124. . ds Th \o'LP'
  125. . ds ae ae
  126. . ds Ae AE
  127. .\}
  128. .rm #[ #] #H #V #F C
  129. .\" ========================================================================
  130. .\"
  131. .IX Title "err 3"
  132. .TH err 3 "2019-09-12" "1.0.2g" "OpenSSL"
  133. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  134. .\" way too many mistakes in technical documents.
  135. .if n .ad l
  136. .nh
  137. .SH "NAME"
  138. err \- error codes
  139. .SH "SYNOPSIS"
  140. .IX Header "SYNOPSIS"
  141. .Vb 1
  142. \& #include <openssl/err.h>
  143. \&
  144. \& unsigned long ERR_get_error(void);
  145. \& unsigned long ERR_peek_error(void);
  146. \& unsigned long ERR_get_error_line(const char **file, int *line);
  147. \& unsigned long ERR_peek_error_line(const char **file, int *line);
  148. \& unsigned long ERR_get_error_line_data(const char **file, int *line,
  149. \& const char **data, int *flags);
  150. \& unsigned long ERR_peek_error_line_data(const char **file, int *line,
  151. \& const char **data, int *flags);
  152. \&
  153. \& int ERR_GET_LIB(unsigned long e);
  154. \& int ERR_GET_FUNC(unsigned long e);
  155. \& int ERR_GET_REASON(unsigned long e);
  156. \&
  157. \& void ERR_clear_error(void);
  158. \&
  159. \& char *ERR_error_string(unsigned long e, char *buf);
  160. \& const char *ERR_lib_error_string(unsigned long e);
  161. \& const char *ERR_func_error_string(unsigned long e);
  162. \& const char *ERR_reason_error_string(unsigned long e);
  163. \&
  164. \& void ERR_print_errors(BIO *bp);
  165. \& void ERR_print_errors_fp(FILE *fp);
  166. \&
  167. \& void ERR_load_crypto_strings(void);
  168. \& void ERR_free_strings(void);
  169. \&
  170. \& void ERR_remove_state(unsigned long pid);
  171. \&
  172. \& void ERR_put_error(int lib, int func, int reason, const char *file,
  173. \& int line);
  174. \& void ERR_add_error_data(int num, ...);
  175. \&
  176. \& void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
  177. \& unsigned long ERR_PACK(int lib, int func, int reason);
  178. \& int ERR_get_next_error_library(void);
  179. .Ve
  180. .SH "DESCRIPTION"
  181. .IX Header "DESCRIPTION"
  182. When a call to the OpenSSL library fails, this is usually signalled
  183. by the return value, and an error code is stored in an error queue
  184. associated with the current thread. The \fBerr\fR library provides
  185. functions to obtain these error codes and textual error messages.
  186. .PP
  187. The \fIERR_get_error\fR\|(3) manpage describes how to
  188. access error codes.
  189. .PP
  190. Error codes contain information about where the error occurred, and
  191. what went wrong. \s-1\fIERR_GET_LIB\s0\fR\|(3) describes how to
  192. extract this information. A method to obtain human-readable error
  193. messages is described in \fIERR_error_string\fR\|(3).
  194. .PP
  195. \&\fIERR_clear_error\fR\|(3) can be used to clear the
  196. error queue.
  197. .PP
  198. Note that \fIERR_remove_state\fR\|(3) should be used to
  199. avoid memory leaks when threads are terminated.
  200. .SH "ADDING NEW ERROR CODES TO OPENSSL"
  201. .IX Header "ADDING NEW ERROR CODES TO OPENSSL"
  202. See \fIERR_put_error\fR\|(3) if you want to record error codes in the
  203. OpenSSL error system from within your application.
  204. .PP
  205. The remainder of this section is of interest only if you want to add
  206. new error codes to OpenSSL or add error codes from external libraries.
  207. .SS "Reporting errors"
  208. .IX Subsection "Reporting errors"
  209. Each sub-library has a specific macro \fIXXXerr()\fR that is used to report
  210. errors. Its first argument is a function code \fB\s-1XXX_F_...\s0\fR, the second
  211. argument is a reason code \fB\s-1XXX_R_...\s0\fR. Function codes are derived
  212. from the function names; reason codes consist of textual error
  213. descriptions. For example, the function \fIssl23_read()\fR reports a
  214. \&\*(L"handshake failure\*(R" as follows:
  215. .PP
  216. .Vb 1
  217. \& SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE);
  218. .Ve
  219. .PP
  220. Function and reason codes should consist of upper case characters,
  221. numbers and underscores only. The error file generation script translates
  222. function codes into function names by looking in the header files
  223. for an appropriate function name, if none is found it just uses
  224. the capitalized form such as \*(L"\s-1SSL23_READ\*(R"\s0 in the above example.
  225. .PP
  226. The trailing section of a reason code (after the \*(L"_R_\*(R") is translated
  227. into lower case and underscores changed to spaces.
  228. .PP
  229. When you are using new function or reason codes, run \fBmake errors\fR.
  230. The necessary \fB#define\fRs will then automatically be added to the
  231. sub-library's header file.
  232. .PP
  233. Although a library will normally report errors using its own specific
  234. XXXerr macro, another library's macro can be used. This is normally
  235. only done when a library wants to include \s-1ASN1\s0 code which must use
  236. the \fIASN1err()\fR macro.
  237. .SS "Adding new libraries"
  238. .IX Subsection "Adding new libraries"
  239. When adding a new sub-library to OpenSSL, assign it a library number
  240. \&\fB\s-1ERR_LIB_XXX\s0\fR, define a macro \fIXXXerr()\fR (both in \fBerr.h\fR), add its
  241. name to \fBERR_str_libraries[]\fR (in \fBcrypto/err/err.c\fR), and add
  242. \&\f(CW\*(C`ERR_load_XXX_strings()\*(C'\fR to the \fIERR_load_crypto_strings()\fR function
  243. (in \fBcrypto/err/err_all.c\fR). Finally, add an entry
  244. .PP
  245. .Vb 1
  246. \& L XXX xxx.h xxx_err.c
  247. .Ve
  248. .PP
  249. to \fBcrypto/err/openssl.ec\fR, and add \fBxxx_err.c\fR to the Makefile.
  250. Running \fBmake errors\fR will then generate a file \fBxxx_err.c\fR, and
  251. add all error codes used in the library to \fBxxx.h\fR.
  252. .PP
  253. Additionally the library include file must have a certain form.
  254. Typically it will initially look like this:
  255. .PP
  256. .Vb 2
  257. \& #ifndef HEADER_XXX_H
  258. \& #define HEADER_XXX_H
  259. \&
  260. \& #ifdef _\|_cplusplus
  261. \& extern "C" {
  262. \& #endif
  263. \&
  264. \& /* Include files */
  265. \&
  266. \& #include <openssl/bio.h>
  267. \& #include <openssl/x509.h>
  268. \&
  269. \& /* Macros, structures and function prototypes */
  270. \&
  271. \&
  272. \& /* BEGIN ERROR CODES */
  273. .Ve
  274. .PP
  275. The \fB\s-1BEGIN ERROR CODES\s0\fR sequence is used by the error code
  276. generation script as the point to place new error codes, any text
  277. after this point will be overwritten when \fBmake errors\fR is run.
  278. The closing #endif etc will be automatically added by the script.
  279. .PP
  280. The generated C error code file \fBxxx_err.c\fR will load the header
  281. files \fBstdio.h\fR, \fBopenssl/err.h\fR and \fBopenssl/xxx.h\fR so the
  282. header file must load any additional header files containing any
  283. definitions it uses.
  284. .SH "USING ERROR CODES IN EXTERNAL LIBRARIES"
  285. .IX Header "USING ERROR CODES IN EXTERNAL LIBRARIES"
  286. It is also possible to use OpenSSL's error code scheme in external
  287. libraries. The library needs to load its own codes and call the OpenSSL
  288. error code insertion script \fBmkerr.pl\fR explicitly to add codes to
  289. the header file and generate the C error code file. This will normally
  290. be done if the external library needs to generate new \s-1ASN1\s0 structures
  291. but it can also be used to add more general purpose error code handling.
  292. .PP
  293. \&\s-1TBA\s0 more details
  294. .SH "INTERNALS"
  295. .IX Header "INTERNALS"
  296. The error queues are stored in a hash table with one \fB\s-1ERR_STATE\s0\fR
  297. entry for each pid. \fIERR_get_state()\fR returns the current thread's
  298. \&\fB\s-1ERR_STATE\s0\fR. An \fB\s-1ERR_STATE\s0\fR can hold up to \fB\s-1ERR_NUM_ERRORS\s0\fR error
  299. codes. When more error codes are added, the old ones are overwritten,
  300. on the assumption that the most recent errors are most important.
  301. .PP
  302. Error strings are also stored in hash table. The hash tables can
  303. be obtained by calling ERR_get_err_state_table(void) and
  304. ERR_get_string_table(void) respectively.
  305. .SH "SEE ALSO"
  306. .IX Header "SEE ALSO"
  307. \&\fICRYPTO_set_locking_callback\fR\|(3),
  308. \&\fIERR_get_error\fR\|(3),
  309. \&\s-1\fIERR_GET_LIB\s0\fR\|(3),
  310. \&\fIERR_clear_error\fR\|(3),
  311. \&\fIERR_error_string\fR\|(3),
  312. \&\fIERR_print_errors\fR\|(3),
  313. \&\fIERR_load_crypto_strings\fR\|(3),
  314. \&\fIERR_remove_state\fR\|(3),
  315. \&\fIERR_put_error\fR\|(3),
  316. \&\fIERR_load_strings\fR\|(3),
  317. \&\fISSL_get_error\fR\|(3)