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