summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dso
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/dso')
-rw-r--r--src/lib/libcrypto/dso/Makefile.ssl71
-rw-r--r--src/lib/libcrypto/dso/README24
-rw-r--r--src/lib/libcrypto/dso/dso.h168
-rw-r--r--src/lib/libcrypto/dso/dso_dl.c112
-rw-r--r--src/lib/libcrypto/dso/dso_dlfcn.c97
-rw-r--r--src/lib/libcrypto/dso/dso_err.c23
-rw-r--r--src/lib/libcrypto/dso/dso_lib.c179
-rw-r--r--src/lib/libcrypto/dso/dso_vms.c82
-rw-r--r--src/lib/libcrypto/dso/dso_win32.c112
9 files changed, 567 insertions, 301 deletions
diff --git a/src/lib/libcrypto/dso/Makefile.ssl b/src/lib/libcrypto/dso/Makefile.ssl
index 48b36c8330..cca9376bdb 100644
--- a/src/lib/libcrypto/dso/Makefile.ssl
+++ b/src/lib/libcrypto/dso/Makefile.ssl
@@ -5,13 +5,14 @@
5DIR= dso 5DIR= dso
6TOP= ../.. 6TOP= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX= 10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl 11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
14MAKEDEPEND= $(TOP)/util/domd $(TOP) 14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
15MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
16AR= ar r 17AR= ar r
17 18
@@ -41,8 +42,7 @@ all: lib
41 42
42lib: $(LIBOBJ) 43lib: $(LIBOBJ)
43 $(AR) $(LIB) $(LIBOBJ) 44 $(AR) $(LIB) $(LIBOBJ)
44 @echo You may get an error following this line. Please ignore. 45 $(RANLIB) $(LIB) || echo Never mind.
45 - $(RANLIB) $(LIB)
46 @touch lib 46 @touch lib
47 47
48files: 48files:
@@ -81,61 +81,62 @@ clean:
81 81
82# DO NOT DELETE THIS LINE -- make depend depends on it. 82# DO NOT DELETE THIS LINE -- make depend depends on it.
83 83
84dso_dl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 84dso_dl.o: ../../e_os.h ../../include/openssl/bio.h
85dso_dl.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h 85dso_dl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
86dso_dl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 86dso_dl.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
87dso_dl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 87dso_dl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
88dso_dl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 88dso_dl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
89dso_dl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 89dso_dl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
90dso_dl.o: ../../include/openssl/symhacks.h ../cryptlib.h 90dso_dl.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_dl.c
91dso_dlfcn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 91dso_dlfcn.o: ../../e_os.h ../../include/openssl/bio.h
92dso_dlfcn.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h 92dso_dlfcn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
93dso_dlfcn.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 93dso_dlfcn.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
94dso_dlfcn.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 94dso_dlfcn.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
95dso_dlfcn.o: ../../include/openssl/opensslconf.h 95dso_dlfcn.o: ../../include/openssl/opensslconf.h
96dso_dlfcn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 96dso_dlfcn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
97dso_dlfcn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 97dso_dlfcn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
98dso_dlfcn.o: ../cryptlib.h 98dso_dlfcn.o: ../cryptlib.h dso_dlfcn.c
99dso_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h 99dso_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
100dso_err.o: ../../include/openssl/dso.h ../../include/openssl/err.h 100dso_err.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
101dso_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslv.h 101dso_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
102dso_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
102dso_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 103dso_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
103dso_err.o: ../../include/openssl/symhacks.h 104dso_err.o: ../../include/openssl/symhacks.h dso_err.c
104dso_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 105dso_lib.o: ../../e_os.h ../../include/openssl/bio.h
105dso_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h 106dso_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
106dso_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 107dso_lib.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
107dso_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 108dso_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
108dso_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 109dso_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
109dso_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 110dso_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
110dso_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h 111dso_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_lib.c
111dso_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 112dso_null.o: ../../e_os.h ../../include/openssl/bio.h
112dso_null.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h 113dso_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
113dso_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 114dso_null.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
114dso_null.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 115dso_null.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
115dso_null.o: ../../include/openssl/opensslconf.h 116dso_null.o: ../../include/openssl/opensslconf.h
116dso_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 117dso_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
117dso_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 118dso_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
118dso_null.o: ../cryptlib.h 119dso_null.o: ../cryptlib.h dso_null.c
119dso_openssl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 120dso_openssl.o: ../../e_os.h ../../include/openssl/bio.h
120dso_openssl.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h 121dso_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
121dso_openssl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 122dso_openssl.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
122dso_openssl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 123dso_openssl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
123dso_openssl.o: ../../include/openssl/opensslconf.h 124dso_openssl.o: ../../include/openssl/opensslconf.h
124dso_openssl.o: ../../include/openssl/opensslv.h 125dso_openssl.o: ../../include/openssl/opensslv.h
125dso_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 126dso_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
126dso_openssl.o: ../../include/openssl/symhacks.h ../cryptlib.h 127dso_openssl.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_openssl.c
127dso_vms.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 128dso_vms.o: ../../e_os.h ../../include/openssl/bio.h
128dso_vms.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h 129dso_vms.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
129dso_vms.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 130dso_vms.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
130dso_vms.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 131dso_vms.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
131dso_vms.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 132dso_vms.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
132dso_vms.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 133dso_vms.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
133dso_vms.o: ../../include/openssl/symhacks.h ../cryptlib.h 134dso_vms.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_vms.c
134dso_win32.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 135dso_win32.o: ../../e_os.h ../../include/openssl/bio.h
135dso_win32.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h 136dso_win32.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
136dso_win32.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 137dso_win32.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
137dso_win32.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 138dso_win32.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
138dso_win32.o: ../../include/openssl/opensslconf.h 139dso_win32.o: ../../include/openssl/opensslconf.h
139dso_win32.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 140dso_win32.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
140dso_win32.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 141dso_win32.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
141dso_win32.o: ../cryptlib.h 142dso_win32.o: ../cryptlib.h dso_win32.c
diff --git a/src/lib/libcrypto/dso/README b/src/lib/libcrypto/dso/README
index 6ba03c5631..d0bc9a89fb 100644
--- a/src/lib/libcrypto/dso/README
+++ b/src/lib/libcrypto/dso/README
@@ -1,16 +1,3 @@
1TODO
2----
3
4Find a way where name-translation can be done in a way that is
5sensitive to particular methods (ie. generic code could still do
6different path/filename substitutions on win32 to what it does on
7*nix) but doesn't assume some canonical form. Already one case
8exists where the "blah -> (libblah.so,blah.dll)" mapping doesn't
9suffice. I suspect a callback with an enumerated (or string?)
10parameter could be the way to go here ... DSO_ctrl the callback
11into place and it can be invoked to handle name translation with
12some clue to the calling code as to what kind of system it is.
13
14NOTES 1NOTES
15----- 2-----
16 3
@@ -21,4 +8,15 @@ according to their man page, prefer developers to move to that.
21I'll leave Richard's changes there as I guess dso_dl is needed 8I'll leave Richard's changes there as I guess dso_dl is needed
22for HPUX10.20. 9for HPUX10.20.
23 10
11There is now a callback scheme in place where filename conversion can
12(a) be turned off altogether through the use of the
13 DSO_FLAG_NO_NAME_TRANSLATION flag,
14(b) be handled by default using the default DSO_METHOD's converter
15(c) overriden per-DSO by setting the override callback
16(d) a mix of (b) and (c) - eg. implement an override callback that;
17 (i) checks if we're win32 (if(strstr(dso->meth->name, "win32")....)
18 and if so, convert "blah" into "blah32.dll" (the default is
19 otherwise to make it "blah.dll").
20 (ii) default to the normal behaviour - we're not on win32, eg.
21 finish with (return dso->meth->dso_name_converter(dso,NULL)).
24 22
diff --git a/src/lib/libcrypto/dso/dso.h b/src/lib/libcrypto/dso/dso.h
index bed7c464a6..aa721f7feb 100644
--- a/src/lib/libcrypto/dso/dso.h
+++ b/src/lib/libcrypto/dso/dso.h
@@ -70,31 +70,51 @@ extern "C" {
70#define DSO_CTRL_SET_FLAGS 2 70#define DSO_CTRL_SET_FLAGS 2
71#define DSO_CTRL_OR_FLAGS 3 71#define DSO_CTRL_OR_FLAGS 3
72 72
73/* These flags control the translation of file-names from canonical to 73/* By default, DSO_load() will translate the provided filename into a form
74 * native. Eg. in the CryptoSwift support, the "dl" and "dlfcn" 74 * typical for the platform (more specifically the DSO_METHOD) using the
75 * methods will translate "swift" -> "libswift.so" whereas the "win32" 75 * dso_name_converter function of the method. Eg. win32 will transform "blah"
76 * method will translate "swift" -> "swift.dll". NB: Until I can figure 76 * into "blah.dll", and dlfcn will transform it into "libblah.so". The
77 * out how to be more "conventional" with this, the methods will only 77 * behaviour can be overriden by setting the name_converter callback in the DSO
78 * honour this flag if it looks like it was passed a file without any 78 * object (using DSO_set_name_converter()). This callback could even utilise
79 * path and if the filename is small enough. 79 * the DSO_METHOD's converter too if it only wants to override behaviour for
80 */ 80 * one or two possible DSO methods. However, the following flag can be set in a
81#define DSO_FLAG_NAME_TRANSLATION 0x01 81 * DSO to prevent *any* native name-translation at all - eg. if the caller has
82 * prompted the user for a path to a driver library so the filename should be
83 * interpreted as-is. */
84#define DSO_FLAG_NO_NAME_TRANSLATION 0x01
85/* An extra flag to give if only the extension should be added as
86 * translation. This is obviously only of importance on Unix and
87 * other operating systems where the translation also may prefix
88 * the name with something, like 'lib', and ignored everywhere else.
89 * This flag is also ignored if DSO_FLAG_NO_NAME_TRANSLATION is used
90 * at the same time. */
91#define DSO_FLAG_NAME_TRANSLATION_EXT_ONLY 0x02
82 92
83/* The following flag controls the translation of symbol names to upper 93/* The following flag controls the translation of symbol names to upper
84 * case. This is currently only being implemented for OpenVMS. 94 * case. This is currently only being implemented for OpenVMS.
85 */ 95 */
86#define DSO_FLAG_UPCASE_SYMBOL 0x02 96#define DSO_FLAG_UPCASE_SYMBOL 0x10
87 97
88 98
89typedef void (*DSO_FUNC_TYPE)(void); 99typedef void (*DSO_FUNC_TYPE)(void);
90 100
91typedef struct dso_st DSO; 101typedef struct dso_st DSO;
92 102
103/* The function prototype used for method functions (or caller-provided
104 * callbacks) that transform filenames. They are passed a DSO structure pointer
105 * (or NULL if they are to be used independantly of a DSO object) and a
106 * filename to transform. They should either return NULL (if there is an error
107 * condition) or a newly allocated string containing the transformed form that
108 * the caller will need to free with OPENSSL_free() when done. */
109typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *);
110
93typedef struct dso_meth_st 111typedef struct dso_meth_st
94 { 112 {
95 const char *name; 113 const char *name;
96 /* Loads a shared library */ 114 /* Loads a shared library, NB: new DSO_METHODs must ensure that a
97 int (*dso_load)(DSO *dso, const char *filename); 115 * successful load populates the loaded_filename field, and likewise a
116 * successful unload OPENSSL_frees and NULLs it out. */
117 int (*dso_load)(DSO *dso);
98 /* Unloads a shared library */ 118 /* Unloads a shared library */
99 int (*dso_unload)(DSO *dso); 119 int (*dso_unload)(DSO *dso);
100 /* Binds a variable */ 120 /* Binds a variable */
@@ -117,6 +137,9 @@ typedef struct dso_meth_st
117 /* The generic (yuck) "ctrl()" function. NB: Negative return 137 /* The generic (yuck) "ctrl()" function. NB: Negative return
118 * values (rather than zero) indicate errors. */ 138 * values (rather than zero) indicate errors. */
119 long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg); 139 long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg);
140 /* The default DSO_METHOD-specific function for converting filenames to
141 * a canonical native form. */
142 DSO_NAME_CONVERTER_FUNC dso_name_converter;
120 143
121 /* [De]Initialisation handlers. */ 144 /* [De]Initialisation handlers. */
122 int (*init)(DSO *dso); 145 int (*init)(DSO *dso);
@@ -140,6 +163,23 @@ struct dso_st
140 /* For use by applications etc ... use this for your bits'n'pieces, 163 /* For use by applications etc ... use this for your bits'n'pieces,
141 * don't touch meth_data! */ 164 * don't touch meth_data! */
142 CRYPTO_EX_DATA ex_data; 165 CRYPTO_EX_DATA ex_data;
166 /* If this callback function pointer is set to non-NULL, then it will
167 * be used on DSO_load() in place of meth->dso_name_converter. NB: This
168 * should normally set using DSO_set_name_converter(). */
169 DSO_NAME_CONVERTER_FUNC name_converter;
170 /* This is populated with (a copy of) the platform-independant
171 * filename used for this DSO. */
172 char *filename;
173 /* This is populated with (a copy of) the translated filename by which
174 * the DSO was actually loaded. It is NULL iff the DSO is not currently
175 * loaded. NB: This is here because the filename translation process
176 * may involve a callback being invoked more than once not only to
177 * convert to a platform-specific form, but also to try different
178 * filenames in the process of trying to perform a load. As such, this
179 * variable can be used to indicate (a) whether this DSO structure
180 * corresponds to a loaded library or not, and (b) the filename with
181 * which it was actually loaded. */
182 char *loaded_filename;
143 }; 183 };
144 184
145 185
@@ -147,10 +187,38 @@ DSO * DSO_new(void);
147DSO * DSO_new_method(DSO_METHOD *method); 187DSO * DSO_new_method(DSO_METHOD *method);
148int DSO_free(DSO *dso); 188int DSO_free(DSO *dso);
149int DSO_flags(DSO *dso); 189int DSO_flags(DSO *dso);
150int DSO_up(DSO *dso); 190int DSO_up_ref(DSO *dso);
151long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg); 191long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg);
152 192
153void DSO_set_default_method(DSO_METHOD *meth); 193/* This function sets the DSO's name_converter callback. If it is non-NULL,
194 * then it will be used instead of the associated DSO_METHOD's function. If
195 * oldcb is non-NULL then it is set to the function pointer value being
196 * replaced. Return value is non-zero for success. */
197int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
198 DSO_NAME_CONVERTER_FUNC *oldcb);
199/* These functions can be used to get/set the platform-independant filename
200 * used for a DSO. NB: set will fail if the DSO is already loaded. */
201const char *DSO_get_filename(DSO *dso);
202int DSO_set_filename(DSO *dso, const char *filename);
203/* This function will invoke the DSO's name_converter callback to translate a
204 * filename, or if the callback isn't set it will instead use the DSO_METHOD's
205 * converter. If "filename" is NULL, the "filename" in the DSO itself will be
206 * used. If the DSO_FLAG_NO_NAME_TRANSLATION flag is set, then the filename is
207 * simply duplicated. NB: This function is usually called from within a
208 * DSO_METHOD during the processing of a DSO_load() call, and is exposed so that
209 * caller-created DSO_METHODs can do the same thing. A non-NULL return value
210 * will need to be OPENSSL_free()'d. */
211char *DSO_convert_filename(DSO *dso, const char *filename);
212/* If the DSO is currently loaded, this returns the filename that it was loaded
213 * under, otherwise it returns NULL. So it is also useful as a test as to
214 * whether the DSO is currently loaded. NB: This will not necessarily return
215 * the same value as DSO_convert_filename(dso, dso->filename), because the
216 * DSO_METHOD's load function may have tried a variety of filenames (with
217 * and/or without the aid of the converters) before settling on the one it
218 * actually loaded. */
219const char *DSO_get_loaded_filename(DSO *dso);
220
221void DSO_set_default_method(DSO_METHOD *meth);
154DSO_METHOD *DSO_get_default_method(void); 222DSO_METHOD *DSO_get_default_method(void);
155DSO_METHOD *DSO_get_method(DSO *dso); 223DSO_METHOD *DSO_get_method(DSO *dso);
156DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth); 224DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth);
@@ -159,8 +227,7 @@ DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth);
159 * for the first and third parameters. Use DSO_up and DSO_free for 227 * for the first and third parameters. Use DSO_up and DSO_free for
160 * subsequent reference count handling. Any flags passed in will be set 228 * subsequent reference count handling. Any flags passed in will be set
161 * in the constructed DSO after its init() function but before the 229 * in the constructed DSO after its init() function but before the
162 * load operation. This will be done with; 230 * load operation. If 'dso' is non-NULL, 'flags' is ignored. */
163 * DSO_ctrl(dso, DSO_CTRL_SET_FLAGS, flags, NULL); */
164DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags); 231DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags);
165 232
166/* This function binds to a variable inside a shared library. */ 233/* This function binds to a variable inside a shared library. */
@@ -194,52 +261,58 @@ DSO_METHOD *DSO_METHOD_win32(void);
194/* If VMS is defined, use shared images. If not, return NULL. */ 261/* If VMS is defined, use shared images. If not, return NULL. */
195DSO_METHOD *DSO_METHOD_vms(void); 262DSO_METHOD *DSO_METHOD_vms(void);
196 263
197void ERR_load_DSO_strings(void);
198
199/* BEGIN ERROR CODES */ 264/* BEGIN ERROR CODES */
200/* The following lines are auto generated by the script mkerr.pl. Any changes 265/* The following lines are auto generated by the script mkerr.pl. Any changes
201 * made after this point may be overwritten when the script is next run. 266 * made after this point may be overwritten when the script is next run.
202 */ 267 */
268void ERR_load_DSO_strings(void);
203 269
204/* Error codes for the DSO functions. */ 270/* Error codes for the DSO functions. */
205 271
206/* Function codes. */ 272/* Function codes. */
207#define DSO_F_DLFCN_BIND_FUNC 100 273#define DSO_F_DLFCN_BIND_FUNC 100
208#define DSO_F_DLFCN_BIND_VAR 101 274#define DSO_F_DLFCN_BIND_VAR 101
209#define DSO_F_DLFCN_CTRL 102 275#define DSO_F_DLFCN_LOAD 102
210#define DSO_F_DLFCN_LOAD 103 276#define DSO_F_DLFCN_NAME_CONVERTER 123
211#define DSO_F_DLFCN_UNLOAD 104 277#define DSO_F_DLFCN_UNLOAD 103
212#define DSO_F_DL_BIND_FUNC 105 278#define DSO_F_DL_BIND_FUNC 104
213#define DSO_F_DL_BIND_VAR 106 279#define DSO_F_DL_BIND_VAR 105
214#define DSO_F_DL_CTRL 107 280#define DSO_F_DL_LOAD 106
215#define DSO_F_DL_LOAD 108 281#define DSO_F_DL_NAME_CONVERTER 124
216#define DSO_F_DL_UNLOAD 109 282#define DSO_F_DL_UNLOAD 107
217#define DSO_F_DSO_BIND_FUNC 110 283#define DSO_F_DSO_BIND_FUNC 108
218#define DSO_F_DSO_BIND_VAR 111 284#define DSO_F_DSO_BIND_VAR 109
219#define DSO_F_DSO_CTRL 112 285#define DSO_F_DSO_CONVERT_FILENAME 126
220#define DSO_F_DSO_FREE 113 286#define DSO_F_DSO_CTRL 110
221#define DSO_F_DSO_LOAD 114 287#define DSO_F_DSO_FREE 111
222#define DSO_F_DSO_NEW_METHOD 115 288#define DSO_F_DSO_GET_FILENAME 127
223#define DSO_F_DSO_UP 116 289#define DSO_F_DSO_GET_LOADED_FILENAME 128
224#define DSO_F_VMS_BIND_VAR 122 290#define DSO_F_DSO_LOAD 112
225#define DSO_F_VMS_CTRL 123 291#define DSO_F_DSO_NEW_METHOD 113
226#define DSO_F_VMS_LOAD 124 292#define DSO_F_DSO_SET_FILENAME 129
227#define DSO_F_VMS_UNLOAD 125 293#define DSO_F_DSO_SET_NAME_CONVERTER 122
228#define DSO_F_WIN32_BIND_FUNC 117 294#define DSO_F_DSO_UP_REF 114
229#define DSO_F_WIN32_BIND_VAR 118 295#define DSO_F_VMS_BIND_VAR 115
230#define DSO_F_WIN32_CTRL 119 296#define DSO_F_VMS_LOAD 116
297#define DSO_F_VMS_UNLOAD 117
298#define DSO_F_WIN32_BIND_FUNC 118
299#define DSO_F_WIN32_BIND_VAR 119
231#define DSO_F_WIN32_LOAD 120 300#define DSO_F_WIN32_LOAD 120
301#define DSO_F_WIN32_NAME_CONVERTER 125
232#define DSO_F_WIN32_UNLOAD 121 302#define DSO_F_WIN32_UNLOAD 121
233 303
234/* Reason codes. */ 304/* Reason codes. */
235#define DSO_R_CTRL_FAILED 100 305#define DSO_R_CTRL_FAILED 100
236#define DSO_R_FILENAME_TOO_BIG 109 306#define DSO_R_DSO_ALREADY_LOADED 110
237#define DSO_R_FINISH_FAILED 101 307#define DSO_R_FILENAME_TOO_BIG 101
238#define DSO_R_LOAD_FAILED 102 308#define DSO_R_FINISH_FAILED 102
239#define DSO_R_NULL_HANDLE 103 309#define DSO_R_LOAD_FAILED 103
240#define DSO_R_STACK_ERROR 104 310#define DSO_R_NAME_TRANSLATION_FAILED 109
241#define DSO_R_SYM_FAILURE 105 311#define DSO_R_NO_FILENAME 111
242#define DSO_R_UNKNOWN_COMMAND 106 312#define DSO_R_NULL_HANDLE 104
313#define DSO_R_SET_FILENAME_FAILED 112
314#define DSO_R_STACK_ERROR 105
315#define DSO_R_SYM_FAILURE 106
243#define DSO_R_UNLOAD_FAILED 107 316#define DSO_R_UNLOAD_FAILED 107
244#define DSO_R_UNSUPPORTED 108 317#define DSO_R_UNSUPPORTED 108
245 318
@@ -247,4 +320,3 @@ void ERR_load_DSO_strings(void);
247} 320}
248#endif 321#endif
249#endif 322#endif
250
diff --git a/src/lib/libcrypto/dso/dso_dl.c b/src/lib/libcrypto/dso/dso_dl.c
index 455bd66ecf..195717e993 100644
--- a/src/lib/libcrypto/dso/dso_dl.c
+++ b/src/lib/libcrypto/dso/dso_dl.c
@@ -1,5 +1,5 @@
1/* dso_dl.c */ 1/* dso_dl.c */
2/* Written by Richard Levitte (levitte@openssl.org) for the OpenSSL 2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
@@ -72,7 +72,7 @@ DSO_METHOD *DSO_METHOD_dl(void)
72/* Part of the hack in "dl_load" ... */ 72/* Part of the hack in "dl_load" ... */
73#define DSO_MAX_TRANSLATED_SIZE 256 73#define DSO_MAX_TRANSLATED_SIZE 256
74 74
75static int dl_load(DSO *dso, const char *filename); 75static int dl_load(DSO *dso);
76static int dl_unload(DSO *dso); 76static int dl_unload(DSO *dso);
77static void *dl_bind_var(DSO *dso, const char *symname); 77static void *dl_bind_var(DSO *dso, const char *symname);
78static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname); 78static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname);
@@ -81,8 +81,9 @@ static int dl_unbind_var(DSO *dso, char *symname, void *symptr);
81static int dl_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); 81static int dl_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
82static int dl_init(DSO *dso); 82static int dl_init(DSO *dso);
83static int dl_finish(DSO *dso); 83static int dl_finish(DSO *dso);
84static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg);
84#endif 85#endif
85static long dl_ctrl(DSO *dso, int cmd, long larg, void *parg); 86static char *dl_name_converter(DSO *dso, const char *filename);
86 87
87static DSO_METHOD dso_meth_dl = { 88static DSO_METHOD dso_meth_dl = {
88 "OpenSSL 'dl' shared library method", 89 "OpenSSL 'dl' shared library method",
@@ -95,7 +96,8 @@ static DSO_METHOD dso_meth_dl = {
95 NULL, /* unbind_var */ 96 NULL, /* unbind_var */
96 NULL, /* unbind_func */ 97 NULL, /* unbind_func */
97#endif 98#endif
98 dl_ctrl, 99 NULL, /* ctrl */
100 dl_name_converter,
99 NULL, /* init */ 101 NULL, /* init */
100 NULL /* finish */ 102 NULL /* finish */
101 }; 103 };
@@ -111,40 +113,43 @@ DSO_METHOD *DSO_METHOD_dl(void)
111 * type so the cast is safe. 113 * type so the cast is safe.
112 */ 114 */
113 115
114#if defined(__hpux) 116static int dl_load(DSO *dso)
115static const char extension[] = ".sl";
116#else
117static const char extension[] = ".so";
118#endif
119static int dl_load(DSO *dso, const char *filename)
120 { 117 {
121 shl_t ptr; 118 shl_t ptr = NULL;
122 char translated[DSO_MAX_TRANSLATED_SIZE]; 119 /* We don't do any fancy retries or anything, just take the method's
123 int len; 120 * (or DSO's if it has the callback set) best translation of the
121 * platform-independant filename and try once with that. */
122 char *filename= DSO_convert_filename(dso, NULL);
124 123
125 /* The same comment as in dlfcn_load applies here. bleurgh. */ 124 if(filename == NULL)
126 len = strlen(filename) + strlen(extension);
127 if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
128 (len + 3 < DSO_MAX_TRANSLATED_SIZE) &&
129 (strstr(filename, "/") == NULL))
130 { 125 {
131 sprintf(translated, "lib%s%s", filename, extension); 126 DSOerr(DSO_F_DL_LOAD,DSO_R_NO_FILENAME);
132 ptr = shl_load(translated, BIND_IMMEDIATE, NULL); 127 goto err;
133 } 128 }
134 else 129 ptr = shl_load(filename, BIND_IMMEDIATE|DYNAMIC_PATH, NULL);
135 ptr = shl_load(filename, BIND_IMMEDIATE, NULL);
136 if(ptr == NULL) 130 if(ptr == NULL)
137 { 131 {
138 DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED); 132 DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED);
139 return(0); 133 ERR_add_error_data(4, "filename(", filename, "): ",
134 strerror(errno));
135 goto err;
140 } 136 }
141 if(!sk_push(dso->meth_data, (char *)ptr)) 137 if(!sk_push(dso->meth_data, (char *)ptr))
142 { 138 {
143 DSOerr(DSO_F_DL_LOAD,DSO_R_STACK_ERROR); 139 DSOerr(DSO_F_DL_LOAD,DSO_R_STACK_ERROR);
144 shl_unload(ptr); 140 goto err;
145 return(0);
146 } 141 }
142 /* Success, stick the converted filename we've loaded under into the DSO
143 * (it also serves as the indicator that we are currently loaded). */
144 dso->loaded_filename = filename;
147 return(1); 145 return(1);
146err:
147 /* Cleanup! */
148 if(filename != NULL)
149 OPENSSL_free(filename);
150 if(ptr != NULL)
151 shl_unload(ptr);
152 return(0);
148 } 153 }
149 154
150static int dl_unload(DSO *dso) 155static int dl_unload(DSO *dso)
@@ -195,6 +200,8 @@ static void *dl_bind_var(DSO *dso, const char *symname)
195 if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0) 200 if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0)
196 { 201 {
197 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_SYM_FAILURE); 202 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_SYM_FAILURE);
203 ERR_add_error_data(4, "symname(", symname, "): ",
204 strerror(errno));
198 return(NULL); 205 return(NULL);
199 } 206 }
200 return(sym); 207 return(sym);
@@ -224,33 +231,54 @@ static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname)
224 if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0) 231 if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0)
225 { 232 {
226 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_SYM_FAILURE); 233 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_SYM_FAILURE);
234 ERR_add_error_data(4, "symname(", symname, "): ",
235 strerror(errno));
227 return(NULL); 236 return(NULL);
228 } 237 }
229 return((DSO_FUNC_TYPE)sym); 238 return((DSO_FUNC_TYPE)sym);
230 } 239 }
231 240
232static long dl_ctrl(DSO *dso, int cmd, long larg, void *parg) 241/* This function is identical to the one in dso_dlfcn.c, but as it is highly
242 * unlikely that both the "dl" *and* "dlfcn" variants are being compiled at the
243 * same time, there's no great duplicating the code. Figuring out an elegant
244 * way to share one copy of the code would be more difficult and would not
245 * leave the implementations independant. */
246#if defined(__hpux)
247static const char extension[] = ".sl";
248#else
249static const char extension[] = ".so";
250#endif
251static char *dl_name_converter(DSO *dso, const char *filename)
233 { 252 {
234 if(dso == NULL) 253 char *translated;
254 int len, rsize, transform;
255
256 len = strlen(filename);
257 rsize = len + 1;
258 transform = (strstr(filename, "/") == NULL);
235 { 259 {
236 DSOerr(DSO_F_DL_CTRL,ERR_R_PASSED_NULL_PARAMETER); 260 /* We will convert this to "%s.s?" or "lib%s.s?" */
237 return(-1); 261 rsize += strlen(extension);/* The length of ".s?" */
262 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
263 rsize += 3; /* The length of "lib" */
238 } 264 }
239 switch(cmd) 265 translated = OPENSSL_malloc(rsize);
266 if(translated == NULL)
240 { 267 {
241 case DSO_CTRL_GET_FLAGS: 268 DSOerr(DSO_F_DL_NAME_CONVERTER,
242 return dso->flags; 269 DSO_R_NAME_TRANSLATION_FAILED);
243 case DSO_CTRL_SET_FLAGS: 270 return(NULL);
244 dso->flags = larg;
245 return(0);
246 case DSO_CTRL_OR_FLAGS:
247 dso->flags |= larg;
248 return(0);
249 default:
250 break;
251 } 271 }
252 DSOerr(DSO_F_DL_CTRL,DSO_R_UNKNOWN_COMMAND); 272 if(transform)
253 return(-1); 273 {
274 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
275 sprintf(translated, "lib%s%s", filename, extension);
276 else
277 sprintf(translated, "%s%s", filename, extension);
278 }
279 else
280 sprintf(translated, "%s", filename);
281 return(translated);
254 } 282 }
255 283
256#endif /* DSO_DL */ 284#endif /* DSO_DL */
diff --git a/src/lib/libcrypto/dso/dso_dlfcn.c b/src/lib/libcrypto/dso/dso_dlfcn.c
index e709c721cc..1a19164d3b 100644
--- a/src/lib/libcrypto/dso/dso_dlfcn.c
+++ b/src/lib/libcrypto/dso/dso_dlfcn.c
@@ -74,7 +74,7 @@ DSO_METHOD *DSO_METHOD_dlfcn(void)
74/* Part of the hack in "dlfcn_load" ... */ 74/* Part of the hack in "dlfcn_load" ... */
75#define DSO_MAX_TRANSLATED_SIZE 256 75#define DSO_MAX_TRANSLATED_SIZE 256
76 76
77static int dlfcn_load(DSO *dso, const char *filename); 77static int dlfcn_load(DSO *dso);
78static int dlfcn_unload(DSO *dso); 78static int dlfcn_unload(DSO *dso);
79static void *dlfcn_bind_var(DSO *dso, const char *symname); 79static void *dlfcn_bind_var(DSO *dso, const char *symname);
80static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname); 80static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname);
@@ -82,8 +82,9 @@ static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname);
82static int dlfcn_unbind(DSO *dso, char *symname, void *symptr); 82static int dlfcn_unbind(DSO *dso, char *symname, void *symptr);
83static int dlfcn_init(DSO *dso); 83static int dlfcn_init(DSO *dso);
84static int dlfcn_finish(DSO *dso); 84static int dlfcn_finish(DSO *dso);
85#endif
86static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg); 85static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg);
86#endif
87static char *dlfcn_name_converter(DSO *dso, const char *filename);
87 88
88static DSO_METHOD dso_meth_dlfcn = { 89static DSO_METHOD dso_meth_dlfcn = {
89 "OpenSSL 'dlfcn' shared library method", 90 "OpenSSL 'dlfcn' shared library method",
@@ -96,7 +97,8 @@ static DSO_METHOD dso_meth_dlfcn = {
96 NULL, /* unbind_var */ 97 NULL, /* unbind_var */
97 NULL, /* unbind_func */ 98 NULL, /* unbind_func */
98#endif 99#endif
99 dlfcn_ctrl, 100 NULL, /* ctrl */
101 dlfcn_name_converter,
100 NULL, /* init */ 102 NULL, /* init */
101 NULL /* finish */ 103 NULL /* finish */
102 }; 104 };
@@ -130,41 +132,40 @@ DSO_METHOD *DSO_METHOD_dlfcn(void)
130 * (i) the handle (void*) returned from dlopen(). 132 * (i) the handle (void*) returned from dlopen().
131 */ 133 */
132 134
133static int dlfcn_load(DSO *dso, const char *filename) 135static int dlfcn_load(DSO *dso)
134 { 136 {
135 void *ptr; 137 void *ptr = NULL;
136 char translated[DSO_MAX_TRANSLATED_SIZE]; 138 /* See applicable comments in dso_dl.c */
137 int len; 139 char *filename = DSO_convert_filename(dso, NULL);
138 140
139 /* NB: This is a hideous hack, but I'm not yet sure what 141 if(filename == NULL)
140 * to replace it with. This attempts to convert any filename,
141 * that looks like it has no path information, into a
142 * translated form, e. "blah" -> "libblah.so" */
143 len = strlen(filename);
144 if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
145 (len + 6 < DSO_MAX_TRANSLATED_SIZE) &&
146 (strstr(filename, "/") == NULL))
147 { 142 {
148 sprintf(translated, "lib%s.so", filename); 143 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME);
149 ptr = dlopen(translated, DLOPEN_FLAG); 144 goto err;
150 }
151 else
152 {
153 ptr = dlopen(filename, DLOPEN_FLAG);
154 } 145 }
146 ptr = dlopen(filename, DLOPEN_FLAG);
155 if(ptr == NULL) 147 if(ptr == NULL)
156 { 148 {
157 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED); 149 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED);
158 return(0); 150 ERR_add_error_data(4, "filename(", filename, "): ", dlerror());
151 goto err;
159 } 152 }
160 if(!sk_push(dso->meth_data, (char *)ptr)) 153 if(!sk_push(dso->meth_data, (char *)ptr))
161 { 154 {
162 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR); 155 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR);
163 dlclose(ptr); 156 goto err;
164 return(0);
165 } 157 }
158 /* Success */
159 dso->loaded_filename = filename;
166 return(1); 160 return(1);
167 } 161err:
162 /* Cleanup! */
163 if(filename != NULL)
164 OPENSSL_free(filename);
165 if(ptr != NULL)
166 dlclose(ptr);
167 return(0);
168}
168 169
169static int dlfcn_unload(DSO *dso) 170static int dlfcn_unload(DSO *dso)
170 { 171 {
@@ -214,6 +215,7 @@ static void *dlfcn_bind_var(DSO *dso, const char *symname)
214 if(sym == NULL) 215 if(sym == NULL)
215 { 216 {
216 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_SYM_FAILURE); 217 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_SYM_FAILURE);
218 ERR_add_error_data(4, "symname(", symname, "): ", dlerror());
217 return(NULL); 219 return(NULL);
218 } 220 }
219 return(sym); 221 return(sym);
@@ -244,33 +246,44 @@ static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname)
244 if(sym == NULL) 246 if(sym == NULL)
245 { 247 {
246 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE); 248 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE);
249 ERR_add_error_data(4, "symname(", symname, "): ", dlerror());
247 return(NULL); 250 return(NULL);
248 } 251 }
249 return(sym); 252 return(sym);
250 } 253 }
251 254
252static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg) 255static char *dlfcn_name_converter(DSO *dso, const char *filename)
253 { 256 {
254 if(dso == NULL) 257 char *translated;
258 int len, rsize, transform;
259
260 len = strlen(filename);
261 rsize = len + 1;
262 transform = (strstr(filename, "/") == NULL);
263 if(transform)
255 { 264 {
256 DSOerr(DSO_F_DLFCN_CTRL,ERR_R_PASSED_NULL_PARAMETER); 265 /* We will convert this to "%s.so" or "lib%s.so" */
257 return(-1); 266 rsize += 3; /* The length of ".so" */
267 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
268 rsize += 3; /* The length of "lib" */
258 } 269 }
259 switch(cmd) 270 translated = OPENSSL_malloc(rsize);
271 if(translated == NULL)
260 { 272 {
261 case DSO_CTRL_GET_FLAGS: 273 DSOerr(DSO_F_DLFCN_NAME_CONVERTER,
262 return dso->flags; 274 DSO_R_NAME_TRANSLATION_FAILED);
263 case DSO_CTRL_SET_FLAGS: 275 return(NULL);
264 dso->flags = (int)larg;
265 return(0);
266 case DSO_CTRL_OR_FLAGS:
267 dso->flags |= (int)larg;
268 return(0);
269 default:
270 break;
271 } 276 }
272 DSOerr(DSO_F_DLFCN_CTRL,DSO_R_UNKNOWN_COMMAND); 277 if(transform)
273 return(-1); 278 {
279 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
280 sprintf(translated, "lib%s.so", filename);
281 else
282 sprintf(translated, "%s.so", filename);
283 }
284 else
285 sprintf(translated, "%s", filename);
286 return(translated);
274 } 287 }
275 288
276#endif /* DSO_DLFCN */ 289#endif /* DSO_DLFCN */
diff --git a/src/lib/libcrypto/dso/dso_err.c b/src/lib/libcrypto/dso/dso_err.c
index a3d7321c9b..cf452de1aa 100644
--- a/src/lib/libcrypto/dso/dso_err.c
+++ b/src/lib/libcrypto/dso/dso_err.c
@@ -63,34 +63,38 @@
63#include <openssl/dso.h> 63#include <openssl/dso.h>
64 64
65/* BEGIN ERROR CODES */ 65/* BEGIN ERROR CODES */
66#ifndef NO_ERR 66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA DSO_str_functs[]= 67static ERR_STRING_DATA DSO_str_functs[]=
68 { 68 {
69{ERR_PACK(0,DSO_F_DLFCN_BIND_FUNC,0), "DLFCN_BIND_FUNC"}, 69{ERR_PACK(0,DSO_F_DLFCN_BIND_FUNC,0), "DLFCN_BIND_FUNC"},
70{ERR_PACK(0,DSO_F_DLFCN_BIND_VAR,0), "DLFCN_BIND_VAR"}, 70{ERR_PACK(0,DSO_F_DLFCN_BIND_VAR,0), "DLFCN_BIND_VAR"},
71{ERR_PACK(0,DSO_F_DLFCN_CTRL,0), "DLFCN_CTRL"},
72{ERR_PACK(0,DSO_F_DLFCN_LOAD,0), "DLFCN_LOAD"}, 71{ERR_PACK(0,DSO_F_DLFCN_LOAD,0), "DLFCN_LOAD"},
72{ERR_PACK(0,DSO_F_DLFCN_NAME_CONVERTER,0), "DLFCN_NAME_CONVERTER"},
73{ERR_PACK(0,DSO_F_DLFCN_UNLOAD,0), "DLFCN_UNLOAD"}, 73{ERR_PACK(0,DSO_F_DLFCN_UNLOAD,0), "DLFCN_UNLOAD"},
74{ERR_PACK(0,DSO_F_DL_BIND_FUNC,0), "DL_BIND_FUNC"}, 74{ERR_PACK(0,DSO_F_DL_BIND_FUNC,0), "DL_BIND_FUNC"},
75{ERR_PACK(0,DSO_F_DL_BIND_VAR,0), "DL_BIND_VAR"}, 75{ERR_PACK(0,DSO_F_DL_BIND_VAR,0), "DL_BIND_VAR"},
76{ERR_PACK(0,DSO_F_DL_CTRL,0), "DL_CTRL"},
77{ERR_PACK(0,DSO_F_DL_LOAD,0), "DL_LOAD"}, 76{ERR_PACK(0,DSO_F_DL_LOAD,0), "DL_LOAD"},
77{ERR_PACK(0,DSO_F_DL_NAME_CONVERTER,0), "DL_NAME_CONVERTER"},
78{ERR_PACK(0,DSO_F_DL_UNLOAD,0), "DL_UNLOAD"}, 78{ERR_PACK(0,DSO_F_DL_UNLOAD,0), "DL_UNLOAD"},
79{ERR_PACK(0,DSO_F_DSO_BIND_FUNC,0), "DSO_bind_func"}, 79{ERR_PACK(0,DSO_F_DSO_BIND_FUNC,0), "DSO_bind_func"},
80{ERR_PACK(0,DSO_F_DSO_BIND_VAR,0), "DSO_bind_var"}, 80{ERR_PACK(0,DSO_F_DSO_BIND_VAR,0), "DSO_bind_var"},
81{ERR_PACK(0,DSO_F_DSO_CONVERT_FILENAME,0), "DSO_convert_filename"},
81{ERR_PACK(0,DSO_F_DSO_CTRL,0), "DSO_ctrl"}, 82{ERR_PACK(0,DSO_F_DSO_CTRL,0), "DSO_ctrl"},
82{ERR_PACK(0,DSO_F_DSO_FREE,0), "DSO_free"}, 83{ERR_PACK(0,DSO_F_DSO_FREE,0), "DSO_free"},
84{ERR_PACK(0,DSO_F_DSO_GET_FILENAME,0), "DSO_get_filename"},
85{ERR_PACK(0,DSO_F_DSO_GET_LOADED_FILENAME,0), "DSO_get_loaded_filename"},
83{ERR_PACK(0,DSO_F_DSO_LOAD,0), "DSO_load"}, 86{ERR_PACK(0,DSO_F_DSO_LOAD,0), "DSO_load"},
84{ERR_PACK(0,DSO_F_DSO_NEW_METHOD,0), "DSO_new_method"}, 87{ERR_PACK(0,DSO_F_DSO_NEW_METHOD,0), "DSO_new_method"},
85{ERR_PACK(0,DSO_F_DSO_UP,0), "DSO_up"}, 88{ERR_PACK(0,DSO_F_DSO_SET_FILENAME,0), "DSO_set_filename"},
89{ERR_PACK(0,DSO_F_DSO_SET_NAME_CONVERTER,0), "DSO_set_name_converter"},
90{ERR_PACK(0,DSO_F_DSO_UP_REF,0), "DSO_up_ref"},
86{ERR_PACK(0,DSO_F_VMS_BIND_VAR,0), "VMS_BIND_VAR"}, 91{ERR_PACK(0,DSO_F_VMS_BIND_VAR,0), "VMS_BIND_VAR"},
87{ERR_PACK(0,DSO_F_VMS_CTRL,0), "VMS_CTRL"},
88{ERR_PACK(0,DSO_F_VMS_LOAD,0), "VMS_LOAD"}, 92{ERR_PACK(0,DSO_F_VMS_LOAD,0), "VMS_LOAD"},
89{ERR_PACK(0,DSO_F_VMS_UNLOAD,0), "VMS_UNLOAD"}, 93{ERR_PACK(0,DSO_F_VMS_UNLOAD,0), "VMS_UNLOAD"},
90{ERR_PACK(0,DSO_F_WIN32_BIND_FUNC,0), "WIN32_BIND_FUNC"}, 94{ERR_PACK(0,DSO_F_WIN32_BIND_FUNC,0), "WIN32_BIND_FUNC"},
91{ERR_PACK(0,DSO_F_WIN32_BIND_VAR,0), "WIN32_BIND_VAR"}, 95{ERR_PACK(0,DSO_F_WIN32_BIND_VAR,0), "WIN32_BIND_VAR"},
92{ERR_PACK(0,DSO_F_WIN32_CTRL,0), "WIN32_CTRL"},
93{ERR_PACK(0,DSO_F_WIN32_LOAD,0), "WIN32_LOAD"}, 96{ERR_PACK(0,DSO_F_WIN32_LOAD,0), "WIN32_LOAD"},
97{ERR_PACK(0,DSO_F_WIN32_NAME_CONVERTER,0), "WIN32_NAME_CONVERTER"},
94{ERR_PACK(0,DSO_F_WIN32_UNLOAD,0), "WIN32_UNLOAD"}, 98{ERR_PACK(0,DSO_F_WIN32_UNLOAD,0), "WIN32_UNLOAD"},
95{0,NULL} 99{0,NULL}
96 }; 100 };
@@ -98,13 +102,16 @@ static ERR_STRING_DATA DSO_str_functs[]=
98static ERR_STRING_DATA DSO_str_reasons[]= 102static ERR_STRING_DATA DSO_str_reasons[]=
99 { 103 {
100{DSO_R_CTRL_FAILED ,"control command failed"}, 104{DSO_R_CTRL_FAILED ,"control command failed"},
105{DSO_R_DSO_ALREADY_LOADED ,"dso already loaded"},
101{DSO_R_FILENAME_TOO_BIG ,"filename too big"}, 106{DSO_R_FILENAME_TOO_BIG ,"filename too big"},
102{DSO_R_FINISH_FAILED ,"cleanup method function failed"}, 107{DSO_R_FINISH_FAILED ,"cleanup method function failed"},
103{DSO_R_LOAD_FAILED ,"could not load the shared library"}, 108{DSO_R_LOAD_FAILED ,"could not load the shared library"},
109{DSO_R_NAME_TRANSLATION_FAILED ,"name translation failed"},
110{DSO_R_NO_FILENAME ,"no filename"},
104{DSO_R_NULL_HANDLE ,"a null shared library handle was used"}, 111{DSO_R_NULL_HANDLE ,"a null shared library handle was used"},
112{DSO_R_SET_FILENAME_FAILED ,"set filename failed"},
105{DSO_R_STACK_ERROR ,"the meth_data stack is corrupt"}, 113{DSO_R_STACK_ERROR ,"the meth_data stack is corrupt"},
106{DSO_R_SYM_FAILURE ,"could not bind to the requested symbol name"}, 114{DSO_R_SYM_FAILURE ,"could not bind to the requested symbol name"},
107{DSO_R_UNKNOWN_COMMAND ,"unknown control command"},
108{DSO_R_UNLOAD_FAILED ,"could not unload the shared library"}, 115{DSO_R_UNLOAD_FAILED ,"could not unload the shared library"},
109{DSO_R_UNSUPPORTED ,"functionality not supported"}, 116{DSO_R_UNSUPPORTED ,"functionality not supported"},
110{0,NULL} 117{0,NULL}
@@ -119,7 +126,7 @@ void ERR_load_DSO_strings(void)
119 if (init) 126 if (init)
120 { 127 {
121 init=0; 128 init=0;
122#ifndef NO_ERR 129#ifndef OPENSSL_NO_ERR
123 ERR_load_strings(ERR_LIB_DSO,DSO_str_functs); 130 ERR_load_strings(ERR_LIB_DSO,DSO_str_functs);
124 ERR_load_strings(ERR_LIB_DSO,DSO_str_reasons); 131 ERR_load_strings(ERR_LIB_DSO,DSO_str_reasons);
125#endif 132#endif
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c
index acd166697e..556069b9b8 100644
--- a/src/lib/libcrypto/dso/dso_lib.c
+++ b/src/lib/libcrypto/dso/dso_lib.c
@@ -108,7 +108,7 @@ DSO *DSO_new_method(DSO_METHOD *meth)
108 } 108 }
109 memset(ret, 0, sizeof(DSO)); 109 memset(ret, 0, sizeof(DSO));
110 ret->meth_data = sk_new_null(); 110 ret->meth_data = sk_new_null();
111 if((ret->meth_data = sk_new_null()) == NULL) 111 if(ret->meth_data == NULL)
112 { 112 {
113 /* sk_new doesn't generate any errors so we do */ 113 /* sk_new doesn't generate any errors so we do */
114 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); 114 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -164,6 +164,10 @@ int DSO_free(DSO *dso)
164 } 164 }
165 165
166 sk_free(dso->meth_data); 166 sk_free(dso->meth_data);
167 if(dso->filename != NULL)
168 OPENSSL_free(dso->filename);
169 if(dso->loaded_filename != NULL)
170 OPENSSL_free(dso->loaded_filename);
167 171
168 OPENSSL_free(dso); 172 OPENSSL_free(dso);
169 return(1); 173 return(1);
@@ -175,11 +179,11 @@ int DSO_flags(DSO *dso)
175 } 179 }
176 180
177 181
178int DSO_up(DSO *dso) 182int DSO_up_ref(DSO *dso)
179 { 183 {
180 if (dso == NULL) 184 if (dso == NULL)
181 { 185 {
182 DSOerr(DSO_F_DSO_UP,ERR_R_PASSED_NULL_PARAMETER); 186 DSOerr(DSO_F_DSO_UP_REF,ERR_R_PASSED_NULL_PARAMETER);
183 return(0); 187 return(0);
184 } 188 }
185 189
@@ -192,48 +196,60 @@ DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
192 DSO *ret; 196 DSO *ret;
193 int allocated = 0; 197 int allocated = 0;
194 198
195 if(filename == NULL)
196 {
197 DSOerr(DSO_F_DSO_LOAD,ERR_R_PASSED_NULL_PARAMETER);
198 return(NULL);
199 }
200 if(dso == NULL) 199 if(dso == NULL)
201 { 200 {
202 ret = DSO_new_method(meth); 201 ret = DSO_new_method(meth);
203 if(ret == NULL) 202 if(ret == NULL)
204 { 203 {
205 DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE); 204 DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE);
206 return(NULL); 205 goto err;
207 } 206 }
208 allocated = 1; 207 allocated = 1;
208 /* Pass the provided flags to the new DSO object */
209 if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0)
210 {
211 DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED);
212 goto err;
213 }
209 } 214 }
210 else 215 else
211 ret = dso; 216 ret = dso;
212 /* Bleurgh ... have to check for negative return values for 217 /* Don't load if we're currently already loaded */
213 * errors. <grimace> */ 218 if(ret->filename != NULL)
214 if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0)
215 { 219 {
216 DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED); 220 DSOerr(DSO_F_DSO_LOAD,DSO_R_DSO_ALREADY_LOADED);
217 if(allocated) 221 goto err;
218 DSO_free(ret); 222 }
219 return(NULL); 223 /* filename can only be NULL if we were passed a dso that already has
224 * one set. */
225 if(filename != NULL)
226 if(!DSO_set_filename(ret, filename))
227 {
228 DSOerr(DSO_F_DSO_LOAD,DSO_R_SET_FILENAME_FAILED);
229 goto err;
230 }
231 filename = ret->filename;
232 if(filename == NULL)
233 {
234 DSOerr(DSO_F_DSO_LOAD,DSO_R_NO_FILENAME);
235 goto err;
220 } 236 }
221 if(ret->meth->dso_load == NULL) 237 if(ret->meth->dso_load == NULL)
222 { 238 {
223 DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED); 239 DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED);
224 if(allocated) 240 goto err;
225 DSO_free(ret);
226 return(NULL);
227 } 241 }
228 if(!ret->meth->dso_load(ret, filename)) 242 if(!ret->meth->dso_load(ret))
229 { 243 {
230 DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED); 244 DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED);
231 if(allocated) 245 goto err;
232 DSO_free(ret);
233 return(NULL);
234 } 246 }
235 /* Load succeeded */ 247 /* Load succeeded */
236 return(ret); 248 return(ret);
249err:
250 if(allocated)
251 DSO_free(ret);
252 return(NULL);
237 } 253 }
238 254
239void *DSO_bind_var(DSO *dso, const char *symname) 255void *DSO_bind_var(DSO *dso, const char *symname)
@@ -297,6 +313,22 @@ long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
297 DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER); 313 DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER);
298 return(-1); 314 return(-1);
299 } 315 }
316 /* We should intercept certain generic commands and only pass control
317 * to the method-specific ctrl() function if it's something we don't
318 * handle. */
319 switch(cmd)
320 {
321 case DSO_CTRL_GET_FLAGS:
322 return dso->flags;
323 case DSO_CTRL_SET_FLAGS:
324 dso->flags = (int)larg;
325 return(0);
326 case DSO_CTRL_OR_FLAGS:
327 dso->flags |= (int)larg;
328 return(0);
329 default:
330 break;
331 }
300 if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) 332 if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL))
301 { 333 {
302 DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED); 334 DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED);
@@ -304,3 +336,104 @@ long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
304 } 336 }
305 return(dso->meth->dso_ctrl(dso,cmd,larg,parg)); 337 return(dso->meth->dso_ctrl(dso,cmd,larg,parg));
306 } 338 }
339
340int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
341 DSO_NAME_CONVERTER_FUNC *oldcb)
342 {
343 if(dso == NULL)
344 {
345 DSOerr(DSO_F_DSO_SET_NAME_CONVERTER,
346 ERR_R_PASSED_NULL_PARAMETER);
347 return(0);
348 }
349 if(oldcb)
350 *oldcb = dso->name_converter;
351 dso->name_converter = cb;
352 return(1);
353 }
354
355const char *DSO_get_filename(DSO *dso)
356 {
357 if(dso == NULL)
358 {
359 DSOerr(DSO_F_DSO_GET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
360 return(NULL);
361 }
362 return(dso->filename);
363 }
364
365int DSO_set_filename(DSO *dso, const char *filename)
366 {
367 char *copied;
368
369 if((dso == NULL) || (filename == NULL))
370 {
371 DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
372 return(0);
373 }
374 if(dso->loaded_filename)
375 {
376 DSOerr(DSO_F_DSO_SET_FILENAME,DSO_R_DSO_ALREADY_LOADED);
377 return(0);
378 }
379 /* We'll duplicate filename */
380 copied = OPENSSL_malloc(strlen(filename) + 1);
381 if(copied == NULL)
382 {
383 DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE);
384 return(0);
385 }
386 strcpy(copied, filename);
387 if(dso->filename)
388 OPENSSL_free(dso->filename);
389 dso->filename = copied;
390 return(1);
391 }
392
393char *DSO_convert_filename(DSO *dso, const char *filename)
394 {
395 char *result = NULL;
396
397 if(dso == NULL)
398 {
399 DSOerr(DSO_F_DSO_CONVERT_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
400 return(NULL);
401 }
402 if(filename == NULL)
403 filename = dso->filename;
404 if(filename == NULL)
405 {
406 DSOerr(DSO_F_DSO_CONVERT_FILENAME,DSO_R_NO_FILENAME);
407 return(NULL);
408 }
409 if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
410 {
411 if(dso->name_converter != NULL)
412 result = dso->name_converter(dso, filename);
413 else if(dso->meth->dso_name_converter != NULL)
414 result = dso->meth->dso_name_converter(dso, filename);
415 }
416 if(result == NULL)
417 {
418 result = OPENSSL_malloc(strlen(filename) + 1);
419 if(result == NULL)
420 {
421 DSOerr(DSO_F_DSO_CONVERT_FILENAME,
422 ERR_R_MALLOC_FAILURE);
423 return(NULL);
424 }
425 strcpy(result, filename);
426 }
427 return(result);
428 }
429
430const char *DSO_get_loaded_filename(DSO *dso)
431 {
432 if(dso == NULL)
433 {
434 DSOerr(DSO_F_DSO_GET_LOADED_FILENAME,
435 ERR_R_PASSED_NULL_PARAMETER);
436 return(NULL);
437 }
438 return(dso->loaded_filename);
439 }
diff --git a/src/lib/libcrypto/dso/dso_vms.c b/src/lib/libcrypto/dso/dso_vms.c
index ab48b63eb7..1674619d17 100644
--- a/src/lib/libcrypto/dso/dso_vms.c
+++ b/src/lib/libcrypto/dso/dso_vms.c
@@ -59,17 +59,17 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include <errno.h> 61#include <errno.h>
62#ifdef VMS 62#include "cryptlib.h"
63#include <openssl/dso.h>
64#ifdef OPENSSL_SYS_VMS
63#pragma message disable DOLLARID 65#pragma message disable DOLLARID
64#include <lib$routines.h> 66#include <lib$routines.h>
65#include <stsdef.h> 67#include <stsdef.h>
66#include <descrip.h> 68#include <descrip.h>
67#include <starlet.h> 69#include <starlet.h>
68#endif 70#endif
69#include "cryptlib.h"
70#include <openssl/dso.h>
71 71
72#ifndef VMS 72#ifndef OPENSSL_SYS_VMS
73DSO_METHOD *DSO_METHOD_vms(void) 73DSO_METHOD *DSO_METHOD_vms(void)
74 { 74 {
75 return NULL; 75 return NULL;
@@ -77,7 +77,7 @@ DSO_METHOD *DSO_METHOD_vms(void)
77#else 77#else
78#pragma message disable DOLLARID 78#pragma message disable DOLLARID
79 79
80static int vms_load(DSO *dso, const char *filename); 80static int vms_load(DSO *dso);
81static int vms_unload(DSO *dso); 81static int vms_unload(DSO *dso);
82static void *vms_bind_var(DSO *dso, const char *symname); 82static void *vms_bind_var(DSO *dso, const char *symname);
83static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname); 83static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname);
@@ -86,8 +86,9 @@ static int vms_unbind_var(DSO *dso, char *symname, void *symptr);
86static int vms_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); 86static int vms_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
87static int vms_init(DSO *dso); 87static int vms_init(DSO *dso);
88static int vms_finish(DSO *dso); 88static int vms_finish(DSO *dso);
89#endif
90static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg); 89static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
90#endif
91static char *vms_name_converter(DSO *dso, const char *filename);
91 92
92static DSO_METHOD dso_meth_vms = { 93static DSO_METHOD dso_meth_vms = {
93 "OpenSSL 'VMS' shared library method", 94 "OpenSSL 'VMS' shared library method",
@@ -100,7 +101,8 @@ static DSO_METHOD dso_meth_vms = {
100 NULL, /* unbind_var */ 101 NULL, /* unbind_var */
101 NULL, /* unbind_func */ 102 NULL, /* unbind_func */
102#endif 103#endif
103 vms_ctrl, 104 NULL, /* ctrl */
105 vms_name_converter,
104 NULL, /* init */ 106 NULL, /* init */
105 NULL /* finish */ 107 NULL /* finish */
106 }; 108 };
@@ -128,11 +130,20 @@ DSO_METHOD *DSO_METHOD_vms(void)
128 return(&dso_meth_vms); 130 return(&dso_meth_vms);
129 } 131 }
130 132
131static int vms_load(DSO *dso, const char *filename) 133static int vms_load(DSO *dso)
132 { 134 {
135 void *ptr = NULL;
136 /* See applicable comments in dso_dl.c */
137 char *filename = DSO_convert_filename(dso, NULL);
133 DSO_VMS_INTERNAL *p; 138 DSO_VMS_INTERNAL *p;
134 const char *sp1, *sp2; /* Search result */ 139 const char *sp1, *sp2; /* Search result */
135 140
141 if(filename == NULL)
142 {
143 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME);
144 goto err;
145 }
146
136 /* A file specification may look like this: 147 /* A file specification may look like this:
137 * 148 *
138 * node::dev:[dir-spec]name.type;ver 149 * node::dev:[dir-spec]name.type;ver
@@ -174,14 +185,14 @@ static int vms_load(DSO *dso, const char *filename)
174 || (sp1 - filename) + strlen(sp2) > FILENAME_MAX) 185 || (sp1 - filename) + strlen(sp2) > FILENAME_MAX)
175 { 186 {
176 DSOerr(DSO_F_VMS_LOAD,DSO_R_FILENAME_TOO_BIG); 187 DSOerr(DSO_F_VMS_LOAD,DSO_R_FILENAME_TOO_BIG);
177 return(0); 188 goto err;
178 } 189 }
179 190
180 p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL)); 191 p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL));
181 if(p == NULL) 192 if(p == NULL)
182 { 193 {
183 DSOerr(DSO_F_VMS_LOAD,ERR_R_MALLOC_FAILURE); 194 DSOerr(DSO_F_VMS_LOAD,ERR_R_MALLOC_FAILURE);
184 return(0); 195 goto err;
185 } 196 }
186 197
187 strncpy(p->filename, sp1, sp2-sp1); 198 strncpy(p->filename, sp1, sp2-sp1);
@@ -203,10 +214,19 @@ static int vms_load(DSO *dso, const char *filename)
203 if(!sk_push(dso->meth_data, (char *)p)) 214 if(!sk_push(dso->meth_data, (char *)p))
204 { 215 {
205 DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR); 216 DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR);
206 OPENSSL_free(p); 217 goto err;
207 return(0);
208 } 218 }
219
220 /* Success (for now, we lie. We actually do not know...) */
221 dso->loaded_filename = filename;
209 return(1); 222 return(1);
223err:
224 /* Cleanup! */
225 if(p != NULL)
226 OPENSSL_free(p);
227 if(filename != NULL)
228 OPENSSL_free(filename);
229 return(0);
210 } 230 }
211 231
212/* Note that this doesn't actually unload the shared image, as there is no 232/* Note that this doesn't actually unload the shared image, as there is no
@@ -259,8 +279,12 @@ void vms_bind_sym(DSO *dso, const char *symname, void **sym)
259 { 279 {
260 DSO_VMS_INTERNAL *ptr; 280 DSO_VMS_INTERNAL *ptr;
261 int status; 281 int status;
282#if 0
262 int flags = (1<<4); /* LIB$M_FIS_MIXEDCASE, but this symbol isn't 283 int flags = (1<<4); /* LIB$M_FIS_MIXEDCASE, but this symbol isn't
263 defined in VMS older than 7.0 or so */ 284 defined in VMS older than 7.0 or so */
285#else
286 int flags = 0;
287#endif
264 struct dsc$descriptor_s symname_dsc; 288 struct dsc$descriptor_s symname_dsc;
265 *sym = NULL; 289 *sym = NULL;
266 290
@@ -344,28 +368,12 @@ static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
344 return sym; 368 return sym;
345 } 369 }
346 370
347static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg) 371static char *vms_name_converter(DSO *dso, const char *filename)
348 { 372 {
349 if(dso == NULL) 373 int len = strlen(filename);
350 { 374 char *not_translated = OPENSSL_malloc(len+1);
351 DSOerr(DSO_F_VMS_CTRL,ERR_R_PASSED_NULL_PARAMETER); 375 strcpy(not_translated,filename);
352 return(-1); 376 return(not_translated);
353 } 377 }
354 switch(cmd) 378
355 { 379#endif /* OPENSSL_SYS_VMS */
356 case DSO_CTRL_GET_FLAGS:
357 return dso->flags;
358 case DSO_CTRL_SET_FLAGS:
359 dso->flags = (int)larg;
360 return(0);
361 case DSO_CTRL_OR_FLAGS:
362 dso->flags |= (int)larg;
363 return(0);
364 default:
365 break;
366 }
367 DSOerr(DSO_F_VMS_CTRL,DSO_R_UNKNOWN_COMMAND);
368 return(-1);
369 }
370
371#endif /* VMS */
diff --git a/src/lib/libcrypto/dso/dso_win32.c b/src/lib/libcrypto/dso/dso_win32.c
index 7f1d904806..af8586d754 100644
--- a/src/lib/libcrypto/dso/dso_win32.c
+++ b/src/lib/libcrypto/dso/dso_win32.c
@@ -61,7 +61,7 @@
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include <openssl/dso.h> 62#include <openssl/dso.h>
63 63
64#ifndef WIN32 64#ifndef OPENSSL_SYS_WIN32
65DSO_METHOD *DSO_METHOD_win32(void) 65DSO_METHOD *DSO_METHOD_win32(void)
66 { 66 {
67 return NULL; 67 return NULL;
@@ -71,7 +71,7 @@ DSO_METHOD *DSO_METHOD_win32(void)
71/* Part of the hack in "win32_load" ... */ 71/* Part of the hack in "win32_load" ... */
72#define DSO_MAX_TRANSLATED_SIZE 256 72#define DSO_MAX_TRANSLATED_SIZE 256
73 73
74static int win32_load(DSO *dso, const char *filename); 74static int win32_load(DSO *dso);
75static int win32_unload(DSO *dso); 75static int win32_unload(DSO *dso);
76static void *win32_bind_var(DSO *dso, const char *symname); 76static void *win32_bind_var(DSO *dso, const char *symname);
77static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname); 77static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname);
@@ -80,8 +80,9 @@ static int win32_unbind_var(DSO *dso, char *symname, void *symptr);
80static int win32_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); 80static int win32_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
81static int win32_init(DSO *dso); 81static int win32_init(DSO *dso);
82static int win32_finish(DSO *dso); 82static int win32_finish(DSO *dso);
83#endif
84static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg); 83static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg);
84#endif
85static char *win32_name_converter(DSO *dso, const char *filename);
85 86
86static DSO_METHOD dso_meth_win32 = { 87static DSO_METHOD dso_meth_win32 = {
87 "OpenSSL 'win32' shared library method", 88 "OpenSSL 'win32' shared library method",
@@ -94,7 +95,8 @@ static DSO_METHOD dso_meth_win32 = {
94 NULL, /* unbind_var */ 95 NULL, /* unbind_var */
95 NULL, /* unbind_func */ 96 NULL, /* unbind_func */
96#endif 97#endif
97 win32_ctrl, 98 NULL, /* ctrl */
99 win32_name_converter,
98 NULL, /* init */ 100 NULL, /* init */
99 NULL /* finish */ 101 NULL /* finish */
100 }; 102 };
@@ -109,50 +111,48 @@ DSO_METHOD *DSO_METHOD_win32(void)
109 * LoadLibrary(), and copied. 111 * LoadLibrary(), and copied.
110 */ 112 */
111 113
112static int win32_load(DSO *dso, const char *filename) 114static int win32_load(DSO *dso)
113 { 115 {
114 HINSTANCE h, *p; 116 HINSTANCE h = NULL, *p = NULL;
115 char translated[DSO_MAX_TRANSLATED_SIZE]; 117 /* See applicable comments from dso_dl.c */
116 int len; 118 char *filename = DSO_convert_filename(dso, NULL);
117 119
118 /* NB: This is a hideous hack, but I'm not yet sure what 120 if(filename == NULL)
119 * to replace it with. This attempts to convert any filename,
120 * that looks like it has no path information, into a
121 * translated form, e. "blah" -> "blah.dll" ... I'm more
122 * comfortable putting hacks into win32 code though ;-) */
123 len = strlen(filename);
124 if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
125 (len + 4 < DSO_MAX_TRANSLATED_SIZE) &&
126 (strstr(filename, "/") == NULL) &&
127 (strstr(filename, "\\") == NULL) &&
128 (strstr(filename, ":") == NULL))
129 { 121 {
130 sprintf(translated, "%s.dll", filename); 122 DSOerr(DSO_F_WIN32_LOAD,DSO_R_NO_FILENAME);
131 h = LoadLibrary(translated); 123 goto err;
132 } 124 }
133 else 125 h = LoadLibrary(filename);
134 h = LoadLibrary(filename);
135 if(h == NULL) 126 if(h == NULL)
136 { 127 {
137 DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED); 128 DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED);
138 return(0); 129 ERR_add_error_data(3, "filename(", filename, ")");
130 goto err;
139 } 131 }
140 p = (HINSTANCE *)OPENSSL_malloc(sizeof(HINSTANCE)); 132 p = (HINSTANCE *)OPENSSL_malloc(sizeof(HINSTANCE));
141 if(p == NULL) 133 if(p == NULL)
142 { 134 {
143 DSOerr(DSO_F_WIN32_LOAD,ERR_R_MALLOC_FAILURE); 135 DSOerr(DSO_F_WIN32_LOAD,ERR_R_MALLOC_FAILURE);
144 FreeLibrary(h); 136 goto err;
145 return(0);
146 } 137 }
147 *p = h; 138 *p = h;
148 if(!sk_push(dso->meth_data, (char *)p)) 139 if(!sk_push(dso->meth_data, (char *)p))
149 { 140 {
150 DSOerr(DSO_F_WIN32_LOAD,DSO_R_STACK_ERROR); 141 DSOerr(DSO_F_WIN32_LOAD,DSO_R_STACK_ERROR);
151 FreeLibrary(h); 142 goto err;
152 OPENSSL_free(p);
153 return(0);
154 } 143 }
144 /* Success */
145 dso->loaded_filename = filename;
155 return(1); 146 return(1);
147err:
148 /* Cleanup !*/
149 if(filename != NULL)
150 OPENSSL_free(filename);
151 if(p != NULL)
152 OPENSSL_free(p);
153 if(h != NULL)
154 FreeLibrary(h);
155 return(0);
156 } 156 }
157 157
158static int win32_unload(DSO *dso) 158static int win32_unload(DSO *dso)
@@ -211,6 +211,7 @@ static void *win32_bind_var(DSO *dso, const char *symname)
211 if(sym == NULL) 211 if(sym == NULL)
212 { 212 {
213 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_SYM_FAILURE); 213 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_SYM_FAILURE);
214 ERR_add_error_data(3, "symname(", symname, ")");
214 return(NULL); 215 return(NULL);
215 } 216 }
216 return(sym); 217 return(sym);
@@ -241,33 +242,38 @@ static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
241 if(sym == NULL) 242 if(sym == NULL)
242 { 243 {
243 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_SYM_FAILURE); 244 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_SYM_FAILURE);
245 ERR_add_error_data(3, "symname(", symname, ")");
244 return(NULL); 246 return(NULL);
245 } 247 }
246 return((DSO_FUNC_TYPE)sym); 248 return((DSO_FUNC_TYPE)sym);
247 } 249 }
248 250
249static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg) 251static char *win32_name_converter(DSO *dso, const char *filename)
250 { 252 {
251 if(dso == NULL) 253 char *translated;
252 { 254 int len, transform;
253 DSOerr(DSO_F_WIN32_CTRL,ERR_R_PASSED_NULL_PARAMETER); 255
254 return(-1); 256 len = strlen(filename);
255 } 257 transform = ((strstr(filename, "/") == NULL) &&
256 switch(cmd) 258 (strstr(filename, "\\") == NULL) &&
257 { 259 (strstr(filename, ":") == NULL));
258 case DSO_CTRL_GET_FLAGS: 260 if(transform)
259 return dso->flags; 261 /* We will convert this to "%s.dll" */
260 case DSO_CTRL_SET_FLAGS: 262 translated = OPENSSL_malloc(len + 5);
261 dso->flags = (int)larg; 263 else
262 return(0); 264 /* We will simply duplicate filename */
263 case DSO_CTRL_OR_FLAGS: 265 translated = OPENSSL_malloc(len + 1);
264 dso->flags |= (int)larg; 266 if(translated == NULL)
265 return(0); 267 {
266 default: 268 DSOerr(DSO_F_WIN32_NAME_CONVERTER,
267 break; 269 DSO_R_NAME_TRANSLATION_FAILED);
268 } 270 return(NULL);
269 DSOerr(DSO_F_WIN32_CTRL,DSO_R_UNKNOWN_COMMAND); 271 }
270 return(-1); 272 if(transform)
271 } 273 sprintf(translated, "%s.dll", filename);
274 else
275 sprintf(translated, "%s", filename);
276 return(translated);
277 }
272 278
273#endif /* WIN32 */ 279#endif /* OPENSSL_SYS_WIN32 */