xref: /freebsd/crypto/openssl/doc/man3/ERR_put_error.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3*b077aed3SPierre Pronchery=for openssl foreign manual errno(3)
4*b077aed3SPierre Pronchery
5e71b7053SJung-uk Kim=head1 NAME
6e71b7053SJung-uk Kim
7*b077aed3SPierre ProncheryERR_raise, ERR_raise_data,
8*b077aed3SPierre ProncheryERR_put_error, ERR_add_error_data, ERR_add_error_vdata,
9*b077aed3SPierre ProncheryERR_add_error_txt, ERR_add_error_mem_bio
10*b077aed3SPierre Pronchery- record an error
11e71b7053SJung-uk Kim
12e71b7053SJung-uk Kim=head1 SYNOPSIS
13e71b7053SJung-uk Kim
14e71b7053SJung-uk Kim #include <openssl/err.h>
15e71b7053SJung-uk Kim
16*b077aed3SPierre Pronchery void ERR_raise(int lib, int reason);
17*b077aed3SPierre Pronchery void ERR_raise_data(int lib, int reason, const char *fmt, ...);
18e71b7053SJung-uk Kim
19e71b7053SJung-uk Kim void ERR_add_error_data(int num, ...);
20e71b7053SJung-uk Kim void ERR_add_error_vdata(int num, va_list arg);
21*b077aed3SPierre Pronchery void ERR_add_error_txt(const char *sep, const char *txt);
22*b077aed3SPierre Pronchery void ERR_add_error_mem_bio(const char *sep, BIO *bio);
23*b077aed3SPierre Pronchery
24*b077aed3SPierre ProncheryThe following function has been deprecated since OpenSSL 3.0, and can be
25*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
26*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>:
27*b077aed3SPierre Pronchery
28*b077aed3SPierre Pronchery void ERR_put_error(int lib, int func, int reason, const char *file, int line);
29e71b7053SJung-uk Kim
30e71b7053SJung-uk Kim=head1 DESCRIPTION
31e71b7053SJung-uk Kim
32*b077aed3SPierre ProncheryERR_raise() adds a new error to the thread's error queue.  The
33*b077aed3SPierre Proncheryerror occurred in the library B<lib> for the reason given by the
34*b077aed3SPierre ProncheryB<reason> code.  Furthermore, the name of the file, the line, and name
35*b077aed3SPierre Proncheryof the function where the error occurred is saved with the error
36*b077aed3SPierre Proncheryrecord.
37*b077aed3SPierre Pronchery
38*b077aed3SPierre ProncheryERR_raise_data() does the same thing as ERR_raise(), but also lets the
39*b077aed3SPierre Proncherycaller specify additional information as a format string B<fmt> and an
40*b077aed3SPierre Proncheryarbitrary number of values, which are processed with L<BIO_snprintf(3)>.
41*b077aed3SPierre Pronchery
42e71b7053SJung-uk KimERR_put_error() adds an error code to the thread's error queue. It
43e71b7053SJung-uk Kimsignals that the error of reason code B<reason> occurred in function
44e71b7053SJung-uk KimB<func> of library B<lib>, in line number B<line> of B<file>.
45e71b7053SJung-uk KimThis function is usually called by a macro.
46e71b7053SJung-uk Kim
47e71b7053SJung-uk KimERR_add_error_data() associates the concatenation of its B<num> string
48*b077aed3SPierre Proncheryarguments as additional data with the error code added last.
49e71b7053SJung-uk KimERR_add_error_vdata() is similar except the argument is a B<va_list>.
50*b077aed3SPierre ProncheryMultiple calls to these functions append to the current top of the error queue.
51*b077aed3SPierre ProncheryThe total length of the string data per error is limited to 4096 characters.
52*b077aed3SPierre Pronchery
53*b077aed3SPierre ProncheryERR_add_error_txt() appends the given text string as additional data to the
54*b077aed3SPierre Proncherylast error queue entry, after inserting the optional separator string if it is
55*b077aed3SPierre Proncherynot NULL and the top error entry does not yet have additional data.
56*b077aed3SPierre ProncheryIn case the separator is at the end of the text it is not appended to the data.
57*b077aed3SPierre ProncheryThe B<sep> argument may be for instance "\n" to insert a line break when needed.
58*b077aed3SPierre ProncheryIf the associated data would become more than 4096 characters long
59*b077aed3SPierre Pronchery(which is the limit given above)
60*b077aed3SPierre Proncheryit is split over sufficiently many new copies of the last error queue entry.
61*b077aed3SPierre Pronchery
62*b077aed3SPierre ProncheryERR_add_error_mem_bio() is the same as ERR_add_error_txt() except that
63*b077aed3SPierre Proncherythe text string is taken from the given memory BIO.
64*b077aed3SPierre ProncheryIt appends '\0' to the BIO contents if not already NUL-terminated.
65e71b7053SJung-uk Kim
66e71b7053SJung-uk KimL<ERR_load_strings(3)> can be used to register
67e71b7053SJung-uk Kimerror strings so that the application can a generate human-readable
68e71b7053SJung-uk Kimerror messages for the error code.
69e71b7053SJung-uk Kim
70e71b7053SJung-uk Kim=head2 Reporting errors
71e71b7053SJung-uk Kim
72*b077aed3SPierre Pronchery=head3 OpenSSL library reports
73*b077aed3SPierre Pronchery
74*b077aed3SPierre ProncheryEach OpenSSL sub-library has library code B<ERR_LIB_XXX> and has its own set
75*b077aed3SPierre Proncheryof reason codes B<XXX_R_...>.  These are both passed in combination to
76*b077aed3SPierre ProncheryERR_raise() and ERR_raise_data(), and the combination ultimately produces
77*b077aed3SPierre Proncherythe correct error text for the reported error.
78*b077aed3SPierre Pronchery
79*b077aed3SPierre ProncheryAll these macros and the numbers they have as values are specific to
80*b077aed3SPierre ProncheryOpenSSL's libraries.  OpenSSL reason codes normally consist of textual error
81e71b7053SJung-uk Kimdescriptions. For example, the function ssl3_read_bytes() reports a
82e71b7053SJung-uk Kim"handshake failure" as follows:
83e71b7053SJung-uk Kim
84*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_SSL, SSL_R_SSL_HANDSHAKE_FAILURE);
85e71b7053SJung-uk Kim
86*b077aed3SPierre ProncheryThere are two exceptions:
87e71b7053SJung-uk Kim
88*b077aed3SPierre Pronchery=over 4
89*b077aed3SPierre Pronchery
90*b077aed3SPierre Pronchery=item B<ERR_LIB_SYS>
91*b077aed3SPierre Pronchery
92*b077aed3SPierre ProncheryThis "library code" indicates that a system error is being reported.  In
93*b077aed3SPierre Proncherythis case, the reason code given to ERR_raise() and ERR_raise_data() I<must>
94*b077aed3SPierre Proncherybe L<errno(3)>.
95*b077aed3SPierre Pronchery
96*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_SYS, errno);
97*b077aed3SPierre Pronchery
98*b077aed3SPierre Pronchery=item B<ERR_R_XXX>
99*b077aed3SPierre Pronchery
100*b077aed3SPierre ProncheryThis set of error codes is considered global, and may be used in combination
101*b077aed3SPierre Proncherywith any sub-library code.
102*b077aed3SPierre Pronchery
103*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_RSA, ERR_R_PASSED_INVALID_ARGUMENT);
104*b077aed3SPierre Pronchery
105*b077aed3SPierre Pronchery=back
106*b077aed3SPierre Pronchery
107*b077aed3SPierre Pronchery=head3 Other pieces of software
108*b077aed3SPierre Pronchery
109*b077aed3SPierre ProncheryOther pieces of software that may want to use OpenSSL's error reporting
110*b077aed3SPierre Proncherysystem, such as engines or applications, must normally get their own
111*b077aed3SPierre Proncherynumbers.
112*b077aed3SPierre Pronchery
113*b077aed3SPierre Pronchery=over 4
114*b077aed3SPierre Pronchery
115*b077aed3SPierre Pronchery=item *
116*b077aed3SPierre Pronchery
117*b077aed3SPierre ProncheryTo get a "library" code, call L<ERR_get_next_error_library(3)>; this gives
118*b077aed3SPierre Proncherythe calling code a dynamic number, usable for the duration of the process.
119*b077aed3SPierre Pronchery
120*b077aed3SPierre Pronchery=item *
121*b077aed3SPierre Pronchery
122*b077aed3SPierre ProncheryReason codes for each such "library" are determined or generated by the
123*b077aed3SPierre Proncheryauthors of that code.  They must be numbers in the range 1 to 524287 (in
124*b077aed3SPierre Proncheryother words, they must be nonzero unsigned 18 bit integers).
125*b077aed3SPierre Pronchery
126*b077aed3SPierre Pronchery=back
127*b077aed3SPierre Pronchery
128*b077aed3SPierre ProncheryThe exceptions mentioned in L</OpenSSL library reports> above are valid for
129*b077aed3SPierre Proncheryother pieces of software, i.e. they may use B<ERR_LIB_SYS> to report system
130*b077aed3SPierre Proncheryerrors:
131*b077aed3SPierre Pronchery
132*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_SYS, errno);
133*b077aed3SPierre Pronchery
134*b077aed3SPierre Pronchery... and they may use B<ERR_R_XXX> macros together with their own "library"
135*b077aed3SPierre Proncherycode.
136*b077aed3SPierre Pronchery
137*b077aed3SPierre Pronchery int app_lib_code = ERR_get_next_error_library();
138*b077aed3SPierre Pronchery
139*b077aed3SPierre Pronchery /* ... */
140*b077aed3SPierre Pronchery
141*b077aed3SPierre Pronchery ERR_raise(app_lib_code, ERR_R_PASSED_INVALID_ARGUMENT);
142*b077aed3SPierre Pronchery
143*b077aed3SPierre Pronchery=begin comment
144*b077aed3SPierre Pronchery
145*b077aed3SPierre Pronchery[These are OpenSSL specific recommendations]
146*b077aed3SPierre Pronchery
147*b077aed3SPierre ProncheryReason codes should consist of uppercase characters, numbers and underscores
148*b077aed3SPierre Proncheryonly. The error file generation script translates the trailing section of a
149*b077aed3SPierre Proncheryreason code (after the "_R_") into lowercase with underscores changed to
150*b077aed3SPierre Proncheryspaces.
151e71b7053SJung-uk Kim
152e71b7053SJung-uk KimAlthough a library will normally report errors using its own specific
153*b077aed3SPierre ProncheryB<ERR_LIB_XXX> macro, another library's macro can be used, together with
154*b077aed3SPierre Proncherythat other library's reason codes. This is normally only done when a library
155*b077aed3SPierre Proncherywants to include ASN1 code which must be combined with B<ERR_LIB_ASN1>
156*b077aed3SPierre Proncherymacro.
157e71b7053SJung-uk Kim
158*b077aed3SPierre Pronchery=end comment
159e71b7053SJung-uk Kim
160e71b7053SJung-uk Kim=head1 RETURN VALUES
161e71b7053SJung-uk Kim
162*b077aed3SPierre ProncheryERR_raise(), ERR_raise_data(), ERR_put_error(),
163*b077aed3SPierre ProncheryERR_add_error_data(), ERR_add_error_vdata()
164*b077aed3SPierre ProncheryERR_add_error_txt(), and ERR_add_error_mem_bio()
165*b077aed3SPierre Proncheryreturn no values.
166*b077aed3SPierre Pronchery
167*b077aed3SPierre Pronchery=head1 NOTES
168*b077aed3SPierre Pronchery
169*b077aed3SPierre ProncheryERR_raise(), ERR_raise() and ERR_put_error() are implemented as macros.
170e71b7053SJung-uk Kim
171e71b7053SJung-uk Kim=head1 SEE ALSO
172e71b7053SJung-uk Kim
173*b077aed3SPierre ProncheryL<ERR_load_strings(3)>, L<ERR_get_next_error_library(3)>
174*b077aed3SPierre Pronchery
175*b077aed3SPierre Pronchery=head1 HISTORY
176*b077aed3SPierre Pronchery
177*b077aed3SPierre ProncheryERR_raise, ERR_raise_data, ERR_add_error_txt() and ERR_add_error_mem_bio()
178*b077aed3SPierre Proncherywere added in OpenSSL 3.0.
179e71b7053SJung-uk Kim
180e71b7053SJung-uk Kim=head1 COPYRIGHT
181e71b7053SJung-uk Kim
182*b077aed3SPierre ProncheryCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
183e71b7053SJung-uk Kim
184*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
185e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
186e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
187e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
188e71b7053SJung-uk Kim
189e71b7053SJung-uk Kim=cut
190