sl@0
|
1 |
/* crypto/err/err.c */
|
sl@0
|
2 |
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
*
|
sl@0
|
5 |
* This package is an SSL implementation written
|
sl@0
|
6 |
* by Eric Young (eay@cryptsoft.com).
|
sl@0
|
7 |
* The implementation was written so as to conform with Netscapes SSL.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is free for commercial and non-commercial use as long as
|
sl@0
|
10 |
* the following conditions are aheared to. The following conditions
|
sl@0
|
11 |
* apply to all code found in this distribution, be it the RC4, RSA,
|
sl@0
|
12 |
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
sl@0
|
13 |
* included with this distribution is covered by the same copyright terms
|
sl@0
|
14 |
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
sl@0
|
15 |
*
|
sl@0
|
16 |
* Copyright remains Eric Young's, and as such any Copyright notices in
|
sl@0
|
17 |
* the code are not to be removed.
|
sl@0
|
18 |
* If this package is used in a product, Eric Young should be given attribution
|
sl@0
|
19 |
* as the author of the parts of the library used.
|
sl@0
|
20 |
* This can be in the form of a textual message at program startup or
|
sl@0
|
21 |
* in documentation (online or textual) provided with the package.
|
sl@0
|
22 |
*
|
sl@0
|
23 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
24 |
* modification, are permitted provided that the following conditions
|
sl@0
|
25 |
* are met:
|
sl@0
|
26 |
* 1. Redistributions of source code must retain the copyright
|
sl@0
|
27 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
28 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
29 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
30 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
31 |
* 3. All advertising materials mentioning features or use of this software
|
sl@0
|
32 |
* must display the following acknowledgement:
|
sl@0
|
33 |
* "This product includes cryptographic software written by
|
sl@0
|
34 |
* Eric Young (eay@cryptsoft.com)"
|
sl@0
|
35 |
* The word 'cryptographic' can be left out if the rouines from the library
|
sl@0
|
36 |
* being used are not cryptographic related :-).
|
sl@0
|
37 |
* 4. If you include any Windows specific code (or a derivative thereof) from
|
sl@0
|
38 |
* the apps directory (application code) you must include an acknowledgement:
|
sl@0
|
39 |
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
sl@0
|
40 |
*
|
sl@0
|
41 |
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
sl@0
|
42 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
43 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
44 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
sl@0
|
45 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
sl@0
|
46 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
sl@0
|
47 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
48 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
sl@0
|
49 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
sl@0
|
50 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
sl@0
|
51 |
* SUCH DAMAGE.
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* The licence and distribution terms for any publically available version or
|
sl@0
|
54 |
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
sl@0
|
55 |
* copied and put under another distribution licence
|
sl@0
|
56 |
* [including the GNU Public Licence.]
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
/* ====================================================================
|
sl@0
|
59 |
* Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
|
sl@0
|
60 |
*
|
sl@0
|
61 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
62 |
* modification, are permitted provided that the following conditions
|
sl@0
|
63 |
* are met:
|
sl@0
|
64 |
*
|
sl@0
|
65 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
66 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
67 |
*
|
sl@0
|
68 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
69 |
* notice, this list of conditions and the following disclaimer in
|
sl@0
|
70 |
* the documentation and/or other materials provided with the
|
sl@0
|
71 |
* distribution.
|
sl@0
|
72 |
*
|
sl@0
|
73 |
* 3. All advertising materials mentioning features or use of this
|
sl@0
|
74 |
* software must display the following acknowledgment:
|
sl@0
|
75 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
76 |
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
sl@0
|
77 |
*
|
sl@0
|
78 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
sl@0
|
79 |
* endorse or promote products derived from this software without
|
sl@0
|
80 |
* prior written permission. For written permission, please contact
|
sl@0
|
81 |
* openssl-core@openssl.org.
|
sl@0
|
82 |
*
|
sl@0
|
83 |
* 5. Products derived from this software may not be called "OpenSSL"
|
sl@0
|
84 |
* nor may "OpenSSL" appear in their names without prior written
|
sl@0
|
85 |
* permission of the OpenSSL Project.
|
sl@0
|
86 |
*
|
sl@0
|
87 |
* 6. Redistributions of any form whatsoever must retain the following
|
sl@0
|
88 |
* acknowledgment:
|
sl@0
|
89 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
90 |
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
sl@0
|
91 |
*
|
sl@0
|
92 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
sl@0
|
93 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
94 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
sl@0
|
95 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
sl@0
|
96 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
97 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
sl@0
|
98 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
sl@0
|
99 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
100 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
101 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
sl@0
|
102 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
sl@0
|
103 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
104 |
* ====================================================================
|
sl@0
|
105 |
*
|
sl@0
|
106 |
* This product includes cryptographic software written by Eric Young
|
sl@0
|
107 |
* (eay@cryptsoft.com). This product includes software written by Tim
|
sl@0
|
108 |
* Hudson (tjh@cryptsoft.com).
|
sl@0
|
109 |
*
|
sl@0
|
110 |
*/
|
sl@0
|
111 |
/*
|
sl@0
|
112 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
sl@0
|
113 |
*/
|
sl@0
|
114 |
|
sl@0
|
115 |
|
sl@0
|
116 |
#include <stdio.h>
|
sl@0
|
117 |
#include <stdarg.h>
|
sl@0
|
118 |
#include <string.h>
|
sl@0
|
119 |
#include "cryptlib.h"
|
sl@0
|
120 |
#include <openssl/lhash.h>
|
sl@0
|
121 |
#include <openssl/crypto.h>
|
sl@0
|
122 |
#include <openssl/buffer.h>
|
sl@0
|
123 |
#include <openssl/bio.h>
|
sl@0
|
124 |
#include <openssl/err.h>
|
sl@0
|
125 |
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
|
sl@0
|
126 |
#include "libcrypto_wsd_macros.h"
|
sl@0
|
127 |
#include "libcrypto_wsd.h"
|
sl@0
|
128 |
#endif
|
sl@0
|
129 |
|
sl@0
|
130 |
static void err_load_strings(int lib, ERR_STRING_DATA *str);
|
sl@0
|
131 |
static void ERR_STATE_free(ERR_STATE *s);
|
sl@0
|
132 |
#ifndef OPENSSL_NO_ERR
|
sl@0
|
133 |
#ifndef EMULATOR
|
sl@0
|
134 |
static ERR_STRING_DATA ERR_str_libraries[]=
|
sl@0
|
135 |
{
|
sl@0
|
136 |
{ERR_PACK(ERR_LIB_NONE,0,0) ,"unknown library"},
|
sl@0
|
137 |
{ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"},
|
sl@0
|
138 |
{ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"},
|
sl@0
|
139 |
{ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"},
|
sl@0
|
140 |
{ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"},
|
sl@0
|
141 |
{ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"},
|
sl@0
|
142 |
{ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"},
|
sl@0
|
143 |
{ERR_PACK(ERR_LIB_OBJ,0,0) ,"object identifier routines"},
|
sl@0
|
144 |
{ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"},
|
sl@0
|
145 |
{ERR_PACK(ERR_LIB_DSA,0,0) ,"dsa routines"},
|
sl@0
|
146 |
{ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"},
|
sl@0
|
147 |
{ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"},
|
sl@0
|
148 |
{ERR_PACK(ERR_LIB_CONF,0,0) ,"configuration file routines"},
|
sl@0
|
149 |
{ERR_PACK(ERR_LIB_CRYPTO,0,0) ,"common libcrypto routines"},
|
sl@0
|
150 |
{ERR_PACK(ERR_LIB_EC,0,0) ,"elliptic curve routines"},
|
sl@0
|
151 |
{ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"},
|
sl@0
|
152 |
{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
|
sl@0
|
153 |
{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
|
sl@0
|
154 |
{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
|
sl@0
|
155 |
{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
|
sl@0
|
156 |
{ERR_PACK(ERR_LIB_RAND,0,0) ,"random number generator"},
|
sl@0
|
157 |
{ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"},
|
sl@0
|
158 |
{ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"},
|
sl@0
|
159 |
{ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"},
|
sl@0
|
160 |
{0,NULL},
|
sl@0
|
161 |
};
|
sl@0
|
162 |
|
sl@0
|
163 |
static ERR_STRING_DATA ERR_str_functs[]=
|
sl@0
|
164 |
{
|
sl@0
|
165 |
{ERR_PACK(0,SYS_F_FOPEN,0), "fopen"},
|
sl@0
|
166 |
{ERR_PACK(0,SYS_F_CONNECT,0), "connect"},
|
sl@0
|
167 |
{ERR_PACK(0,SYS_F_GETSERVBYNAME,0), "getservbyname"},
|
sl@0
|
168 |
{ERR_PACK(0,SYS_F_SOCKET,0), "socket"},
|
sl@0
|
169 |
{ERR_PACK(0,SYS_F_IOCTLSOCKET,0), "ioctlsocket"},
|
sl@0
|
170 |
{ERR_PACK(0,SYS_F_BIND,0), "bind"},
|
sl@0
|
171 |
{ERR_PACK(0,SYS_F_LISTEN,0), "listen"},
|
sl@0
|
172 |
{ERR_PACK(0,SYS_F_ACCEPT,0), "accept"},
|
sl@0
|
173 |
#ifdef OPENSSL_SYS_WINDOWS
|
sl@0
|
174 |
{ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
|
sl@0
|
175 |
#endif
|
sl@0
|
176 |
{ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
|
sl@0
|
177 |
{ERR_PACK(0,SYS_F_FREAD,0), "fread"},
|
sl@0
|
178 |
{0,NULL},
|
sl@0
|
179 |
};
|
sl@0
|
180 |
|
sl@0
|
181 |
static ERR_STRING_DATA ERR_str_reasons[]=
|
sl@0
|
182 |
{
|
sl@0
|
183 |
{ERR_R_SYS_LIB ,"system lib"},
|
sl@0
|
184 |
{ERR_R_BN_LIB ,"BN lib"},
|
sl@0
|
185 |
{ERR_R_RSA_LIB ,"RSA lib"},
|
sl@0
|
186 |
{ERR_R_DH_LIB ,"DH lib"},
|
sl@0
|
187 |
{ERR_R_EVP_LIB ,"EVP lib"},
|
sl@0
|
188 |
{ERR_R_BUF_LIB ,"BUF lib"},
|
sl@0
|
189 |
{ERR_R_OBJ_LIB ,"OBJ lib"},
|
sl@0
|
190 |
{ERR_R_PEM_LIB ,"PEM lib"},
|
sl@0
|
191 |
{ERR_R_DSA_LIB ,"DSA lib"},
|
sl@0
|
192 |
{ERR_R_X509_LIB ,"X509 lib"},
|
sl@0
|
193 |
{ERR_R_ASN1_LIB ,"ASN1 lib"},
|
sl@0
|
194 |
{ERR_R_CONF_LIB ,"CONF lib"},
|
sl@0
|
195 |
{ERR_R_CRYPTO_LIB ,"CRYPTO lib"},
|
sl@0
|
196 |
{ERR_R_EC_LIB ,"EC lib"},
|
sl@0
|
197 |
{ERR_R_SSL_LIB ,"SSL lib"},
|
sl@0
|
198 |
{ERR_R_BIO_LIB ,"BIO lib"},
|
sl@0
|
199 |
{ERR_R_PKCS7_LIB ,"PKCS7 lib"},
|
sl@0
|
200 |
{ERR_R_X509V3_LIB ,"X509V3 lib"},
|
sl@0
|
201 |
{ERR_R_PKCS12_LIB ,"PKCS12 lib"},
|
sl@0
|
202 |
{ERR_R_RAND_LIB ,"RAND lib"},
|
sl@0
|
203 |
{ERR_R_DSO_LIB ,"DSO lib"},
|
sl@0
|
204 |
{ERR_R_ENGINE_LIB ,"ENGINE lib"},
|
sl@0
|
205 |
{ERR_R_OCSP_LIB ,"OCSP lib"},
|
sl@0
|
206 |
|
sl@0
|
207 |
{ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"},
|
sl@0
|
208 |
{ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"},
|
sl@0
|
209 |
{ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"},
|
sl@0
|
210 |
{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"},
|
sl@0
|
211 |
{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"},
|
sl@0
|
212 |
{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"},
|
sl@0
|
213 |
|
sl@0
|
214 |
{ERR_R_FATAL ,"fatal"},
|
sl@0
|
215 |
{ERR_R_MALLOC_FAILURE ,"malloc failure"},
|
sl@0
|
216 |
{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
|
sl@0
|
217 |
{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
|
sl@0
|
218 |
{ERR_R_INTERNAL_ERROR ,"internal error"},
|
sl@0
|
219 |
{ERR_R_DISABLED ,"called a function that was disabled at compile-time"},
|
sl@0
|
220 |
|
sl@0
|
221 |
{0,NULL},
|
sl@0
|
222 |
};
|
sl@0
|
223 |
#else //EMULATOR
|
sl@0
|
224 |
const ERR_STRING_DATA temp_ERR_str_libraries[]=
|
sl@0
|
225 |
{
|
sl@0
|
226 |
{ERR_PACK(ERR_LIB_NONE,0,0) ,"unknown library"},
|
sl@0
|
227 |
{ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"},
|
sl@0
|
228 |
{ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"},
|
sl@0
|
229 |
{ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"},
|
sl@0
|
230 |
{ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"},
|
sl@0
|
231 |
{ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"},
|
sl@0
|
232 |
{ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"},
|
sl@0
|
233 |
{ERR_PACK(ERR_LIB_OBJ,0,0) ,"object identifier routines"},
|
sl@0
|
234 |
{ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"},
|
sl@0
|
235 |
{ERR_PACK(ERR_LIB_DSA,0,0) ,"dsa routines"},
|
sl@0
|
236 |
{ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"},
|
sl@0
|
237 |
{ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"},
|
sl@0
|
238 |
{ERR_PACK(ERR_LIB_CONF,0,0) ,"configuration file routines"},
|
sl@0
|
239 |
{ERR_PACK(ERR_LIB_CRYPTO,0,0) ,"common libcrypto routines"},
|
sl@0
|
240 |
{ERR_PACK(ERR_LIB_EC,0,0) ,"elliptic curve routines"},
|
sl@0
|
241 |
{ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"},
|
sl@0
|
242 |
{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
|
sl@0
|
243 |
{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
|
sl@0
|
244 |
{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
|
sl@0
|
245 |
{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
|
sl@0
|
246 |
{ERR_PACK(ERR_LIB_RAND,0,0) ,"random number generator"},
|
sl@0
|
247 |
{ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"},
|
sl@0
|
248 |
{ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"},
|
sl@0
|
249 |
{ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"},
|
sl@0
|
250 |
{0,NULL},
|
sl@0
|
251 |
};
|
sl@0
|
252 |
|
sl@0
|
253 |
const ERR_STRING_DATA temp_ERR_str_functs[]=
|
sl@0
|
254 |
{
|
sl@0
|
255 |
{ERR_PACK(0,SYS_F_FOPEN,0), "fopen"},
|
sl@0
|
256 |
{ERR_PACK(0,SYS_F_CONNECT,0), "connect"},
|
sl@0
|
257 |
{ERR_PACK(0,SYS_F_GETSERVBYNAME,0), "getservbyname"},
|
sl@0
|
258 |
{ERR_PACK(0,SYS_F_SOCKET,0), "socket"},
|
sl@0
|
259 |
{ERR_PACK(0,SYS_F_IOCTLSOCKET,0), "ioctlsocket"},
|
sl@0
|
260 |
{ERR_PACK(0,SYS_F_BIND,0), "bind"},
|
sl@0
|
261 |
{ERR_PACK(0,SYS_F_LISTEN,0), "listen"},
|
sl@0
|
262 |
{ERR_PACK(0,SYS_F_ACCEPT,0), "accept"},
|
sl@0
|
263 |
#ifdef OPENSSL_SYS_WINDOWS
|
sl@0
|
264 |
{ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
|
sl@0
|
265 |
#endif
|
sl@0
|
266 |
{ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
|
sl@0
|
267 |
{ERR_PACK(0,SYS_F_FREAD,0), "fread"},
|
sl@0
|
268 |
{0,NULL},
|
sl@0
|
269 |
};
|
sl@0
|
270 |
|
sl@0
|
271 |
const ERR_STRING_DATA temp_ERR_str_reasons[]=
|
sl@0
|
272 |
{
|
sl@0
|
273 |
{ERR_R_SYS_LIB ,"system lib"},
|
sl@0
|
274 |
{ERR_R_BN_LIB ,"BN lib"},
|
sl@0
|
275 |
{ERR_R_RSA_LIB ,"RSA lib"},
|
sl@0
|
276 |
{ERR_R_DH_LIB ,"DH lib"},
|
sl@0
|
277 |
{ERR_R_EVP_LIB ,"EVP lib"},
|
sl@0
|
278 |
{ERR_R_BUF_LIB ,"BUF lib"},
|
sl@0
|
279 |
{ERR_R_OBJ_LIB ,"OBJ lib"},
|
sl@0
|
280 |
{ERR_R_PEM_LIB ,"PEM lib"},
|
sl@0
|
281 |
{ERR_R_DSA_LIB ,"DSA lib"},
|
sl@0
|
282 |
{ERR_R_X509_LIB ,"X509 lib"},
|
sl@0
|
283 |
{ERR_R_ASN1_LIB ,"ASN1 lib"},
|
sl@0
|
284 |
{ERR_R_CONF_LIB ,"CONF lib"},
|
sl@0
|
285 |
{ERR_R_CRYPTO_LIB ,"CRYPTO lib"},
|
sl@0
|
286 |
{ERR_R_EC_LIB ,"EC lib"},
|
sl@0
|
287 |
{ERR_R_SSL_LIB ,"SSL lib"},
|
sl@0
|
288 |
{ERR_R_BIO_LIB ,"BIO lib"},
|
sl@0
|
289 |
{ERR_R_PKCS7_LIB ,"PKCS7 lib"},
|
sl@0
|
290 |
{ERR_R_X509V3_LIB ,"X509V3 lib"},
|
sl@0
|
291 |
{ERR_R_PKCS12_LIB ,"PKCS12 lib"},
|
sl@0
|
292 |
{ERR_R_RAND_LIB ,"RAND lib"},
|
sl@0
|
293 |
{ERR_R_DSO_LIB ,"DSO lib"},
|
sl@0
|
294 |
{ERR_R_ENGINE_LIB ,"ENGINE lib"},
|
sl@0
|
295 |
{ERR_R_OCSP_LIB ,"OCSP lib"},
|
sl@0
|
296 |
|
sl@0
|
297 |
{ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"},
|
sl@0
|
298 |
{ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"},
|
sl@0
|
299 |
{ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"},
|
sl@0
|
300 |
{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"},
|
sl@0
|
301 |
{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"},
|
sl@0
|
302 |
{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"},
|
sl@0
|
303 |
|
sl@0
|
304 |
{ERR_R_FATAL ,"fatal"},
|
sl@0
|
305 |
{ERR_R_MALLOC_FAILURE ,"malloc failure"},
|
sl@0
|
306 |
{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
|
sl@0
|
307 |
{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
|
sl@0
|
308 |
{ERR_R_INTERNAL_ERROR ,"internal error"},
|
sl@0
|
309 |
{ERR_R_DISABLED ,"called a function that was disabled at compile-time"},
|
sl@0
|
310 |
|
sl@0
|
311 |
{0,NULL},
|
sl@0
|
312 |
};
|
sl@0
|
313 |
GET_STATIC_ARRAY_FROM_TLS(ERR_str_functs,err_err,ERR_STRING_DATA)
|
sl@0
|
314 |
GET_STATIC_ARRAY_FROM_TLS(ERR_str_reasons,err_err,ERR_STRING_DATA)
|
sl@0
|
315 |
GET_STATIC_ARRAY_FROM_TLS(ERR_str_libraries,err_err,ERR_STRING_DATA)
|
sl@0
|
316 |
#define ERR_str_functs (GET_WSD_VAR_NAME(ERR_str_functs,err_err, s)())
|
sl@0
|
317 |
#define ERR_str_reasons (GET_WSD_VAR_NAME(ERR_str_reasons,err_err, s)())
|
sl@0
|
318 |
#define ERR_str_libraries (GET_WSD_VAR_NAME(ERR_str_libraries,err_err, s)())
|
sl@0
|
319 |
#endif //EMULATOR
|
sl@0
|
320 |
#endif
|
sl@0
|
321 |
|
sl@0
|
322 |
#ifndef EMULATOR
|
sl@0
|
323 |
/* Define the predeclared (but externally opaque) "ERR_FNS" type */
|
sl@0
|
324 |
struct st_ERR_FNS
|
sl@0
|
325 |
{
|
sl@0
|
326 |
/* Works on the "error_hash" string table */
|
sl@0
|
327 |
LHASH *(*cb_err_get)(int create);
|
sl@0
|
328 |
void (*cb_err_del)(void);
|
sl@0
|
329 |
ERR_STRING_DATA *(*cb_err_get_item)(const ERR_STRING_DATA *);
|
sl@0
|
330 |
ERR_STRING_DATA *(*cb_err_set_item)(ERR_STRING_DATA *);
|
sl@0
|
331 |
ERR_STRING_DATA *(*cb_err_del_item)(ERR_STRING_DATA *);
|
sl@0
|
332 |
/* Works on the "thread_hash" error-state table */
|
sl@0
|
333 |
LHASH *(*cb_thread_get)(int create);
|
sl@0
|
334 |
void (*cb_thread_release)(LHASH **hash);
|
sl@0
|
335 |
ERR_STATE *(*cb_thread_get_item)(const ERR_STATE *);
|
sl@0
|
336 |
ERR_STATE *(*cb_thread_set_item)(ERR_STATE *);
|
sl@0
|
337 |
void (*cb_thread_del_item)(const ERR_STATE *);
|
sl@0
|
338 |
/* Returns the next available error "library" numbers */
|
sl@0
|
339 |
int (*cb_get_next_lib)(void);
|
sl@0
|
340 |
};
|
sl@0
|
341 |
#endif
|
sl@0
|
342 |
/* Predeclarations of the "err_defaults" functions */
|
sl@0
|
343 |
static LHASH *int_err_get(int create);
|
sl@0
|
344 |
static void int_err_del(void);
|
sl@0
|
345 |
static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *);
|
sl@0
|
346 |
static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *);
|
sl@0
|
347 |
static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *);
|
sl@0
|
348 |
static LHASH *int_thread_get(int create);
|
sl@0
|
349 |
static void int_thread_release(LHASH **hash);
|
sl@0
|
350 |
static ERR_STATE *int_thread_get_item(const ERR_STATE *);
|
sl@0
|
351 |
static ERR_STATE *int_thread_set_item(ERR_STATE *);
|
sl@0
|
352 |
static void int_thread_del_item(const ERR_STATE *);
|
sl@0
|
353 |
static int int_err_get_next_lib(void);
|
sl@0
|
354 |
/* The static ERR_FNS table using these defaults functions */
|
sl@0
|
355 |
static const ERR_FNS err_defaults =
|
sl@0
|
356 |
{
|
sl@0
|
357 |
int_err_get,
|
sl@0
|
358 |
int_err_del,
|
sl@0
|
359 |
int_err_get_item,
|
sl@0
|
360 |
int_err_set_item,
|
sl@0
|
361 |
int_err_del_item,
|
sl@0
|
362 |
int_thread_get,
|
sl@0
|
363 |
int_thread_release,
|
sl@0
|
364 |
int_thread_get_item,
|
sl@0
|
365 |
int_thread_set_item,
|
sl@0
|
366 |
int_thread_del_item,
|
sl@0
|
367 |
int_err_get_next_lib
|
sl@0
|
368 |
};
|
sl@0
|
369 |
|
sl@0
|
370 |
#ifndef EMULATOR
|
sl@0
|
371 |
/* The replacable table of ERR_FNS functions we use at run-time */
|
sl@0
|
372 |
static const ERR_FNS *err_fns = NULL;
|
sl@0
|
373 |
#else
|
sl@0
|
374 |
GET_STATIC_VAR_FROM_TLS(err_fns,err,const ERR_FNS *)
|
sl@0
|
375 |
#define err_fns (*GET_WSD_VAR_NAME(err_fns,err, s)())
|
sl@0
|
376 |
#endif
|
sl@0
|
377 |
|
sl@0
|
378 |
/* Eg. rather than using "err_get()", use "ERRFN(err_get)()". */
|
sl@0
|
379 |
#define ERRFN(a) err_fns->cb_##a
|
sl@0
|
380 |
|
sl@0
|
381 |
#ifndef EMULATOR
|
sl@0
|
382 |
/* The internal state used by "err_defaults" - as such, the setting, reading,
|
sl@0
|
383 |
* creating, and deleting of this data should only be permitted via the
|
sl@0
|
384 |
* "err_defaults" functions. This way, a linked module can completely defer all
|
sl@0
|
385 |
* ERR state operation (together with requisite locking) to the implementations
|
sl@0
|
386 |
* and state in the loading application. */
|
sl@0
|
387 |
static LHASH *int_error_hash = NULL;
|
sl@0
|
388 |
static LHASH *int_thread_hash = NULL;
|
sl@0
|
389 |
static int int_thread_hash_references = 0;
|
sl@0
|
390 |
static int int_err_library_number= ERR_LIB_USER;
|
sl@0
|
391 |
#else
|
sl@0
|
392 |
GET_STATIC_VAR_FROM_TLS(int_error_hash,err,LHASH *)
|
sl@0
|
393 |
#define int_error_hash (*GET_WSD_VAR_NAME(int_error_hash,err,s)())
|
sl@0
|
394 |
|
sl@0
|
395 |
GET_STATIC_VAR_FROM_TLS(int_thread_hash,err,LHASH *)
|
sl@0
|
396 |
#define int_thread_hash (*GET_WSD_VAR_NAME(int_thread_hash,err,s)())
|
sl@0
|
397 |
|
sl@0
|
398 |
GET_STATIC_VAR_FROM_TLS(int_thread_hash_references,err,int)
|
sl@0
|
399 |
#define int_thread_hash_references (*GET_WSD_VAR_NAME(int_thread_hash_references,err,s)())
|
sl@0
|
400 |
|
sl@0
|
401 |
GET_STATIC_VAR_FROM_TLS(int_err_library_number,err,int)
|
sl@0
|
402 |
#define int_err_library_number (*GET_WSD_VAR_NAME(int_err_library_number,err,s)())
|
sl@0
|
403 |
|
sl@0
|
404 |
#endif
|
sl@0
|
405 |
|
sl@0
|
406 |
/* Internal function that checks whether "err_fns" is set and if not, sets it to
|
sl@0
|
407 |
* the defaults. */
|
sl@0
|
408 |
static void err_fns_check(void)
|
sl@0
|
409 |
{
|
sl@0
|
410 |
if (err_fns) return;
|
sl@0
|
411 |
|
sl@0
|
412 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
413 |
if (!err_fns)
|
sl@0
|
414 |
err_fns = &err_defaults;
|
sl@0
|
415 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
416 |
}
|
sl@0
|
417 |
|
sl@0
|
418 |
/* API functions to get or set the underlying ERR functions. */
|
sl@0
|
419 |
|
sl@0
|
420 |
EXPORT_C const ERR_FNS *ERR_get_implementation(void)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
err_fns_check();
|
sl@0
|
423 |
return err_fns;
|
sl@0
|
424 |
}
|
sl@0
|
425 |
|
sl@0
|
426 |
EXPORT_C int ERR_set_implementation(const ERR_FNS *fns)
|
sl@0
|
427 |
{
|
sl@0
|
428 |
int ret = 0;
|
sl@0
|
429 |
|
sl@0
|
430 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
431 |
/* It's too late if 'err_fns' is non-NULL. BTW: not much point setting
|
sl@0
|
432 |
* an error is there?! */
|
sl@0
|
433 |
if (!err_fns)
|
sl@0
|
434 |
{
|
sl@0
|
435 |
err_fns = fns;
|
sl@0
|
436 |
ret = 1;
|
sl@0
|
437 |
}
|
sl@0
|
438 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
439 |
return ret;
|
sl@0
|
440 |
}
|
sl@0
|
441 |
|
sl@0
|
442 |
/* These are the callbacks provided to "lh_new()" when creating the LHASH tables
|
sl@0
|
443 |
* internal to the "err_defaults" implementation. */
|
sl@0
|
444 |
|
sl@0
|
445 |
/* static unsigned long err_hash(ERR_STRING_DATA *a); */
|
sl@0
|
446 |
static unsigned long err_hash(const void *a_void);
|
sl@0
|
447 |
/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); */
|
sl@0
|
448 |
static int err_cmp(const void *a_void, const void *b_void);
|
sl@0
|
449 |
/* static unsigned long pid_hash(ERR_STATE *pid); */
|
sl@0
|
450 |
static unsigned long pid_hash(const void *pid_void);
|
sl@0
|
451 |
/* static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); */
|
sl@0
|
452 |
static int pid_cmp(const void *a_void,const void *pid_void);
|
sl@0
|
453 |
static unsigned long get_error_values(int inc,int top,const char **file,int *line,
|
sl@0
|
454 |
const char **data,int *flags);
|
sl@0
|
455 |
|
sl@0
|
456 |
/* The internal functions used in the "err_defaults" implementation */
|
sl@0
|
457 |
|
sl@0
|
458 |
static LHASH *int_err_get(int create)
|
sl@0
|
459 |
{
|
sl@0
|
460 |
LHASH *ret = NULL;
|
sl@0
|
461 |
|
sl@0
|
462 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
463 |
if (!int_error_hash && create)
|
sl@0
|
464 |
{
|
sl@0
|
465 |
CRYPTO_push_info("int_err_get (err.c)");
|
sl@0
|
466 |
int_error_hash = lh_new(err_hash, err_cmp);
|
sl@0
|
467 |
CRYPTO_pop_info();
|
sl@0
|
468 |
}
|
sl@0
|
469 |
if (int_error_hash)
|
sl@0
|
470 |
ret = int_error_hash;
|
sl@0
|
471 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
472 |
|
sl@0
|
473 |
return ret;
|
sl@0
|
474 |
}
|
sl@0
|
475 |
|
sl@0
|
476 |
static void int_err_del(void)
|
sl@0
|
477 |
{
|
sl@0
|
478 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
479 |
if (int_error_hash)
|
sl@0
|
480 |
{
|
sl@0
|
481 |
lh_free(int_error_hash);
|
sl@0
|
482 |
int_error_hash = NULL;
|
sl@0
|
483 |
}
|
sl@0
|
484 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
485 |
}
|
sl@0
|
486 |
|
sl@0
|
487 |
static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
|
sl@0
|
488 |
{
|
sl@0
|
489 |
ERR_STRING_DATA *p;
|
sl@0
|
490 |
LHASH *hash;
|
sl@0
|
491 |
|
sl@0
|
492 |
err_fns_check();
|
sl@0
|
493 |
hash = ERRFN(err_get)(0);
|
sl@0
|
494 |
if (!hash)
|
sl@0
|
495 |
return NULL;
|
sl@0
|
496 |
|
sl@0
|
497 |
CRYPTO_r_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
498 |
p = (ERR_STRING_DATA *)lh_retrieve(hash, d);
|
sl@0
|
499 |
CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
500 |
|
sl@0
|
501 |
return p;
|
sl@0
|
502 |
}
|
sl@0
|
503 |
|
sl@0
|
504 |
static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d)
|
sl@0
|
505 |
{
|
sl@0
|
506 |
ERR_STRING_DATA *p;
|
sl@0
|
507 |
LHASH *hash;
|
sl@0
|
508 |
|
sl@0
|
509 |
err_fns_check();
|
sl@0
|
510 |
hash = ERRFN(err_get)(1);
|
sl@0
|
511 |
if (!hash)
|
sl@0
|
512 |
return NULL;
|
sl@0
|
513 |
|
sl@0
|
514 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
515 |
p = (ERR_STRING_DATA *)lh_insert(hash, d);
|
sl@0
|
516 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
517 |
|
sl@0
|
518 |
return p;
|
sl@0
|
519 |
}
|
sl@0
|
520 |
|
sl@0
|
521 |
static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d)
|
sl@0
|
522 |
{
|
sl@0
|
523 |
ERR_STRING_DATA *p;
|
sl@0
|
524 |
LHASH *hash;
|
sl@0
|
525 |
|
sl@0
|
526 |
err_fns_check();
|
sl@0
|
527 |
hash = ERRFN(err_get)(0);
|
sl@0
|
528 |
if (!hash)
|
sl@0
|
529 |
return NULL;
|
sl@0
|
530 |
|
sl@0
|
531 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
532 |
p = (ERR_STRING_DATA *)lh_delete(hash, d);
|
sl@0
|
533 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
534 |
|
sl@0
|
535 |
return p;
|
sl@0
|
536 |
}
|
sl@0
|
537 |
|
sl@0
|
538 |
static LHASH *int_thread_get(int create)
|
sl@0
|
539 |
{
|
sl@0
|
540 |
LHASH *ret = NULL;
|
sl@0
|
541 |
|
sl@0
|
542 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
543 |
if (!int_thread_hash && create)
|
sl@0
|
544 |
{
|
sl@0
|
545 |
CRYPTO_push_info("int_thread_get (err.c)");
|
sl@0
|
546 |
int_thread_hash = lh_new(pid_hash, pid_cmp);
|
sl@0
|
547 |
CRYPTO_pop_info();
|
sl@0
|
548 |
}
|
sl@0
|
549 |
if (int_thread_hash)
|
sl@0
|
550 |
{
|
sl@0
|
551 |
int_thread_hash_references++;
|
sl@0
|
552 |
ret = int_thread_hash;
|
sl@0
|
553 |
}
|
sl@0
|
554 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
555 |
return ret;
|
sl@0
|
556 |
}
|
sl@0
|
557 |
|
sl@0
|
558 |
static void int_thread_release(LHASH **hash)
|
sl@0
|
559 |
{
|
sl@0
|
560 |
int i;
|
sl@0
|
561 |
|
sl@0
|
562 |
if (hash == NULL || *hash == NULL)
|
sl@0
|
563 |
return;
|
sl@0
|
564 |
|
sl@0
|
565 |
i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR);
|
sl@0
|
566 |
|
sl@0
|
567 |
#ifdef REF_PRINT
|
sl@0
|
568 |
fprintf(stderr,"%4d:%s\n",int_thread_hash_references,"ERR");
|
sl@0
|
569 |
#endif
|
sl@0
|
570 |
if (i > 0) return;
|
sl@0
|
571 |
#ifdef REF_CHECK
|
sl@0
|
572 |
if (i < 0)
|
sl@0
|
573 |
{
|
sl@0
|
574 |
fprintf(stderr,"int_thread_release, bad reference count\n");
|
sl@0
|
575 |
abort(); /* ok */
|
sl@0
|
576 |
}
|
sl@0
|
577 |
#endif
|
sl@0
|
578 |
*hash = NULL;
|
sl@0
|
579 |
}
|
sl@0
|
580 |
|
sl@0
|
581 |
static ERR_STATE *int_thread_get_item(const ERR_STATE *d)
|
sl@0
|
582 |
{
|
sl@0
|
583 |
ERR_STATE *p;
|
sl@0
|
584 |
LHASH *hash;
|
sl@0
|
585 |
|
sl@0
|
586 |
err_fns_check();
|
sl@0
|
587 |
hash = ERRFN(thread_get)(0);
|
sl@0
|
588 |
if (!hash)
|
sl@0
|
589 |
return NULL;
|
sl@0
|
590 |
|
sl@0
|
591 |
CRYPTO_r_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
592 |
p = (ERR_STATE *)lh_retrieve(hash, d);
|
sl@0
|
593 |
CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
594 |
|
sl@0
|
595 |
ERRFN(thread_release)(&hash);
|
sl@0
|
596 |
return p;
|
sl@0
|
597 |
}
|
sl@0
|
598 |
|
sl@0
|
599 |
static ERR_STATE *int_thread_set_item(ERR_STATE *d)
|
sl@0
|
600 |
{
|
sl@0
|
601 |
ERR_STATE *p;
|
sl@0
|
602 |
LHASH *hash;
|
sl@0
|
603 |
|
sl@0
|
604 |
err_fns_check();
|
sl@0
|
605 |
hash = ERRFN(thread_get)(1);
|
sl@0
|
606 |
if (!hash)
|
sl@0
|
607 |
return NULL;
|
sl@0
|
608 |
|
sl@0
|
609 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
610 |
p = (ERR_STATE *)lh_insert(hash, d);
|
sl@0
|
611 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
612 |
|
sl@0
|
613 |
ERRFN(thread_release)(&hash);
|
sl@0
|
614 |
return p;
|
sl@0
|
615 |
}
|
sl@0
|
616 |
|
sl@0
|
617 |
static void int_thread_del_item(const ERR_STATE *d)
|
sl@0
|
618 |
{
|
sl@0
|
619 |
ERR_STATE *p;
|
sl@0
|
620 |
LHASH *hash;
|
sl@0
|
621 |
|
sl@0
|
622 |
err_fns_check();
|
sl@0
|
623 |
hash = ERRFN(thread_get)(0);
|
sl@0
|
624 |
if (!hash)
|
sl@0
|
625 |
return;
|
sl@0
|
626 |
|
sl@0
|
627 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
628 |
p = (ERR_STATE *)lh_delete(hash, d);
|
sl@0
|
629 |
/* make sure we don't leak memory */
|
sl@0
|
630 |
if (int_thread_hash_references == 1
|
sl@0
|
631 |
&& int_thread_hash && (lh_num_items(int_thread_hash) == 0))
|
sl@0
|
632 |
{
|
sl@0
|
633 |
lh_free(int_thread_hash);
|
sl@0
|
634 |
int_thread_hash = NULL;
|
sl@0
|
635 |
}
|
sl@0
|
636 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
637 |
|
sl@0
|
638 |
ERRFN(thread_release)(&hash);
|
sl@0
|
639 |
if (p)
|
sl@0
|
640 |
ERR_STATE_free(p);
|
sl@0
|
641 |
}
|
sl@0
|
642 |
|
sl@0
|
643 |
static int int_err_get_next_lib(void)
|
sl@0
|
644 |
{
|
sl@0
|
645 |
int ret;
|
sl@0
|
646 |
|
sl@0
|
647 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
648 |
ret = int_err_library_number++;
|
sl@0
|
649 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
650 |
|
sl@0
|
651 |
return ret;
|
sl@0
|
652 |
}
|
sl@0
|
653 |
|
sl@0
|
654 |
|
sl@0
|
655 |
#ifndef OPENSSL_NO_ERR
|
sl@0
|
656 |
#define NUM_SYS_STR_REASONS 127
|
sl@0
|
657 |
#define LEN_SYS_STR_REASON 32
|
sl@0
|
658 |
|
sl@0
|
659 |
#ifndef EMULATOR
|
sl@0
|
660 |
static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
|
sl@0
|
661 |
#endif
|
sl@0
|
662 |
/* SYS_str_reasons is filled with copies of strerror() results at
|
sl@0
|
663 |
* initialization.
|
sl@0
|
664 |
* 'errno' values up to 127 should cover all usual errors,
|
sl@0
|
665 |
* others will be displayed numerically by ERR_error_string.
|
sl@0
|
666 |
* It is crucial that we have something for each reason code
|
sl@0
|
667 |
* that occurs in ERR_str_reasons, or bogus reason strings
|
sl@0
|
668 |
* will be returned for SYSerr(), which always gets an errno
|
sl@0
|
669 |
* value and never one of those 'standard' reason codes. */
|
sl@0
|
670 |
#ifdef EMULATOR
|
sl@0
|
671 |
GET_STATIC_VAR_FROM_TLS(init,err,int)
|
sl@0
|
672 |
#define init (*GET_WSD_VAR_NAME(init,err, s)())
|
sl@0
|
673 |
GET_STATIC_ARRAY_FROM_TLS(SYS_str_reasons,err,ERR_STRING_DATA)
|
sl@0
|
674 |
#define SYS_str_reasons (GET_WSD_VAR_NAME(SYS_str_reasons,err, s)())
|
sl@0
|
675 |
|
sl@0
|
676 |
|
sl@0
|
677 |
//GET_STATIC_ARRAY_FROM_TLS(&strerror_tab,err,char)
|
sl@0
|
678 |
#define strerror_tab libcrypto_ImpurePtr()->strerror_tab
|
sl@0
|
679 |
#endif
|
sl@0
|
680 |
|
sl@0
|
681 |
static void build_SYS_str_reasons(void)
|
sl@0
|
682 |
{
|
sl@0
|
683 |
/* OPENSSL_malloc cannot be used here, use static storage instead */
|
sl@0
|
684 |
#ifndef EMULATOR
|
sl@0
|
685 |
static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
|
sl@0
|
686 |
#endif
|
sl@0
|
687 |
int i;
|
sl@0
|
688 |
#ifndef EMULATOR
|
sl@0
|
689 |
static int init = 1;
|
sl@0
|
690 |
#endif
|
sl@0
|
691 |
|
sl@0
|
692 |
CRYPTO_r_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
693 |
if (!init)
|
sl@0
|
694 |
{
|
sl@0
|
695 |
CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
696 |
return;
|
sl@0
|
697 |
}
|
sl@0
|
698 |
|
sl@0
|
699 |
CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
700 |
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
|
sl@0
|
701 |
if (!init)
|
sl@0
|
702 |
{
|
sl@0
|
703 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
704 |
return;
|
sl@0
|
705 |
}
|
sl@0
|
706 |
|
sl@0
|
707 |
for (i = 1; i <= NUM_SYS_STR_REASONS; i++)
|
sl@0
|
708 |
{
|
sl@0
|
709 |
ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
|
sl@0
|
710 |
|
sl@0
|
711 |
str->error = (unsigned long)i;
|
sl@0
|
712 |
if (str->string == NULL)
|
sl@0
|
713 |
{
|
sl@0
|
714 |
char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]);
|
sl@0
|
715 |
char *src = strerror(i);
|
sl@0
|
716 |
if (src != NULL)
|
sl@0
|
717 |
{
|
sl@0
|
718 |
strncpy(*dest, src, sizeof *dest);
|
sl@0
|
719 |
(*dest)[sizeof *dest - 1] = '\0';
|
sl@0
|
720 |
str->string = *dest;
|
sl@0
|
721 |
}
|
sl@0
|
722 |
}
|
sl@0
|
723 |
if (str->string == NULL)
|
sl@0
|
724 |
str->string = "unknown";
|
sl@0
|
725 |
}
|
sl@0
|
726 |
|
sl@0
|
727 |
/* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
|
sl@0
|
728 |
* as required by ERR_load_strings. */
|
sl@0
|
729 |
|
sl@0
|
730 |
init = 0;
|
sl@0
|
731 |
|
sl@0
|
732 |
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
|
sl@0
|
733 |
}
|
sl@0
|
734 |
#endif
|
sl@0
|
735 |
|
sl@0
|
736 |
#define err_clear_data(p,i) \
|
sl@0
|
737 |
do { \
|
sl@0
|
738 |
if (((p)->err_data[i] != NULL) && \
|
sl@0
|
739 |
(p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
|
sl@0
|
740 |
{ \
|
sl@0
|
741 |
OPENSSL_free((p)->err_data[i]); \
|
sl@0
|
742 |
(p)->err_data[i]=NULL; \
|
sl@0
|
743 |
} \
|
sl@0
|
744 |
(p)->err_data_flags[i]=0; \
|
sl@0
|
745 |
} while(0)
|
sl@0
|
746 |
|
sl@0
|
747 |
#define err_clear(p,i) \
|
sl@0
|
748 |
do { \
|
sl@0
|
749 |
(p)->err_flags[i]=0; \
|
sl@0
|
750 |
(p)->err_buffer[i]=0; \
|
sl@0
|
751 |
err_clear_data(p,i); \
|
sl@0
|
752 |
(p)->err_file[i]=NULL; \
|
sl@0
|
753 |
(p)->err_line[i]= -1; \
|
sl@0
|
754 |
} while(0)
|
sl@0
|
755 |
|
sl@0
|
756 |
static void ERR_STATE_free(ERR_STATE *s)
|
sl@0
|
757 |
{
|
sl@0
|
758 |
int i;
|
sl@0
|
759 |
|
sl@0
|
760 |
if (s == NULL)
|
sl@0
|
761 |
return;
|
sl@0
|
762 |
|
sl@0
|
763 |
for (i=0; i<ERR_NUM_ERRORS; i++)
|
sl@0
|
764 |
{
|
sl@0
|
765 |
err_clear_data(s,i);
|
sl@0
|
766 |
}
|
sl@0
|
767 |
OPENSSL_free(s);
|
sl@0
|
768 |
}
|
sl@0
|
769 |
|
sl@0
|
770 |
EXPORT_C void ERR_load_ERR_strings(void)
|
sl@0
|
771 |
{
|
sl@0
|
772 |
err_fns_check();
|
sl@0
|
773 |
#ifndef OPENSSL_NO_ERR
|
sl@0
|
774 |
err_load_strings(0,ERR_str_libraries);
|
sl@0
|
775 |
err_load_strings(0,ERR_str_reasons);
|
sl@0
|
776 |
err_load_strings(ERR_LIB_SYS,ERR_str_functs);
|
sl@0
|
777 |
build_SYS_str_reasons();
|
sl@0
|
778 |
err_load_strings(ERR_LIB_SYS,SYS_str_reasons);
|
sl@0
|
779 |
#endif
|
sl@0
|
780 |
}
|
sl@0
|
781 |
|
sl@0
|
782 |
static void err_load_strings(int lib, ERR_STRING_DATA *str)
|
sl@0
|
783 |
{
|
sl@0
|
784 |
while (str->error)
|
sl@0
|
785 |
{
|
sl@0
|
786 |
if (lib)
|
sl@0
|
787 |
str->error|=ERR_PACK(lib,0,0);
|
sl@0
|
788 |
ERRFN(err_set_item)(str);
|
sl@0
|
789 |
str++;
|
sl@0
|
790 |
}
|
sl@0
|
791 |
}
|
sl@0
|
792 |
|
sl@0
|
793 |
EXPORT_C void ERR_load_strings(int lib, ERR_STRING_DATA *str)
|
sl@0
|
794 |
{
|
sl@0
|
795 |
ERR_load_ERR_strings();
|
sl@0
|
796 |
err_load_strings(lib, str);
|
sl@0
|
797 |
}
|
sl@0
|
798 |
|
sl@0
|
799 |
EXPORT_C void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
|
sl@0
|
800 |
{
|
sl@0
|
801 |
while (str->error)
|
sl@0
|
802 |
{
|
sl@0
|
803 |
if (lib)
|
sl@0
|
804 |
str->error|=ERR_PACK(lib,0,0);
|
sl@0
|
805 |
ERRFN(err_del_item)(str);
|
sl@0
|
806 |
str++;
|
sl@0
|
807 |
}
|
sl@0
|
808 |
}
|
sl@0
|
809 |
|
sl@0
|
810 |
EXPORT_C void ERR_free_strings(void)
|
sl@0
|
811 |
{
|
sl@0
|
812 |
err_fns_check();
|
sl@0
|
813 |
ERRFN(err_del)();
|
sl@0
|
814 |
}
|
sl@0
|
815 |
|
sl@0
|
816 |
/********************************************************/
|
sl@0
|
817 |
|
sl@0
|
818 |
EXPORT_C void ERR_put_error(int lib, int func, int reason, const char *file,
|
sl@0
|
819 |
int line)
|
sl@0
|
820 |
{
|
sl@0
|
821 |
ERR_STATE *es;
|
sl@0
|
822 |
|
sl@0
|
823 |
#ifdef _OSD_POSIX
|
sl@0
|
824 |
/* In the BS2000-OSD POSIX subsystem, the compiler generates
|
sl@0
|
825 |
* path names in the form "*POSIX(/etc/passwd)".
|
sl@0
|
826 |
* This dirty hack strips them to something sensible.
|
sl@0
|
827 |
* @@@ We shouldn't modify a const string, though.
|
sl@0
|
828 |
*/
|
sl@0
|
829 |
if (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {
|
sl@0
|
830 |
char *end;
|
sl@0
|
831 |
|
sl@0
|
832 |
/* Skip the "*POSIX(" prefix */
|
sl@0
|
833 |
file += sizeof("*POSIX(")-1;
|
sl@0
|
834 |
end = &file[strlen(file)-1];
|
sl@0
|
835 |
if (*end == ')')
|
sl@0
|
836 |
*end = '\0';
|
sl@0
|
837 |
/* Optional: use the basename of the path only. */
|
sl@0
|
838 |
if ((end = strrchr(file, '/')) != NULL)
|
sl@0
|
839 |
file = &end[1];
|
sl@0
|
840 |
}
|
sl@0
|
841 |
#endif
|
sl@0
|
842 |
es=ERR_get_state();
|
sl@0
|
843 |
|
sl@0
|
844 |
es->top=(es->top+1)%ERR_NUM_ERRORS;
|
sl@0
|
845 |
if (es->top == es->bottom)
|
sl@0
|
846 |
es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
|
sl@0
|
847 |
es->err_flags[es->top]=0;
|
sl@0
|
848 |
es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
|
sl@0
|
849 |
es->err_file[es->top]=file;
|
sl@0
|
850 |
es->err_line[es->top]=line;
|
sl@0
|
851 |
err_clear_data(es,es->top);
|
sl@0
|
852 |
}
|
sl@0
|
853 |
|
sl@0
|
854 |
EXPORT_C void ERR_clear_error(void)
|
sl@0
|
855 |
{
|
sl@0
|
856 |
int i;
|
sl@0
|
857 |
ERR_STATE *es;
|
sl@0
|
858 |
|
sl@0
|
859 |
es=ERR_get_state();
|
sl@0
|
860 |
|
sl@0
|
861 |
for (i=0; i<ERR_NUM_ERRORS; i++)
|
sl@0
|
862 |
{
|
sl@0
|
863 |
err_clear(es,i);
|
sl@0
|
864 |
}
|
sl@0
|
865 |
es->top=es->bottom=0;
|
sl@0
|
866 |
}
|
sl@0
|
867 |
|
sl@0
|
868 |
|
sl@0
|
869 |
EXPORT_C unsigned long ERR_get_error(void)
|
sl@0
|
870 |
{ return(get_error_values(1,0,NULL,NULL,NULL,NULL)); }
|
sl@0
|
871 |
|
sl@0
|
872 |
EXPORT_C unsigned long ERR_get_error_line(const char **file,
|
sl@0
|
873 |
int *line)
|
sl@0
|
874 |
{ return(get_error_values(1,0,file,line,NULL,NULL)); }
|
sl@0
|
875 |
|
sl@0
|
876 |
EXPORT_C unsigned long ERR_get_error_line_data(const char **file, int *line,
|
sl@0
|
877 |
const char **data, int *flags)
|
sl@0
|
878 |
{ return(get_error_values(1,0,file,line,data,flags)); }
|
sl@0
|
879 |
|
sl@0
|
880 |
|
sl@0
|
881 |
EXPORT_C unsigned long ERR_peek_error(void)
|
sl@0
|
882 |
{ return(get_error_values(0,0,NULL,NULL,NULL,NULL)); }
|
sl@0
|
883 |
|
sl@0
|
884 |
EXPORT_C unsigned long ERR_peek_error_line(const char **file, int *line)
|
sl@0
|
885 |
{ return(get_error_values(0,0,file,line,NULL,NULL)); }
|
sl@0
|
886 |
|
sl@0
|
887 |
EXPORT_C unsigned long ERR_peek_error_line_data(const char **file, int *line,
|
sl@0
|
888 |
const char **data, int *flags)
|
sl@0
|
889 |
{ return(get_error_values(0,0,file,line,data,flags)); }
|
sl@0
|
890 |
|
sl@0
|
891 |
|
sl@0
|
892 |
EXPORT_C unsigned long ERR_peek_last_error(void)
|
sl@0
|
893 |
{ return(get_error_values(0,1,NULL,NULL,NULL,NULL)); }
|
sl@0
|
894 |
|
sl@0
|
895 |
EXPORT_C unsigned long ERR_peek_last_error_line(const char **file, int *line)
|
sl@0
|
896 |
{ return(get_error_values(0,1,file,line,NULL,NULL)); }
|
sl@0
|
897 |
|
sl@0
|
898 |
EXPORT_C unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
|
sl@0
|
899 |
const char **data, int *flags)
|
sl@0
|
900 |
{ return(get_error_values(0,1,file,line,data,flags)); }
|
sl@0
|
901 |
|
sl@0
|
902 |
|
sl@0
|
903 |
static unsigned long get_error_values(int inc, int top, const char **file, int *line,
|
sl@0
|
904 |
const char **data, int *flags)
|
sl@0
|
905 |
{
|
sl@0
|
906 |
int i=0;
|
sl@0
|
907 |
ERR_STATE *es;
|
sl@0
|
908 |
unsigned long ret;
|
sl@0
|
909 |
|
sl@0
|
910 |
es=ERR_get_state();
|
sl@0
|
911 |
|
sl@0
|
912 |
if (inc && top)
|
sl@0
|
913 |
{
|
sl@0
|
914 |
if (file) *file = "";
|
sl@0
|
915 |
if (line) *line = 0;
|
sl@0
|
916 |
if (data) *data = "";
|
sl@0
|
917 |
if (flags) *flags = 0;
|
sl@0
|
918 |
|
sl@0
|
919 |
return ERR_R_INTERNAL_ERROR;
|
sl@0
|
920 |
}
|
sl@0
|
921 |
|
sl@0
|
922 |
if (es->bottom == es->top) return 0;
|
sl@0
|
923 |
if (top)
|
sl@0
|
924 |
i=es->top; /* last error */
|
sl@0
|
925 |
else
|
sl@0
|
926 |
i=(es->bottom+1)%ERR_NUM_ERRORS; /* first error */
|
sl@0
|
927 |
|
sl@0
|
928 |
ret=es->err_buffer[i];
|
sl@0
|
929 |
if (inc)
|
sl@0
|
930 |
{
|
sl@0
|
931 |
es->bottom=i;
|
sl@0
|
932 |
es->err_buffer[i]=0;
|
sl@0
|
933 |
}
|
sl@0
|
934 |
|
sl@0
|
935 |
if ((file != NULL) && (line != NULL))
|
sl@0
|
936 |
{
|
sl@0
|
937 |
if (es->err_file[i] == NULL)
|
sl@0
|
938 |
{
|
sl@0
|
939 |
*file="NA";
|
sl@0
|
940 |
if (line != NULL) *line=0;
|
sl@0
|
941 |
}
|
sl@0
|
942 |
else
|
sl@0
|
943 |
{
|
sl@0
|
944 |
*file=es->err_file[i];
|
sl@0
|
945 |
if (line != NULL) *line=es->err_line[i];
|
sl@0
|
946 |
}
|
sl@0
|
947 |
}
|
sl@0
|
948 |
|
sl@0
|
949 |
if (data == NULL)
|
sl@0
|
950 |
{
|
sl@0
|
951 |
if (inc)
|
sl@0
|
952 |
{
|
sl@0
|
953 |
err_clear_data(es, i);
|
sl@0
|
954 |
}
|
sl@0
|
955 |
}
|
sl@0
|
956 |
else
|
sl@0
|
957 |
{
|
sl@0
|
958 |
if (es->err_data[i] == NULL)
|
sl@0
|
959 |
{
|
sl@0
|
960 |
*data="";
|
sl@0
|
961 |
if (flags != NULL) *flags=0;
|
sl@0
|
962 |
}
|
sl@0
|
963 |
else
|
sl@0
|
964 |
{
|
sl@0
|
965 |
*data=es->err_data[i];
|
sl@0
|
966 |
if (flags != NULL) *flags=es->err_data_flags[i];
|
sl@0
|
967 |
}
|
sl@0
|
968 |
}
|
sl@0
|
969 |
return ret;
|
sl@0
|
970 |
}
|
sl@0
|
971 |
|
sl@0
|
972 |
EXPORT_C void ERR_error_string_n(unsigned long e, char *buf, size_t len)
|
sl@0
|
973 |
{
|
sl@0
|
974 |
char lsbuf[64], fsbuf[64], rsbuf[64];
|
sl@0
|
975 |
const char *ls,*fs,*rs;
|
sl@0
|
976 |
unsigned long l,f,r;
|
sl@0
|
977 |
|
sl@0
|
978 |
l=ERR_GET_LIB(e);
|
sl@0
|
979 |
f=ERR_GET_FUNC(e);
|
sl@0
|
980 |
r=ERR_GET_REASON(e);
|
sl@0
|
981 |
|
sl@0
|
982 |
ls=ERR_lib_error_string(e);
|
sl@0
|
983 |
fs=ERR_func_error_string(e);
|
sl@0
|
984 |
rs=ERR_reason_error_string(e);
|
sl@0
|
985 |
|
sl@0
|
986 |
if (ls == NULL)
|
sl@0
|
987 |
BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l);
|
sl@0
|
988 |
if (fs == NULL)
|
sl@0
|
989 |
BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f);
|
sl@0
|
990 |
if (rs == NULL)
|
sl@0
|
991 |
BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
|
sl@0
|
992 |
|
sl@0
|
993 |
BIO_snprintf(buf, len,"error:%08lX:%s:%s:%s", e, ls?ls:lsbuf,
|
sl@0
|
994 |
fs?fs:fsbuf, rs?rs:rsbuf);
|
sl@0
|
995 |
if (strlen(buf) == len-1)
|
sl@0
|
996 |
{
|
sl@0
|
997 |
/* output may be truncated; make sure we always have 5
|
sl@0
|
998 |
* colon-separated fields, i.e. 4 colons ... */
|
sl@0
|
999 |
#define NUM_COLONS 4
|
sl@0
|
1000 |
if (len > NUM_COLONS) /* ... if possible */
|
sl@0
|
1001 |
{
|
sl@0
|
1002 |
int i;
|
sl@0
|
1003 |
char *s = buf;
|
sl@0
|
1004 |
|
sl@0
|
1005 |
for (i = 0; i < NUM_COLONS; i++)
|
sl@0
|
1006 |
{
|
sl@0
|
1007 |
char *colon = strchr(s, ':');
|
sl@0
|
1008 |
if (colon == NULL || colon > &buf[len-1] - NUM_COLONS + i)
|
sl@0
|
1009 |
{
|
sl@0
|
1010 |
/* set colon no. i at last possible position
|
sl@0
|
1011 |
* (buf[len-1] is the terminating 0)*/
|
sl@0
|
1012 |
colon = &buf[len-1] - NUM_COLONS + i;
|
sl@0
|
1013 |
*colon = ':';
|
sl@0
|
1014 |
}
|
sl@0
|
1015 |
s = colon + 1;
|
sl@0
|
1016 |
}
|
sl@0
|
1017 |
}
|
sl@0
|
1018 |
}
|
sl@0
|
1019 |
}
|
sl@0
|
1020 |
|
sl@0
|
1021 |
#ifdef EMULATOR
|
sl@0
|
1022 |
GET_STATIC_ARRAY_FROM_TLS(buf,err,char)
|
sl@0
|
1023 |
#define buf (GET_WSD_VAR_NAME(buf,err, s)())
|
sl@0
|
1024 |
#endif
|
sl@0
|
1025 |
|
sl@0
|
1026 |
/* BAD for multi-threading: uses a local buffer if ret == NULL */
|
sl@0
|
1027 |
/* ERR_error_string_n should be used instead for ret != NULL
|
sl@0
|
1028 |
* as ERR_error_string cannot know how large the buffer is */
|
sl@0
|
1029 |
EXPORT_C char *ERR_error_string(unsigned long e, char *ret)
|
sl@0
|
1030 |
{
|
sl@0
|
1031 |
#ifndef EMULATOR
|
sl@0
|
1032 |
static char buf[256];
|
sl@0
|
1033 |
#endif
|
sl@0
|
1034 |
|
sl@0
|
1035 |
if (ret == NULL) ret=buf;
|
sl@0
|
1036 |
ERR_error_string_n(e, ret, 256);
|
sl@0
|
1037 |
|
sl@0
|
1038 |
return ret;
|
sl@0
|
1039 |
}
|
sl@0
|
1040 |
|
sl@0
|
1041 |
EXPORT_C LHASH *ERR_get_string_table(void)
|
sl@0
|
1042 |
{
|
sl@0
|
1043 |
err_fns_check();
|
sl@0
|
1044 |
return ERRFN(err_get)(0);
|
sl@0
|
1045 |
}
|
sl@0
|
1046 |
|
sl@0
|
1047 |
EXPORT_C LHASH *ERR_get_err_state_table(void)
|
sl@0
|
1048 |
{
|
sl@0
|
1049 |
err_fns_check();
|
sl@0
|
1050 |
return ERRFN(thread_get)(0);
|
sl@0
|
1051 |
}
|
sl@0
|
1052 |
|
sl@0
|
1053 |
EXPORT_C void ERR_release_err_state_table(LHASH **hash)
|
sl@0
|
1054 |
{
|
sl@0
|
1055 |
err_fns_check();
|
sl@0
|
1056 |
ERRFN(thread_release)(hash);
|
sl@0
|
1057 |
}
|
sl@0
|
1058 |
|
sl@0
|
1059 |
EXPORT_C const char *ERR_lib_error_string(unsigned long e)
|
sl@0
|
1060 |
{
|
sl@0
|
1061 |
ERR_STRING_DATA d,*p;
|
sl@0
|
1062 |
unsigned long l;
|
sl@0
|
1063 |
|
sl@0
|
1064 |
err_fns_check();
|
sl@0
|
1065 |
l=ERR_GET_LIB(e);
|
sl@0
|
1066 |
d.error=ERR_PACK(l,0,0);
|
sl@0
|
1067 |
p=ERRFN(err_get_item)(&d);
|
sl@0
|
1068 |
return((p == NULL)?NULL:p->string);
|
sl@0
|
1069 |
}
|
sl@0
|
1070 |
|
sl@0
|
1071 |
EXPORT_C const char *ERR_func_error_string(unsigned long e)
|
sl@0
|
1072 |
{
|
sl@0
|
1073 |
ERR_STRING_DATA d,*p;
|
sl@0
|
1074 |
unsigned long l,f;
|
sl@0
|
1075 |
|
sl@0
|
1076 |
err_fns_check();
|
sl@0
|
1077 |
l=ERR_GET_LIB(e);
|
sl@0
|
1078 |
f=ERR_GET_FUNC(e);
|
sl@0
|
1079 |
d.error=ERR_PACK(l,f,0);
|
sl@0
|
1080 |
p=ERRFN(err_get_item)(&d);
|
sl@0
|
1081 |
return((p == NULL)?NULL:p->string);
|
sl@0
|
1082 |
}
|
sl@0
|
1083 |
|
sl@0
|
1084 |
EXPORT_C const char *ERR_reason_error_string(unsigned long e)
|
sl@0
|
1085 |
{
|
sl@0
|
1086 |
ERR_STRING_DATA d,*p=NULL;
|
sl@0
|
1087 |
unsigned long l,r;
|
sl@0
|
1088 |
|
sl@0
|
1089 |
err_fns_check();
|
sl@0
|
1090 |
l=ERR_GET_LIB(e);
|
sl@0
|
1091 |
r=ERR_GET_REASON(e);
|
sl@0
|
1092 |
d.error=ERR_PACK(l,0,r);
|
sl@0
|
1093 |
p=ERRFN(err_get_item)(&d);
|
sl@0
|
1094 |
if (!p)
|
sl@0
|
1095 |
{
|
sl@0
|
1096 |
d.error=ERR_PACK(0,0,r);
|
sl@0
|
1097 |
p=ERRFN(err_get_item)(&d);
|
sl@0
|
1098 |
}
|
sl@0
|
1099 |
return((p == NULL)?NULL:p->string);
|
sl@0
|
1100 |
}
|
sl@0
|
1101 |
|
sl@0
|
1102 |
/* static unsigned long err_hash(ERR_STRING_DATA *a) */
|
sl@0
|
1103 |
static unsigned long err_hash(const void *a_void)
|
sl@0
|
1104 |
{
|
sl@0
|
1105 |
unsigned long ret,l;
|
sl@0
|
1106 |
|
sl@0
|
1107 |
l=((const ERR_STRING_DATA *)a_void)->error;
|
sl@0
|
1108 |
ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
|
sl@0
|
1109 |
return(ret^ret%19*13);
|
sl@0
|
1110 |
}
|
sl@0
|
1111 |
|
sl@0
|
1112 |
/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */
|
sl@0
|
1113 |
static int err_cmp(const void *a_void, const void *b_void)
|
sl@0
|
1114 |
{
|
sl@0
|
1115 |
return((int)(((const ERR_STRING_DATA *)a_void)->error -
|
sl@0
|
1116 |
((const ERR_STRING_DATA *)b_void)->error));
|
sl@0
|
1117 |
}
|
sl@0
|
1118 |
|
sl@0
|
1119 |
/* static unsigned long pid_hash(ERR_STATE *a) */
|
sl@0
|
1120 |
static unsigned long pid_hash(const void *a_void)
|
sl@0
|
1121 |
{
|
sl@0
|
1122 |
return(((const ERR_STATE *)a_void)->pid*13);
|
sl@0
|
1123 |
}
|
sl@0
|
1124 |
|
sl@0
|
1125 |
/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */
|
sl@0
|
1126 |
static int pid_cmp(const void *a_void, const void *b_void)
|
sl@0
|
1127 |
{
|
sl@0
|
1128 |
return((int)((long)((const ERR_STATE *)a_void)->pid -
|
sl@0
|
1129 |
(long)((const ERR_STATE *)b_void)->pid));
|
sl@0
|
1130 |
}
|
sl@0
|
1131 |
|
sl@0
|
1132 |
EXPORT_C void ERR_remove_state(unsigned long pid)
|
sl@0
|
1133 |
{
|
sl@0
|
1134 |
ERR_STATE tmp;
|
sl@0
|
1135 |
|
sl@0
|
1136 |
err_fns_check();
|
sl@0
|
1137 |
if (pid == 0)
|
sl@0
|
1138 |
pid=(unsigned long)CRYPTO_thread_id();
|
sl@0
|
1139 |
tmp.pid=pid;
|
sl@0
|
1140 |
/* thread_del_item automatically destroys the LHASH if the number of
|
sl@0
|
1141 |
* items reaches zero. */
|
sl@0
|
1142 |
ERRFN(thread_del_item)(&tmp);
|
sl@0
|
1143 |
}
|
sl@0
|
1144 |
#ifdef EMULATOR
|
sl@0
|
1145 |
GET_STATIC_VAR_FROM_TLS(fallback,err,ERR_STATE)
|
sl@0
|
1146 |
#define fallback (*GET_WSD_VAR_NAME(fallback,err, s)())
|
sl@0
|
1147 |
#endif
|
sl@0
|
1148 |
EXPORT_C ERR_STATE *ERR_get_state(void)
|
sl@0
|
1149 |
{
|
sl@0
|
1150 |
#ifndef EMULATOR
|
sl@0
|
1151 |
static ERR_STATE fallback;
|
sl@0
|
1152 |
#endif
|
sl@0
|
1153 |
ERR_STATE *ret,tmp,*tmpp=NULL;
|
sl@0
|
1154 |
int i;
|
sl@0
|
1155 |
unsigned long pid;
|
sl@0
|
1156 |
|
sl@0
|
1157 |
err_fns_check();
|
sl@0
|
1158 |
pid=(unsigned long)CRYPTO_thread_id();
|
sl@0
|
1159 |
tmp.pid=pid;
|
sl@0
|
1160 |
ret=ERRFN(thread_get_item)(&tmp);
|
sl@0
|
1161 |
|
sl@0
|
1162 |
/* ret == the error state, if NULL, make a new one */
|
sl@0
|
1163 |
if (ret == NULL)
|
sl@0
|
1164 |
{
|
sl@0
|
1165 |
ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE));
|
sl@0
|
1166 |
if (ret == NULL) return(&fallback);
|
sl@0
|
1167 |
ret->pid=pid;
|
sl@0
|
1168 |
ret->top=0;
|
sl@0
|
1169 |
ret->bottom=0;
|
sl@0
|
1170 |
for (i=0; i<ERR_NUM_ERRORS; i++)
|
sl@0
|
1171 |
{
|
sl@0
|
1172 |
ret->err_data[i]=NULL;
|
sl@0
|
1173 |
ret->err_data_flags[i]=0;
|
sl@0
|
1174 |
}
|
sl@0
|
1175 |
tmpp = ERRFN(thread_set_item)(ret);
|
sl@0
|
1176 |
/* To check if insertion failed, do a get. */
|
sl@0
|
1177 |
if (ERRFN(thread_get_item)(ret) != ret)
|
sl@0
|
1178 |
{
|
sl@0
|
1179 |
ERR_STATE_free(ret); /* could not insert it */
|
sl@0
|
1180 |
return(&fallback);
|
sl@0
|
1181 |
}
|
sl@0
|
1182 |
/* If a race occured in this function and we came second, tmpp
|
sl@0
|
1183 |
* is the first one that we just replaced. */
|
sl@0
|
1184 |
if (tmpp)
|
sl@0
|
1185 |
ERR_STATE_free(tmpp);
|
sl@0
|
1186 |
}
|
sl@0
|
1187 |
return ret;
|
sl@0
|
1188 |
}
|
sl@0
|
1189 |
|
sl@0
|
1190 |
EXPORT_C int ERR_get_next_error_library(void)
|
sl@0
|
1191 |
{
|
sl@0
|
1192 |
err_fns_check();
|
sl@0
|
1193 |
return ERRFN(get_next_lib)();
|
sl@0
|
1194 |
}
|
sl@0
|
1195 |
|
sl@0
|
1196 |
EXPORT_C void ERR_set_error_data(char *data, int flags)
|
sl@0
|
1197 |
{
|
sl@0
|
1198 |
ERR_STATE *es;
|
sl@0
|
1199 |
int i;
|
sl@0
|
1200 |
|
sl@0
|
1201 |
es=ERR_get_state();
|
sl@0
|
1202 |
|
sl@0
|
1203 |
i=es->top;
|
sl@0
|
1204 |
if (i == 0)
|
sl@0
|
1205 |
i=ERR_NUM_ERRORS-1;
|
sl@0
|
1206 |
|
sl@0
|
1207 |
err_clear_data(es,i);
|
sl@0
|
1208 |
es->err_data[i]=data;
|
sl@0
|
1209 |
es->err_data_flags[i]=flags;
|
sl@0
|
1210 |
}
|
sl@0
|
1211 |
|
sl@0
|
1212 |
EXPORT_C void ERR_add_error_data(int num, ...)
|
sl@0
|
1213 |
{
|
sl@0
|
1214 |
va_list args;
|
sl@0
|
1215 |
int i,n,s;
|
sl@0
|
1216 |
char *str,*p,*a;
|
sl@0
|
1217 |
|
sl@0
|
1218 |
s=80;
|
sl@0
|
1219 |
str=OPENSSL_malloc(s+1);
|
sl@0
|
1220 |
if (str == NULL) return;
|
sl@0
|
1221 |
str[0]='\0';
|
sl@0
|
1222 |
|
sl@0
|
1223 |
va_start(args, num);
|
sl@0
|
1224 |
n=0;
|
sl@0
|
1225 |
for (i=0; i<num; i++)
|
sl@0
|
1226 |
{
|
sl@0
|
1227 |
a=va_arg(args, char*);
|
sl@0
|
1228 |
/* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
|
sl@0
|
1229 |
if (a != NULL)
|
sl@0
|
1230 |
{
|
sl@0
|
1231 |
n+=strlen(a);
|
sl@0
|
1232 |
if (n > s)
|
sl@0
|
1233 |
{
|
sl@0
|
1234 |
s=n+20;
|
sl@0
|
1235 |
p=OPENSSL_realloc(str,s+1);
|
sl@0
|
1236 |
if (p == NULL)
|
sl@0
|
1237 |
{
|
sl@0
|
1238 |
OPENSSL_free(str);
|
sl@0
|
1239 |
goto err;
|
sl@0
|
1240 |
}
|
sl@0
|
1241 |
else
|
sl@0
|
1242 |
str=p;
|
sl@0
|
1243 |
}
|
sl@0
|
1244 |
BUF_strlcat(str,a,(size_t)s+1);
|
sl@0
|
1245 |
}
|
sl@0
|
1246 |
}
|
sl@0
|
1247 |
ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
|
sl@0
|
1248 |
|
sl@0
|
1249 |
err:
|
sl@0
|
1250 |
va_end(args);
|
sl@0
|
1251 |
}
|
sl@0
|
1252 |
|
sl@0
|
1253 |
EXPORT_C int ERR_set_mark(void)
|
sl@0
|
1254 |
{
|
sl@0
|
1255 |
ERR_STATE *es;
|
sl@0
|
1256 |
|
sl@0
|
1257 |
es=ERR_get_state();
|
sl@0
|
1258 |
|
sl@0
|
1259 |
if (es->bottom == es->top) return 0;
|
sl@0
|
1260 |
es->err_flags[es->top]|=ERR_FLAG_MARK;
|
sl@0
|
1261 |
return 1;
|
sl@0
|
1262 |
}
|
sl@0
|
1263 |
|
sl@0
|
1264 |
EXPORT_C int ERR_pop_to_mark(void)
|
sl@0
|
1265 |
{
|
sl@0
|
1266 |
ERR_STATE *es;
|
sl@0
|
1267 |
|
sl@0
|
1268 |
es=ERR_get_state();
|
sl@0
|
1269 |
|
sl@0
|
1270 |
while(es->bottom != es->top
|
sl@0
|
1271 |
&& (es->err_flags[es->top] & ERR_FLAG_MARK) == 0)
|
sl@0
|
1272 |
{
|
sl@0
|
1273 |
err_clear(es,es->top);
|
sl@0
|
1274 |
es->top-=1;
|
sl@0
|
1275 |
if (es->top == -1) es->top=ERR_NUM_ERRORS;
|
sl@0
|
1276 |
}
|
sl@0
|
1277 |
|
sl@0
|
1278 |
if (es->bottom == es->top) return 0;
|
sl@0
|
1279 |
es->err_flags[es->top]&=~ERR_FLAG_MARK;
|
sl@0
|
1280 |
return 1;
|
sl@0
|
1281 |
}
|