diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/dso/dso.h | 18 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_dlfcn.c | 320 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_err.c | 165 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_lib.c | 562 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_null.c | 14 | ||||
| -rw-r--r-- | src/lib/libcrypto/dso/dso_openssl.c | 15 |
6 files changed, 530 insertions, 564 deletions
diff --git a/src/lib/libcrypto/dso/dso.h b/src/lib/libcrypto/dso/dso.h index 9010251bbc..71a8a8af39 100644 --- a/src/lib/libcrypto/dso/dso.h +++ b/src/lib/libcrypto/dso/dso.h | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -131,8 +131,7 @@ typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *); | |||
| 131 | * first. */ | 131 | * first. */ |
| 132 | typedef char* (*DSO_MERGER_FUNC)(DSO *, const char *, const char *); | 132 | typedef char* (*DSO_MERGER_FUNC)(DSO *, const char *, const char *); |
| 133 | 133 | ||
| 134 | typedef struct dso_meth_st | 134 | typedef struct dso_meth_st { |
| 135 | { | ||
| 136 | const char *name; | 135 | const char *name; |
| 137 | /* Loads a shared library, NB: new DSO_METHODs must ensure that a | 136 | /* Loads a shared library, NB: new DSO_METHODs must ensure that a |
| 138 | * successful load populates the loaded_filename field, and likewise a | 137 | * successful load populates the loaded_filename field, and likewise a |
| @@ -172,16 +171,15 @@ typedef struct dso_meth_st | |||
| 172 | int (*finish)(DSO *dso); | 171 | int (*finish)(DSO *dso); |
| 173 | 172 | ||
| 174 | /* Return pathname of the module containing location */ | 173 | /* Return pathname of the module containing location */ |
| 175 | int (*pathbyaddr)(void *addr,char *path,int sz); | 174 | int (*pathbyaddr)(void *addr, char *path, int sz); |
| 176 | /* Perform global symbol lookup, i.e. among *all* modules */ | 175 | /* Perform global symbol lookup, i.e. among *all* modules */ |
| 177 | void *(*globallookup)(const char *symname); | 176 | void *(*globallookup)(const char *symname); |
| 178 | } DSO_METHOD; | 177 | } DSO_METHOD; |
| 179 | 178 | ||
| 180 | /**********************************************************************/ | 179 | /**********************************************************************/ |
| 181 | /* The low-level handle type used to refer to a loaded shared library */ | 180 | /* The low-level handle type used to refer to a loaded shared library */ |
| 182 | 181 | ||
| 183 | struct dso_st | 182 | struct dso_st { |
| 184 | { | ||
| 185 | DSO_METHOD *meth; | 183 | DSO_METHOD *meth; |
| 186 | /* Standard dlopen uses a (void *). Win32 uses a HANDLE. VMS | 184 | /* Standard dlopen uses a (void *). Win32 uses a HANDLE. VMS |
| 187 | * doesn't use anything but will need to cache the filename | 185 | * doesn't use anything but will need to cache the filename |
| @@ -215,7 +213,7 @@ struct dso_st | |||
| 215 | * corresponds to a loaded library or not, and (b) the filename with | 213 | * corresponds to a loaded library or not, and (b) the filename with |
| 216 | * which it was actually loaded. */ | 214 | * which it was actually loaded. */ |
| 217 | char *loaded_filename; | 215 | char *loaded_filename; |
| 218 | }; | 216 | }; |
| 219 | 217 | ||
| 220 | 218 | ||
| 221 | DSO * DSO_new(void); | 219 | DSO * DSO_new(void); |
| @@ -230,7 +228,7 @@ long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg); | |||
| 230 | * oldcb is non-NULL then it is set to the function pointer value being | 228 | * oldcb is non-NULL then it is set to the function pointer value being |
| 231 | * replaced. Return value is non-zero for success. */ | 229 | * replaced. Return value is non-zero for success. */ |
| 232 | int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb, | 230 | int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb, |
| 233 | DSO_NAME_CONVERTER_FUNC *oldcb); | 231 | DSO_NAME_CONVERTER_FUNC *oldcb); |
| 234 | /* These functions can be used to get/set the platform-independant filename | 232 | /* These functions can be used to get/set the platform-independant filename |
| 235 | * used for a DSO. NB: set will fail if the DSO is already loaded. */ | 233 | * used for a DSO. NB: set will fail if the DSO is already loaded. */ |
| 236 | const char *DSO_get_filename(DSO *dso); | 234 | const char *DSO_get_filename(DSO *dso); |
| @@ -299,7 +297,7 @@ DSO_METHOD *DSO_METHOD_dlfcn(void); | |||
| 299 | * pathname of cryptolib itself is returned. Negative or zero | 297 | * pathname of cryptolib itself is returned. Negative or zero |
| 300 | * return value denotes error. | 298 | * return value denotes error. |
| 301 | */ | 299 | */ |
| 302 | int DSO_pathbyaddr(void *addr,char *path,int sz); | 300 | int DSO_pathbyaddr(void *addr, char *path, int sz); |
| 303 | 301 | ||
| 304 | /* This function should be used with caution! It looks up symbols in | 302 | /* This function should be used with caution! It looks up symbols in |
| 305 | * *all* loaded modules and if module gets unloaded by somebody else | 303 | * *all* loaded modules and if module gets unloaded by somebody else |
diff --git a/src/lib/libcrypto/dso/dso_dlfcn.c b/src/lib/libcrypto/dso/dso_dlfcn.c index 648ddb5ac0..245b9b1478 100644 --- a/src/lib/libcrypto/dso/dso_dlfcn.c +++ b/src/lib/libcrypto/dso/dso_dlfcn.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -61,10 +61,11 @@ | |||
| 61 | #include <openssl/dso.h> | 61 | #include <openssl/dso.h> |
| 62 | 62 | ||
| 63 | #ifndef DSO_DLFCN | 63 | #ifndef DSO_DLFCN |
| 64 | DSO_METHOD *DSO_METHOD_dlfcn(void) | 64 | DSO_METHOD * |
| 65 | { | 65 | DSO_METHOD_dlfcn(void) |
| 66 | { | ||
| 66 | return NULL; | 67 | return NULL; |
| 67 | } | 68 | } |
| 68 | #else | 69 | #else |
| 69 | 70 | ||
| 70 | #ifdef HAVE_DLFCN_H | 71 | #ifdef HAVE_DLFCN_H |
| @@ -87,8 +88,8 @@ static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg); | |||
| 87 | #endif | 88 | #endif |
| 88 | static char *dlfcn_name_converter(DSO *dso, const char *filename); | 89 | static char *dlfcn_name_converter(DSO *dso, const char *filename); |
| 89 | static char *dlfcn_merger(DSO *dso, const char *filespec1, | 90 | static char *dlfcn_merger(DSO *dso, const char *filespec1, |
| 90 | const char *filespec2); | 91 | const char *filespec2); |
| 91 | static int dlfcn_pathbyaddr(void *addr,char *path,int sz); | 92 | static int dlfcn_pathbyaddr(void *addr, char *path, int sz); |
| 92 | static void *dlfcn_globallookup(const char *name); | 93 | static void *dlfcn_globallookup(const char *name); |
| 93 | 94 | ||
| 94 | static DSO_METHOD dso_meth_dlfcn = { | 95 | static DSO_METHOD dso_meth_dlfcn = { |
| @@ -109,286 +110,269 @@ static DSO_METHOD dso_meth_dlfcn = { | |||
| 109 | NULL, /* finish */ | 110 | NULL, /* finish */ |
| 110 | dlfcn_pathbyaddr, | 111 | dlfcn_pathbyaddr, |
| 111 | dlfcn_globallookup | 112 | dlfcn_globallookup |
| 112 | }; | 113 | }; |
| 113 | 114 | ||
| 114 | DSO_METHOD *DSO_METHOD_dlfcn(void) | 115 | DSO_METHOD * |
| 115 | { | 116 | DSO_METHOD_dlfcn(void) |
| 116 | return(&dso_meth_dlfcn); | 117 | { |
| 117 | } | 118 | return (&dso_meth_dlfcn); |
| 119 | } | ||
| 118 | 120 | ||
| 119 | /* For this DSO_METHOD, our meth_data STACK will contain; | 121 | /* For this DSO_METHOD, our meth_data STACK will contain; |
| 120 | * (i) the handle (void*) returned from dlopen(). | 122 | * (i) the handle (void*) returned from dlopen(). |
| 121 | */ | 123 | */ |
| 122 | 124 | ||
| 123 | static int dlfcn_load(DSO *dso) | 125 | static int |
| 124 | { | 126 | dlfcn_load(DSO *dso) |
| 127 | { | ||
| 125 | void *ptr = NULL; | 128 | void *ptr = NULL; |
| 126 | /* See applicable comments in dso_dl.c */ | 129 | /* See applicable comments in dso_dl.c */ |
| 127 | char *filename = DSO_convert_filename(dso, NULL); | 130 | char *filename = DSO_convert_filename(dso, NULL); |
| 128 | int flags = RTLD_LAZY; | 131 | int flags = RTLD_LAZY; |
| 129 | 132 | ||
| 130 | if(filename == NULL) | 133 | if (filename == NULL) { |
| 131 | { | 134 | DSOerr(DSO_F_DLFCN_LOAD, DSO_R_NO_FILENAME); |
| 132 | DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME); | ||
| 133 | goto err; | 135 | goto err; |
| 134 | } | 136 | } |
| 135 | 137 | ||
| 136 | if (dso->flags & DSO_FLAG_GLOBAL_SYMBOLS) | 138 | if (dso->flags & DSO_FLAG_GLOBAL_SYMBOLS) |
| 137 | flags |= RTLD_GLOBAL; | 139 | flags |= RTLD_GLOBAL; |
| 138 | ptr = dlopen(filename, flags); | 140 | ptr = dlopen(filename, flags); |
| 139 | if(ptr == NULL) | 141 | if (ptr == NULL) { |
| 140 | { | 142 | DSOerr(DSO_F_DLFCN_LOAD, DSO_R_LOAD_FAILED); |
| 141 | DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED); | ||
| 142 | ERR_add_error_data(4, "filename(", filename, "): ", dlerror()); | 143 | ERR_add_error_data(4, "filename(", filename, "): ", dlerror()); |
| 143 | goto err; | 144 | goto err; |
| 144 | } | 145 | } |
| 145 | if(!sk_void_push(dso->meth_data, (char *)ptr)) | 146 | if (!sk_void_push(dso->meth_data, (char *)ptr)) { |
| 146 | { | 147 | DSOerr(DSO_F_DLFCN_LOAD, DSO_R_STACK_ERROR); |
| 147 | DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR); | ||
| 148 | goto err; | 148 | goto err; |
| 149 | } | 149 | } |
| 150 | /* Success */ | 150 | /* Success */ |
| 151 | dso->loaded_filename = filename; | 151 | dso->loaded_filename = filename; |
| 152 | return(1); | 152 | return (1); |
| 153 | |||
| 153 | err: | 154 | err: |
| 154 | /* Cleanup! */ | 155 | /* Cleanup! */ |
| 155 | if(filename != NULL) | 156 | if (filename != NULL) |
| 156 | free(filename); | 157 | free(filename); |
| 157 | if(ptr != NULL) | 158 | if (ptr != NULL) |
| 158 | dlclose(ptr); | 159 | dlclose(ptr); |
| 159 | return(0); | 160 | return (0); |
| 160 | } | 161 | } |
| 161 | 162 | ||
| 162 | static int dlfcn_unload(DSO *dso) | 163 | static int |
| 163 | { | 164 | dlfcn_unload(DSO *dso) |
| 165 | { | ||
| 164 | void *ptr; | 166 | void *ptr; |
| 165 | if(dso == NULL) | 167 | if (dso == NULL) { |
| 166 | { | 168 | DSOerr(DSO_F_DLFCN_UNLOAD, ERR_R_PASSED_NULL_PARAMETER); |
| 167 | DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); | 169 | return (0); |
| 168 | return(0); | 170 | } |
| 169 | } | 171 | if (sk_void_num(dso->meth_data) < 1) |
| 170 | if(sk_void_num(dso->meth_data) < 1) | 172 | return (1); |
| 171 | return(1); | ||
| 172 | ptr = sk_void_pop(dso->meth_data); | 173 | ptr = sk_void_pop(dso->meth_data); |
| 173 | if(ptr == NULL) | 174 | if (ptr == NULL) { |
| 174 | { | 175 | DSOerr(DSO_F_DLFCN_UNLOAD, DSO_R_NULL_HANDLE); |
| 175 | DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE); | ||
| 176 | /* Should push the value back onto the stack in | 176 | /* Should push the value back onto the stack in |
| 177 | * case of a retry. */ | 177 | * case of a retry. */ |
| 178 | sk_void_push(dso->meth_data, ptr); | 178 | sk_void_push(dso->meth_data, ptr); |
| 179 | return(0); | 179 | return (0); |
| 180 | } | 180 | } |
| 181 | /* For now I'm not aware of any errors associated with dlclose() */ | 181 | /* For now I'm not aware of any errors associated with dlclose() */ |
| 182 | dlclose(ptr); | 182 | dlclose(ptr); |
| 183 | return(1); | 183 | return (1); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | static void *dlfcn_bind_var(DSO *dso, const char *symname) | 186 | static void * |
| 187 | { | 187 | dlfcn_bind_var(DSO *dso, const char *symname) |
| 188 | { | ||
| 188 | void *ptr, *sym; | 189 | void *ptr, *sym; |
| 189 | 190 | ||
| 190 | if((dso == NULL) || (symname == NULL)) | 191 | if ((dso == NULL) || (symname == NULL)) { |
| 191 | { | 192 | DSOerr(DSO_F_DLFCN_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER); |
| 192 | DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | 193 | return (NULL); |
| 193 | return(NULL); | 194 | } |
| 194 | } | 195 | if (sk_void_num(dso->meth_data) < 1) { |
| 195 | if(sk_void_num(dso->meth_data) < 1) | 196 | DSOerr(DSO_F_DLFCN_BIND_VAR, DSO_R_STACK_ERROR); |
| 196 | { | 197 | return (NULL); |
| 197 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR); | 198 | } |
| 198 | return(NULL); | ||
| 199 | } | ||
| 200 | ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); | 199 | ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); |
| 201 | if(ptr == NULL) | 200 | if (ptr == NULL) { |
| 202 | { | 201 | DSOerr(DSO_F_DLFCN_BIND_VAR, DSO_R_NULL_HANDLE); |
| 203 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE); | 202 | return (NULL); |
| 204 | return(NULL); | 203 | } |
| 205 | } | ||
| 206 | sym = dlsym(ptr, symname); | 204 | sym = dlsym(ptr, symname); |
| 207 | if(sym == NULL) | 205 | if (sym == NULL) { |
| 208 | { | 206 | DSOerr(DSO_F_DLFCN_BIND_VAR, DSO_R_SYM_FAILURE); |
| 209 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_SYM_FAILURE); | ||
| 210 | ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); | 207 | ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); |
| 211 | return(NULL); | 208 | return (NULL); |
| 212 | } | ||
| 213 | return(sym); | ||
| 214 | } | 209 | } |
| 210 | return (sym); | ||
| 211 | } | ||
| 215 | 212 | ||
| 216 | static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname) | 213 | static DSO_FUNC_TYPE |
| 217 | { | 214 | dlfcn_bind_func(DSO *dso, const char *symname) |
| 215 | { | ||
| 218 | void *ptr; | 216 | void *ptr; |
| 219 | union { | 217 | union { |
| 220 | DSO_FUNC_TYPE sym; | 218 | DSO_FUNC_TYPE sym; |
| 221 | void *dlret; | 219 | void *dlret; |
| 222 | } u; | 220 | } u; |
| 223 | 221 | ||
| 224 | if((dso == NULL) || (symname == NULL)) | 222 | if ((dso == NULL) || (symname == NULL)) { |
| 225 | { | 223 | DSOerr(DSO_F_DLFCN_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER); |
| 226 | DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); | 224 | return (NULL); |
| 227 | return(NULL); | 225 | } |
| 228 | } | 226 | if (sk_void_num(dso->meth_data) < 1) { |
| 229 | if(sk_void_num(dso->meth_data) < 1) | 227 | DSOerr(DSO_F_DLFCN_BIND_FUNC, DSO_R_STACK_ERROR); |
| 230 | { | 228 | return (NULL); |
| 231 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR); | 229 | } |
| 232 | return(NULL); | ||
| 233 | } | ||
| 234 | ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); | 230 | ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); |
| 235 | if(ptr == NULL) | 231 | if (ptr == NULL) { |
| 236 | { | 232 | DSOerr(DSO_F_DLFCN_BIND_FUNC, DSO_R_NULL_HANDLE); |
| 237 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE); | 233 | return (NULL); |
| 238 | return(NULL); | 234 | } |
| 239 | } | ||
| 240 | u.dlret = dlsym(ptr, symname); | 235 | u.dlret = dlsym(ptr, symname); |
| 241 | if(u.dlret == NULL) | 236 | if (u.dlret == NULL) { |
| 242 | { | 237 | DSOerr(DSO_F_DLFCN_BIND_FUNC, DSO_R_SYM_FAILURE); |
| 243 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE); | ||
| 244 | ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); | 238 | ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); |
| 245 | return(NULL); | 239 | return (NULL); |
| 246 | } | ||
| 247 | return u.sym; | ||
| 248 | } | 240 | } |
| 241 | return u.sym; | ||
| 242 | } | ||
| 249 | 243 | ||
| 250 | static char *dlfcn_merger(DSO *dso, const char *filespec1, | 244 | static char * |
| 251 | const char *filespec2) | 245 | dlfcn_merger(DSO *dso, const char *filespec1, const char *filespec2) |
| 252 | { | 246 | { |
| 253 | char *merged; | 247 | char *merged; |
| 254 | size_t len; | 248 | size_t len; |
| 255 | 249 | ||
| 256 | if(!filespec1 && !filespec2) | 250 | if (!filespec1 && !filespec2) { |
| 257 | { | ||
| 258 | DSOerr(DSO_F_DLFCN_MERGER, | 251 | DSOerr(DSO_F_DLFCN_MERGER, |
| 259 | ERR_R_PASSED_NULL_PARAMETER); | 252 | ERR_R_PASSED_NULL_PARAMETER); |
| 260 | return(NULL); | 253 | return (NULL); |
| 261 | } | 254 | } |
| 262 | /* If the first file specification is a rooted path, it rules. | 255 | /* If the first file specification is a rooted path, it rules. |
| 263 | same goes if the second file specification is missing. */ | 256 | same goes if the second file specification is missing. */ |
| 264 | if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) | 257 | if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) { |
| 265 | { | ||
| 266 | len = strlen(filespec1) + 1; | 258 | len = strlen(filespec1) + 1; |
| 267 | merged = malloc(len); | 259 | merged = malloc(len); |
| 268 | if(!merged) | 260 | if (!merged) { |
| 269 | { | ||
| 270 | DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); | 261 | DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); |
| 271 | return(NULL); | 262 | return (NULL); |
| 272 | } | ||
| 273 | strlcpy(merged, filespec1, len); | ||
| 274 | } | 263 | } |
| 264 | strlcpy(merged, filespec1, len); | ||
| 265 | } | ||
| 275 | /* If the first file specification is missing, the second one rules. */ | 266 | /* If the first file specification is missing, the second one rules. */ |
| 276 | else if (!filespec1) | 267 | else if (!filespec1) { |
| 277 | { | ||
| 278 | len = strlen(filespec2) + 1; | 268 | len = strlen(filespec2) + 1; |
| 279 | merged = malloc(strlen(filespec2) + 1); | 269 | merged = malloc(strlen(filespec2) + 1); |
| 280 | if(!merged) | 270 | if (!merged) { |
| 281 | { | 271 | DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); |
| 282 | DSOerr(DSO_F_DLFCN_MERGER, | 272 | return (NULL); |
| 283 | ERR_R_MALLOC_FAILURE); | ||
| 284 | return(NULL); | ||
| 285 | } | ||
| 286 | strlcpy(merged, filespec2, len); | ||
| 287 | } | 273 | } |
| 288 | else | 274 | strlcpy(merged, filespec2, len); |
| 275 | } else | ||
| 289 | /* This part isn't as trivial as it looks. It assumes that | 276 | /* This part isn't as trivial as it looks. It assumes that |
| 290 | the second file specification really is a directory, and | 277 | the second file specification really is a directory, and |
| 291 | makes no checks whatsoever. Therefore, the result becomes | 278 | makes no checks whatsoever. Therefore, the result becomes |
| 292 | the concatenation of filespec2 followed by a slash followed | 279 | the concatenation of filespec2 followed by a slash followed |
| 293 | by filespec1. */ | 280 | by filespec1. */ |
| 294 | { | 281 | { |
| 295 | int spec2len, len; | 282 | int spec2len, len; |
| 296 | 283 | ||
| 297 | spec2len = strlen(filespec2); | 284 | spec2len = strlen(filespec2); |
| 298 | len = spec2len + (filespec1 ? strlen(filespec1) : 0); | 285 | len = spec2len + (filespec1 ? strlen(filespec1) : 0); |
| 299 | 286 | ||
| 300 | if(filespec2 && filespec2[spec2len - 1] == '/') | 287 | if (filespec2 && filespec2[spec2len - 1] == '/') { |
| 301 | { | ||
| 302 | spec2len--; | 288 | spec2len--; |
| 303 | len--; | 289 | len--; |
| 304 | } | 290 | } |
| 305 | merged = malloc(len + 2); | 291 | merged = malloc(len + 2); |
| 306 | if(!merged) | 292 | if (!merged) { |
| 307 | { | 293 | DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); |
| 308 | DSOerr(DSO_F_DLFCN_MERGER, | 294 | return (NULL); |
| 309 | ERR_R_MALLOC_FAILURE); | 295 | } |
| 310 | return(NULL); | ||
| 311 | } | ||
| 312 | strlcpy(merged, filespec2, len + 2); | 296 | strlcpy(merged, filespec2, len + 2); |
| 313 | merged[spec2len] = '/'; | 297 | merged[spec2len] = '/'; |
| 314 | strlcpy(&merged[spec2len + 1], filespec1, len + 1 - spec2len); | 298 | strlcpy(&merged[spec2len + 1], filespec1, len + 1 - spec2len); |
| 315 | } | ||
| 316 | return(merged); | ||
| 317 | } | 299 | } |
| 300 | return (merged); | ||
| 301 | } | ||
| 318 | 302 | ||
| 319 | #define DSO_ext ".so" | 303 | #define DSO_ext ".so" |
| 320 | #define DSO_extlen 3 | 304 | #define DSO_extlen 3 |
| 321 | 305 | ||
| 322 | static char *dlfcn_name_converter(DSO *dso, const char *filename) | 306 | static char * |
| 323 | { | 307 | dlfcn_name_converter(DSO *dso, const char *filename) |
| 308 | { | ||
| 324 | char *translated; | 309 | char *translated; |
| 325 | int len, rsize, transform; | 310 | int len, rsize, transform; |
| 326 | 311 | ||
| 327 | len = strlen(filename); | 312 | len = strlen(filename); |
| 328 | rsize = len + 1; | 313 | rsize = len + 1; |
| 329 | transform = (strstr(filename, "/") == NULL); | 314 | transform = (strstr(filename, "/") == NULL); |
| 330 | if(transform) | 315 | if (transform) { |
| 331 | { | ||
| 332 | /* We will convert this to "%s.so" or "lib%s.so" etc */ | 316 | /* We will convert this to "%s.so" or "lib%s.so" etc */ |
| 333 | rsize += DSO_extlen; /* The length of ".so" */ | 317 | rsize += DSO_extlen; /* The length of ".so" */ |
| 334 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) | 318 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) |
| 335 | rsize += 3; /* The length of "lib" */ | 319 | rsize += 3; /* The length of "lib" */ |
| 336 | } | 320 | } |
| 337 | translated = malloc(rsize); | 321 | translated = malloc(rsize); |
| 338 | if(translated == NULL) | 322 | if (translated == NULL) { |
| 339 | { | ||
| 340 | DSOerr(DSO_F_DLFCN_NAME_CONVERTER, | 323 | DSOerr(DSO_F_DLFCN_NAME_CONVERTER, |
| 341 | DSO_R_NAME_TRANSLATION_FAILED); | 324 | DSO_R_NAME_TRANSLATION_FAILED); |
| 342 | return(NULL); | 325 | return (NULL); |
| 343 | } | 326 | } |
| 344 | if(transform) | 327 | if (transform) { |
| 345 | { | ||
| 346 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) | 328 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) |
| 347 | snprintf(translated, rsize, "lib%s" DSO_ext, filename); | 329 | snprintf(translated, rsize, "lib%s" DSO_ext, filename); |
| 348 | else | 330 | else |
| 349 | snprintf(translated, rsize, "%s" DSO_ext, filename); | 331 | snprintf(translated, rsize, "%s" DSO_ext, filename); |
| 350 | } | 332 | } else |
| 351 | else | ||
| 352 | snprintf(translated, rsize, "%s", filename); | 333 | snprintf(translated, rsize, "%s", filename); |
| 353 | return(translated); | 334 | return (translated); |
| 354 | } | 335 | } |
| 355 | 336 | ||
| 356 | static int dlfcn_pathbyaddr(void *addr,char *path,int sz) | 337 | static int |
| 357 | { | 338 | dlfcn_pathbyaddr(void *addr, char *path, int sz) |
| 339 | { | ||
| 358 | Dl_info dli; | 340 | Dl_info dli; |
| 359 | int len; | 341 | int len; |
| 360 | 342 | ||
| 361 | if (addr == NULL) | 343 | if (addr == NULL) { |
| 362 | { | 344 | union{ |
| 363 | union { int(*f)(void*,char*,int); void *p; } t = | 345 | int(*f)(void*, char*, int); |
| 364 | { dlfcn_pathbyaddr }; | 346 | void *p; |
| 347 | } t = { dlfcn_pathbyaddr }; | ||
| 365 | addr = t.p; | 348 | addr = t.p; |
| 366 | } | 349 | } |
| 367 | 350 | ||
| 368 | if (dladdr(addr,&dli)) | 351 | if (dladdr(addr, &dli)) { |
| 369 | { | ||
| 370 | len = (int)strlen(dli.dli_fname); | 352 | len = (int)strlen(dli.dli_fname); |
| 371 | if (sz <= 0) return len+1; | 353 | if (sz <= 0) |
| 372 | if (len >= sz) len=sz-1; | 354 | return len + 1; |
| 373 | memcpy(path,dli.dli_fname,len); | 355 | if (len >= sz) |
| 374 | path[len++]=0; | 356 | len = sz - 1; |
| 357 | memcpy(path, dli.dli_fname, len); | ||
| 358 | path[len++] = 0; | ||
| 375 | return len; | 359 | return len; |
| 376 | } | 360 | } |
| 377 | 361 | ||
| 378 | ERR_add_error_data(4, "dlfcn_pathbyaddr(): ", dlerror()); | 362 | ERR_add_error_data(4, "dlfcn_pathbyaddr(): ", dlerror()); |
| 379 | return -1; | 363 | return -1; |
| 380 | } | 364 | } |
| 381 | 365 | ||
| 382 | static void *dlfcn_globallookup(const char *name) | 366 | static void * |
| 383 | { | 367 | dlfcn_globallookup(const char *name) |
| 384 | void *ret = NULL,*handle = dlopen(NULL,RTLD_LAZY); | 368 | { |
| 385 | 369 | void *ret = NULL, *handle = dlopen(NULL, RTLD_LAZY); | |
| 386 | if (handle) | 370 | |
| 387 | { | 371 | if (handle) { |
| 388 | ret = dlsym(handle,name); | 372 | ret = dlsym(handle, name); |
| 389 | dlclose(handle); | 373 | dlclose(handle); |
| 390 | } | 374 | } |
| 391 | 375 | ||
| 392 | return ret; | 376 | return ret; |
| 393 | } | 377 | } |
| 394 | #endif /* DSO_DLFCN */ | 378 | #endif /* DSO_DLFCN */ |
diff --git a/src/lib/libcrypto/dso/dso_err.c b/src/lib/libcrypto/dso/dso_err.c index 2bb07c2514..e0105f773c 100644 --- a/src/lib/libcrypto/dso/dso_err.c +++ b/src/lib/libcrypto/dso/dso_err.c | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | * are met: | 7 | * are met: |
| 8 | * | 8 | * |
| 9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * | 11 | * |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
| @@ -68,92 +68,89 @@ | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_DSO,func,0) | 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_DSO,func,0) |
| 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSO,0,reason) | 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSO,0,reason) |
| 70 | 70 | ||
| 71 | static ERR_STRING_DATA DSO_str_functs[]= | 71 | static ERR_STRING_DATA DSO_str_functs[]= { |
| 72 | { | 72 | {ERR_FUNC(DSO_F_BEOS_BIND_FUNC), "BEOS_BIND_FUNC"}, |
| 73 | {ERR_FUNC(DSO_F_BEOS_BIND_FUNC), "BEOS_BIND_FUNC"}, | 73 | {ERR_FUNC(DSO_F_BEOS_BIND_VAR), "BEOS_BIND_VAR"}, |
| 74 | {ERR_FUNC(DSO_F_BEOS_BIND_VAR), "BEOS_BIND_VAR"}, | 74 | {ERR_FUNC(DSO_F_BEOS_LOAD), "BEOS_LOAD"}, |
| 75 | {ERR_FUNC(DSO_F_BEOS_LOAD), "BEOS_LOAD"}, | 75 | {ERR_FUNC(DSO_F_BEOS_NAME_CONVERTER), "BEOS_NAME_CONVERTER"}, |
| 76 | {ERR_FUNC(DSO_F_BEOS_NAME_CONVERTER), "BEOS_NAME_CONVERTER"}, | 76 | {ERR_FUNC(DSO_F_BEOS_UNLOAD), "BEOS_UNLOAD"}, |
| 77 | {ERR_FUNC(DSO_F_BEOS_UNLOAD), "BEOS_UNLOAD"}, | 77 | {ERR_FUNC(DSO_F_DLFCN_BIND_FUNC), "DLFCN_BIND_FUNC"}, |
| 78 | {ERR_FUNC(DSO_F_DLFCN_BIND_FUNC), "DLFCN_BIND_FUNC"}, | 78 | {ERR_FUNC(DSO_F_DLFCN_BIND_VAR), "DLFCN_BIND_VAR"}, |
| 79 | {ERR_FUNC(DSO_F_DLFCN_BIND_VAR), "DLFCN_BIND_VAR"}, | 79 | {ERR_FUNC(DSO_F_DLFCN_LOAD), "DLFCN_LOAD"}, |
| 80 | {ERR_FUNC(DSO_F_DLFCN_LOAD), "DLFCN_LOAD"}, | 80 | {ERR_FUNC(DSO_F_DLFCN_MERGER), "DLFCN_MERGER"}, |
| 81 | {ERR_FUNC(DSO_F_DLFCN_MERGER), "DLFCN_MERGER"}, | 81 | {ERR_FUNC(DSO_F_DLFCN_NAME_CONVERTER), "DLFCN_NAME_CONVERTER"}, |
| 82 | {ERR_FUNC(DSO_F_DLFCN_NAME_CONVERTER), "DLFCN_NAME_CONVERTER"}, | 82 | {ERR_FUNC(DSO_F_DLFCN_UNLOAD), "DLFCN_UNLOAD"}, |
| 83 | {ERR_FUNC(DSO_F_DLFCN_UNLOAD), "DLFCN_UNLOAD"}, | 83 | {ERR_FUNC(DSO_F_DL_BIND_FUNC), "DL_BIND_FUNC"}, |
| 84 | {ERR_FUNC(DSO_F_DL_BIND_FUNC), "DL_BIND_FUNC"}, | 84 | {ERR_FUNC(DSO_F_DL_BIND_VAR), "DL_BIND_VAR"}, |
| 85 | {ERR_FUNC(DSO_F_DL_BIND_VAR), "DL_BIND_VAR"}, | 85 | {ERR_FUNC(DSO_F_DL_LOAD), "DL_LOAD"}, |
| 86 | {ERR_FUNC(DSO_F_DL_LOAD), "DL_LOAD"}, | 86 | {ERR_FUNC(DSO_F_DL_MERGER), "DL_MERGER"}, |
| 87 | {ERR_FUNC(DSO_F_DL_MERGER), "DL_MERGER"}, | 87 | {ERR_FUNC(DSO_F_DL_NAME_CONVERTER), "DL_NAME_CONVERTER"}, |
| 88 | {ERR_FUNC(DSO_F_DL_NAME_CONVERTER), "DL_NAME_CONVERTER"}, | 88 | {ERR_FUNC(DSO_F_DL_UNLOAD), "DL_UNLOAD"}, |
| 89 | {ERR_FUNC(DSO_F_DL_UNLOAD), "DL_UNLOAD"}, | 89 | {ERR_FUNC(DSO_F_DSO_BIND_FUNC), "DSO_bind_func"}, |
| 90 | {ERR_FUNC(DSO_F_DSO_BIND_FUNC), "DSO_bind_func"}, | 90 | {ERR_FUNC(DSO_F_DSO_BIND_VAR), "DSO_bind_var"}, |
| 91 | {ERR_FUNC(DSO_F_DSO_BIND_VAR), "DSO_bind_var"}, | 91 | {ERR_FUNC(DSO_F_DSO_CONVERT_FILENAME), "DSO_convert_filename"}, |
| 92 | {ERR_FUNC(DSO_F_DSO_CONVERT_FILENAME), "DSO_convert_filename"}, | 92 | {ERR_FUNC(DSO_F_DSO_CTRL), "DSO_ctrl"}, |
| 93 | {ERR_FUNC(DSO_F_DSO_CTRL), "DSO_ctrl"}, | 93 | {ERR_FUNC(DSO_F_DSO_FREE), "DSO_free"}, |
| 94 | {ERR_FUNC(DSO_F_DSO_FREE), "DSO_free"}, | 94 | {ERR_FUNC(DSO_F_DSO_GET_FILENAME), "DSO_get_filename"}, |
| 95 | {ERR_FUNC(DSO_F_DSO_GET_FILENAME), "DSO_get_filename"}, | 95 | {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"}, | 96 | {ERR_FUNC(DSO_F_DSO_GLOBAL_LOOKUP), "DSO_global_lookup"}, |
| 97 | {ERR_FUNC(DSO_F_DSO_GLOBAL_LOOKUP), "DSO_global_lookup"}, | 97 | {ERR_FUNC(DSO_F_DSO_LOAD), "DSO_load"}, |
| 98 | {ERR_FUNC(DSO_F_DSO_LOAD), "DSO_load"}, | 98 | {ERR_FUNC(DSO_F_DSO_MERGE), "DSO_merge"}, |
| 99 | {ERR_FUNC(DSO_F_DSO_MERGE), "DSO_merge"}, | 99 | {ERR_FUNC(DSO_F_DSO_NEW_METHOD), "DSO_new_method"}, |
| 100 | {ERR_FUNC(DSO_F_DSO_NEW_METHOD), "DSO_new_method"}, | 100 | {ERR_FUNC(DSO_F_DSO_PATHBYADDR), "DSO_pathbyaddr"}, |
| 101 | {ERR_FUNC(DSO_F_DSO_PATHBYADDR), "DSO_pathbyaddr"}, | 101 | {ERR_FUNC(DSO_F_DSO_SET_FILENAME), "DSO_set_filename"}, |
| 102 | {ERR_FUNC(DSO_F_DSO_SET_FILENAME), "DSO_set_filename"}, | 102 | {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"}, | 103 | {ERR_FUNC(DSO_F_DSO_UP_REF), "DSO_up_ref"}, |
| 104 | {ERR_FUNC(DSO_F_DSO_UP_REF), "DSO_up_ref"}, | 104 | {ERR_FUNC(DSO_F_GLOBAL_LOOKUP_FUNC), "GLOBAL_LOOKUP_FUNC"}, |
| 105 | {ERR_FUNC(DSO_F_GLOBAL_LOOKUP_FUNC), "GLOBAL_LOOKUP_FUNC"}, | 105 | {ERR_FUNC(DSO_F_PATHBYADDR), "PATHBYADDR"}, |
| 106 | {ERR_FUNC(DSO_F_PATHBYADDR), "PATHBYADDR"}, | 106 | {ERR_FUNC(DSO_F_VMS_BIND_SYM), "VMS_BIND_SYM"}, |
| 107 | {ERR_FUNC(DSO_F_VMS_BIND_SYM), "VMS_BIND_SYM"}, | 107 | {ERR_FUNC(DSO_F_VMS_LOAD), "VMS_LOAD"}, |
| 108 | {ERR_FUNC(DSO_F_VMS_LOAD), "VMS_LOAD"}, | 108 | {ERR_FUNC(DSO_F_VMS_MERGER), "VMS_MERGER"}, |
| 109 | {ERR_FUNC(DSO_F_VMS_MERGER), "VMS_MERGER"}, | 109 | {ERR_FUNC(DSO_F_VMS_UNLOAD), "VMS_UNLOAD"}, |
| 110 | {ERR_FUNC(DSO_F_VMS_UNLOAD), "VMS_UNLOAD"}, | 110 | {ERR_FUNC(DSO_F_WIN32_BIND_FUNC), "WIN32_BIND_FUNC"}, |
| 111 | {ERR_FUNC(DSO_F_WIN32_BIND_FUNC), "WIN32_BIND_FUNC"}, | 111 | {ERR_FUNC(DSO_F_WIN32_BIND_VAR), "WIN32_BIND_VAR"}, |
| 112 | {ERR_FUNC(DSO_F_WIN32_BIND_VAR), "WIN32_BIND_VAR"}, | 112 | {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP), "WIN32_GLOBALLOOKUP"}, |
| 113 | {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP), "WIN32_GLOBALLOOKUP"}, | 113 | {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP_FUNC), "WIN32_GLOBALLOOKUP_FUNC"}, |
| 114 | {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP_FUNC), "WIN32_GLOBALLOOKUP_FUNC"}, | 114 | {ERR_FUNC(DSO_F_WIN32_JOINER), "WIN32_JOINER"}, |
| 115 | {ERR_FUNC(DSO_F_WIN32_JOINER), "WIN32_JOINER"}, | 115 | {ERR_FUNC(DSO_F_WIN32_LOAD), "WIN32_LOAD"}, |
| 116 | {ERR_FUNC(DSO_F_WIN32_LOAD), "WIN32_LOAD"}, | 116 | {ERR_FUNC(DSO_F_WIN32_MERGER), "WIN32_MERGER"}, |
| 117 | {ERR_FUNC(DSO_F_WIN32_MERGER), "WIN32_MERGER"}, | 117 | {ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"}, |
| 118 | {ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"}, | 118 | {ERR_FUNC(DSO_F_WIN32_PATHBYADDR), "WIN32_PATHBYADDR"}, |
| 119 | {ERR_FUNC(DSO_F_WIN32_PATHBYADDR), "WIN32_PATHBYADDR"}, | 119 | {ERR_FUNC(DSO_F_WIN32_SPLITTER), "WIN32_SPLITTER"}, |
| 120 | {ERR_FUNC(DSO_F_WIN32_SPLITTER), "WIN32_SPLITTER"}, | 120 | {ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"}, |
| 121 | {ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"}, | 121 | {0, NULL} |
| 122 | {0,NULL} | 122 | }; |
| 123 | }; | ||
| 124 | 123 | ||
| 125 | static ERR_STRING_DATA DSO_str_reasons[]= | 124 | static ERR_STRING_DATA DSO_str_reasons[]= { |
| 126 | { | 125 | {ERR_REASON(DSO_R_CTRL_FAILED) , "control command failed"}, |
| 127 | {ERR_REASON(DSO_R_CTRL_FAILED) ,"control command failed"}, | 126 | {ERR_REASON(DSO_R_DSO_ALREADY_LOADED) , "dso already loaded"}, |
| 128 | {ERR_REASON(DSO_R_DSO_ALREADY_LOADED) ,"dso already loaded"}, | 127 | {ERR_REASON(DSO_R_EMPTY_FILE_STRUCTURE) , "empty file structure"}, |
| 129 | {ERR_REASON(DSO_R_EMPTY_FILE_STRUCTURE) ,"empty file structure"}, | 128 | {ERR_REASON(DSO_R_FAILURE) , "failure"}, |
| 130 | {ERR_REASON(DSO_R_FAILURE) ,"failure"}, | 129 | {ERR_REASON(DSO_R_FILENAME_TOO_BIG) , "filename too big"}, |
| 131 | {ERR_REASON(DSO_R_FILENAME_TOO_BIG) ,"filename too big"}, | 130 | {ERR_REASON(DSO_R_FINISH_FAILED) , "cleanup method function failed"}, |
| 132 | {ERR_REASON(DSO_R_FINISH_FAILED) ,"cleanup method function failed"}, | 131 | {ERR_REASON(DSO_R_INCORRECT_FILE_SYNTAX) , "incorrect file syntax"}, |
| 133 | {ERR_REASON(DSO_R_INCORRECT_FILE_SYNTAX) ,"incorrect file syntax"}, | 132 | {ERR_REASON(DSO_R_LOAD_FAILED) , "could not load the shared library"}, |
| 134 | {ERR_REASON(DSO_R_LOAD_FAILED) ,"could not load the shared library"}, | 133 | {ERR_REASON(DSO_R_NAME_TRANSLATION_FAILED), "name translation failed"}, |
| 135 | {ERR_REASON(DSO_R_NAME_TRANSLATION_FAILED),"name translation failed"}, | 134 | {ERR_REASON(DSO_R_NO_FILENAME) , "no filename"}, |
| 136 | {ERR_REASON(DSO_R_NO_FILENAME) ,"no filename"}, | 135 | {ERR_REASON(DSO_R_NO_FILE_SPECIFICATION) , "no file specification"}, |
| 137 | {ERR_REASON(DSO_R_NO_FILE_SPECIFICATION) ,"no file specification"}, | 136 | {ERR_REASON(DSO_R_NULL_HANDLE) , "a null shared library handle was used"}, |
| 138 | {ERR_REASON(DSO_R_NULL_HANDLE) ,"a null shared library handle was used"}, | 137 | {ERR_REASON(DSO_R_SET_FILENAME_FAILED) , "set filename failed"}, |
| 139 | {ERR_REASON(DSO_R_SET_FILENAME_FAILED) ,"set filename failed"}, | 138 | {ERR_REASON(DSO_R_STACK_ERROR) , "the meth_data stack is corrupt"}, |
| 140 | {ERR_REASON(DSO_R_STACK_ERROR) ,"the meth_data stack is corrupt"}, | 139 | {ERR_REASON(DSO_R_SYM_FAILURE) , "could not bind to the requested symbol name"}, |
| 141 | {ERR_REASON(DSO_R_SYM_FAILURE) ,"could not bind to the requested symbol name"}, | 140 | {ERR_REASON(DSO_R_UNLOAD_FAILED) , "could not unload the shared library"}, |
| 142 | {ERR_REASON(DSO_R_UNLOAD_FAILED) ,"could not unload the shared library"}, | 141 | {ERR_REASON(DSO_R_UNSUPPORTED) , "functionality not supported"}, |
| 143 | {ERR_REASON(DSO_R_UNSUPPORTED) ,"functionality not supported"}, | 142 | {0, NULL} |
| 144 | {0,NULL} | 143 | }; |
| 145 | }; | ||
| 146 | 144 | ||
| 147 | #endif | 145 | #endif |
| 148 | 146 | ||
| 149 | void ERR_load_DSO_strings(void) | 147 | void |
| 150 | { | 148 | ERR_load_DSO_strings(void) |
| 149 | { | ||
| 151 | #ifndef OPENSSL_NO_ERR | 150 | #ifndef OPENSSL_NO_ERR |
| 152 | 151 | if (ERR_func_error_string(DSO_str_functs[0].error) == NULL) { | |
| 153 | if (ERR_func_error_string(DSO_str_functs[0].error) == NULL) | 152 | ERR_load_strings(0, DSO_str_functs); |
| 154 | { | 153 | ERR_load_strings(0, DSO_str_reasons); |
| 155 | ERR_load_strings(0,DSO_str_functs); | ||
| 156 | ERR_load_strings(0,DSO_str_reasons); | ||
| 157 | } | ||
| 158 | #endif | ||
| 159 | } | 154 | } |
| 155 | #endif | ||
| 156 | } | ||
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c index 2f77242d47..1ee4e45dce 100644 --- a/src/lib/libcrypto/dso/dso_lib.c +++ b/src/lib/libcrypto/dso/dso_lib.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -63,230 +63,223 @@ | |||
| 63 | 63 | ||
| 64 | static DSO_METHOD *default_DSO_meth = NULL; | 64 | static DSO_METHOD *default_DSO_meth = NULL; |
| 65 | 65 | ||
| 66 | DSO *DSO_new(void) | 66 | DSO * |
| 67 | { | 67 | DSO_new(void) |
| 68 | return(DSO_new_method(NULL)); | 68 | { |
| 69 | } | 69 | return (DSO_new_method(NULL)); |
| 70 | } | ||
| 70 | 71 | ||
| 71 | void DSO_set_default_method(DSO_METHOD *meth) | 72 | void |
| 72 | { | 73 | DSO_set_default_method(DSO_METHOD *meth) |
| 74 | { | ||
| 73 | default_DSO_meth = meth; | 75 | default_DSO_meth = meth; |
| 74 | } | 76 | } |
| 75 | 77 | ||
| 76 | DSO_METHOD *DSO_get_default_method(void) | 78 | DSO_METHOD * |
| 77 | { | 79 | DSO_get_default_method(void) |
| 78 | return(default_DSO_meth); | 80 | { |
| 79 | } | 81 | return (default_DSO_meth); |
| 80 | 82 | } | |
| 81 | DSO_METHOD *DSO_get_method(DSO *dso) | 83 | |
| 82 | { | 84 | DSO_METHOD * |
| 83 | return(dso->meth); | 85 | DSO_get_method(DSO *dso) |
| 84 | } | 86 | { |
| 85 | 87 | return (dso->meth); | |
| 86 | DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth) | 88 | } |
| 87 | { | 89 | |
| 90 | DSO_METHOD * | ||
| 91 | DSO_set_method(DSO *dso, DSO_METHOD *meth) | ||
| 92 | { | ||
| 88 | DSO_METHOD *mtmp; | 93 | DSO_METHOD *mtmp; |
| 94 | |||
| 89 | mtmp = dso->meth; | 95 | mtmp = dso->meth; |
| 90 | dso->meth = meth; | 96 | dso->meth = meth; |
| 91 | return(mtmp); | 97 | return (mtmp); |
| 92 | } | 98 | } |
| 93 | 99 | ||
| 94 | DSO *DSO_new_method(DSO_METHOD *meth) | 100 | DSO * |
| 95 | { | 101 | DSO_new_method(DSO_METHOD *meth) |
| 102 | { | ||
| 96 | DSO *ret; | 103 | DSO *ret; |
| 97 | 104 | ||
| 98 | if(default_DSO_meth == NULL) | 105 | if (default_DSO_meth == NULL) |
| 99 | /* We default to DSO_METH_openssl() which in turn defaults | 106 | /* We default to DSO_METH_openssl() which in turn defaults |
| 100 | * to stealing the "best available" method. Will fallback | 107 | * to stealing the "best available" method. Will fallback |
| 101 | * to DSO_METH_null() in the worst case. */ | 108 | * to DSO_METH_null() in the worst case. */ |
| 102 | default_DSO_meth = DSO_METHOD_openssl(); | 109 | default_DSO_meth = DSO_METHOD_openssl(); |
| 103 | ret = (DSO *)malloc(sizeof(DSO)); | 110 | ret = (DSO *)malloc(sizeof(DSO)); |
| 104 | if(ret == NULL) | 111 | if (ret == NULL) { |
| 105 | { | 112 | DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE); |
| 106 | DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); | 113 | return (NULL); |
| 107 | return(NULL); | 114 | } |
| 108 | } | ||
| 109 | memset(ret, 0, sizeof(DSO)); | 115 | memset(ret, 0, sizeof(DSO)); |
| 110 | ret->meth_data = sk_void_new_null(); | 116 | ret->meth_data = sk_void_new_null(); |
| 111 | if(ret->meth_data == NULL) | 117 | if (ret->meth_data == NULL) { |
| 112 | { | ||
| 113 | /* sk_new doesn't generate any errors so we do */ | 118 | /* sk_new doesn't generate any errors so we do */ |
| 114 | DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); | 119 | DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE); |
| 115 | free(ret); | 120 | free(ret); |
| 116 | return(NULL); | 121 | return (NULL); |
| 117 | } | 122 | } |
| 118 | if(meth == NULL) | 123 | if (meth == NULL) |
| 119 | ret->meth = default_DSO_meth; | 124 | ret->meth = default_DSO_meth; |
| 120 | else | 125 | else |
| 121 | ret->meth = meth; | 126 | ret->meth = meth; |
| 122 | ret->references = 1; | 127 | ret->references = 1; |
| 123 | if((ret->meth->init != NULL) && !ret->meth->init(ret)) | 128 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { |
| 124 | { | ||
| 125 | free(ret); | 129 | free(ret); |
| 126 | ret=NULL; | 130 | ret = NULL; |
| 127 | } | ||
| 128 | return(ret); | ||
| 129 | } | 131 | } |
| 132 | return (ret); | ||
| 133 | } | ||
| 130 | 134 | ||
| 131 | int DSO_free(DSO *dso) | 135 | int |
| 132 | { | 136 | DSO_free(DSO *dso) |
| 133 | int i; | 137 | { |
| 134 | 138 | int i; | |
| 135 | if(dso == NULL) | 139 | |
| 136 | { | 140 | if (dso == NULL) { |
| 137 | DSOerr(DSO_F_DSO_FREE,ERR_R_PASSED_NULL_PARAMETER); | 141 | DSOerr(DSO_F_DSO_FREE, ERR_R_PASSED_NULL_PARAMETER); |
| 138 | return(0); | 142 | return (0); |
| 139 | } | ||
| 140 | |||
| 141 | i=CRYPTO_add(&dso->references,-1,CRYPTO_LOCK_DSO); | ||
| 142 | if(i > 0) return(1); | ||
| 143 | |||
| 144 | if((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) | ||
| 145 | { | ||
| 146 | DSOerr(DSO_F_DSO_FREE,DSO_R_UNLOAD_FAILED); | ||
| 147 | return(0); | ||
| 148 | } | ||
| 149 | |||
| 150 | if((dso->meth->finish != NULL) && !dso->meth->finish(dso)) | ||
| 151 | { | ||
| 152 | DSOerr(DSO_F_DSO_FREE,DSO_R_FINISH_FAILED); | ||
| 153 | return(0); | ||
| 154 | } | ||
| 155 | |||
| 156 | sk_void_free(dso->meth_data); | ||
| 157 | if(dso->filename != NULL) | ||
| 158 | free(dso->filename); | ||
| 159 | if(dso->loaded_filename != NULL) | ||
| 160 | free(dso->loaded_filename); | ||
| 161 | |||
| 162 | free(dso); | ||
| 163 | return(1); | ||
| 164 | } | 143 | } |
| 165 | 144 | ||
| 166 | int DSO_flags(DSO *dso) | 145 | i = CRYPTO_add(&dso->references, -1, CRYPTO_LOCK_DSO); |
| 167 | { | 146 | if (i > 0) |
| 168 | return((dso == NULL) ? 0 : dso->flags); | 147 | return (1); |
| 148 | |||
| 149 | if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) { | ||
| 150 | DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED); | ||
| 151 | return (0); | ||
| 169 | } | 152 | } |
| 170 | 153 | ||
| 154 | if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) { | ||
| 155 | DSOerr(DSO_F_DSO_FREE, DSO_R_FINISH_FAILED); | ||
| 156 | return (0); | ||
| 157 | } | ||
| 171 | 158 | ||
| 172 | int DSO_up_ref(DSO *dso) | 159 | sk_void_free(dso->meth_data); |
| 173 | { | 160 | if (dso->filename != NULL) |
| 174 | if (dso == NULL) | 161 | free(dso->filename); |
| 175 | { | 162 | if (dso->loaded_filename != NULL) |
| 176 | DSOerr(DSO_F_DSO_UP_REF,ERR_R_PASSED_NULL_PARAMETER); | 163 | free(dso->loaded_filename); |
| 177 | return(0); | ||
| 178 | } | ||
| 179 | 164 | ||
| 180 | CRYPTO_add(&dso->references,1,CRYPTO_LOCK_DSO); | 165 | free(dso); |
| 181 | return(1); | 166 | return (1); |
| 167 | } | ||
| 168 | |||
| 169 | int | ||
| 170 | DSO_flags(DSO *dso) | ||
| 171 | { | ||
| 172 | return ((dso == NULL) ? 0 : dso->flags); | ||
| 173 | } | ||
| 174 | |||
| 175 | |||
| 176 | int | ||
| 177 | DSO_up_ref(DSO *dso) | ||
| 178 | { | ||
| 179 | if (dso == NULL) { | ||
| 180 | DSOerr(DSO_F_DSO_UP_REF, ERR_R_PASSED_NULL_PARAMETER); | ||
| 181 | return (0); | ||
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags) | 184 | CRYPTO_add(&dso->references, 1, CRYPTO_LOCK_DSO); |
| 185 | { | 185 | return (1); |
| 186 | } | ||
| 187 | |||
| 188 | DSO * | ||
| 189 | DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags) | ||
| 190 | { | ||
| 186 | DSO *ret; | 191 | DSO *ret; |
| 187 | int allocated = 0; | 192 | int allocated = 0; |
| 188 | 193 | ||
| 189 | if(dso == NULL) | 194 | if (dso == NULL) { |
| 190 | { | ||
| 191 | ret = DSO_new_method(meth); | 195 | ret = DSO_new_method(meth); |
| 192 | if(ret == NULL) | 196 | if (ret == NULL) { |
| 193 | { | 197 | DSOerr(DSO_F_DSO_LOAD, ERR_R_MALLOC_FAILURE); |
| 194 | DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE); | ||
| 195 | goto err; | 198 | goto err; |
| 196 | } | 199 | } |
| 197 | allocated = 1; | 200 | allocated = 1; |
| 198 | /* Pass the provided flags to the new DSO object */ | 201 | /* Pass the provided flags to the new DSO object */ |
| 199 | if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) | 202 | if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) { |
| 200 | { | 203 | DSOerr(DSO_F_DSO_LOAD, DSO_R_CTRL_FAILED); |
| 201 | DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED); | ||
| 202 | goto err; | 204 | goto err; |
| 203 | } | ||
| 204 | } | 205 | } |
| 205 | else | 206 | } else |
| 206 | ret = dso; | 207 | ret = dso; |
| 207 | /* Don't load if we're currently already loaded */ | 208 | /* Don't load if we're currently already loaded */ |
| 208 | if(ret->filename != NULL) | 209 | if (ret->filename != NULL) { |
| 209 | { | 210 | DSOerr(DSO_F_DSO_LOAD, DSO_R_DSO_ALREADY_LOADED); |
| 210 | DSOerr(DSO_F_DSO_LOAD,DSO_R_DSO_ALREADY_LOADED); | ||
| 211 | goto err; | 211 | goto err; |
| 212 | } | 212 | } |
| 213 | /* filename can only be NULL if we were passed a dso that already has | 213 | /* filename can only be NULL if we were passed a dso that already has |
| 214 | * one set. */ | 214 | * one set. */ |
| 215 | if(filename != NULL) | 215 | if (filename != NULL) |
| 216 | if(!DSO_set_filename(ret, filename)) | 216 | if (!DSO_set_filename(ret, filename)) { |
| 217 | { | 217 | DSOerr(DSO_F_DSO_LOAD, DSO_R_SET_FILENAME_FAILED); |
| 218 | DSOerr(DSO_F_DSO_LOAD,DSO_R_SET_FILENAME_FAILED); | 218 | goto err; |
| 219 | goto err; | 219 | } |
| 220 | } | ||
| 221 | filename = ret->filename; | 220 | filename = ret->filename; |
| 222 | if(filename == NULL) | 221 | if (filename == NULL) { |
| 223 | { | 222 | DSOerr(DSO_F_DSO_LOAD, DSO_R_NO_FILENAME); |
| 224 | DSOerr(DSO_F_DSO_LOAD,DSO_R_NO_FILENAME); | ||
| 225 | goto err; | 223 | goto err; |
| 226 | } | 224 | } |
| 227 | if(ret->meth->dso_load == NULL) | 225 | if (ret->meth->dso_load == NULL) { |
| 228 | { | 226 | DSOerr(DSO_F_DSO_LOAD, DSO_R_UNSUPPORTED); |
| 229 | DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED); | ||
| 230 | goto err; | 227 | goto err; |
| 231 | } | 228 | } |
| 232 | if(!ret->meth->dso_load(ret)) | 229 | if (!ret->meth->dso_load(ret)) { |
| 233 | { | 230 | DSOerr(DSO_F_DSO_LOAD, DSO_R_LOAD_FAILED); |
| 234 | DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED); | ||
| 235 | goto err; | 231 | goto err; |
| 236 | } | 232 | } |
| 237 | /* Load succeeded */ | 233 | /* Load succeeded */ |
| 238 | return(ret); | 234 | return (ret); |
| 235 | |||
| 239 | err: | 236 | err: |
| 240 | if(allocated) | 237 | if (allocated) |
| 241 | DSO_free(ret); | 238 | DSO_free(ret); |
| 242 | return(NULL); | 239 | return (NULL); |
| 243 | } | 240 | } |
| 244 | 241 | ||
| 245 | void *DSO_bind_var(DSO *dso, const char *symname) | 242 | void * |
| 246 | { | 243 | DSO_bind_var(DSO *dso, const char *symname) |
| 244 | { | ||
| 247 | void *ret = NULL; | 245 | void *ret = NULL; |
| 248 | 246 | ||
| 249 | if((dso == NULL) || (symname == NULL)) | 247 | if ((dso == NULL) || (symname == NULL)) { |
| 250 | { | 248 | DSOerr(DSO_F_DSO_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER); |
| 251 | DSOerr(DSO_F_DSO_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | 249 | return (NULL); |
| 252 | return(NULL); | 250 | } |
| 253 | } | 251 | if (dso->meth->dso_bind_var == NULL) { |
| 254 | if(dso->meth->dso_bind_var == NULL) | 252 | DSOerr(DSO_F_DSO_BIND_VAR, DSO_R_UNSUPPORTED); |
| 255 | { | 253 | return (NULL); |
| 256 | DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_UNSUPPORTED); | ||
| 257 | return(NULL); | ||
| 258 | } | ||
| 259 | if((ret = dso->meth->dso_bind_var(dso, symname)) == NULL) | ||
| 260 | { | ||
| 261 | DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_SYM_FAILURE); | ||
| 262 | return(NULL); | ||
| 263 | } | ||
| 264 | /* Success */ | ||
| 265 | return(ret); | ||
| 266 | } | 254 | } |
| 255 | if ((ret = dso->meth->dso_bind_var(dso, symname)) == NULL) { | ||
| 256 | DSOerr(DSO_F_DSO_BIND_VAR, DSO_R_SYM_FAILURE); | ||
| 257 | return (NULL); | ||
| 258 | } | ||
| 259 | /* Success */ | ||
| 260 | return (ret); | ||
| 261 | } | ||
| 267 | 262 | ||
| 268 | DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname) | 263 | DSO_FUNC_TYPE |
| 269 | { | 264 | DSO_bind_func(DSO *dso, const char *symname) |
| 265 | { | ||
| 270 | DSO_FUNC_TYPE ret = NULL; | 266 | DSO_FUNC_TYPE ret = NULL; |
| 271 | 267 | ||
| 272 | if((dso == NULL) || (symname == NULL)) | 268 | if ((dso == NULL) || (symname == NULL)) { |
| 273 | { | 269 | DSOerr(DSO_F_DSO_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER); |
| 274 | DSOerr(DSO_F_DSO_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); | 270 | return (NULL); |
| 275 | return(NULL); | ||
| 276 | } | ||
| 277 | if(dso->meth->dso_bind_func == NULL) | ||
| 278 | { | ||
| 279 | DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_UNSUPPORTED); | ||
| 280 | return(NULL); | ||
| 281 | } | ||
| 282 | if((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) | ||
| 283 | { | ||
| 284 | DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_SYM_FAILURE); | ||
| 285 | return(NULL); | ||
| 286 | } | ||
| 287 | /* Success */ | ||
| 288 | return(ret); | ||
| 289 | } | 271 | } |
| 272 | if (dso->meth->dso_bind_func == NULL) { | ||
| 273 | DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_UNSUPPORTED); | ||
| 274 | return (NULL); | ||
| 275 | } | ||
| 276 | if ((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) { | ||
| 277 | DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_SYM_FAILURE); | ||
| 278 | return (NULL); | ||
| 279 | } | ||
| 280 | /* Success */ | ||
| 281 | return (ret); | ||
| 282 | } | ||
| 290 | 283 | ||
| 291 | /* I don't really like these *_ctrl functions very much to be perfectly | 284 | /* I don't really like these *_ctrl functions very much to be perfectly |
| 292 | * honest. For one thing, I think I have to return a negative value for | 285 | * honest. For one thing, I think I have to return a negative value for |
| @@ -296,178 +289,171 @@ DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname) | |||
| 296 | * odd times. I'd prefer "output" values to be passed by reference and | 289 | * odd times. I'd prefer "output" values to be passed by reference and |
| 297 | * the return value as success/failure like usual ... but we conform | 290 | * the return value as success/failure like usual ... but we conform |
| 298 | * when we must... :-) */ | 291 | * when we must... :-) */ |
| 299 | long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) | 292 | long |
| 300 | { | 293 | DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) |
| 301 | if(dso == NULL) | 294 | { |
| 302 | { | 295 | if (dso == NULL) { |
| 303 | DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER); | 296 | DSOerr(DSO_F_DSO_CTRL, ERR_R_PASSED_NULL_PARAMETER); |
| 304 | return(-1); | 297 | return (-1); |
| 305 | } | 298 | } |
| 306 | /* We should intercept certain generic commands and only pass control | 299 | /* We should intercept certain generic commands and only pass control |
| 307 | * to the method-specific ctrl() function if it's something we don't | 300 | * to the method-specific ctrl() function if it's something we don't |
| 308 | * handle. */ | 301 | * handle. */ |
| 309 | switch(cmd) | 302 | switch (cmd) { |
| 310 | { | ||
| 311 | case DSO_CTRL_GET_FLAGS: | 303 | case DSO_CTRL_GET_FLAGS: |
| 312 | return dso->flags; | 304 | return dso->flags; |
| 313 | case DSO_CTRL_SET_FLAGS: | 305 | case DSO_CTRL_SET_FLAGS: |
| 314 | dso->flags = (int)larg; | 306 | dso->flags = (int)larg; |
| 315 | return(0); | 307 | return (0); |
| 316 | case DSO_CTRL_OR_FLAGS: | 308 | case DSO_CTRL_OR_FLAGS: |
| 317 | dso->flags |= (int)larg; | 309 | dso->flags |= (int)larg; |
| 318 | return(0); | 310 | return (0); |
| 319 | default: | 311 | default: |
| 320 | break; | 312 | break; |
| 321 | } | ||
| 322 | if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) | ||
| 323 | { | ||
| 324 | DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED); | ||
| 325 | return(-1); | ||
| 326 | } | ||
| 327 | return(dso->meth->dso_ctrl(dso,cmd,larg,parg)); | ||
| 328 | } | 313 | } |
| 329 | 314 | if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) { | |
| 330 | int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb, | 315 | DSOerr(DSO_F_DSO_CTRL, DSO_R_UNSUPPORTED); |
| 331 | DSO_NAME_CONVERTER_FUNC *oldcb) | 316 | return (-1); |
| 332 | { | 317 | } |
| 333 | if(dso == NULL) | 318 | return (dso->meth->dso_ctrl(dso, cmd, larg, parg)); |
| 334 | { | 319 | } |
| 320 | |||
| 321 | int | ||
| 322 | DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb, | ||
| 323 | DSO_NAME_CONVERTER_FUNC *oldcb) | ||
| 324 | { | ||
| 325 | if (dso == NULL) { | ||
| 335 | DSOerr(DSO_F_DSO_SET_NAME_CONVERTER, | 326 | DSOerr(DSO_F_DSO_SET_NAME_CONVERTER, |
| 336 | ERR_R_PASSED_NULL_PARAMETER); | 327 | ERR_R_PASSED_NULL_PARAMETER); |
| 337 | return(0); | 328 | return (0); |
| 338 | } | 329 | } |
| 339 | if(oldcb) | 330 | if (oldcb) |
| 340 | *oldcb = dso->name_converter; | 331 | *oldcb = dso->name_converter; |
| 341 | dso->name_converter = cb; | 332 | dso->name_converter = cb; |
| 342 | return(1); | 333 | return (1); |
| 343 | } | 334 | } |
| 344 | 335 | ||
| 345 | const char *DSO_get_filename(DSO *dso) | 336 | const char * |
| 346 | { | 337 | DSO_get_filename(DSO *dso) |
| 347 | if(dso == NULL) | 338 | { |
| 348 | { | 339 | if (dso == NULL) { |
| 349 | DSOerr(DSO_F_DSO_GET_FILENAME,ERR_R_PASSED_NULL_PARAMETER); | 340 | DSOerr(DSO_F_DSO_GET_FILENAME, ERR_R_PASSED_NULL_PARAMETER); |
| 350 | return(NULL); | 341 | return (NULL); |
| 351 | } | ||
| 352 | return(dso->filename); | ||
| 353 | } | 342 | } |
| 343 | return (dso->filename); | ||
| 344 | } | ||
| 354 | 345 | ||
| 355 | int DSO_set_filename(DSO *dso, const char *filename) | 346 | int |
| 356 | { | 347 | DSO_set_filename(DSO *dso, const char *filename) |
| 348 | { | ||
| 357 | char *copied; | 349 | char *copied; |
| 358 | 350 | ||
| 359 | if((dso == NULL) || (filename == NULL)) | 351 | if ((dso == NULL) || (filename == NULL)) { |
| 360 | { | 352 | DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_PASSED_NULL_PARAMETER); |
| 361 | DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_PASSED_NULL_PARAMETER); | 353 | return (0); |
| 362 | return(0); | 354 | } |
| 363 | } | 355 | if (dso->loaded_filename) { |
| 364 | if(dso->loaded_filename) | 356 | DSOerr(DSO_F_DSO_SET_FILENAME, DSO_R_DSO_ALREADY_LOADED); |
| 365 | { | 357 | return (0); |
| 366 | DSOerr(DSO_F_DSO_SET_FILENAME,DSO_R_DSO_ALREADY_LOADED); | 358 | } |
| 367 | return(0); | ||
| 368 | } | ||
| 369 | /* We'll duplicate filename */ | 359 | /* We'll duplicate filename */ |
| 370 | copied = malloc(strlen(filename) + 1); | 360 | copied = malloc(strlen(filename) + 1); |
| 371 | if(copied == NULL) | 361 | if (copied == NULL) { |
| 372 | { | 362 | DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE); |
| 373 | DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE); | 363 | return (0); |
| 374 | return(0); | 364 | } |
| 375 | } | ||
| 376 | strlcpy(copied, filename, strlen(filename) + 1); | 365 | strlcpy(copied, filename, strlen(filename) + 1); |
| 377 | if(dso->filename) | 366 | if (dso->filename) |
| 378 | free(dso->filename); | 367 | free(dso->filename); |
| 379 | dso->filename = copied; | 368 | dso->filename = copied; |
| 380 | return(1); | 369 | return (1); |
| 381 | } | 370 | } |
| 382 | 371 | ||
| 383 | char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2) | 372 | char * |
| 384 | { | 373 | DSO_merge(DSO *dso, const char *filespec1, const char *filespec2) |
| 374 | { | ||
| 385 | char *result = NULL; | 375 | char *result = NULL; |
| 386 | 376 | ||
| 387 | if(dso == NULL || filespec1 == NULL) | 377 | if (dso == NULL || filespec1 == NULL) { |
| 388 | { | 378 | DSOerr(DSO_F_DSO_MERGE, ERR_R_PASSED_NULL_PARAMETER); |
| 389 | DSOerr(DSO_F_DSO_MERGE,ERR_R_PASSED_NULL_PARAMETER); | 379 | return (NULL); |
| 390 | return(NULL); | 380 | } |
| 391 | } | 381 | if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) { |
| 392 | if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) | 382 | if (dso->merger != NULL) |
| 393 | { | ||
| 394 | if(dso->merger != NULL) | ||
| 395 | result = dso->merger(dso, filespec1, filespec2); | 383 | result = dso->merger(dso, filespec1, filespec2); |
| 396 | else if(dso->meth->dso_merger != NULL) | 384 | else if (dso->meth->dso_merger != NULL) |
| 397 | result = dso->meth->dso_merger(dso, | 385 | result = dso->meth->dso_merger(dso, |
| 398 | filespec1, filespec2); | 386 | filespec1, filespec2); |
| 399 | } | ||
| 400 | return(result); | ||
| 401 | } | 387 | } |
| 388 | return (result); | ||
| 389 | } | ||
| 402 | 390 | ||
| 403 | char *DSO_convert_filename(DSO *dso, const char *filename) | 391 | char * |
| 404 | { | 392 | DSO_convert_filename(DSO *dso, const char *filename) |
| 393 | { | ||
| 405 | char *result = NULL; | 394 | char *result = NULL; |
| 406 | 395 | ||
| 407 | if(dso == NULL) | 396 | if (dso == NULL) { |
| 408 | { | 397 | DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_PASSED_NULL_PARAMETER); |
| 409 | DSOerr(DSO_F_DSO_CONVERT_FILENAME,ERR_R_PASSED_NULL_PARAMETER); | 398 | return (NULL); |
| 410 | return(NULL); | 399 | } |
| 411 | } | 400 | if (filename == NULL) |
| 412 | if(filename == NULL) | ||
| 413 | filename = dso->filename; | 401 | filename = dso->filename; |
| 414 | if(filename == NULL) | 402 | if (filename == NULL) { |
| 415 | { | 403 | DSOerr(DSO_F_DSO_CONVERT_FILENAME, DSO_R_NO_FILENAME); |
| 416 | DSOerr(DSO_F_DSO_CONVERT_FILENAME,DSO_R_NO_FILENAME); | 404 | return (NULL); |
| 417 | return(NULL); | 405 | } |
| 418 | } | 406 | if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) { |
| 419 | if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) | 407 | if (dso->name_converter != NULL) |
| 420 | { | ||
| 421 | if(dso->name_converter != NULL) | ||
| 422 | result = dso->name_converter(dso, filename); | 408 | result = dso->name_converter(dso, filename); |
| 423 | else if(dso->meth->dso_name_converter != NULL) | 409 | else if (dso->meth->dso_name_converter != NULL) |
| 424 | result = dso->meth->dso_name_converter(dso, filename); | 410 | result = dso->meth->dso_name_converter(dso, filename); |
| 425 | } | 411 | } |
| 426 | if(result == NULL) | 412 | if (result == NULL) { |
| 427 | { | ||
| 428 | result = malloc(strlen(filename) + 1); | 413 | result = malloc(strlen(filename) + 1); |
| 429 | if(result == NULL) | 414 | if (result == NULL) { |
| 430 | { | ||
| 431 | DSOerr(DSO_F_DSO_CONVERT_FILENAME, | 415 | DSOerr(DSO_F_DSO_CONVERT_FILENAME, |
| 432 | ERR_R_MALLOC_FAILURE); | 416 | ERR_R_MALLOC_FAILURE); |
| 433 | return(NULL); | 417 | return (NULL); |
| 434 | } | ||
| 435 | strlcpy(result, filename, strlen(filename) + 1); | ||
| 436 | } | 418 | } |
| 437 | return(result); | 419 | strlcpy(result, filename, strlen(filename) + 1); |
| 438 | } | 420 | } |
| 421 | return (result); | ||
| 422 | } | ||
| 439 | 423 | ||
| 440 | const char *DSO_get_loaded_filename(DSO *dso) | 424 | const char * |
| 441 | { | 425 | DSO_get_loaded_filename(DSO *dso) |
| 442 | if(dso == NULL) | 426 | { |
| 443 | { | 427 | if (dso == NULL) { |
| 444 | DSOerr(DSO_F_DSO_GET_LOADED_FILENAME, | 428 | DSOerr(DSO_F_DSO_GET_LOADED_FILENAME, |
| 445 | ERR_R_PASSED_NULL_PARAMETER); | 429 | ERR_R_PASSED_NULL_PARAMETER); |
| 446 | return(NULL); | 430 | return (NULL); |
| 447 | } | ||
| 448 | return(dso->loaded_filename); | ||
| 449 | } | 431 | } |
| 432 | return (dso->loaded_filename); | ||
| 433 | } | ||
| 450 | 434 | ||
| 451 | int DSO_pathbyaddr(void *addr,char *path,int sz) | 435 | int |
| 452 | { | 436 | DSO_pathbyaddr(void *addr, char *path, int sz) |
| 437 | { | ||
| 453 | DSO_METHOD *meth = default_DSO_meth; | 438 | DSO_METHOD *meth = default_DSO_meth; |
| 454 | if (meth == NULL) meth = DSO_METHOD_openssl(); | 439 | if (meth == NULL) |
| 455 | if (meth->pathbyaddr == NULL) | 440 | meth = DSO_METHOD_openssl(); |
| 456 | { | 441 | if (meth->pathbyaddr == NULL) { |
| 457 | DSOerr(DSO_F_DSO_PATHBYADDR,DSO_R_UNSUPPORTED); | 442 | DSOerr(DSO_F_DSO_PATHBYADDR, DSO_R_UNSUPPORTED); |
| 458 | return -1; | 443 | return -1; |
| 459 | } | ||
| 460 | return (*meth->pathbyaddr)(addr,path,sz); | ||
| 461 | } | 444 | } |
| 445 | return (*meth->pathbyaddr)(addr, path, sz); | ||
| 446 | } | ||
| 462 | 447 | ||
| 463 | void *DSO_global_lookup(const char *name) | 448 | void * |
| 464 | { | 449 | DSO_global_lookup(const char *name) |
| 450 | { | ||
| 465 | DSO_METHOD *meth = default_DSO_meth; | 451 | DSO_METHOD *meth = default_DSO_meth; |
| 466 | if (meth == NULL) meth = DSO_METHOD_openssl(); | 452 | if (meth == NULL) |
| 467 | if (meth->globallookup == NULL) | 453 | meth = DSO_METHOD_openssl(); |
| 468 | { | 454 | if (meth->globallookup == NULL) { |
| 469 | DSOerr(DSO_F_DSO_GLOBAL_LOOKUP,DSO_R_UNSUPPORTED); | 455 | DSOerr(DSO_F_DSO_GLOBAL_LOOKUP, DSO_R_UNSUPPORTED); |
| 470 | return NULL; | 456 | return NULL; |
| 471 | } | ||
| 472 | return (*meth->globallookup)(name); | ||
| 473 | } | 457 | } |
| 458 | return (*meth->globallookup)(name); | ||
| 459 | } | ||
diff --git a/src/lib/libcrypto/dso/dso_null.c b/src/lib/libcrypto/dso/dso_null.c index 49d842d1f5..0c877ab2f2 100644 --- a/src/lib/libcrypto/dso/dso_null.c +++ b/src/lib/libcrypto/dso/dso_null.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -81,10 +81,10 @@ static DSO_METHOD dso_meth_null = { | |||
| 81 | NULL, /* finish */ | 81 | NULL, /* finish */ |
| 82 | NULL, /* pathbyaddr */ | 82 | NULL, /* pathbyaddr */ |
| 83 | NULL /* globallookup */ | 83 | NULL /* globallookup */ |
| 84 | }; | 84 | }; |
| 85 | |||
| 86 | DSO_METHOD *DSO_METHOD_null(void) | ||
| 87 | { | ||
| 88 | return(&dso_meth_null); | ||
| 89 | } | ||
| 90 | 85 | ||
| 86 | DSO_METHOD * | ||
| 87 | DSO_METHOD_null(void) | ||
| 88 | { | ||
| 89 | return (&dso_meth_null); | ||
| 90 | } | ||
diff --git a/src/lib/libcrypto/dso/dso_openssl.c b/src/lib/libcrypto/dso/dso_openssl.c index 75fdfbd0e1..b79151f3bb 100644 --- a/src/lib/libcrypto/dso/dso_openssl.c +++ b/src/lib/libcrypto/dso/dso_openssl.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -62,13 +62,14 @@ | |||
| 62 | 62 | ||
| 63 | /* We just pinch the method from an appropriate "default" method. */ | 63 | /* We just pinch the method from an appropriate "default" method. */ |
| 64 | 64 | ||
| 65 | DSO_METHOD *DSO_METHOD_openssl(void) | 65 | DSO_METHOD * |
| 66 | { | 66 | DSO_METHOD_openssl(void) |
| 67 | { | ||
| 67 | #ifdef DEF_DSO_METHOD | 68 | #ifdef DEF_DSO_METHOD |
| 68 | return(DEF_DSO_METHOD()); | 69 | return (DEF_DSO_METHOD()); |
| 69 | #elif defined(DSO_DLFCN) | 70 | #elif defined(DSO_DLFCN) |
| 70 | return(DSO_METHOD_dlfcn()); | 71 | return (DSO_METHOD_dlfcn()); |
| 71 | #else | 72 | #else |
| 72 | return(DSO_METHOD_null()); | 73 | return (DSO_METHOD_null()); |
| 73 | #endif | 74 | #endif |
| 74 | } | 75 | } |
