1err(3) OpenSSL err(3)
2
3
4
6 err - error codes
7
9 #include <openssl/err.h>
10
11 unsigned long ERR_get_error(void);
12 unsigned long ERR_peek_error(void);
13 unsigned long ERR_get_error_line(const char **file, int *line);
14 unsigned long ERR_peek_error_line(const char **file, int *line);
15 unsigned long ERR_get_error_line_data(const char **file, int *line,
16 const char **data, int *flags);
17 unsigned long ERR_peek_error_line_data(const char **file, int *line,
18 const char **data, int *flags);
19
20 int ERR_GET_LIB(unsigned long e);
21 int ERR_GET_FUNC(unsigned long e);
22 int ERR_GET_REASON(unsigned long e);
23
24 void ERR_clear_error(void);
25
26 char *ERR_error_string(unsigned long e, char *buf);
27 const char *ERR_lib_error_string(unsigned long e);
28 const char *ERR_func_error_string(unsigned long e);
29 const char *ERR_reason_error_string(unsigned long e);
30
31 void ERR_print_errors(BIO *bp);
32 void ERR_print_errors_fp(FILE *fp);
33
34 void ERR_load_crypto_strings(void);
35 void ERR_free_strings(void);
36
37 void ERR_remove_state(unsigned long pid);
38
39 void ERR_put_error(int lib, int func, int reason, const char *file,
40 int line);
41 void ERR_add_error_data(int num, ...);
42
43 void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
44 unsigned long ERR_PACK(int lib, int func, int reason);
45 int ERR_get_next_error_library(void);
46
48 When a call to the OpenSSL library fails, this is usually signalled by
49 the return value, and an error code is stored in an error queue
50 associated with the current thread. The err library provides functions
51 to obtain these error codes and textual error messages.
52
53 The ERR_get_error(3) manpage describes how to access error codes.
54
55 Error codes contain information about where the error occurred, and
56 what went wrong. ERR_GET_LIB(3) describes how to extract this
57 information. A method to obtain human-readable error messages is
58 described in ERR_error_string(3).
59
60 ERR_clear_error(3) can be used to clear the error queue.
61
62 Note that ERR_remove_state(3) should be used to avoid memory leaks when
63 threads are terminated.
64
66 See ERR_put_error(3) if you want to record error codes in the OpenSSL
67 error system from within your application.
68
69 The remainder of this section is of interest only if you want to add
70 new error codes to OpenSSL or add error codes from external libraries.
71
72 Reporting errors
73 Each sub-library has a specific macro XXXerr() that is used to report
74 errors. Its first argument is a function code XXX_F_..., the second
75 argument is a reason code XXX_R_.... Function codes are derived from
76 the function names; reason codes consist of textual error descriptions.
77 For example, the function ssl23_read() reports a "handshake failure" as
78 follows:
79
80 SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE);
81
82 Function and reason codes should consist of upper case characters,
83 numbers and underscores only. The error file generation script
84 translates function codes into function names by looking in the header
85 files for an appropriate function name, if none is found it just uses
86 the capitalized form such as "SSL23_READ" in the above example.
87
88 The trailing section of a reason code (after the "_R_") is translated
89 into lower case and underscores changed to spaces.
90
91 When you are using new function or reason codes, run make errors. The
92 necessary #defines will then automatically be added to the sub-
93 library's header file.
94
95 Although a library will normally report errors using its own specific
96 XXXerr macro, another library's macro can be used. This is normally
97 only done when a library wants to include ASN1 code which must use the
98 ASN1err() macro.
99
100 Adding new libraries
101 When adding a new sub-library to OpenSSL, assign it a library number
102 ERR_LIB_XXX, define a macro XXXerr() (both in err.h), add its name to
103 ERR_str_libraries[] (in crypto/err/err.c), and add
104 "ERR_load_XXX_strings()" to the ERR_load_crypto_strings() function (in
105 crypto/err/err_all.c). Finally, add an entry
106
107 L XXX xxx.h xxx_err.c
108
109 to crypto/err/openssl.ec, and add xxx_err.c to the Makefile. Running
110 make errors will then generate a file xxx_err.c, and add all error
111 codes used in the library to xxx.h.
112
113 Additionally the library include file must have a certain form.
114 Typically it will initially look like this:
115
116 #ifndef HEADER_XXX_H
117 #define HEADER_XXX_H
118
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
122
123 /* Include files */
124
125 #include <openssl/bio.h>
126 #include <openssl/x509.h>
127
128 /* Macros, structures and function prototypes */
129
130
131 /* BEGIN ERROR CODES */
132
133 The BEGIN ERROR CODES sequence is used by the error code generation
134 script as the point to place new error codes, any text after this point
135 will be overwritten when make errors is run. The closing #endif etc
136 will be automatically added by the script.
137
138 The generated C error code file xxx_err.c will load the header files
139 stdio.h, openssl/err.h and openssl/xxx.h so the header file must load
140 any additional header files containing any definitions it uses.
141
143 It is also possible to use OpenSSL's error code scheme in external
144 libraries. The library needs to load its own codes and call the OpenSSL
145 error code insertion script mkerr.pl explicitly to add codes to the
146 header file and generate the C error code file. This will normally be
147 done if the external library needs to generate new ASN1 structures but
148 it can also be used to add more general purpose error code handling.
149
150 TBA more details
151
153 The error queues are stored in a hash table with one ERR_STATE entry
154 for each pid. ERR_get_state() returns the current thread's ERR_STATE.
155 An ERR_STATE can hold up to ERR_NUM_ERRORS error codes. When more error
156 codes are added, the old ones are overwritten, on the assumption that
157 the most recent errors are most important.
158
159 Error strings are also stored in hash table. The hash tables can be
160 obtained by calling ERR_get_err_state_table(void) and
161 ERR_get_string_table(void) respectively.
162
164 CRYPTO_set_locking_callback(3), ERR_get_error(3), ERR_GET_LIB(3),
165 ERR_clear_error(3), ERR_error_string(3), ERR_print_errors(3),
166 ERR_load_crypto_strings(3), ERR_remove_state(3), ERR_put_error(3),
167 ERR_load_strings(3), SSL_get_error(3)
168
169
170
1711.0.2k 2017-01-26 err(3)