diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/dso/dso_lib.c | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/dso/dso_lib.c')
-rw-r--r-- | src/lib/libcrypto/dso/dso_lib.c | 179 |
1 files changed, 156 insertions, 23 deletions
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c index acd166697e..556069b9b8 100644 --- a/src/lib/libcrypto/dso/dso_lib.c +++ b/src/lib/libcrypto/dso/dso_lib.c | |||
@@ -108,7 +108,7 @@ DSO *DSO_new_method(DSO_METHOD *meth) | |||
108 | } | 108 | } |
109 | memset(ret, 0, sizeof(DSO)); | 109 | memset(ret, 0, sizeof(DSO)); |
110 | ret->meth_data = sk_new_null(); | 110 | ret->meth_data = sk_new_null(); |
111 | if((ret->meth_data = sk_new_null()) == NULL) | 111 | if(ret->meth_data == NULL) |
112 | { | 112 | { |
113 | /* sk_new doesn't generate any errors so we do */ | 113 | /* sk_new doesn't generate any errors so we do */ |
114 | DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); | 114 | DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); |
@@ -164,6 +164,10 @@ int DSO_free(DSO *dso) | |||
164 | } | 164 | } |
165 | 165 | ||
166 | sk_free(dso->meth_data); | 166 | sk_free(dso->meth_data); |
167 | if(dso->filename != NULL) | ||
168 | OPENSSL_free(dso->filename); | ||
169 | if(dso->loaded_filename != NULL) | ||
170 | OPENSSL_free(dso->loaded_filename); | ||
167 | 171 | ||
168 | OPENSSL_free(dso); | 172 | OPENSSL_free(dso); |
169 | return(1); | 173 | return(1); |
@@ -175,11 +179,11 @@ int DSO_flags(DSO *dso) | |||
175 | } | 179 | } |
176 | 180 | ||
177 | 181 | ||
178 | int DSO_up(DSO *dso) | 182 | int DSO_up_ref(DSO *dso) |
179 | { | 183 | { |
180 | if (dso == NULL) | 184 | if (dso == NULL) |
181 | { | 185 | { |
182 | DSOerr(DSO_F_DSO_UP,ERR_R_PASSED_NULL_PARAMETER); | 186 | DSOerr(DSO_F_DSO_UP_REF,ERR_R_PASSED_NULL_PARAMETER); |
183 | return(0); | 187 | return(0); |
184 | } | 188 | } |
185 | 189 | ||
@@ -192,48 +196,60 @@ DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags) | |||
192 | DSO *ret; | 196 | DSO *ret; |
193 | int allocated = 0; | 197 | int allocated = 0; |
194 | 198 | ||
195 | if(filename == NULL) | ||
196 | { | ||
197 | DSOerr(DSO_F_DSO_LOAD,ERR_R_PASSED_NULL_PARAMETER); | ||
198 | return(NULL); | ||
199 | } | ||
200 | if(dso == NULL) | 199 | if(dso == NULL) |
201 | { | 200 | { |
202 | ret = DSO_new_method(meth); | 201 | ret = DSO_new_method(meth); |
203 | if(ret == NULL) | 202 | if(ret == NULL) |
204 | { | 203 | { |
205 | DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE); | 204 | DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE); |
206 | return(NULL); | 205 | goto err; |
207 | } | 206 | } |
208 | allocated = 1; | 207 | allocated = 1; |
208 | /* Pass the provided flags to the new DSO object */ | ||
209 | if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) | ||
210 | { | ||
211 | DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED); | ||
212 | goto err; | ||
213 | } | ||
209 | } | 214 | } |
210 | else | 215 | else |
211 | ret = dso; | 216 | ret = dso; |
212 | /* Bleurgh ... have to check for negative return values for | 217 | /* Don't load if we're currently already loaded */ |
213 | * errors. <grimace> */ | 218 | if(ret->filename != NULL) |
214 | if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) | ||
215 | { | 219 | { |
216 | DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED); | 220 | DSOerr(DSO_F_DSO_LOAD,DSO_R_DSO_ALREADY_LOADED); |
217 | if(allocated) | 221 | goto err; |
218 | DSO_free(ret); | 222 | } |
219 | return(NULL); | 223 | /* filename can only be NULL if we were passed a dso that already has |
224 | * one set. */ | ||
225 | if(filename != NULL) | ||
226 | if(!DSO_set_filename(ret, filename)) | ||
227 | { | ||
228 | DSOerr(DSO_F_DSO_LOAD,DSO_R_SET_FILENAME_FAILED); | ||
229 | goto err; | ||
230 | } | ||
231 | filename = ret->filename; | ||
232 | if(filename == NULL) | ||
233 | { | ||
234 | DSOerr(DSO_F_DSO_LOAD,DSO_R_NO_FILENAME); | ||
235 | goto err; | ||
220 | } | 236 | } |
221 | if(ret->meth->dso_load == NULL) | 237 | if(ret->meth->dso_load == NULL) |
222 | { | 238 | { |
223 | DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED); | 239 | DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED); |
224 | if(allocated) | 240 | goto err; |
225 | DSO_free(ret); | ||
226 | return(NULL); | ||
227 | } | 241 | } |
228 | if(!ret->meth->dso_load(ret, filename)) | 242 | if(!ret->meth->dso_load(ret)) |
229 | { | 243 | { |
230 | DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED); | 244 | DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED); |
231 | if(allocated) | 245 | goto err; |
232 | DSO_free(ret); | ||
233 | return(NULL); | ||
234 | } | 246 | } |
235 | /* Load succeeded */ | 247 | /* Load succeeded */ |
236 | return(ret); | 248 | return(ret); |
249 | err: | ||
250 | if(allocated) | ||
251 | DSO_free(ret); | ||
252 | return(NULL); | ||
237 | } | 253 | } |
238 | 254 | ||
239 | void *DSO_bind_var(DSO *dso, const char *symname) | 255 | void *DSO_bind_var(DSO *dso, const char *symname) |
@@ -297,6 +313,22 @@ long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) | |||
297 | DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER); | 313 | DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER); |
298 | return(-1); | 314 | return(-1); |
299 | } | 315 | } |
316 | /* We should intercept certain generic commands and only pass control | ||
317 | * to the method-specific ctrl() function if it's something we don't | ||
318 | * handle. */ | ||
319 | switch(cmd) | ||
320 | { | ||
321 | case DSO_CTRL_GET_FLAGS: | ||
322 | return dso->flags; | ||
323 | case DSO_CTRL_SET_FLAGS: | ||
324 | dso->flags = (int)larg; | ||
325 | return(0); | ||
326 | case DSO_CTRL_OR_FLAGS: | ||
327 | dso->flags |= (int)larg; | ||
328 | return(0); | ||
329 | default: | ||
330 | break; | ||
331 | } | ||
300 | if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) | 332 | if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) |
301 | { | 333 | { |
302 | DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED); | 334 | DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED); |
@@ -304,3 +336,104 @@ long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) | |||
304 | } | 336 | } |
305 | return(dso->meth->dso_ctrl(dso,cmd,larg,parg)); | 337 | return(dso->meth->dso_ctrl(dso,cmd,larg,parg)); |
306 | } | 338 | } |
339 | |||
340 | int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb, | ||
341 | DSO_NAME_CONVERTER_FUNC *oldcb) | ||
342 | { | ||
343 | if(dso == NULL) | ||
344 | { | ||
345 | DSOerr(DSO_F_DSO_SET_NAME_CONVERTER, | ||
346 | ERR_R_PASSED_NULL_PARAMETER); | ||
347 | return(0); | ||
348 | } | ||
349 | if(oldcb) | ||
350 | *oldcb = dso->name_converter; | ||
351 | dso->name_converter = cb; | ||
352 | return(1); | ||
353 | } | ||
354 | |||
355 | const char *DSO_get_filename(DSO *dso) | ||
356 | { | ||
357 | if(dso == NULL) | ||
358 | { | ||
359 | DSOerr(DSO_F_DSO_GET_FILENAME,ERR_R_PASSED_NULL_PARAMETER); | ||
360 | return(NULL); | ||
361 | } | ||
362 | return(dso->filename); | ||
363 | } | ||
364 | |||
365 | int DSO_set_filename(DSO *dso, const char *filename) | ||
366 | { | ||
367 | char *copied; | ||
368 | |||
369 | if((dso == NULL) || (filename == NULL)) | ||
370 | { | ||
371 | DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_PASSED_NULL_PARAMETER); | ||
372 | return(0); | ||
373 | } | ||
374 | if(dso->loaded_filename) | ||
375 | { | ||
376 | DSOerr(DSO_F_DSO_SET_FILENAME,DSO_R_DSO_ALREADY_LOADED); | ||
377 | return(0); | ||
378 | } | ||
379 | /* We'll duplicate filename */ | ||
380 | copied = OPENSSL_malloc(strlen(filename) + 1); | ||
381 | if(copied == NULL) | ||
382 | { | ||
383 | DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE); | ||
384 | return(0); | ||
385 | } | ||
386 | strcpy(copied, filename); | ||
387 | if(dso->filename) | ||
388 | OPENSSL_free(dso->filename); | ||
389 | dso->filename = copied; | ||
390 | return(1); | ||
391 | } | ||
392 | |||
393 | char *DSO_convert_filename(DSO *dso, const char *filename) | ||
394 | { | ||
395 | char *result = NULL; | ||
396 | |||
397 | if(dso == NULL) | ||
398 | { | ||
399 | DSOerr(DSO_F_DSO_CONVERT_FILENAME,ERR_R_PASSED_NULL_PARAMETER); | ||
400 | return(NULL); | ||
401 | } | ||
402 | if(filename == NULL) | ||
403 | filename = dso->filename; | ||
404 | if(filename == NULL) | ||
405 | { | ||
406 | DSOerr(DSO_F_DSO_CONVERT_FILENAME,DSO_R_NO_FILENAME); | ||
407 | return(NULL); | ||
408 | } | ||
409 | if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) | ||
410 | { | ||
411 | if(dso->name_converter != NULL) | ||
412 | result = dso->name_converter(dso, filename); | ||
413 | else if(dso->meth->dso_name_converter != NULL) | ||
414 | result = dso->meth->dso_name_converter(dso, filename); | ||
415 | } | ||
416 | if(result == NULL) | ||
417 | { | ||
418 | result = OPENSSL_malloc(strlen(filename) + 1); | ||
419 | if(result == NULL) | ||
420 | { | ||
421 | DSOerr(DSO_F_DSO_CONVERT_FILENAME, | ||
422 | ERR_R_MALLOC_FAILURE); | ||
423 | return(NULL); | ||
424 | } | ||
425 | strcpy(result, filename); | ||
426 | } | ||
427 | return(result); | ||
428 | } | ||
429 | |||
430 | const char *DSO_get_loaded_filename(DSO *dso) | ||
431 | { | ||
432 | if(dso == NULL) | ||
433 | { | ||
434 | DSOerr(DSO_F_DSO_GET_LOADED_FILENAME, | ||
435 | ERR_R_PASSED_NULL_PARAMETER); | ||
436 | return(NULL); | ||
437 | } | ||
438 | return(dso->loaded_filename); | ||
439 | } | ||