Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1 | /* |
Rich Salz | d2e9e32 | 2016-05-17 14:51:26 -0400 | [diff] [blame] | 2 | * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 3 | * |
Rich Salz | d2e9e32 | 2016-05-17 14:51:26 -0400 | [diff] [blame] | 4 | * Licensed under the OpenSSL license (the "License"). You may not use |
| 5 | * this file except in compliance with the License. You can obtain a copy |
| 6 | * in the file LICENSE in the source distribution or at |
| 7 | * https://www.openssl.org/source/license.html |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Rich Salz | 73decf5 | 2016-03-22 13:16:54 -0400 | [diff] [blame] | 10 | #include "dso_locl.h" |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 11 | |
| 12 | static DSO_METHOD *default_DSO_meth = NULL; |
| 13 | |
Rich Salz | 3d8b2ec | 2016-03-22 14:33:00 -0400 | [diff] [blame] | 14 | static DSO *DSO_new_method(DSO_METHOD *meth) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 15 | { |
| 16 | DSO *ret; |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 17 | |
Rich Salz | b196e7d | 2015-04-28 15:28:14 -0400 | [diff] [blame] | 18 | if (default_DSO_meth == NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 19 | /* |
| 20 | * We default to DSO_METH_openssl() which in turn defaults to |
| 21 | * stealing the "best available" method. Will fallback to |
| 22 | * DSO_METH_null() in the worst case. |
| 23 | */ |
| 24 | default_DSO_meth = DSO_METHOD_openssl(); |
Rich Salz | b196e7d | 2015-04-28 15:28:14 -0400 | [diff] [blame] | 25 | } |
Rich Salz | b51bce9 | 2015-08-25 13:25:58 -0400 | [diff] [blame] | 26 | ret = OPENSSL_zalloc(sizeof(*ret)); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 27 | if (ret == NULL) { |
| 28 | DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE); |
| 29 | return (NULL); |
| 30 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 31 | ret->meth_data = sk_void_new_null(); |
| 32 | if (ret->meth_data == NULL) { |
| 33 | /* sk_new doesn't generate any errors so we do */ |
| 34 | DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE); |
| 35 | OPENSSL_free(ret); |
| 36 | return (NULL); |
| 37 | } |
Rich Salz | 3d8b2ec | 2016-03-22 14:33:00 -0400 | [diff] [blame] | 38 | ret->meth = default_DSO_meth; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 39 | ret->references = 1; |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 40 | ret->lock = CRYPTO_THREAD_lock_new(); |
| 41 | if (ret->lock == NULL) { |
FdaSilvaYY | b2b361f | 2016-04-30 16:23:33 +0200 | [diff] [blame] | 42 | DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE); |
FdaSilvaYY | 98637bd | 2016-01-21 23:10:29 +0100 | [diff] [blame] | 43 | sk_void_free(ret->meth_data); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 44 | OPENSSL_free(ret); |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 45 | return NULL; |
| 46 | } |
| 47 | |
| 48 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { |
| 49 | DSO_free(ret); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 50 | ret = NULL; |
| 51 | } |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 52 | |
| 53 | return ret; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 54 | } |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 55 | |
Rich Salz | 3d8b2ec | 2016-03-22 14:33:00 -0400 | [diff] [blame] | 56 | DSO *DSO_new(void) |
| 57 | { |
| 58 | return DSO_new_method(NULL); |
| 59 | } |
| 60 | |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 61 | int DSO_free(DSO *dso) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 62 | { |
| 63 | int i; |
| 64 | |
Rich Salz | efa7dd6 | 2015-05-01 10:15:18 -0400 | [diff] [blame] | 65 | if (dso == NULL) |
| 66 | return (1); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 67 | |
Kurt Roeckx | 2f545ae | 2016-08-27 16:01:08 +0200 | [diff] [blame] | 68 | if (CRYPTO_DOWN_REF(&dso->references, &i, dso->lock) <= 0) |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 69 | return 0; |
| 70 | |
Rich Salz | f3f1cf8 | 2016-01-30 12:04:25 -0500 | [diff] [blame] | 71 | REF_PRINT_COUNT("DSO", dso); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 72 | if (i > 0) |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 73 | return 1; |
Rich Salz | f3f1cf8 | 2016-01-30 12:04:25 -0500 | [diff] [blame] | 74 | REF_ASSERT_ISNT(i < 0); |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 75 | |
Matt Caswell | b39eda7 | 2016-10-15 16:01:40 +0100 | [diff] [blame] | 76 | if ((dso->flags & DSO_FLAG_NO_UNLOAD_ON_FREE) == 0) { |
| 77 | if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) { |
| 78 | DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED); |
| 79 | return 0; |
| 80 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) { |
| 84 | DSOerr(DSO_F_DSO_FREE, DSO_R_FINISH_FAILED); |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 85 | return 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | sk_void_free(dso->meth_data); |
Rich Salz | b548a1f | 2015-05-01 10:02:07 -0400 | [diff] [blame] | 89 | OPENSSL_free(dso->filename); |
| 90 | OPENSSL_free(dso->loaded_filename); |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 91 | CRYPTO_THREAD_lock_free(dso->lock); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 92 | OPENSSL_free(dso); |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 93 | return 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 94 | } |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 95 | |
| 96 | int DSO_flags(DSO *dso) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 97 | { |
| 98 | return ((dso == NULL) ? 0 : dso->flags); |
| 99 | } |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 100 | |
Geoff Thorpe | d9ff889 | 2001-09-04 20:40:41 +0000 | [diff] [blame] | 101 | int DSO_up_ref(DSO *dso) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 102 | { |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 103 | int i; |
| 104 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 105 | if (dso == NULL) { |
| 106 | DSOerr(DSO_F_DSO_UP_REF, ERR_R_PASSED_NULL_PARAMETER); |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 107 | return 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 108 | } |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 109 | |
Kurt Roeckx | 2f545ae | 2016-08-27 16:01:08 +0200 | [diff] [blame] | 110 | if (CRYPTO_UP_REF(&dso->references, &i, dso->lock) <= 0) |
Alessandro Ghedini | c74471d | 2016-03-04 16:04:37 +0000 | [diff] [blame] | 111 | return 0; |
| 112 | |
| 113 | REF_PRINT_COUNT("DSO", r); |
| 114 | REF_ASSERT_ISNT(i < 2); |
| 115 | return ((i > 1) ? 1 : 0); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 116 | } |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 117 | |
Geoff Thorpe | b9e6391 | 2000-04-19 21:45:17 +0000 | [diff] [blame] | 118 | DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 119 | { |
| 120 | DSO *ret; |
| 121 | int allocated = 0; |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 122 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 123 | if (dso == NULL) { |
| 124 | ret = DSO_new_method(meth); |
| 125 | if (ret == NULL) { |
| 126 | DSOerr(DSO_F_DSO_LOAD, ERR_R_MALLOC_FAILURE); |
| 127 | goto err; |
| 128 | } |
| 129 | allocated = 1; |
| 130 | /* Pass the provided flags to the new DSO object */ |
| 131 | if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) { |
| 132 | DSOerr(DSO_F_DSO_LOAD, DSO_R_CTRL_FAILED); |
| 133 | goto err; |
| 134 | } |
| 135 | } else |
| 136 | ret = dso; |
| 137 | /* Don't load if we're currently already loaded */ |
| 138 | if (ret->filename != NULL) { |
| 139 | DSOerr(DSO_F_DSO_LOAD, DSO_R_DSO_ALREADY_LOADED); |
| 140 | goto err; |
| 141 | } |
| 142 | /* |
| 143 | * filename can only be NULL if we were passed a dso that already has one |
| 144 | * set. |
| 145 | */ |
| 146 | if (filename != NULL) |
| 147 | if (!DSO_set_filename(ret, filename)) { |
| 148 | DSOerr(DSO_F_DSO_LOAD, DSO_R_SET_FILENAME_FAILED); |
| 149 | goto err; |
| 150 | } |
| 151 | filename = ret->filename; |
| 152 | if (filename == NULL) { |
| 153 | DSOerr(DSO_F_DSO_LOAD, DSO_R_NO_FILENAME); |
| 154 | goto err; |
| 155 | } |
| 156 | if (ret->meth->dso_load == NULL) { |
| 157 | DSOerr(DSO_F_DSO_LOAD, DSO_R_UNSUPPORTED); |
| 158 | goto err; |
| 159 | } |
| 160 | if (!ret->meth->dso_load(ret)) { |
| 161 | DSOerr(DSO_F_DSO_LOAD, DSO_R_LOAD_FAILED); |
| 162 | goto err; |
| 163 | } |
| 164 | /* Load succeeded */ |
| 165 | return (ret); |
| 166 | err: |
| 167 | if (allocated) |
| 168 | DSO_free(ret); |
| 169 | return (NULL); |
| 170 | } |
Geoff Thorpe | 8f4fac7 | 2000-04-04 21:57:11 +0000 | [diff] [blame] | 171 | |
Geoff Thorpe | e9a68cf | 2000-06-16 10:45:36 +0000 | [diff] [blame] | 172 | DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 173 | { |
| 174 | DSO_FUNC_TYPE ret = NULL; |
Geoff Thorpe | e9a68cf | 2000-06-16 10:45:36 +0000 | [diff] [blame] | 175 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 176 | if ((dso == NULL) || (symname == NULL)) { |
| 177 | DSOerr(DSO_F_DSO_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER); |
| 178 | return (NULL); |
| 179 | } |
| 180 | if (dso->meth->dso_bind_func == NULL) { |
| 181 | DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_UNSUPPORTED); |
| 182 | return (NULL); |
| 183 | } |
| 184 | if ((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) { |
| 185 | DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_SYM_FAILURE); |
| 186 | return (NULL); |
| 187 | } |
| 188 | /* Success */ |
| 189 | return (ret); |
| 190 | } |
Geoff Thorpe | b9e6391 | 2000-04-19 21:45:17 +0000 | [diff] [blame] | 191 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 192 | /* |
| 193 | * I don't really like these *_ctrl functions very much to be perfectly |
| 194 | * honest. For one thing, I think I have to return a negative value for any |
| 195 | * error because possible DSO_ctrl() commands may return values such as |
| 196 | * "size"s that can legitimately be zero (making the standard |
Viktor Dukhovni | 61986d3 | 2015-04-16 01:50:03 -0400 | [diff] [blame] | 197 | * "if (DSO_cmd(...))" form that works almost everywhere else fail at odd |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 198 | * times. I'd prefer "output" values to be passed by reference and the return |
| 199 | * value as success/failure like usual ... but we conform when we must... :-) |
| 200 | */ |
Geoff Thorpe | b9e6391 | 2000-04-19 21:45:17 +0000 | [diff] [blame] | 201 | long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 202 | { |
| 203 | if (dso == NULL) { |
| 204 | DSOerr(DSO_F_DSO_CTRL, ERR_R_PASSED_NULL_PARAMETER); |
| 205 | return (-1); |
| 206 | } |
| 207 | /* |
| 208 | * We should intercept certain generic commands and only pass control to |
| 209 | * the method-specific ctrl() function if it's something we don't handle. |
| 210 | */ |
| 211 | switch (cmd) { |
| 212 | case DSO_CTRL_GET_FLAGS: |
| 213 | return dso->flags; |
| 214 | case DSO_CTRL_SET_FLAGS: |
| 215 | dso->flags = (int)larg; |
| 216 | return (0); |
| 217 | case DSO_CTRL_OR_FLAGS: |
| 218 | dso->flags |= (int)larg; |
| 219 | return (0); |
| 220 | default: |
| 221 | break; |
| 222 | } |
| 223 | if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) { |
| 224 | DSOerr(DSO_F_DSO_CTRL, DSO_R_UNSUPPORTED); |
| 225 | return (-1); |
| 226 | } |
| 227 | return (dso->meth->dso_ctrl(dso, cmd, larg, parg)); |
| 228 | } |
Geoff Thorpe | 51c8dc3 | 2000-10-26 17:38:59 +0000 | [diff] [blame] | 229 | |
Geoff Thorpe | 51c8dc3 | 2000-10-26 17:38:59 +0000 | [diff] [blame] | 230 | const char *DSO_get_filename(DSO *dso) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 231 | { |
| 232 | if (dso == NULL) { |
| 233 | DSOerr(DSO_F_DSO_GET_FILENAME, ERR_R_PASSED_NULL_PARAMETER); |
| 234 | return (NULL); |
| 235 | } |
| 236 | return (dso->filename); |
| 237 | } |
Geoff Thorpe | 51c8dc3 | 2000-10-26 17:38:59 +0000 | [diff] [blame] | 238 | |
| 239 | int DSO_set_filename(DSO *dso, const char *filename) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 240 | { |
| 241 | char *copied; |
Geoff Thorpe | 51c8dc3 | 2000-10-26 17:38:59 +0000 | [diff] [blame] | 242 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 243 | if ((dso == NULL) || (filename == NULL)) { |
| 244 | DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_PASSED_NULL_PARAMETER); |
| 245 | return (0); |
| 246 | } |
| 247 | if (dso->loaded_filename) { |
| 248 | DSOerr(DSO_F_DSO_SET_FILENAME, DSO_R_DSO_ALREADY_LOADED); |
| 249 | return (0); |
| 250 | } |
| 251 | /* We'll duplicate filename */ |
Dmitry-Me | edae983 | 2016-02-29 11:55:13 +0300 | [diff] [blame] | 252 | copied = OPENSSL_strdup(filename); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 253 | if (copied == NULL) { |
| 254 | DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE); |
| 255 | return (0); |
| 256 | } |
Rich Salz | b548a1f | 2015-05-01 10:02:07 -0400 | [diff] [blame] | 257 | OPENSSL_free(dso->filename); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 258 | dso->filename = copied; |
| 259 | return (1); |
| 260 | } |
Geoff Thorpe | 51c8dc3 | 2000-10-26 17:38:59 +0000 | [diff] [blame] | 261 | |
Richard Levitte | cbecb3a | 2002-07-15 15:35:40 +0000 | [diff] [blame] | 262 | char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 263 | { |
| 264 | char *result = NULL; |
Richard Levitte | cbecb3a | 2002-07-15 15:35:40 +0000 | [diff] [blame] | 265 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 266 | if (dso == NULL || filespec1 == NULL) { |
| 267 | DSOerr(DSO_F_DSO_MERGE, ERR_R_PASSED_NULL_PARAMETER); |
| 268 | return (NULL); |
| 269 | } |
| 270 | if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) { |
| 271 | if (dso->merger != NULL) |
| 272 | result = dso->merger(dso, filespec1, filespec2); |
| 273 | else if (dso->meth->dso_merger != NULL) |
| 274 | result = dso->meth->dso_merger(dso, filespec1, filespec2); |
| 275 | } |
| 276 | return (result); |
| 277 | } |
Richard Levitte | cbecb3a | 2002-07-15 15:35:40 +0000 | [diff] [blame] | 278 | |
Geoff Thorpe | 51c8dc3 | 2000-10-26 17:38:59 +0000 | [diff] [blame] | 279 | char *DSO_convert_filename(DSO *dso, const char *filename) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 280 | { |
| 281 | char *result = NULL; |
Geoff Thorpe | 51c8dc3 | 2000-10-26 17:38:59 +0000 | [diff] [blame] | 282 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 283 | if (dso == NULL) { |
| 284 | DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_PASSED_NULL_PARAMETER); |
| 285 | return (NULL); |
| 286 | } |
| 287 | if (filename == NULL) |
| 288 | filename = dso->filename; |
| 289 | if (filename == NULL) { |
| 290 | DSOerr(DSO_F_DSO_CONVERT_FILENAME, DSO_R_NO_FILENAME); |
| 291 | return (NULL); |
| 292 | } |
| 293 | if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) { |
| 294 | if (dso->name_converter != NULL) |
| 295 | result = dso->name_converter(dso, filename); |
| 296 | else if (dso->meth->dso_name_converter != NULL) |
| 297 | result = dso->meth->dso_name_converter(dso, filename); |
| 298 | } |
| 299 | if (result == NULL) { |
Dmitry-Me | edae983 | 2016-02-29 11:55:13 +0300 | [diff] [blame] | 300 | result = OPENSSL_strdup(filename); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 301 | if (result == NULL) { |
| 302 | DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_MALLOC_FAILURE); |
| 303 | return (NULL); |
| 304 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 305 | } |
| 306 | return (result); |
| 307 | } |
Geoff Thorpe | 51c8dc3 | 2000-10-26 17:38:59 +0000 | [diff] [blame] | 308 | |
Matt Caswell | cb6ea61 | 2016-10-15 15:23:03 +0100 | [diff] [blame] | 309 | int DSO_pathbyaddr(void *addr, char *path, int sz) |
| 310 | { |
| 311 | DSO_METHOD *meth = default_DSO_meth; |
| 312 | if (meth == NULL) |
| 313 | meth = DSO_METHOD_openssl(); |
| 314 | if (meth->pathbyaddr == NULL) { |
| 315 | DSOerr(DSO_F_DSO_PATHBYADDR, DSO_R_UNSUPPORTED); |
| 316 | return -1; |
| 317 | } |
| 318 | return (*meth->pathbyaddr) (addr, path, sz); |
| 319 | } |
| 320 | |
Matt Caswell | b39eda7 | 2016-10-15 16:01:40 +0100 | [diff] [blame] | 321 | DSO *DSO_dsobyaddr(void *addr, int flags) |
| 322 | { |
| 323 | DSO *ret = NULL; |
| 324 | char *filename = NULL; |
| 325 | int len = DSO_pathbyaddr(addr, NULL, 0); |
| 326 | |
Davide Galassi | 210fe4e | 2016-12-02 17:10:37 +0100 | [diff] [blame] | 327 | if (len < 0) |
| 328 | return NULL; |
| 329 | |
Matt Caswell | b39eda7 | 2016-10-15 16:01:40 +0100 | [diff] [blame] | 330 | filename = OPENSSL_malloc(len); |
| 331 | if (filename != NULL |
| 332 | && DSO_pathbyaddr(addr, filename, len) == len) |
| 333 | ret = DSO_load(NULL, filename, NULL, flags); |
| 334 | |
| 335 | OPENSSL_free(filename); |
| 336 | return ret; |
| 337 | } |
| 338 | |
Andy Polyakov | c6cb42e | 2006-01-02 08:59:20 +0000 | [diff] [blame] | 339 | void *DSO_global_lookup(const char *name) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 340 | { |
| 341 | DSO_METHOD *meth = default_DSO_meth; |
| 342 | if (meth == NULL) |
| 343 | meth = DSO_METHOD_openssl(); |
| 344 | if (meth->globallookup == NULL) { |
| 345 | DSOerr(DSO_F_DSO_GLOBAL_LOOKUP, DSO_R_UNSUPPORTED); |
| 346 | return NULL; |
| 347 | } |
| 348 | return (*meth->globallookup) (name); |
| 349 | } |