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