sl@0
|
1 |
/* dso_lib.c -*- mode:C; c-file-style: "eay" -*- */
|
sl@0
|
2 |
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
|
sl@0
|
3 |
* project 2000.
|
sl@0
|
4 |
*/
|
sl@0
|
5 |
/* ====================================================================
|
sl@0
|
6 |
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
9 |
* modification, are permitted provided that the following conditions
|
sl@0
|
10 |
* are met:
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
13 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
16 |
* notice, this list of conditions and the following disclaimer in
|
sl@0
|
17 |
* the documentation and/or other materials provided with the
|
sl@0
|
18 |
* distribution.
|
sl@0
|
19 |
*
|
sl@0
|
20 |
* 3. All advertising materials mentioning features or use of this
|
sl@0
|
21 |
* software must display the following acknowledgment:
|
sl@0
|
22 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
23 |
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
sl@0
|
24 |
*
|
sl@0
|
25 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
sl@0
|
26 |
* endorse or promote products derived from this software without
|
sl@0
|
27 |
* prior written permission. For written permission, please contact
|
sl@0
|
28 |
* licensing@OpenSSL.org.
|
sl@0
|
29 |
*
|
sl@0
|
30 |
* 5. Products derived from this software may not be called "OpenSSL"
|
sl@0
|
31 |
* nor may "OpenSSL" appear in their names without prior written
|
sl@0
|
32 |
* permission of the OpenSSL Project.
|
sl@0
|
33 |
*
|
sl@0
|
34 |
* 6. Redistributions of any form whatsoever must retain the following
|
sl@0
|
35 |
* acknowledgment:
|
sl@0
|
36 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
37 |
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
sl@0
|
38 |
*
|
sl@0
|
39 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
sl@0
|
40 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
41 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
sl@0
|
42 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
sl@0
|
43 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
44 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
sl@0
|
45 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
sl@0
|
46 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
47 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
48 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
sl@0
|
49 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
sl@0
|
50 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
51 |
* ====================================================================
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* This product includes cryptographic software written by Eric Young
|
sl@0
|
54 |
* (eay@cryptsoft.com). This product includes software written by Tim
|
sl@0
|
55 |
* Hudson (tjh@cryptsoft.com).
|
sl@0
|
56 |
*
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
/*
|
sl@0
|
59 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
|
sl@0
|
62 |
#include <stdio.h>
|
sl@0
|
63 |
#include <openssl/crypto.h>
|
sl@0
|
64 |
#include "cryptlib.h"
|
sl@0
|
65 |
#include <openssl/dso.h>
|
sl@0
|
66 |
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
|
sl@0
|
67 |
#include "libcrypto_wsd_macros.h"
|
sl@0
|
68 |
#include "libcrypto_wsd.h"
|
sl@0
|
69 |
#endif
|
sl@0
|
70 |
#ifndef EMULATOR
|
sl@0
|
71 |
static DSO_METHOD *default_DSO_meth = NULL;
|
sl@0
|
72 |
#else
|
sl@0
|
73 |
GET_STATIC_VAR_FROM_TLS(default_DSO_meth,dso_lib,DSO_METHOD *)
|
sl@0
|
74 |
#define default_DSO_meth (*GET_WSD_VAR_NAME(default_DSO_meth,dso_lib, s)())
|
sl@0
|
75 |
#endif
|
sl@0
|
76 |
|
sl@0
|
77 |
EXPORT_C DSO *DSO_new(void)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
return(DSO_new_method(NULL));
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
EXPORT_C void DSO_set_default_method(DSO_METHOD *meth)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
default_DSO_meth = meth;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
EXPORT_C DSO_METHOD *DSO_get_default_method(void)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
return(default_DSO_meth);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
EXPORT_C DSO_METHOD *DSO_get_method(DSO *dso)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
return(dso->meth);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
EXPORT_C DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
DSO_METHOD *mtmp;
|
sl@0
|
100 |
mtmp = dso->meth;
|
sl@0
|
101 |
dso->meth = meth;
|
sl@0
|
102 |
return(mtmp);
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
EXPORT_C DSO *DSO_new_method(DSO_METHOD *meth)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
DSO *ret;
|
sl@0
|
108 |
|
sl@0
|
109 |
if(default_DSO_meth == NULL)
|
sl@0
|
110 |
/* We default to DSO_METH_openssl() which in turn defaults
|
sl@0
|
111 |
* to stealing the "best available" method. Will fallback
|
sl@0
|
112 |
* to DSO_METH_null() in the worst case. */
|
sl@0
|
113 |
default_DSO_meth = DSO_METHOD_openssl();
|
sl@0
|
114 |
ret = (DSO *)OPENSSL_malloc(sizeof(DSO));
|
sl@0
|
115 |
if(ret == NULL)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
|
sl@0
|
118 |
return(NULL);
|
sl@0
|
119 |
}
|
sl@0
|
120 |
memset(ret, 0, sizeof(DSO));
|
sl@0
|
121 |
ret->meth_data = sk_new_null();
|
sl@0
|
122 |
if(ret->meth_data == NULL)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
/* sk_new doesn't generate any errors so we do */
|
sl@0
|
125 |
DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
|
sl@0
|
126 |
OPENSSL_free(ret);
|
sl@0
|
127 |
return(NULL);
|
sl@0
|
128 |
}
|
sl@0
|
129 |
if(meth == NULL)
|
sl@0
|
130 |
ret->meth = default_DSO_meth;
|
sl@0
|
131 |
else
|
sl@0
|
132 |
ret->meth = meth;
|
sl@0
|
133 |
ret->references = 1;
|
sl@0
|
134 |
if((ret->meth->init != NULL) && !ret->meth->init(ret))
|
sl@0
|
135 |
{
|
sl@0
|
136 |
OPENSSL_free(ret);
|
sl@0
|
137 |
ret=NULL;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
return(ret);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
EXPORT_C int DSO_free(DSO *dso)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
int i;
|
sl@0
|
145 |
|
sl@0
|
146 |
if(dso == NULL)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
DSOerr(DSO_F_DSO_FREE,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
149 |
return(0);
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
i=CRYPTO_add(&dso->references,-1,CRYPTO_LOCK_DSO);
|
sl@0
|
153 |
#ifdef REF_PRINT
|
sl@0
|
154 |
REF_PRINT("DSO",dso);
|
sl@0
|
155 |
#endif
|
sl@0
|
156 |
if(i > 0) return(1);
|
sl@0
|
157 |
#ifdef REF_CHECK
|
sl@0
|
158 |
if(i < 0)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
fprintf(stderr,"DSO_free, bad reference count\n");
|
sl@0
|
161 |
abort();
|
sl@0
|
162 |
}
|
sl@0
|
163 |
#endif
|
sl@0
|
164 |
|
sl@0
|
165 |
if((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso))
|
sl@0
|
166 |
{
|
sl@0
|
167 |
DSOerr(DSO_F_DSO_FREE,DSO_R_UNLOAD_FAILED);
|
sl@0
|
168 |
return(0);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
if((dso->meth->finish != NULL) && !dso->meth->finish(dso))
|
sl@0
|
172 |
{
|
sl@0
|
173 |
DSOerr(DSO_F_DSO_FREE,DSO_R_FINISH_FAILED);
|
sl@0
|
174 |
return(0);
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
sk_free(dso->meth_data);
|
sl@0
|
178 |
if(dso->filename != NULL)
|
sl@0
|
179 |
OPENSSL_free(dso->filename);
|
sl@0
|
180 |
if(dso->loaded_filename != NULL)
|
sl@0
|
181 |
OPENSSL_free(dso->loaded_filename);
|
sl@0
|
182 |
|
sl@0
|
183 |
OPENSSL_free(dso);
|
sl@0
|
184 |
return(1);
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
EXPORT_C int DSO_flags(DSO *dso)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
return((dso == NULL) ? 0 : dso->flags);
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
|
sl@0
|
193 |
EXPORT_C int DSO_up_ref(DSO *dso)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
if (dso == NULL)
|
sl@0
|
196 |
{
|
sl@0
|
197 |
DSOerr(DSO_F_DSO_UP_REF,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
198 |
return(0);
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
CRYPTO_add(&dso->references,1,CRYPTO_LOCK_DSO);
|
sl@0
|
202 |
return(1);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
EXPORT_C DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
DSO *ret;
|
sl@0
|
208 |
int allocated = 0;
|
sl@0
|
209 |
|
sl@0
|
210 |
if(dso == NULL)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
ret = DSO_new_method(meth);
|
sl@0
|
213 |
if(ret == NULL)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE);
|
sl@0
|
216 |
goto err;
|
sl@0
|
217 |
}
|
sl@0
|
218 |
allocated = 1;
|
sl@0
|
219 |
/* Pass the provided flags to the new DSO object */
|
sl@0
|
220 |
if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED);
|
sl@0
|
223 |
goto err;
|
sl@0
|
224 |
}
|
sl@0
|
225 |
}
|
sl@0
|
226 |
else
|
sl@0
|
227 |
ret = dso;
|
sl@0
|
228 |
/* Don't load if we're currently already loaded */
|
sl@0
|
229 |
if(ret->filename != NULL)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
DSOerr(DSO_F_DSO_LOAD,DSO_R_DSO_ALREADY_LOADED);
|
sl@0
|
232 |
goto err;
|
sl@0
|
233 |
}
|
sl@0
|
234 |
/* filename can only be NULL if we were passed a dso that already has
|
sl@0
|
235 |
* one set. */
|
sl@0
|
236 |
if(filename != NULL)
|
sl@0
|
237 |
if(!DSO_set_filename(ret, filename))
|
sl@0
|
238 |
{
|
sl@0
|
239 |
DSOerr(DSO_F_DSO_LOAD,DSO_R_SET_FILENAME_FAILED);
|
sl@0
|
240 |
goto err;
|
sl@0
|
241 |
}
|
sl@0
|
242 |
filename = ret->filename;
|
sl@0
|
243 |
if(filename == NULL)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
DSOerr(DSO_F_DSO_LOAD,DSO_R_NO_FILENAME);
|
sl@0
|
246 |
goto err;
|
sl@0
|
247 |
}
|
sl@0
|
248 |
if(ret->meth->dso_load == NULL)
|
sl@0
|
249 |
{
|
sl@0
|
250 |
DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED);
|
sl@0
|
251 |
goto err;
|
sl@0
|
252 |
}
|
sl@0
|
253 |
if(!ret->meth->dso_load(ret))
|
sl@0
|
254 |
{
|
sl@0
|
255 |
DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED);
|
sl@0
|
256 |
goto err;
|
sl@0
|
257 |
}
|
sl@0
|
258 |
/* Load succeeded */
|
sl@0
|
259 |
return(ret);
|
sl@0
|
260 |
err:
|
sl@0
|
261 |
if(allocated)
|
sl@0
|
262 |
DSO_free(ret);
|
sl@0
|
263 |
return(NULL);
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
EXPORT_C void *DSO_bind_var(DSO *dso, const char *symname)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
void *ret = NULL;
|
sl@0
|
269 |
|
sl@0
|
270 |
if((dso == NULL) || (symname == NULL))
|
sl@0
|
271 |
{
|
sl@0
|
272 |
DSOerr(DSO_F_DSO_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
273 |
return(NULL);
|
sl@0
|
274 |
}
|
sl@0
|
275 |
if(dso->meth->dso_bind_var == NULL)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_UNSUPPORTED);
|
sl@0
|
278 |
return(NULL);
|
sl@0
|
279 |
}
|
sl@0
|
280 |
if((ret = dso->meth->dso_bind_var(dso, symname)) == NULL)
|
sl@0
|
281 |
{
|
sl@0
|
282 |
DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_SYM_FAILURE);
|
sl@0
|
283 |
return(NULL);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
/* Success */
|
sl@0
|
286 |
return(ret);
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
EXPORT_C DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname)
|
sl@0
|
290 |
{
|
sl@0
|
291 |
DSO_FUNC_TYPE ret = NULL;
|
sl@0
|
292 |
|
sl@0
|
293 |
if((dso == NULL) || (symname == NULL))
|
sl@0
|
294 |
{
|
sl@0
|
295 |
DSOerr(DSO_F_DSO_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
296 |
return(NULL);
|
sl@0
|
297 |
}
|
sl@0
|
298 |
if(dso->meth->dso_bind_func == NULL)
|
sl@0
|
299 |
{
|
sl@0
|
300 |
DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_UNSUPPORTED);
|
sl@0
|
301 |
return(NULL);
|
sl@0
|
302 |
}
|
sl@0
|
303 |
if((ret = dso->meth->dso_bind_func(dso, symname)) == NULL)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_SYM_FAILURE);
|
sl@0
|
306 |
return(NULL);
|
sl@0
|
307 |
}
|
sl@0
|
308 |
/* Success */
|
sl@0
|
309 |
return(ret);
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
/* I don't really like these *_ctrl functions very much to be perfectly
|
sl@0
|
313 |
* honest. For one thing, I think I have to return a negative value for
|
sl@0
|
314 |
* any error because possible DSO_ctrl() commands may return values
|
sl@0
|
315 |
* such as "size"s that can legitimately be zero (making the standard
|
sl@0
|
316 |
* "if(DSO_cmd(...))" form that works almost everywhere else fail at
|
sl@0
|
317 |
* odd times. I'd prefer "output" values to be passed by reference and
|
sl@0
|
318 |
* the return value as success/failure like usual ... but we conform
|
sl@0
|
319 |
* when we must... :-) */
|
sl@0
|
320 |
EXPORT_C long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
|
sl@0
|
321 |
{
|
sl@0
|
322 |
if(dso == NULL)
|
sl@0
|
323 |
{
|
sl@0
|
324 |
DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
325 |
return(-1);
|
sl@0
|
326 |
}
|
sl@0
|
327 |
/* We should intercept certain generic commands and only pass control
|
sl@0
|
328 |
* to the method-specific ctrl() function if it's something we don't
|
sl@0
|
329 |
* handle. */
|
sl@0
|
330 |
switch(cmd)
|
sl@0
|
331 |
{
|
sl@0
|
332 |
case DSO_CTRL_GET_FLAGS:
|
sl@0
|
333 |
return dso->flags;
|
sl@0
|
334 |
case DSO_CTRL_SET_FLAGS:
|
sl@0
|
335 |
dso->flags = (int)larg;
|
sl@0
|
336 |
return(0);
|
sl@0
|
337 |
case DSO_CTRL_OR_FLAGS:
|
sl@0
|
338 |
dso->flags |= (int)larg;
|
sl@0
|
339 |
return(0);
|
sl@0
|
340 |
default:
|
sl@0
|
341 |
break;
|
sl@0
|
342 |
}
|
sl@0
|
343 |
if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL))
|
sl@0
|
344 |
{
|
sl@0
|
345 |
DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED);
|
sl@0
|
346 |
return(-1);
|
sl@0
|
347 |
}
|
sl@0
|
348 |
return(dso->meth->dso_ctrl(dso,cmd,larg,parg));
|
sl@0
|
349 |
}
|
sl@0
|
350 |
|
sl@0
|
351 |
EXPORT_C int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
|
sl@0
|
352 |
DSO_NAME_CONVERTER_FUNC *oldcb)
|
sl@0
|
353 |
{
|
sl@0
|
354 |
if(dso == NULL)
|
sl@0
|
355 |
{
|
sl@0
|
356 |
DSOerr(DSO_F_DSO_SET_NAME_CONVERTER,
|
sl@0
|
357 |
ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
358 |
return(0);
|
sl@0
|
359 |
}
|
sl@0
|
360 |
if(oldcb)
|
sl@0
|
361 |
*oldcb = dso->name_converter;
|
sl@0
|
362 |
dso->name_converter = cb;
|
sl@0
|
363 |
return(1);
|
sl@0
|
364 |
}
|
sl@0
|
365 |
|
sl@0
|
366 |
EXPORT_C const char *DSO_get_filename(DSO *dso)
|
sl@0
|
367 |
{
|
sl@0
|
368 |
if(dso == NULL)
|
sl@0
|
369 |
{
|
sl@0
|
370 |
DSOerr(DSO_F_DSO_GET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
371 |
return(NULL);
|
sl@0
|
372 |
}
|
sl@0
|
373 |
return(dso->filename);
|
sl@0
|
374 |
}
|
sl@0
|
375 |
|
sl@0
|
376 |
EXPORT_C int DSO_set_filename(DSO *dso, const char *filename)
|
sl@0
|
377 |
{
|
sl@0
|
378 |
char *copied;
|
sl@0
|
379 |
|
sl@0
|
380 |
if((dso == NULL) || (filename == NULL))
|
sl@0
|
381 |
{
|
sl@0
|
382 |
DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
383 |
return(0);
|
sl@0
|
384 |
}
|
sl@0
|
385 |
if(dso->loaded_filename)
|
sl@0
|
386 |
{
|
sl@0
|
387 |
DSOerr(DSO_F_DSO_SET_FILENAME,DSO_R_DSO_ALREADY_LOADED);
|
sl@0
|
388 |
return(0);
|
sl@0
|
389 |
}
|
sl@0
|
390 |
/* We'll duplicate filename */
|
sl@0
|
391 |
copied = OPENSSL_malloc(strlen(filename) + 1);
|
sl@0
|
392 |
if(copied == NULL)
|
sl@0
|
393 |
{
|
sl@0
|
394 |
DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE);
|
sl@0
|
395 |
return(0);
|
sl@0
|
396 |
}
|
sl@0
|
397 |
BUF_strlcpy(copied, filename, strlen(filename) + 1);
|
sl@0
|
398 |
if(dso->filename)
|
sl@0
|
399 |
OPENSSL_free(dso->filename);
|
sl@0
|
400 |
dso->filename = copied;
|
sl@0
|
401 |
return(1);
|
sl@0
|
402 |
}
|
sl@0
|
403 |
|
sl@0
|
404 |
EXPORT_C char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
|
sl@0
|
405 |
{
|
sl@0
|
406 |
char *result = NULL;
|
sl@0
|
407 |
|
sl@0
|
408 |
if(dso == NULL || filespec1 == NULL)
|
sl@0
|
409 |
{
|
sl@0
|
410 |
DSOerr(DSO_F_DSO_MERGE,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
411 |
return(NULL);
|
sl@0
|
412 |
}
|
sl@0
|
413 |
if(filespec1 == NULL)
|
sl@0
|
414 |
filespec1 = dso->filename;
|
sl@0
|
415 |
if(filespec1 == NULL)
|
sl@0
|
416 |
{
|
sl@0
|
417 |
DSOerr(DSO_F_DSO_MERGE,DSO_R_NO_FILE_SPECIFICATION);
|
sl@0
|
418 |
return(NULL);
|
sl@0
|
419 |
}
|
sl@0
|
420 |
if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
if(dso->merger != NULL)
|
sl@0
|
423 |
result = dso->merger(dso, filespec1, filespec2);
|
sl@0
|
424 |
else if(dso->meth->dso_merger != NULL)
|
sl@0
|
425 |
result = dso->meth->dso_merger(dso,
|
sl@0
|
426 |
filespec1, filespec2);
|
sl@0
|
427 |
}
|
sl@0
|
428 |
return(result);
|
sl@0
|
429 |
}
|
sl@0
|
430 |
|
sl@0
|
431 |
EXPORT_C char *DSO_convert_filename(DSO *dso, const char *filename)
|
sl@0
|
432 |
{
|
sl@0
|
433 |
char *result = NULL;
|
sl@0
|
434 |
|
sl@0
|
435 |
if(dso == NULL)
|
sl@0
|
436 |
{
|
sl@0
|
437 |
DSOerr(DSO_F_DSO_CONVERT_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
438 |
return(NULL);
|
sl@0
|
439 |
}
|
sl@0
|
440 |
if(filename == NULL)
|
sl@0
|
441 |
filename = dso->filename;
|
sl@0
|
442 |
if(filename == NULL)
|
sl@0
|
443 |
{
|
sl@0
|
444 |
DSOerr(DSO_F_DSO_CONVERT_FILENAME,DSO_R_NO_FILENAME);
|
sl@0
|
445 |
return(NULL);
|
sl@0
|
446 |
}
|
sl@0
|
447 |
if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
|
sl@0
|
448 |
{
|
sl@0
|
449 |
if(dso->name_converter != NULL)
|
sl@0
|
450 |
result = dso->name_converter(dso, filename);
|
sl@0
|
451 |
else if(dso->meth->dso_name_converter != NULL)
|
sl@0
|
452 |
result = dso->meth->dso_name_converter(dso, filename);
|
sl@0
|
453 |
}
|
sl@0
|
454 |
if(result == NULL)
|
sl@0
|
455 |
{
|
sl@0
|
456 |
result = OPENSSL_malloc(strlen(filename) + 1);
|
sl@0
|
457 |
if(result == NULL)
|
sl@0
|
458 |
{
|
sl@0
|
459 |
DSOerr(DSO_F_DSO_CONVERT_FILENAME,
|
sl@0
|
460 |
ERR_R_MALLOC_FAILURE);
|
sl@0
|
461 |
return(NULL);
|
sl@0
|
462 |
}
|
sl@0
|
463 |
BUF_strlcpy(result, filename, strlen(filename) + 1);
|
sl@0
|
464 |
}
|
sl@0
|
465 |
return(result);
|
sl@0
|
466 |
}
|
sl@0
|
467 |
|
sl@0
|
468 |
EXPORT_C const char *DSO_get_loaded_filename(DSO *dso)
|
sl@0
|
469 |
{
|
sl@0
|
470 |
if(dso == NULL)
|
sl@0
|
471 |
{
|
sl@0
|
472 |
DSOerr(DSO_F_DSO_GET_LOADED_FILENAME,
|
sl@0
|
473 |
ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
474 |
return(NULL);
|
sl@0
|
475 |
}
|
sl@0
|
476 |
return(dso->loaded_filename);
|
sl@0
|
477 |
}
|