2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2020-05-15 21:09:49 +08:00
|
|
|
* Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2000-04-05 05:57:11 +08:00
|
|
|
*
|
2018-12-06 20:37:48 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:26 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2000-04-05 05:57:11 +08:00
|
|
|
*/
|
|
|
|
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "dso_local.h"
|
2017-08-22 05:17:35 +08:00
|
|
|
#include "internal/refcount.h"
|
2000-04-05 05:57:11 +08:00
|
|
|
|
|
|
|
static DSO_METHOD *default_DSO_meth = NULL;
|
|
|
|
|
Remove several unused undocumented functions.
Removed the following:
DSO_bind_var, DSO_bind_var, DSO_get_default_method,
DSO_get_loaded_filename, DSO_get_loaded_filename, DSO_get_method,
DSO_new_method, DSO_pathbyaddr, DSO_set_default_method, DSO_set_method,
DSO_set_name_converter, DSO_set_name_converter
Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-03-23 02:33:00 +08:00
|
|
|
static DSO *DSO_new_method(DSO_METHOD *meth)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
DSO *ret;
|
|
|
|
|
2015-04-29 03:28:14 +08:00
|
|
|
if (default_DSO_meth == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
|
|
|
* We default to DSO_METH_openssl() which in turn defaults to
|
|
|
|
* stealing the "best available" method. Will fallback to
|
|
|
|
* DSO_METH_null() in the worst case.
|
|
|
|
*/
|
|
|
|
default_DSO_meth = DSO_METHOD_openssl();
|
2015-04-29 03:28:14 +08:00
|
|
|
}
|
2015-08-26 01:25:58 +08:00
|
|
|
ret = OPENSSL_zalloc(sizeof(*ret));
|
2015-01-22 11:40:55 +08:00
|
|
|
if (ret == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_MALLOC_FAILURE);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
ret->meth_data = sk_void_new_null();
|
|
|
|
if (ret->meth_data == NULL) {
|
|
|
|
/* sk_new doesn't generate any errors so we do */
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_MALLOC_FAILURE);
|
2015-01-22 11:40:55 +08:00
|
|
|
OPENSSL_free(ret);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
Remove several unused undocumented functions.
Removed the following:
DSO_bind_var, DSO_bind_var, DSO_get_default_method,
DSO_get_loaded_filename, DSO_get_loaded_filename, DSO_get_method,
DSO_new_method, DSO_pathbyaddr, DSO_set_default_method, DSO_set_method,
DSO_set_name_converter, DSO_set_name_converter
Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-03-23 02:33:00 +08:00
|
|
|
ret->meth = default_DSO_meth;
|
2015-01-22 11:40:55 +08:00
|
|
|
ret->references = 1;
|
2016-03-05 00:04:37 +08:00
|
|
|
ret->lock = CRYPTO_THREAD_lock_new();
|
|
|
|
if (ret->lock == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_MALLOC_FAILURE);
|
2016-01-22 06:10:29 +08:00
|
|
|
sk_void_free(ret->meth_data);
|
2015-01-22 11:40:55 +08:00
|
|
|
OPENSSL_free(ret);
|
2016-03-05 00:04:37 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
|
|
|
|
DSO_free(ret);
|
2015-01-22 11:40:55 +08:00
|
|
|
ret = NULL;
|
|
|
|
}
|
2016-03-05 00:04:37 +08:00
|
|
|
|
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2000-04-05 05:57:11 +08:00
|
|
|
|
Remove several unused undocumented functions.
Removed the following:
DSO_bind_var, DSO_bind_var, DSO_get_default_method,
DSO_get_loaded_filename, DSO_get_loaded_filename, DSO_get_method,
DSO_new_method, DSO_pathbyaddr, DSO_set_default_method, DSO_set_method,
DSO_set_name_converter, DSO_set_name_converter
Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-03-23 02:33:00 +08:00
|
|
|
DSO *DSO_new(void)
|
|
|
|
{
|
|
|
|
return DSO_new_method(NULL);
|
|
|
|
}
|
|
|
|
|
2000-04-05 05:57:11 +08:00
|
|
|
int DSO_free(DSO *dso)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2015-05-01 22:15:18 +08:00
|
|
|
if (dso == NULL)
|
2017-10-09 19:05:58 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2016-08-27 22:01:08 +08:00
|
|
|
if (CRYPTO_DOWN_REF(&dso->references, &i, dso->lock) <= 0)
|
2016-03-05 00:04:37 +08:00
|
|
|
return 0;
|
|
|
|
|
2016-01-31 01:04:25 +08:00
|
|
|
REF_PRINT_COUNT("DSO", dso);
|
2015-01-22 11:40:55 +08:00
|
|
|
if (i > 0)
|
2016-03-05 00:04:37 +08:00
|
|
|
return 1;
|
2016-01-31 01:04:25 +08:00
|
|
|
REF_ASSERT_ISNT(i < 0);
|
2000-04-05 05:57:11 +08:00
|
|
|
|
2016-10-15 23:01:40 +08:00
|
|
|
if ((dso->flags & DSO_FLAG_NO_UNLOAD_ON_FREE) == 0) {
|
|
|
|
if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_UNLOAD_FAILED);
|
2016-10-15 23:01:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2000-04-05 05:57:11 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_FINISH_FAILED);
|
2016-03-05 00:04:37 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sk_void_free(dso->meth_data);
|
2015-05-01 22:02:07 +08:00
|
|
|
OPENSSL_free(dso->filename);
|
|
|
|
OPENSSL_free(dso->loaded_filename);
|
2016-03-05 00:04:37 +08:00
|
|
|
CRYPTO_THREAD_lock_free(dso->lock);
|
2015-01-22 11:40:55 +08:00
|
|
|
OPENSSL_free(dso);
|
2016-03-05 00:04:37 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int DSO_flags(DSO *dso)
|
|
|
|
{
|
|
|
|
return ((dso == NULL) ? 0 : dso->flags);
|
|
|
|
}
|
2000-04-05 05:57:11 +08:00
|
|
|
|
2001-09-05 04:40:41 +08:00
|
|
|
int DSO_up_ref(DSO *dso)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2016-03-05 00:04:37 +08:00
|
|
|
int i;
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (dso == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
|
2016-03-05 00:04:37 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2000-04-05 05:57:11 +08:00
|
|
|
|
2016-08-27 22:01:08 +08:00
|
|
|
if (CRYPTO_UP_REF(&dso->references, &i, dso->lock) <= 0)
|
2016-03-05 00:04:37 +08:00
|
|
|
return 0;
|
|
|
|
|
2019-01-14 01:26:43 +08:00
|
|
|
REF_PRINT_COUNT("DSO", dso);
|
2016-03-05 00:04:37 +08:00
|
|
|
REF_ASSERT_ISNT(i < 2);
|
|
|
|
return ((i > 1) ? 1 : 0);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2000-04-05 05:57:11 +08:00
|
|
|
|
2000-04-20 05:45:17 +08:00
|
|
|
DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
DSO *ret;
|
|
|
|
int allocated = 0;
|
|
|
|
|
|
|
|
if (dso == NULL) {
|
|
|
|
ret = DSO_new_method(meth);
|
|
|
|
if (ret == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_MALLOC_FAILURE);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
allocated = 1;
|
|
|
|
/* Pass the provided flags to the new DSO object */
|
|
|
|
if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_CTRL_FAILED);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ret = dso;
|
|
|
|
/* Don't load if we're currently already loaded */
|
|
|
|
if (ret->filename != NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_DSO_ALREADY_LOADED);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* filename can only be NULL if we were passed a dso that already has one
|
|
|
|
* set.
|
|
|
|
*/
|
|
|
|
if (filename != NULL)
|
|
|
|
if (!DSO_set_filename(ret, filename)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_SET_FILENAME_FAILED);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
filename = ret->filename;
|
|
|
|
if (filename == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_NO_FILENAME);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (ret->meth->dso_load == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (!ret->meth->dso_load(ret)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_LOAD_FAILED);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* Load succeeded */
|
2017-10-17 22:04:09 +08:00
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
err:
|
|
|
|
if (allocated)
|
|
|
|
DSO_free(ret);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2000-04-05 05:57:11 +08:00
|
|
|
|
2000-06-16 18:45:36 +08:00
|
|
|
DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
DSO_FUNC_TYPE ret = NULL;
|
|
|
|
|
|
|
|
if ((dso == NULL) || (symname == NULL)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
if (dso->meth->dso_bind_func == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
if ((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_SYM_FAILURE);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
/* Success */
|
2017-10-17 22:04:09 +08:00
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I don't really like these *_ctrl functions very much to be perfectly
|
|
|
|
* honest. For one thing, I think I have to return a negative value for any
|
|
|
|
* error because possible DSO_ctrl() commands may return values such as
|
|
|
|
* "size"s that can legitimately be zero (making the standard
|
2015-04-16 13:50:03 +08:00
|
|
|
* "if (DSO_cmd(...))" form that works almost everywhere else fail at odd
|
2015-01-22 11:40:55 +08:00
|
|
|
* times. I'd prefer "output" values to be passed by reference and the return
|
|
|
|
* value as success/failure like usual ... but we conform when we must... :-)
|
|
|
|
*/
|
2000-04-20 05:45:17 +08:00
|
|
|
long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
if (dso == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
|
2017-10-17 22:04:09 +08:00
|
|
|
return -1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We should intercept certain generic commands and only pass control to
|
|
|
|
* the method-specific ctrl() function if it's something we don't handle.
|
|
|
|
*/
|
|
|
|
switch (cmd) {
|
|
|
|
case DSO_CTRL_GET_FLAGS:
|
|
|
|
return dso->flags;
|
|
|
|
case DSO_CTRL_SET_FLAGS:
|
|
|
|
dso->flags = (int)larg;
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
case DSO_CTRL_OR_FLAGS:
|
|
|
|
dso->flags |= (int)larg;
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
|
2017-10-17 22:04:09 +08:00
|
|
|
return -1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2017-10-17 22:04:09 +08:00
|
|
|
return dso->meth->dso_ctrl(dso, cmd, larg, parg);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
This changes the behaviour of the DSO mechanism for determining an
appropriate filename translation on the host system. Apart from this point,
users should also note that there's a slight change in the API functions
too. The DSO now contains its own to-be-converted filename
("dso->filename"), and at the time the DSO loads the "dso->loaded_filename"
value is set to the translated form. As such, this also provides an impicit
way of determining if the DSO is currently loaded or not. Except, perhaps,
VMS .... :-)
The various DSO_METHODs have been updated for this mechanism except VMS
which is deliberately broken for now, Richard is going to look at how to
fit it in (the source comments in there explain "the issue").
Basically, the new callback scheme allows the filename conversion to
(a) be turned off altogether through the use of the
DSO_FLAG_NO_NAME_TRANSLATION flag,
(b) be handled in the default way using the default DSO_METHOD's converter
(c) overriden per-DSO by setting the override callback
(d) a mix of (b) and (c) - eg. implement an override callback that;
(i) checks if we're win32 "if(strstr(dso->meth->name, "win32"))..."
and if so, convert "blah" into "blah32.dll" (the default is
otherwise to make it "blah.dll").
(ii) default to the normal behaviour - eg. we're not on win32, so
finish with (return dso->meth->dso_name_converter(dso,NULL)).
(e) be retried a number of times by writing a new DSO_METHOD where the
"dso_load()" handler will call the converter repeatedly. Then the
custom converter could use state information in the DSO to suggest
different conversions or paths each time it is invoked.
2000-10-27 01:38:59 +08:00
|
|
|
|
|
|
|
const char *DSO_get_filename(DSO *dso)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
if (dso == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2017-10-17 22:04:09 +08:00
|
|
|
return dso->filename;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
This changes the behaviour of the DSO mechanism for determining an
appropriate filename translation on the host system. Apart from this point,
users should also note that there's a slight change in the API functions
too. The DSO now contains its own to-be-converted filename
("dso->filename"), and at the time the DSO loads the "dso->loaded_filename"
value is set to the translated form. As such, this also provides an impicit
way of determining if the DSO is currently loaded or not. Except, perhaps,
VMS .... :-)
The various DSO_METHODs have been updated for this mechanism except VMS
which is deliberately broken for now, Richard is going to look at how to
fit it in (the source comments in there explain "the issue").
Basically, the new callback scheme allows the filename conversion to
(a) be turned off altogether through the use of the
DSO_FLAG_NO_NAME_TRANSLATION flag,
(b) be handled in the default way using the default DSO_METHOD's converter
(c) overriden per-DSO by setting the override callback
(d) a mix of (b) and (c) - eg. implement an override callback that;
(i) checks if we're win32 "if(strstr(dso->meth->name, "win32"))..."
and if so, convert "blah" into "blah32.dll" (the default is
otherwise to make it "blah.dll").
(ii) default to the normal behaviour - eg. we're not on win32, so
finish with (return dso->meth->dso_name_converter(dso,NULL)).
(e) be retried a number of times by writing a new DSO_METHOD where the
"dso_load()" handler will call the converter repeatedly. Then the
custom converter could use state information in the DSO to suggest
different conversions or paths each time it is invoked.
2000-10-27 01:38:59 +08:00
|
|
|
|
|
|
|
int DSO_set_filename(DSO *dso, const char *filename)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
char *copied;
|
|
|
|
|
|
|
|
if ((dso == NULL) || (filename == NULL)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
if (dso->loaded_filename) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_DSO_ALREADY_LOADED);
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
/* We'll duplicate filename */
|
2016-02-29 16:55:13 +08:00
|
|
|
copied = OPENSSL_strdup(filename);
|
2015-01-22 11:40:55 +08:00
|
|
|
if (copied == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_MALLOC_FAILURE);
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2015-05-01 22:02:07 +08:00
|
|
|
OPENSSL_free(dso->filename);
|
2015-01-22 11:40:55 +08:00
|
|
|
dso->filename = copied;
|
2017-10-09 19:05:58 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
This changes the behaviour of the DSO mechanism for determining an
appropriate filename translation on the host system. Apart from this point,
users should also note that there's a slight change in the API functions
too. The DSO now contains its own to-be-converted filename
("dso->filename"), and at the time the DSO loads the "dso->loaded_filename"
value is set to the translated form. As such, this also provides an impicit
way of determining if the DSO is currently loaded or not. Except, perhaps,
VMS .... :-)
The various DSO_METHODs have been updated for this mechanism except VMS
which is deliberately broken for now, Richard is going to look at how to
fit it in (the source comments in there explain "the issue").
Basically, the new callback scheme allows the filename conversion to
(a) be turned off altogether through the use of the
DSO_FLAG_NO_NAME_TRANSLATION flag,
(b) be handled in the default way using the default DSO_METHOD's converter
(c) overriden per-DSO by setting the override callback
(d) a mix of (b) and (c) - eg. implement an override callback that;
(i) checks if we're win32 "if(strstr(dso->meth->name, "win32"))..."
and if so, convert "blah" into "blah32.dll" (the default is
otherwise to make it "blah.dll").
(ii) default to the normal behaviour - eg. we're not on win32, so
finish with (return dso->meth->dso_name_converter(dso,NULL)).
(e) be retried a number of times by writing a new DSO_METHOD where the
"dso_load()" handler will call the converter repeatedly. Then the
custom converter could use state information in the DSO to suggest
different conversions or paths each time it is invoked.
2000-10-27 01:38:59 +08:00
|
|
|
|
2002-07-15 23:35:40 +08:00
|
|
|
char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
char *result = NULL;
|
|
|
|
|
|
|
|
if (dso == NULL || filespec1 == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
|
|
|
|
if (dso->merger != NULL)
|
|
|
|
result = dso->merger(dso, filespec1, filespec2);
|
|
|
|
else if (dso->meth->dso_merger != NULL)
|
|
|
|
result = dso->meth->dso_merger(dso, filespec1, filespec2);
|
|
|
|
}
|
2017-10-17 22:04:09 +08:00
|
|
|
return result;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2002-07-15 23:35:40 +08:00
|
|
|
|
This changes the behaviour of the DSO mechanism for determining an
appropriate filename translation on the host system. Apart from this point,
users should also note that there's a slight change in the API functions
too. The DSO now contains its own to-be-converted filename
("dso->filename"), and at the time the DSO loads the "dso->loaded_filename"
value is set to the translated form. As such, this also provides an impicit
way of determining if the DSO is currently loaded or not. Except, perhaps,
VMS .... :-)
The various DSO_METHODs have been updated for this mechanism except VMS
which is deliberately broken for now, Richard is going to look at how to
fit it in (the source comments in there explain "the issue").
Basically, the new callback scheme allows the filename conversion to
(a) be turned off altogether through the use of the
DSO_FLAG_NO_NAME_TRANSLATION flag,
(b) be handled in the default way using the default DSO_METHOD's converter
(c) overriden per-DSO by setting the override callback
(d) a mix of (b) and (c) - eg. implement an override callback that;
(i) checks if we're win32 "if(strstr(dso->meth->name, "win32"))..."
and if so, convert "blah" into "blah32.dll" (the default is
otherwise to make it "blah.dll").
(ii) default to the normal behaviour - eg. we're not on win32, so
finish with (return dso->meth->dso_name_converter(dso,NULL)).
(e) be retried a number of times by writing a new DSO_METHOD where the
"dso_load()" handler will call the converter repeatedly. Then the
custom converter could use state information in the DSO to suggest
different conversions or paths each time it is invoked.
2000-10-27 01:38:59 +08:00
|
|
|
char *DSO_convert_filename(DSO *dso, const char *filename)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
char *result = NULL;
|
|
|
|
|
|
|
|
if (dso == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
if (filename == NULL)
|
|
|
|
filename = dso->filename;
|
|
|
|
if (filename == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_NO_FILENAME);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
|
|
|
|
if (dso->name_converter != NULL)
|
|
|
|
result = dso->name_converter(dso, filename);
|
|
|
|
else if (dso->meth->dso_name_converter != NULL)
|
|
|
|
result = dso->meth->dso_name_converter(dso, filename);
|
|
|
|
}
|
|
|
|
if (result == NULL) {
|
2016-02-29 16:55:13 +08:00
|
|
|
result = OPENSSL_strdup(filename);
|
2015-01-22 11:40:55 +08:00
|
|
|
if (result == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, ERR_R_MALLOC_FAILURE);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
}
|
2017-10-17 22:04:09 +08:00
|
|
|
return result;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
This changes the behaviour of the DSO mechanism for determining an
appropriate filename translation on the host system. Apart from this point,
users should also note that there's a slight change in the API functions
too. The DSO now contains its own to-be-converted filename
("dso->filename"), and at the time the DSO loads the "dso->loaded_filename"
value is set to the translated form. As such, this also provides an impicit
way of determining if the DSO is currently loaded or not. Except, perhaps,
VMS .... :-)
The various DSO_METHODs have been updated for this mechanism except VMS
which is deliberately broken for now, Richard is going to look at how to
fit it in (the source comments in there explain "the issue").
Basically, the new callback scheme allows the filename conversion to
(a) be turned off altogether through the use of the
DSO_FLAG_NO_NAME_TRANSLATION flag,
(b) be handled in the default way using the default DSO_METHOD's converter
(c) overriden per-DSO by setting the override callback
(d) a mix of (b) and (c) - eg. implement an override callback that;
(i) checks if we're win32 "if(strstr(dso->meth->name, "win32"))..."
and if so, convert "blah" into "blah32.dll" (the default is
otherwise to make it "blah.dll").
(ii) default to the normal behaviour - eg. we're not on win32, so
finish with (return dso->meth->dso_name_converter(dso,NULL)).
(e) be retried a number of times by writing a new DSO_METHOD where the
"dso_load()" handler will call the converter repeatedly. Then the
custom converter could use state information in the DSO to suggest
different conversions or paths each time it is invoked.
2000-10-27 01:38:59 +08:00
|
|
|
|
2016-10-15 22:23:03 +08:00
|
|
|
int DSO_pathbyaddr(void *addr, char *path, int sz)
|
|
|
|
{
|
|
|
|
DSO_METHOD *meth = default_DSO_meth;
|
|
|
|
if (meth == NULL)
|
|
|
|
meth = DSO_METHOD_openssl();
|
|
|
|
if (meth->pathbyaddr == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
|
2016-10-15 22:23:03 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return (*meth->pathbyaddr) (addr, path, sz);
|
|
|
|
}
|
|
|
|
|
2016-10-15 23:01:40 +08:00
|
|
|
DSO *DSO_dsobyaddr(void *addr, int flags)
|
|
|
|
{
|
|
|
|
DSO *ret = NULL;
|
|
|
|
char *filename = NULL;
|
|
|
|
int len = DSO_pathbyaddr(addr, NULL, 0);
|
|
|
|
|
2016-12-03 00:10:37 +08:00
|
|
|
if (len < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2016-10-15 23:01:40 +08:00
|
|
|
filename = OPENSSL_malloc(len);
|
|
|
|
if (filename != NULL
|
|
|
|
&& DSO_pathbyaddr(addr, filename, len) == len)
|
|
|
|
ret = DSO_load(NULL, filename, NULL, flags);
|
|
|
|
|
|
|
|
OPENSSL_free(filename);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-01-02 16:59:20 +08:00
|
|
|
void *DSO_global_lookup(const char *name)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
DSO_METHOD *meth = default_DSO_meth;
|
|
|
|
if (meth == NULL)
|
|
|
|
meth = DSO_METHOD_openssl();
|
|
|
|
if (meth->globallookup == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return (*meth->globallookup) (name);
|
|
|
|
}
|