diff options
| author | djm <> | 2010-10-01 22:54:21 +0000 |
|---|---|---|
| committer | djm <> | 2010-10-01 22:54:21 +0000 |
| commit | 829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2 (patch) | |
| tree | e03b9f1bd051e844b971936729e9df549a209130 /src/lib/libcrypto/dso | |
| parent | e6b755d2a53d3cac7a344dfdd6bf7c951cac754c (diff) | |
| download | openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.tar.gz openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.tar.bz2 openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.zip | |
import OpenSSL-1.0.0a
Diffstat (limited to 'src/lib/libcrypto/dso')
| -rw-r--r-- | src/lib/libcrypto/dso/dso.h | 43 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_dlfcn.c | 157 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_err.c | 14 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_lib.c | 35 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_null.c | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_openssl.c | 2 |
6 files changed, 221 insertions, 34 deletions
diff --git a/src/lib/libcrypto/dso/dso.h b/src/lib/libcrypto/dso/dso.h index 3e51913a72..839f2e0617 100644 --- a/src/lib/libcrypto/dso/dso.h +++ b/src/lib/libcrypto/dso/dso.h | |||
| @@ -170,6 +170,11 @@ typedef struct dso_meth_st | |||
| 170 | /* [De]Initialisation handlers. */ | 170 | /* [De]Initialisation handlers. */ |
| 171 | int (*init)(DSO *dso); | 171 | int (*init)(DSO *dso); |
| 172 | int (*finish)(DSO *dso); | 172 | int (*finish)(DSO *dso); |
| 173 | |||
| 174 | /* Return pathname of the module containing location */ | ||
| 175 | int (*pathbyaddr)(void *addr,char *path,int sz); | ||
| 176 | /* Perform global symbol lookup, i.e. among *all* modules */ | ||
| 177 | void *(*globallookup)(const char *symname); | ||
| 173 | } DSO_METHOD; | 178 | } DSO_METHOD; |
| 174 | 179 | ||
| 175 | /**********************************************************************/ | 180 | /**********************************************************************/ |
| @@ -183,7 +188,7 @@ struct dso_st | |||
| 183 | * for use in the dso_bind handler. All in all, let each | 188 | * for use in the dso_bind handler. All in all, let each |
| 184 | * method control its own destiny. "Handles" and such go in | 189 | * method control its own destiny. "Handles" and such go in |
| 185 | * a STACK. */ | 190 | * a STACK. */ |
| 186 | STACK *meth_data; | 191 | STACK_OF(void) *meth_data; |
| 187 | int references; | 192 | int references; |
| 188 | int flags; | 193 | int flags; |
| 189 | /* For use by applications etc ... use this for your bits'n'pieces, | 194 | /* For use by applications etc ... use this for your bits'n'pieces, |
| @@ -296,6 +301,30 @@ DSO_METHOD *DSO_METHOD_win32(void); | |||
| 296 | /* If VMS is defined, use shared images. If not, return NULL. */ | 301 | /* If VMS is defined, use shared images. If not, return NULL. */ |
| 297 | DSO_METHOD *DSO_METHOD_vms(void); | 302 | DSO_METHOD *DSO_METHOD_vms(void); |
| 298 | 303 | ||
| 304 | /* This function writes null-terminated pathname of DSO module | ||
| 305 | * containing 'addr' into 'sz' large caller-provided 'path' and | ||
| 306 | * returns the number of characters [including trailing zero] | ||
| 307 | * written to it. If 'sz' is 0 or negative, 'path' is ignored and | ||
| 308 | * required amount of charachers [including trailing zero] to | ||
| 309 | * accomodate pathname is returned. If 'addr' is NULL, then | ||
| 310 | * pathname of cryptolib itself is returned. Negative or zero | ||
| 311 | * return value denotes error. | ||
| 312 | */ | ||
| 313 | int DSO_pathbyaddr(void *addr,char *path,int sz); | ||
| 314 | |||
| 315 | /* This function should be used with caution! It looks up symbols in | ||
| 316 | * *all* loaded modules and if module gets unloaded by somebody else | ||
| 317 | * attempt to dereference the pointer is doomed to have fatal | ||
| 318 | * consequences. Primary usage for this function is to probe *core* | ||
| 319 | * system functionality, e.g. check if getnameinfo(3) is available | ||
| 320 | * at run-time without bothering about OS-specific details such as | ||
| 321 | * libc.so.versioning or where does it actually reside: in libc | ||
| 322 | * itself or libsocket. */ | ||
| 323 | void *DSO_global_lookup(const char *name); | ||
| 324 | |||
| 325 | /* If BeOS is defined, use shared images. If not, return NULL. */ | ||
| 326 | DSO_METHOD *DSO_METHOD_beos(void); | ||
| 327 | |||
| 299 | /* BEGIN ERROR CODES */ | 328 | /* BEGIN ERROR CODES */ |
| 300 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 329 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 301 | * made after this point may be overwritten when the script is next run. | 330 | * made after this point may be overwritten when the script is next run. |
| @@ -305,6 +334,11 @@ void ERR_load_DSO_strings(void); | |||
| 305 | /* Error codes for the DSO functions. */ | 334 | /* Error codes for the DSO functions. */ |
| 306 | 335 | ||
| 307 | /* Function codes. */ | 336 | /* Function codes. */ |
| 337 | #define DSO_F_BEOS_BIND_FUNC 144 | ||
| 338 | #define DSO_F_BEOS_BIND_VAR 145 | ||
| 339 | #define DSO_F_BEOS_LOAD 146 | ||
| 340 | #define DSO_F_BEOS_NAME_CONVERTER 147 | ||
| 341 | #define DSO_F_BEOS_UNLOAD 148 | ||
| 308 | #define DSO_F_DLFCN_BIND_FUNC 100 | 342 | #define DSO_F_DLFCN_BIND_FUNC 100 |
| 309 | #define DSO_F_DLFCN_BIND_VAR 101 | 343 | #define DSO_F_DLFCN_BIND_VAR 101 |
| 310 | #define DSO_F_DLFCN_LOAD 102 | 344 | #define DSO_F_DLFCN_LOAD 102 |
| @@ -324,22 +358,29 @@ void ERR_load_DSO_strings(void); | |||
| 324 | #define DSO_F_DSO_FREE 111 | 358 | #define DSO_F_DSO_FREE 111 |
| 325 | #define DSO_F_DSO_GET_FILENAME 127 | 359 | #define DSO_F_DSO_GET_FILENAME 127 |
| 326 | #define DSO_F_DSO_GET_LOADED_FILENAME 128 | 360 | #define DSO_F_DSO_GET_LOADED_FILENAME 128 |
| 361 | #define DSO_F_DSO_GLOBAL_LOOKUP 139 | ||
| 327 | #define DSO_F_DSO_LOAD 112 | 362 | #define DSO_F_DSO_LOAD 112 |
| 328 | #define DSO_F_DSO_MERGE 132 | 363 | #define DSO_F_DSO_MERGE 132 |
| 329 | #define DSO_F_DSO_NEW_METHOD 113 | 364 | #define DSO_F_DSO_NEW_METHOD 113 |
| 365 | #define DSO_F_DSO_PATHBYADDR 140 | ||
| 330 | #define DSO_F_DSO_SET_FILENAME 129 | 366 | #define DSO_F_DSO_SET_FILENAME 129 |
| 331 | #define DSO_F_DSO_SET_NAME_CONVERTER 122 | 367 | #define DSO_F_DSO_SET_NAME_CONVERTER 122 |
| 332 | #define DSO_F_DSO_UP_REF 114 | 368 | #define DSO_F_DSO_UP_REF 114 |
| 369 | #define DSO_F_GLOBAL_LOOKUP_FUNC 138 | ||
| 370 | #define DSO_F_PATHBYADDR 137 | ||
| 333 | #define DSO_F_VMS_BIND_SYM 115 | 371 | #define DSO_F_VMS_BIND_SYM 115 |
| 334 | #define DSO_F_VMS_LOAD 116 | 372 | #define DSO_F_VMS_LOAD 116 |
| 335 | #define DSO_F_VMS_MERGER 133 | 373 | #define DSO_F_VMS_MERGER 133 |
| 336 | #define DSO_F_VMS_UNLOAD 117 | 374 | #define DSO_F_VMS_UNLOAD 117 |
| 337 | #define DSO_F_WIN32_BIND_FUNC 118 | 375 | #define DSO_F_WIN32_BIND_FUNC 118 |
| 338 | #define DSO_F_WIN32_BIND_VAR 119 | 376 | #define DSO_F_WIN32_BIND_VAR 119 |
| 377 | #define DSO_F_WIN32_GLOBALLOOKUP 142 | ||
| 378 | #define DSO_F_WIN32_GLOBALLOOKUP_FUNC 143 | ||
| 339 | #define DSO_F_WIN32_JOINER 135 | 379 | #define DSO_F_WIN32_JOINER 135 |
| 340 | #define DSO_F_WIN32_LOAD 120 | 380 | #define DSO_F_WIN32_LOAD 120 |
| 341 | #define DSO_F_WIN32_MERGER 134 | 381 | #define DSO_F_WIN32_MERGER 134 |
| 342 | #define DSO_F_WIN32_NAME_CONVERTER 125 | 382 | #define DSO_F_WIN32_NAME_CONVERTER 125 |
| 383 | #define DSO_F_WIN32_PATHBYADDR 141 | ||
| 343 | #define DSO_F_WIN32_SPLITTER 136 | 384 | #define DSO_F_WIN32_SPLITTER 136 |
| 344 | #define DSO_F_WIN32_UNLOAD 121 | 385 | #define DSO_F_WIN32_UNLOAD 121 |
| 345 | 386 | ||
diff --git a/src/lib/libcrypto/dso/dso_dlfcn.c b/src/lib/libcrypto/dso/dso_dlfcn.c index 1fd10104c5..14bd322fb8 100644 --- a/src/lib/libcrypto/dso/dso_dlfcn.c +++ b/src/lib/libcrypto/dso/dso_dlfcn.c | |||
| @@ -56,6 +56,16 @@ | |||
| 56 | * | 56 | * |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | /* We need to do this early, because stdio.h includes the header files | ||
| 60 | that handle _GNU_SOURCE and other similar macros. Defining it later | ||
| 61 | is simply too late, because those headers are protected from re- | ||
| 62 | inclusion. */ | ||
| 63 | #ifdef __linux | ||
| 64 | # ifndef _GNU_SOURCE | ||
| 65 | # define _GNU_SOURCE /* make sure dladdr is declared */ | ||
| 66 | # endif | ||
| 67 | #endif | ||
| 68 | |||
| 59 | #include <stdio.h> | 69 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 70 | #include "cryptlib.h" |
| 61 | #include <openssl/dso.h> | 71 | #include <openssl/dso.h> |
| @@ -68,7 +78,16 @@ DSO_METHOD *DSO_METHOD_dlfcn(void) | |||
| 68 | #else | 78 | #else |
| 69 | 79 | ||
| 70 | #ifdef HAVE_DLFCN_H | 80 | #ifdef HAVE_DLFCN_H |
| 71 | #include <dlfcn.h> | 81 | # ifdef __osf__ |
| 82 | # define __EXTENSIONS__ | ||
| 83 | # endif | ||
| 84 | # include <dlfcn.h> | ||
| 85 | # define HAVE_DLINFO 1 | ||
| 86 | # if defined(_AIX) || defined(__CYGWIN__) || \ | ||
| 87 | defined(__SCO_VERSION__) || defined(_SCO_ELF) || \ | ||
| 88 | (defined(__OpenBSD__) && !defined(RTLD_SELF)) | ||
| 89 | # undef HAVE_DLINFO | ||
| 90 | # endif | ||
| 72 | #endif | 91 | #endif |
| 73 | 92 | ||
| 74 | /* Part of the hack in "dlfcn_load" ... */ | 93 | /* Part of the hack in "dlfcn_load" ... */ |
| @@ -87,6 +106,8 @@ static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg); | |||
| 87 | static char *dlfcn_name_converter(DSO *dso, const char *filename); | 106 | static char *dlfcn_name_converter(DSO *dso, const char *filename); |
| 88 | static char *dlfcn_merger(DSO *dso, const char *filespec1, | 107 | static char *dlfcn_merger(DSO *dso, const char *filespec1, |
| 89 | const char *filespec2); | 108 | const char *filespec2); |
| 109 | static int dlfcn_pathbyaddr(void *addr,char *path,int sz); | ||
| 110 | static void *dlfcn_globallookup(const char *name); | ||
| 90 | 111 | ||
| 91 | static DSO_METHOD dso_meth_dlfcn = { | 112 | static DSO_METHOD dso_meth_dlfcn = { |
| 92 | "OpenSSL 'dlfcn' shared library method", | 113 | "OpenSSL 'dlfcn' shared library method", |
| @@ -103,7 +124,9 @@ static DSO_METHOD dso_meth_dlfcn = { | |||
| 103 | dlfcn_name_converter, | 124 | dlfcn_name_converter, |
| 104 | dlfcn_merger, | 125 | dlfcn_merger, |
| 105 | NULL, /* init */ | 126 | NULL, /* init */ |
| 106 | NULL /* finish */ | 127 | NULL, /* finish */ |
| 128 | dlfcn_pathbyaddr, | ||
| 129 | dlfcn_globallookup | ||
| 107 | }; | 130 | }; |
| 108 | 131 | ||
| 109 | DSO_METHOD *DSO_METHOD_dlfcn(void) | 132 | DSO_METHOD *DSO_METHOD_dlfcn(void) |
| @@ -163,7 +186,7 @@ static int dlfcn_load(DSO *dso) | |||
| 163 | ERR_add_error_data(4, "filename(", filename, "): ", dlerror()); | 186 | ERR_add_error_data(4, "filename(", filename, "): ", dlerror()); |
| 164 | goto err; | 187 | goto err; |
| 165 | } | 188 | } |
| 166 | if(!sk_push(dso->meth_data, (char *)ptr)) | 189 | if(!sk_void_push(dso->meth_data, (char *)ptr)) |
| 167 | { | 190 | { |
| 168 | DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR); | 191 | DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR); |
| 169 | goto err; | 192 | goto err; |
| @@ -188,15 +211,15 @@ static int dlfcn_unload(DSO *dso) | |||
| 188 | DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); | 211 | DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); |
| 189 | return(0); | 212 | return(0); |
| 190 | } | 213 | } |
| 191 | if(sk_num(dso->meth_data) < 1) | 214 | if(sk_void_num(dso->meth_data) < 1) |
| 192 | return(1); | 215 | return(1); |
| 193 | ptr = (void *)sk_pop(dso->meth_data); | 216 | ptr = sk_void_pop(dso->meth_data); |
| 194 | if(ptr == NULL) | 217 | if(ptr == NULL) |
| 195 | { | 218 | { |
| 196 | DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE); | 219 | DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE); |
| 197 | /* Should push the value back onto the stack in | 220 | /* Should push the value back onto the stack in |
| 198 | * case of a retry. */ | 221 | * case of a retry. */ |
| 199 | sk_push(dso->meth_data, (char *)ptr); | 222 | sk_void_push(dso->meth_data, ptr); |
| 200 | return(0); | 223 | return(0); |
| 201 | } | 224 | } |
| 202 | /* For now I'm not aware of any errors associated with dlclose() */ | 225 | /* For now I'm not aware of any errors associated with dlclose() */ |
| @@ -213,12 +236,12 @@ static void *dlfcn_bind_var(DSO *dso, const char *symname) | |||
| 213 | DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | 236 | DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); |
| 214 | return(NULL); | 237 | return(NULL); |
| 215 | } | 238 | } |
| 216 | if(sk_num(dso->meth_data) < 1) | 239 | if(sk_void_num(dso->meth_data) < 1) |
| 217 | { | 240 | { |
| 218 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR); | 241 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR); |
| 219 | return(NULL); | 242 | return(NULL); |
| 220 | } | 243 | } |
| 221 | ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | 244 | ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); |
| 222 | if(ptr == NULL) | 245 | if(ptr == NULL) |
| 223 | { | 246 | { |
| 224 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE); | 247 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE); |
| @@ -237,32 +260,35 @@ static void *dlfcn_bind_var(DSO *dso, const char *symname) | |||
| 237 | static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname) | 260 | static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname) |
| 238 | { | 261 | { |
| 239 | void *ptr; | 262 | void *ptr; |
| 240 | DSO_FUNC_TYPE sym, *tsym = &sym; | 263 | union { |
| 264 | DSO_FUNC_TYPE sym; | ||
| 265 | void *dlret; | ||
| 266 | } u; | ||
| 241 | 267 | ||
| 242 | if((dso == NULL) || (symname == NULL)) | 268 | if((dso == NULL) || (symname == NULL)) |
| 243 | { | 269 | { |
| 244 | DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); | 270 | DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); |
| 245 | return(NULL); | 271 | return(NULL); |
| 246 | } | 272 | } |
| 247 | if(sk_num(dso->meth_data) < 1) | 273 | if(sk_void_num(dso->meth_data) < 1) |
| 248 | { | 274 | { |
| 249 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR); | 275 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR); |
| 250 | return(NULL); | 276 | return(NULL); |
| 251 | } | 277 | } |
| 252 | ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | 278 | ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); |
| 253 | if(ptr == NULL) | 279 | if(ptr == NULL) |
| 254 | { | 280 | { |
| 255 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE); | 281 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE); |
| 256 | return(NULL); | 282 | return(NULL); |
| 257 | } | 283 | } |
| 258 | *(void **)(tsym) = dlsym(ptr, symname); | 284 | u.dlret = dlsym(ptr, symname); |
| 259 | if(sym == NULL) | 285 | if(u.dlret == NULL) |
| 260 | { | 286 | { |
| 261 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE); | 287 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE); |
| 262 | ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); | 288 | ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); |
| 263 | return(NULL); | 289 | return(NULL); |
| 264 | } | 290 | } |
| 265 | return(sym); | 291 | return u.sym; |
| 266 | } | 292 | } |
| 267 | 293 | ||
| 268 | static char *dlfcn_merger(DSO *dso, const char *filespec1, | 294 | static char *dlfcn_merger(DSO *dso, const char *filespec1, |
| @@ -278,13 +304,12 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1, | |||
| 278 | } | 304 | } |
| 279 | /* If the first file specification is a rooted path, it rules. | 305 | /* If the first file specification is a rooted path, it rules. |
| 280 | same goes if the second file specification is missing. */ | 306 | same goes if the second file specification is missing. */ |
| 281 | if (!filespec2 || filespec1[0] == '/') | 307 | if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) |
| 282 | { | 308 | { |
| 283 | merged = OPENSSL_malloc(strlen(filespec1) + 1); | 309 | merged = OPENSSL_malloc(strlen(filespec1) + 1); |
| 284 | if(!merged) | 310 | if(!merged) |
| 285 | { | 311 | { |
| 286 | DSOerr(DSO_F_DLFCN_MERGER, | 312 | DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); |
| 287 | ERR_R_MALLOC_FAILURE); | ||
| 288 | return(NULL); | 313 | return(NULL); |
| 289 | } | 314 | } |
| 290 | strcpy(merged, filespec1); | 315 | strcpy(merged, filespec1); |
| @@ -310,7 +335,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1, | |||
| 310 | { | 335 | { |
| 311 | int spec2len, len; | 336 | int spec2len, len; |
| 312 | 337 | ||
| 313 | spec2len = (filespec2 ? strlen(filespec2) : 0); | 338 | spec2len = strlen(filespec2); |
| 314 | len = spec2len + (filespec1 ? strlen(filespec1) : 0); | 339 | len = spec2len + (filespec1 ? strlen(filespec1) : 0); |
| 315 | 340 | ||
| 316 | if(filespec2 && filespec2[spec2len - 1] == '/') | 341 | if(filespec2 && filespec2[spec2len - 1] == '/') |
| @@ -332,6 +357,15 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1, | |||
| 332 | return(merged); | 357 | return(merged); |
| 333 | } | 358 | } |
| 334 | 359 | ||
| 360 | #ifdef OPENSSL_SYS_MACOSX | ||
| 361 | #define DSO_ext ".dylib" | ||
| 362 | #define DSO_extlen 6 | ||
| 363 | #else | ||
| 364 | #define DSO_ext ".so" | ||
| 365 | #define DSO_extlen 3 | ||
| 366 | #endif | ||
| 367 | |||
| 368 | |||
| 335 | static char *dlfcn_name_converter(DSO *dso, const char *filename) | 369 | static char *dlfcn_name_converter(DSO *dso, const char *filename) |
| 336 | { | 370 | { |
| 337 | char *translated; | 371 | char *translated; |
| @@ -342,8 +376,8 @@ static char *dlfcn_name_converter(DSO *dso, const char *filename) | |||
| 342 | transform = (strstr(filename, "/") == NULL); | 376 | transform = (strstr(filename, "/") == NULL); |
| 343 | if(transform) | 377 | if(transform) |
| 344 | { | 378 | { |
| 345 | /* We will convert this to "%s.so" or "lib%s.so" */ | 379 | /* We will convert this to "%s.so" or "lib%s.so" etc */ |
| 346 | rsize += 3; /* The length of ".so" */ | 380 | rsize += DSO_extlen; /* The length of ".so" */ |
| 347 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) | 381 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) |
| 348 | rsize += 3; /* The length of "lib" */ | 382 | rsize += 3; /* The length of "lib" */ |
| 349 | } | 383 | } |
| @@ -357,13 +391,92 @@ static char *dlfcn_name_converter(DSO *dso, const char *filename) | |||
| 357 | if(transform) | 391 | if(transform) |
| 358 | { | 392 | { |
| 359 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) | 393 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) |
| 360 | sprintf(translated, "lib%s.so", filename); | 394 | sprintf(translated, "lib%s" DSO_ext, filename); |
| 361 | else | 395 | else |
| 362 | sprintf(translated, "%s.so", filename); | 396 | sprintf(translated, "%s" DSO_ext, filename); |
| 363 | } | 397 | } |
| 364 | else | 398 | else |
| 365 | sprintf(translated, "%s", filename); | 399 | sprintf(translated, "%s", filename); |
| 366 | return(translated); | 400 | return(translated); |
| 367 | } | 401 | } |
| 368 | 402 | ||
| 403 | #ifdef __sgi | ||
| 404 | /* | ||
| 405 | This is a quote from IRIX manual for dladdr(3c): | ||
| 406 | |||
| 407 | <dlfcn.h> does not contain a prototype for dladdr or definition of | ||
| 408 | Dl_info. The #include <dlfcn.h> in the SYNOPSIS line is traditional, | ||
| 409 | but contains no dladdr prototype and no IRIX library contains an | ||
| 410 | implementation. Write your own declaration based on the code below. | ||
| 411 | |||
| 412 | The following code is dependent on internal interfaces that are not | ||
| 413 | part of the IRIX compatibility guarantee; however, there is no future | ||
| 414 | intention to change this interface, so on a practical level, the code | ||
| 415 | below is safe to use on IRIX. | ||
| 416 | */ | ||
| 417 | #include <rld_interface.h> | ||
| 418 | #ifndef _RLD_INTERFACE_DLFCN_H_DLADDR | ||
| 419 | #define _RLD_INTERFACE_DLFCN_H_DLADDR | ||
| 420 | typedef struct Dl_info { | ||
| 421 | const char * dli_fname; | ||
| 422 | void * dli_fbase; | ||
| 423 | const char * dli_sname; | ||
| 424 | void * dli_saddr; | ||
| 425 | int dli_version; | ||
| 426 | int dli_reserved1; | ||
| 427 | long dli_reserved[4]; | ||
| 428 | } Dl_info; | ||
| 429 | #else | ||
| 430 | typedef struct Dl_info Dl_info; | ||
| 431 | #endif | ||
| 432 | #define _RLD_DLADDR 14 | ||
| 433 | |||
| 434 | static int dladdr(void *address, Dl_info *dl) | ||
| 435 | { | ||
| 436 | void *v; | ||
| 437 | v = _rld_new_interface(_RLD_DLADDR,address,dl); | ||
| 438 | return (int)v; | ||
| 439 | } | ||
| 440 | #endif /* __sgi */ | ||
| 441 | |||
| 442 | static int dlfcn_pathbyaddr(void *addr,char *path,int sz) | ||
| 443 | { | ||
| 444 | #ifdef HAVE_DLINFO | ||
| 445 | Dl_info dli; | ||
| 446 | int len; | ||
| 447 | |||
| 448 | if (addr == NULL) | ||
| 449 | { | ||
| 450 | union { int(*f)(void*,char*,int); void *p; } t = | ||
| 451 | { dlfcn_pathbyaddr }; | ||
| 452 | addr = t.p; | ||
| 453 | } | ||
| 454 | |||
| 455 | if (dladdr(addr,&dli)) | ||
| 456 | { | ||
| 457 | len = (int)strlen(dli.dli_fname); | ||
| 458 | if (sz <= 0) return len+1; | ||
| 459 | if (len >= sz) len=sz-1; | ||
| 460 | memcpy(path,dli.dli_fname,len); | ||
| 461 | path[len++]=0; | ||
| 462 | return len; | ||
| 463 | } | ||
| 464 | |||
| 465 | ERR_add_error_data(4, "dlfcn_pathbyaddr(): ", dlerror()); | ||
| 466 | #endif | ||
| 467 | return -1; | ||
| 468 | } | ||
| 469 | |||
| 470 | static void *dlfcn_globallookup(const char *name) | ||
| 471 | { | ||
| 472 | void *ret = NULL,*handle = dlopen(NULL,RTLD_LAZY); | ||
| 473 | |||
| 474 | if (handle) | ||
| 475 | { | ||
| 476 | ret = dlsym(handle,name); | ||
| 477 | dlclose(handle); | ||
| 478 | } | ||
| 479 | |||
| 480 | return ret; | ||
| 481 | } | ||
| 369 | #endif /* DSO_DLFCN */ | 482 | #endif /* DSO_DLFCN */ |
diff --git a/src/lib/libcrypto/dso/dso_err.c b/src/lib/libcrypto/dso/dso_err.c index a8b0a210de..2bb07c2514 100644 --- a/src/lib/libcrypto/dso/dso_err.c +++ b/src/lib/libcrypto/dso/dso_err.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* crypto/dso/dso_err.c */ | 1 | /* crypto/dso/dso_err.c */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -70,6 +70,11 @@ | |||
| 70 | 70 | ||
| 71 | static ERR_STRING_DATA DSO_str_functs[]= | 71 | static ERR_STRING_DATA DSO_str_functs[]= |
| 72 | { | 72 | { |
| 73 | {ERR_FUNC(DSO_F_BEOS_BIND_FUNC), "BEOS_BIND_FUNC"}, | ||
| 74 | {ERR_FUNC(DSO_F_BEOS_BIND_VAR), "BEOS_BIND_VAR"}, | ||
| 75 | {ERR_FUNC(DSO_F_BEOS_LOAD), "BEOS_LOAD"}, | ||
| 76 | {ERR_FUNC(DSO_F_BEOS_NAME_CONVERTER), "BEOS_NAME_CONVERTER"}, | ||
| 77 | {ERR_FUNC(DSO_F_BEOS_UNLOAD), "BEOS_UNLOAD"}, | ||
| 73 | {ERR_FUNC(DSO_F_DLFCN_BIND_FUNC), "DLFCN_BIND_FUNC"}, | 78 | {ERR_FUNC(DSO_F_DLFCN_BIND_FUNC), "DLFCN_BIND_FUNC"}, |
| 74 | {ERR_FUNC(DSO_F_DLFCN_BIND_VAR), "DLFCN_BIND_VAR"}, | 79 | {ERR_FUNC(DSO_F_DLFCN_BIND_VAR), "DLFCN_BIND_VAR"}, |
| 75 | {ERR_FUNC(DSO_F_DLFCN_LOAD), "DLFCN_LOAD"}, | 80 | {ERR_FUNC(DSO_F_DLFCN_LOAD), "DLFCN_LOAD"}, |
| @@ -89,22 +94,29 @@ static ERR_STRING_DATA DSO_str_functs[]= | |||
| 89 | {ERR_FUNC(DSO_F_DSO_FREE), "DSO_free"}, | 94 | {ERR_FUNC(DSO_F_DSO_FREE), "DSO_free"}, |
| 90 | {ERR_FUNC(DSO_F_DSO_GET_FILENAME), "DSO_get_filename"}, | 95 | {ERR_FUNC(DSO_F_DSO_GET_FILENAME), "DSO_get_filename"}, |
| 91 | {ERR_FUNC(DSO_F_DSO_GET_LOADED_FILENAME), "DSO_get_loaded_filename"}, | 96 | {ERR_FUNC(DSO_F_DSO_GET_LOADED_FILENAME), "DSO_get_loaded_filename"}, |
| 97 | {ERR_FUNC(DSO_F_DSO_GLOBAL_LOOKUP), "DSO_global_lookup"}, | ||
| 92 | {ERR_FUNC(DSO_F_DSO_LOAD), "DSO_load"}, | 98 | {ERR_FUNC(DSO_F_DSO_LOAD), "DSO_load"}, |
| 93 | {ERR_FUNC(DSO_F_DSO_MERGE), "DSO_merge"}, | 99 | {ERR_FUNC(DSO_F_DSO_MERGE), "DSO_merge"}, |
| 94 | {ERR_FUNC(DSO_F_DSO_NEW_METHOD), "DSO_new_method"}, | 100 | {ERR_FUNC(DSO_F_DSO_NEW_METHOD), "DSO_new_method"}, |
| 101 | {ERR_FUNC(DSO_F_DSO_PATHBYADDR), "DSO_pathbyaddr"}, | ||
| 95 | {ERR_FUNC(DSO_F_DSO_SET_FILENAME), "DSO_set_filename"}, | 102 | {ERR_FUNC(DSO_F_DSO_SET_FILENAME), "DSO_set_filename"}, |
| 96 | {ERR_FUNC(DSO_F_DSO_SET_NAME_CONVERTER), "DSO_set_name_converter"}, | 103 | {ERR_FUNC(DSO_F_DSO_SET_NAME_CONVERTER), "DSO_set_name_converter"}, |
| 97 | {ERR_FUNC(DSO_F_DSO_UP_REF), "DSO_up_ref"}, | 104 | {ERR_FUNC(DSO_F_DSO_UP_REF), "DSO_up_ref"}, |
| 105 | {ERR_FUNC(DSO_F_GLOBAL_LOOKUP_FUNC), "GLOBAL_LOOKUP_FUNC"}, | ||
| 106 | {ERR_FUNC(DSO_F_PATHBYADDR), "PATHBYADDR"}, | ||
| 98 | {ERR_FUNC(DSO_F_VMS_BIND_SYM), "VMS_BIND_SYM"}, | 107 | {ERR_FUNC(DSO_F_VMS_BIND_SYM), "VMS_BIND_SYM"}, |
| 99 | {ERR_FUNC(DSO_F_VMS_LOAD), "VMS_LOAD"}, | 108 | {ERR_FUNC(DSO_F_VMS_LOAD), "VMS_LOAD"}, |
| 100 | {ERR_FUNC(DSO_F_VMS_MERGER), "VMS_MERGER"}, | 109 | {ERR_FUNC(DSO_F_VMS_MERGER), "VMS_MERGER"}, |
| 101 | {ERR_FUNC(DSO_F_VMS_UNLOAD), "VMS_UNLOAD"}, | 110 | {ERR_FUNC(DSO_F_VMS_UNLOAD), "VMS_UNLOAD"}, |
| 102 | {ERR_FUNC(DSO_F_WIN32_BIND_FUNC), "WIN32_BIND_FUNC"}, | 111 | {ERR_FUNC(DSO_F_WIN32_BIND_FUNC), "WIN32_BIND_FUNC"}, |
| 103 | {ERR_FUNC(DSO_F_WIN32_BIND_VAR), "WIN32_BIND_VAR"}, | 112 | {ERR_FUNC(DSO_F_WIN32_BIND_VAR), "WIN32_BIND_VAR"}, |
| 113 | {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP), "WIN32_GLOBALLOOKUP"}, | ||
| 114 | {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP_FUNC), "WIN32_GLOBALLOOKUP_FUNC"}, | ||
| 104 | {ERR_FUNC(DSO_F_WIN32_JOINER), "WIN32_JOINER"}, | 115 | {ERR_FUNC(DSO_F_WIN32_JOINER), "WIN32_JOINER"}, |
| 105 | {ERR_FUNC(DSO_F_WIN32_LOAD), "WIN32_LOAD"}, | 116 | {ERR_FUNC(DSO_F_WIN32_LOAD), "WIN32_LOAD"}, |
| 106 | {ERR_FUNC(DSO_F_WIN32_MERGER), "WIN32_MERGER"}, | 117 | {ERR_FUNC(DSO_F_WIN32_MERGER), "WIN32_MERGER"}, |
| 107 | {ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"}, | 118 | {ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"}, |
| 119 | {ERR_FUNC(DSO_F_WIN32_PATHBYADDR), "WIN32_PATHBYADDR"}, | ||
| 108 | {ERR_FUNC(DSO_F_WIN32_SPLITTER), "WIN32_SPLITTER"}, | 120 | {ERR_FUNC(DSO_F_WIN32_SPLITTER), "WIN32_SPLITTER"}, |
| 109 | {ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"}, | 121 | {ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"}, |
| 110 | {0,NULL} | 122 | {0,NULL} |
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c index 49bdd71309..8a15b794ab 100644 --- a/src/lib/libcrypto/dso/dso_lib.c +++ b/src/lib/libcrypto/dso/dso_lib.c | |||
| @@ -107,7 +107,7 @@ DSO *DSO_new_method(DSO_METHOD *meth) | |||
| 107 | return(NULL); | 107 | return(NULL); |
| 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_void_new_null(); |
| 111 | if(ret->meth_data == 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 */ |
| @@ -163,7 +163,7 @@ int DSO_free(DSO *dso) | |||
| 163 | return(0); | 163 | return(0); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | sk_free(dso->meth_data); | 166 | sk_void_free(dso->meth_data); |
| 167 | if(dso->filename != NULL) | 167 | if(dso->filename != NULL) |
| 168 | OPENSSL_free(dso->filename); | 168 | OPENSSL_free(dso->filename); |
| 169 | if(dso->loaded_filename != NULL) | 169 | if(dso->loaded_filename != NULL) |
| @@ -399,13 +399,6 @@ char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2) | |||
| 399 | DSOerr(DSO_F_DSO_MERGE,ERR_R_PASSED_NULL_PARAMETER); | 399 | DSOerr(DSO_F_DSO_MERGE,ERR_R_PASSED_NULL_PARAMETER); |
| 400 | return(NULL); | 400 | return(NULL); |
| 401 | } | 401 | } |
| 402 | if(filespec1 == NULL) | ||
| 403 | filespec1 = dso->filename; | ||
| 404 | if(filespec1 == NULL) | ||
| 405 | { | ||
| 406 | DSOerr(DSO_F_DSO_MERGE,DSO_R_NO_FILE_SPECIFICATION); | ||
| 407 | return(NULL); | ||
| 408 | } | ||
| 409 | if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) | 402 | if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) |
| 410 | { | 403 | { |
| 411 | if(dso->merger != NULL) | 404 | if(dso->merger != NULL) |
| @@ -464,3 +457,27 @@ const char *DSO_get_loaded_filename(DSO *dso) | |||
| 464 | } | 457 | } |
| 465 | return(dso->loaded_filename); | 458 | return(dso->loaded_filename); |
| 466 | } | 459 | } |
| 460 | |||
| 461 | int DSO_pathbyaddr(void *addr,char *path,int sz) | ||
| 462 | { | ||
| 463 | DSO_METHOD *meth = default_DSO_meth; | ||
| 464 | if (meth == NULL) meth = DSO_METHOD_openssl(); | ||
| 465 | if (meth->pathbyaddr == NULL) | ||
| 466 | { | ||
| 467 | DSOerr(DSO_F_DSO_PATHBYADDR,DSO_R_UNSUPPORTED); | ||
| 468 | return -1; | ||
| 469 | } | ||
| 470 | return (*meth->pathbyaddr)(addr,path,sz); | ||
| 471 | } | ||
| 472 | |||
| 473 | void *DSO_global_lookup(const char *name) | ||
| 474 | { | ||
| 475 | DSO_METHOD *meth = default_DSO_meth; | ||
| 476 | if (meth == NULL) meth = DSO_METHOD_openssl(); | ||
| 477 | if (meth->globallookup == NULL) | ||
| 478 | { | ||
| 479 | DSOerr(DSO_F_DSO_GLOBAL_LOOKUP,DSO_R_UNSUPPORTED); | ||
| 480 | return NULL; | ||
| 481 | } | ||
| 482 | return (*meth->globallookup)(name); | ||
| 483 | } | ||
diff --git a/src/lib/libcrypto/dso/dso_null.c b/src/lib/libcrypto/dso/dso_null.c index 4972984651..49d842d1f5 100644 --- a/src/lib/libcrypto/dso/dso_null.c +++ b/src/lib/libcrypto/dso/dso_null.c | |||
| @@ -78,7 +78,9 @@ static DSO_METHOD dso_meth_null = { | |||
| 78 | NULL, /* dso_name_converter */ | 78 | NULL, /* dso_name_converter */ |
| 79 | NULL, /* dso_merger */ | 79 | NULL, /* dso_merger */ |
| 80 | NULL, /* init */ | 80 | NULL, /* init */ |
| 81 | NULL /* finish */ | 81 | NULL, /* finish */ |
| 82 | NULL, /* pathbyaddr */ | ||
| 83 | NULL /* globallookup */ | ||
| 82 | }; | 84 | }; |
| 83 | 85 | ||
| 84 | DSO_METHOD *DSO_METHOD_null(void) | 86 | DSO_METHOD *DSO_METHOD_null(void) |
diff --git a/src/lib/libcrypto/dso/dso_openssl.c b/src/lib/libcrypto/dso/dso_openssl.c index a4395ebffe..b17e8e8e9e 100644 --- a/src/lib/libcrypto/dso/dso_openssl.c +++ b/src/lib/libcrypto/dso/dso_openssl.c | |||
| @@ -74,6 +74,8 @@ DSO_METHOD *DSO_METHOD_openssl(void) | |||
| 74 | return(DSO_METHOD_win32()); | 74 | return(DSO_METHOD_win32()); |
| 75 | #elif defined(DSO_VMS) | 75 | #elif defined(DSO_VMS) |
| 76 | return(DSO_METHOD_vms()); | 76 | return(DSO_METHOD_vms()); |
| 77 | #elif defined(DSO_BEOS) | ||
| 78 | return(DSO_METHOD_beos()); | ||
| 77 | #else | 79 | #else |
| 78 | return(DSO_METHOD_null()); | 80 | return(DSO_METHOD_null()); |
| 79 | #endif | 81 | #endif |
