diff options
Diffstat (limited to 'src/lib/libcrypto/dso')
-rw-r--r-- | src/lib/libcrypto/dso/Makefile.ssl | 140 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/README | 24 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/dso.h | 250 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/dso_dl.c | 251 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/dso_dlfcn.c | 276 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/dso_err.c | 128 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/dso_lib.c | 306 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/dso_null.c | 86 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/dso_openssl.c | 81 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/dso_vms.c | 371 | ||||
-rw-r--r-- | src/lib/libcrypto/dso/dso_win32.c | 273 |
11 files changed, 2186 insertions, 0 deletions
diff --git a/src/lib/libcrypto/dso/Makefile.ssl b/src/lib/libcrypto/dso/Makefile.ssl new file mode 100644 index 0000000000..effc46d2dc --- /dev/null +++ b/src/lib/libcrypto/dso/Makefile.ssl | |||
@@ -0,0 +1,140 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/dso/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= dso | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALL_PREFIX= | ||
11 | OPENSSLDIR= /usr/local/ssl | ||
12 | INSTALLTOP=/usr/local/ssl | ||
13 | MAKE= make -f Makefile.ssl | ||
14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) | ||
15 | MAKEFILE= Makefile.ssl | ||
16 | AR= ar r | ||
17 | |||
18 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
19 | |||
20 | GENERAL=Makefile | ||
21 | TEST= | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= dso_dl.c dso_dlfcn.c dso_err.c dso_lib.c dso_null.c \ | ||
26 | dso_openssl.c dso_win32.c dso_vms.c | ||
27 | LIBOBJ= dso_dl.o dso_dlfcn.o dso_err.o dso_lib.o dso_null.o \ | ||
28 | dso_openssl.o dso_win32.o dso_vms.o | ||
29 | |||
30 | SRC= $(LIBSRC) | ||
31 | |||
32 | EXHEADER= dso.h | ||
33 | HEADER= $(EXHEADER) | ||
34 | |||
35 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
36 | |||
37 | top: | ||
38 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
39 | |||
40 | all: lib | ||
41 | |||
42 | lib: $(LIBOBJ) | ||
43 | $(AR) $(LIB) $(LIBOBJ) | ||
44 | $(RANLIB) $(LIB) | ||
45 | @touch lib | ||
46 | |||
47 | files: | ||
48 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
49 | |||
50 | links: | ||
51 | @$(TOP)/util/point.sh Makefile.ssl Makefile | ||
52 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
53 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
54 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
55 | |||
56 | install: | ||
57 | @for i in $(EXHEADER) ; \ | ||
58 | do \ | ||
59 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
60 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
61 | done; | ||
62 | |||
63 | tags: | ||
64 | ctags $(SRC) | ||
65 | |||
66 | tests: | ||
67 | |||
68 | lint: | ||
69 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
70 | |||
71 | depend: | ||
72 | $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) | ||
73 | |||
74 | dclean: | ||
75 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
76 | mv -f Makefile.new $(MAKEFILE) | ||
77 | |||
78 | clean: | ||
79 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
80 | |||
81 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
82 | |||
83 | dso_dl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
84 | dso_dl.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h | ||
85 | dso_dl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
86 | dso_dl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
87 | dso_dl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
88 | dso_dl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
89 | dso_dl.o: ../../include/openssl/symhacks.h ../cryptlib.h | ||
90 | dso_dlfcn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
91 | dso_dlfcn.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h | ||
92 | dso_dlfcn.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
93 | dso_dlfcn.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
94 | dso_dlfcn.o: ../../include/openssl/opensslconf.h | ||
95 | dso_dlfcn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
96 | dso_dlfcn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
97 | dso_dlfcn.o: ../cryptlib.h | ||
98 | dso_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
99 | dso_err.o: ../../include/openssl/dso.h ../../include/openssl/err.h | ||
100 | dso_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslv.h | ||
101 | dso_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
102 | dso_err.o: ../../include/openssl/symhacks.h | ||
103 | dso_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
104 | dso_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h | ||
105 | dso_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
106 | dso_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
107 | dso_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
108 | dso_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
109 | dso_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h | ||
110 | dso_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
111 | dso_null.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h | ||
112 | dso_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
113 | dso_null.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
114 | dso_null.o: ../../include/openssl/opensslconf.h | ||
115 | dso_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
116 | dso_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
117 | dso_null.o: ../cryptlib.h | ||
118 | dso_openssl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
119 | dso_openssl.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h | ||
120 | dso_openssl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
121 | dso_openssl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
122 | dso_openssl.o: ../../include/openssl/opensslconf.h | ||
123 | dso_openssl.o: ../../include/openssl/opensslv.h | ||
124 | dso_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
125 | dso_openssl.o: ../../include/openssl/symhacks.h ../cryptlib.h | ||
126 | dso_vms.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
127 | dso_vms.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h | ||
128 | dso_vms.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
129 | dso_vms.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
130 | dso_vms.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
131 | dso_vms.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
132 | dso_vms.o: ../../include/openssl/symhacks.h ../cryptlib.h | ||
133 | dso_win32.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
134 | dso_win32.o: ../../include/openssl/crypto.h ../../include/openssl/dso.h | ||
135 | dso_win32.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
136 | dso_win32.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
137 | dso_win32.o: ../../include/openssl/opensslconf.h | ||
138 | dso_win32.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
139 | dso_win32.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
140 | dso_win32.o: ../cryptlib.h | ||
diff --git a/src/lib/libcrypto/dso/README b/src/lib/libcrypto/dso/README new file mode 100644 index 0000000000..6ba03c5631 --- /dev/null +++ b/src/lib/libcrypto/dso/README | |||
@@ -0,0 +1,24 @@ | |||
1 | TODO | ||
2 | ---- | ||
3 | |||
4 | Find a way where name-translation can be done in a way that is | ||
5 | sensitive to particular methods (ie. generic code could still do | ||
6 | different path/filename substitutions on win32 to what it does on | ||
7 | *nix) but doesn't assume some canonical form. Already one case | ||
8 | exists where the "blah -> (libblah.so,blah.dll)" mapping doesn't | ||
9 | suffice. I suspect a callback with an enumerated (or string?) | ||
10 | parameter could be the way to go here ... DSO_ctrl the callback | ||
11 | into place and it can be invoked to handle name translation with | ||
12 | some clue to the calling code as to what kind of system it is. | ||
13 | |||
14 | NOTES | ||
15 | ----- | ||
16 | |||
17 | I've checked out HPUX (well, version 11 at least) and shl_t is | ||
18 | a pointer type so it's safe to use in the way it has been in | ||
19 | dso_dl.c. On the other hand, HPUX11 support dlfcn too and | ||
20 | according to their man page, prefer developers to move to that. | ||
21 | I'll leave Richard's changes there as I guess dso_dl is needed | ||
22 | for HPUX10.20. | ||
23 | |||
24 | |||
diff --git a/src/lib/libcrypto/dso/dso.h b/src/lib/libcrypto/dso/dso.h new file mode 100644 index 0000000000..bed7c464a6 --- /dev/null +++ b/src/lib/libcrypto/dso/dso.h | |||
@@ -0,0 +1,250 @@ | |||
1 | /* dso.h */ | ||
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 | #ifndef HEADER_DSO_H | ||
60 | #define HEADER_DSO_H | ||
61 | |||
62 | #include <openssl/crypto.h> | ||
63 | |||
64 | #ifdef __cplusplus | ||
65 | extern "C" { | ||
66 | #endif | ||
67 | |||
68 | /* These values are used as commands to DSO_ctrl() */ | ||
69 | #define DSO_CTRL_GET_FLAGS 1 | ||
70 | #define DSO_CTRL_SET_FLAGS 2 | ||
71 | #define DSO_CTRL_OR_FLAGS 3 | ||
72 | |||
73 | /* These flags control the translation of file-names from canonical to | ||
74 | * native. Eg. in the CryptoSwift support, the "dl" and "dlfcn" | ||
75 | * methods will translate "swift" -> "libswift.so" whereas the "win32" | ||
76 | * method will translate "swift" -> "swift.dll". NB: Until I can figure | ||
77 | * out how to be more "conventional" with this, the methods will only | ||
78 | * honour this flag if it looks like it was passed a file without any | ||
79 | * path and if the filename is small enough. | ||
80 | */ | ||
81 | #define DSO_FLAG_NAME_TRANSLATION 0x01 | ||
82 | |||
83 | /* The following flag controls the translation of symbol names to upper | ||
84 | * case. This is currently only being implemented for OpenVMS. | ||
85 | */ | ||
86 | #define DSO_FLAG_UPCASE_SYMBOL 0x02 | ||
87 | |||
88 | |||
89 | typedef void (*DSO_FUNC_TYPE)(void); | ||
90 | |||
91 | typedef struct dso_st DSO; | ||
92 | |||
93 | typedef struct dso_meth_st | ||
94 | { | ||
95 | const char *name; | ||
96 | /* Loads a shared library */ | ||
97 | int (*dso_load)(DSO *dso, const char *filename); | ||
98 | /* Unloads a shared library */ | ||
99 | int (*dso_unload)(DSO *dso); | ||
100 | /* Binds a variable */ | ||
101 | void *(*dso_bind_var)(DSO *dso, const char *symname); | ||
102 | /* Binds a function - assumes a return type of DSO_FUNC_TYPE. | ||
103 | * This should be cast to the real function prototype by the | ||
104 | * caller. Platforms that don't have compatible representations | ||
105 | * for different prototypes (this is possible within ANSI C) | ||
106 | * are highly unlikely to have shared libraries at all, let | ||
107 | * alone a DSO_METHOD implemented for them. */ | ||
108 | DSO_FUNC_TYPE (*dso_bind_func)(DSO *dso, const char *symname); | ||
109 | |||
110 | /* I don't think this would actually be used in any circumstances. */ | ||
111 | #if 0 | ||
112 | /* Unbinds a variable */ | ||
113 | int (*dso_unbind_var)(DSO *dso, char *symname, void *symptr); | ||
114 | /* Unbinds a function */ | ||
115 | int (*dso_unbind_func)(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); | ||
116 | #endif | ||
117 | /* The generic (yuck) "ctrl()" function. NB: Negative return | ||
118 | * values (rather than zero) indicate errors. */ | ||
119 | long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg); | ||
120 | |||
121 | /* [De]Initialisation handlers. */ | ||
122 | int (*init)(DSO *dso); | ||
123 | int (*finish)(DSO *dso); | ||
124 | } DSO_METHOD; | ||
125 | |||
126 | /**********************************************************************/ | ||
127 | /* The low-level handle type used to refer to a loaded shared library */ | ||
128 | |||
129 | struct dso_st | ||
130 | { | ||
131 | DSO_METHOD *meth; | ||
132 | /* Standard dlopen uses a (void *). Win32 uses a HANDLE. VMS | ||
133 | * doesn't use anything but will need to cache the filename | ||
134 | * for use in the dso_bind handler. All in all, let each | ||
135 | * method control its own destiny. "Handles" and such go in | ||
136 | * a STACK. */ | ||
137 | STACK *meth_data; | ||
138 | int references; | ||
139 | int flags; | ||
140 | /* For use by applications etc ... use this for your bits'n'pieces, | ||
141 | * don't touch meth_data! */ | ||
142 | CRYPTO_EX_DATA ex_data; | ||
143 | }; | ||
144 | |||
145 | |||
146 | DSO * DSO_new(void); | ||
147 | DSO * DSO_new_method(DSO_METHOD *method); | ||
148 | int DSO_free(DSO *dso); | ||
149 | int DSO_flags(DSO *dso); | ||
150 | int DSO_up(DSO *dso); | ||
151 | long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg); | ||
152 | |||
153 | void DSO_set_default_method(DSO_METHOD *meth); | ||
154 | DSO_METHOD *DSO_get_default_method(void); | ||
155 | DSO_METHOD *DSO_get_method(DSO *dso); | ||
156 | DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth); | ||
157 | |||
158 | /* The all-singing all-dancing load function, you normally pass NULL | ||
159 | * 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 | ||
161 | * in the constructed DSO after its init() function but before the | ||
162 | * load operation. This will be done with; | ||
163 | * DSO_ctrl(dso, DSO_CTRL_SET_FLAGS, flags, NULL); */ | ||
164 | DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags); | ||
165 | |||
166 | /* This function binds to a variable inside a shared library. */ | ||
167 | void *DSO_bind_var(DSO *dso, const char *symname); | ||
168 | |||
169 | /* This function binds to a function inside a shared library. */ | ||
170 | DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname); | ||
171 | |||
172 | /* This method is the default, but will beg, borrow, or steal whatever | ||
173 | * method should be the default on any particular platform (including | ||
174 | * DSO_METH_null() if necessary). */ | ||
175 | DSO_METHOD *DSO_METHOD_openssl(void); | ||
176 | |||
177 | /* This method is defined for all platforms - if a platform has no | ||
178 | * DSO support then this will be the only method! */ | ||
179 | DSO_METHOD *DSO_METHOD_null(void); | ||
180 | |||
181 | /* If DSO_DLFCN is defined, the standard dlfcn.h-style functions | ||
182 | * (dlopen, dlclose, dlsym, etc) will be used and incorporated into | ||
183 | * this method. If not, this method will return NULL. */ | ||
184 | DSO_METHOD *DSO_METHOD_dlfcn(void); | ||
185 | |||
186 | /* If DSO_DL is defined, the standard dl.h-style functions (shl_load, | ||
187 | * shl_unload, shl_findsym, etc) will be used and incorporated into | ||
188 | * this method. If not, this method will return NULL. */ | ||
189 | DSO_METHOD *DSO_METHOD_dl(void); | ||
190 | |||
191 | /* If WIN32 is defined, use DLLs. If not, return NULL. */ | ||
192 | DSO_METHOD *DSO_METHOD_win32(void); | ||
193 | |||
194 | /* If VMS is defined, use shared images. If not, return NULL. */ | ||
195 | DSO_METHOD *DSO_METHOD_vms(void); | ||
196 | |||
197 | void ERR_load_DSO_strings(void); | ||
198 | |||
199 | /* BEGIN ERROR CODES */ | ||
200 | /* 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. | ||
202 | */ | ||
203 | |||
204 | /* Error codes for the DSO functions. */ | ||
205 | |||
206 | /* Function codes. */ | ||
207 | #define DSO_F_DLFCN_BIND_FUNC 100 | ||
208 | #define DSO_F_DLFCN_BIND_VAR 101 | ||
209 | #define DSO_F_DLFCN_CTRL 102 | ||
210 | #define DSO_F_DLFCN_LOAD 103 | ||
211 | #define DSO_F_DLFCN_UNLOAD 104 | ||
212 | #define DSO_F_DL_BIND_FUNC 105 | ||
213 | #define DSO_F_DL_BIND_VAR 106 | ||
214 | #define DSO_F_DL_CTRL 107 | ||
215 | #define DSO_F_DL_LOAD 108 | ||
216 | #define DSO_F_DL_UNLOAD 109 | ||
217 | #define DSO_F_DSO_BIND_FUNC 110 | ||
218 | #define DSO_F_DSO_BIND_VAR 111 | ||
219 | #define DSO_F_DSO_CTRL 112 | ||
220 | #define DSO_F_DSO_FREE 113 | ||
221 | #define DSO_F_DSO_LOAD 114 | ||
222 | #define DSO_F_DSO_NEW_METHOD 115 | ||
223 | #define DSO_F_DSO_UP 116 | ||
224 | #define DSO_F_VMS_BIND_VAR 122 | ||
225 | #define DSO_F_VMS_CTRL 123 | ||
226 | #define DSO_F_VMS_LOAD 124 | ||
227 | #define DSO_F_VMS_UNLOAD 125 | ||
228 | #define DSO_F_WIN32_BIND_FUNC 117 | ||
229 | #define DSO_F_WIN32_BIND_VAR 118 | ||
230 | #define DSO_F_WIN32_CTRL 119 | ||
231 | #define DSO_F_WIN32_LOAD 120 | ||
232 | #define DSO_F_WIN32_UNLOAD 121 | ||
233 | |||
234 | /* Reason codes. */ | ||
235 | #define DSO_R_CTRL_FAILED 100 | ||
236 | #define DSO_R_FILENAME_TOO_BIG 109 | ||
237 | #define DSO_R_FINISH_FAILED 101 | ||
238 | #define DSO_R_LOAD_FAILED 102 | ||
239 | #define DSO_R_NULL_HANDLE 103 | ||
240 | #define DSO_R_STACK_ERROR 104 | ||
241 | #define DSO_R_SYM_FAILURE 105 | ||
242 | #define DSO_R_UNKNOWN_COMMAND 106 | ||
243 | #define DSO_R_UNLOAD_FAILED 107 | ||
244 | #define DSO_R_UNSUPPORTED 108 | ||
245 | |||
246 | #ifdef __cplusplus | ||
247 | } | ||
248 | #endif | ||
249 | #endif | ||
250 | |||
diff --git a/src/lib/libcrypto/dso/dso_dl.c b/src/lib/libcrypto/dso/dso_dl.c new file mode 100644 index 0000000000..69810fc3bb --- /dev/null +++ b/src/lib/libcrypto/dso/dso_dl.c | |||
@@ -0,0 +1,251 @@ | |||
1 | /* dso_dl.c */ | ||
2 | /* Written by Richard Levitte (levitte@openssl.org) 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 "cryptlib.h" | ||
61 | #include <openssl/dso.h> | ||
62 | |||
63 | #ifndef DSO_DL | ||
64 | DSO_METHOD *DSO_METHOD_dl(void) | ||
65 | { | ||
66 | return NULL; | ||
67 | } | ||
68 | #else | ||
69 | |||
70 | #include <dl.h> | ||
71 | |||
72 | /* Part of the hack in "dl_load" ... */ | ||
73 | #define DSO_MAX_TRANSLATED_SIZE 256 | ||
74 | |||
75 | static int dl_load(DSO *dso, const char *filename); | ||
76 | static int dl_unload(DSO *dso); | ||
77 | static void *dl_bind_var(DSO *dso, const char *symname); | ||
78 | static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname); | ||
79 | #if 0 | ||
80 | static int dl_unbind_var(DSO *dso, char *symname, void *symptr); | ||
81 | static int dl_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); | ||
82 | static int dl_init(DSO *dso); | ||
83 | static int dl_finish(DSO *dso); | ||
84 | #endif | ||
85 | static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg); | ||
86 | |||
87 | static DSO_METHOD dso_meth_dl = { | ||
88 | "OpenSSL 'dl' shared library method", | ||
89 | dl_load, | ||
90 | dl_unload, | ||
91 | dl_bind_var, | ||
92 | dl_bind_func, | ||
93 | /* For now, "unbind" doesn't exist */ | ||
94 | #if 0 | ||
95 | NULL, /* unbind_var */ | ||
96 | NULL, /* unbind_func */ | ||
97 | #endif | ||
98 | dl_ctrl, | ||
99 | NULL, /* init */ | ||
100 | NULL /* finish */ | ||
101 | }; | ||
102 | |||
103 | DSO_METHOD *DSO_METHOD_dl(void) | ||
104 | { | ||
105 | return(&dso_meth_dl); | ||
106 | } | ||
107 | |||
108 | /* For this DSO_METHOD, our meth_data STACK will contain; | ||
109 | * (i) the handle (shl_t) returned from shl_load(). | ||
110 | * NB: I checked on HPUX11 and shl_t is itself a pointer | ||
111 | * type so the cast is safe. | ||
112 | */ | ||
113 | |||
114 | static int dl_load(DSO *dso, const char *filename) | ||
115 | { | ||
116 | shl_t ptr; | ||
117 | char translated[DSO_MAX_TRANSLATED_SIZE]; | ||
118 | int len; | ||
119 | |||
120 | /* The same comment as in dlfcn_load applies here. bleurgh. */ | ||
121 | len = strlen(filename); | ||
122 | if((dso->flags & DSO_FLAG_NAME_TRANSLATION) && | ||
123 | (len + 6 < DSO_MAX_TRANSLATED_SIZE) && | ||
124 | (strstr(filename, "/") == NULL)) | ||
125 | { | ||
126 | sprintf(translated, "lib%s.so", filename); | ||
127 | ptr = shl_load(translated, BIND_IMMEDIATE, NULL); | ||
128 | } | ||
129 | else | ||
130 | ptr = shl_load(filename, BIND_IMMEDIATE, NULL); | ||
131 | if(ptr == NULL) | ||
132 | { | ||
133 | DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED); | ||
134 | return(0); | ||
135 | } | ||
136 | if(!sk_push(dso->meth_data, (char *)ptr)) | ||
137 | { | ||
138 | DSOerr(DSO_F_DL_LOAD,DSO_R_STACK_ERROR); | ||
139 | shl_unload(ptr); | ||
140 | return(0); | ||
141 | } | ||
142 | return(1); | ||
143 | } | ||
144 | |||
145 | static int dl_unload(DSO *dso) | ||
146 | { | ||
147 | shl_t ptr; | ||
148 | if(dso == NULL) | ||
149 | { | ||
150 | DSOerr(DSO_F_DL_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); | ||
151 | return(0); | ||
152 | } | ||
153 | if(sk_num(dso->meth_data) < 1) | ||
154 | return(1); | ||
155 | /* Is this statement legal? */ | ||
156 | ptr = (shl_t)sk_pop(dso->meth_data); | ||
157 | if(ptr == NULL) | ||
158 | { | ||
159 | DSOerr(DSO_F_DL_UNLOAD,DSO_R_NULL_HANDLE); | ||
160 | /* Should push the value back onto the stack in | ||
161 | * case of a retry. */ | ||
162 | sk_push(dso->meth_data, (char *)ptr); | ||
163 | return(0); | ||
164 | } | ||
165 | shl_unload(ptr); | ||
166 | return(1); | ||
167 | } | ||
168 | |||
169 | static void *dl_bind_var(DSO *dso, const char *symname) | ||
170 | { | ||
171 | shl_t ptr; | ||
172 | void *sym; | ||
173 | |||
174 | if((dso == NULL) || (symname == NULL)) | ||
175 | { | ||
176 | DSOerr(DSO_F_DL_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | ||
177 | return(NULL); | ||
178 | } | ||
179 | if(sk_num(dso->meth_data) < 1) | ||
180 | { | ||
181 | DSOerr(DSO_F_DL_BIND_VAR,DSO_R_STACK_ERROR); | ||
182 | return(NULL); | ||
183 | } | ||
184 | ptr = (shl_t)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | ||
185 | if(ptr == NULL) | ||
186 | { | ||
187 | DSOerr(DSO_F_DL_BIND_VAR,DSO_R_NULL_HANDLE); | ||
188 | return(NULL); | ||
189 | } | ||
190 | if (shl_findsym(ptr, symname, TYPE_UNDEFINED, &sym) < 0) | ||
191 | { | ||
192 | DSOerr(DSO_F_DL_BIND_VAR,DSO_R_SYM_FAILURE); | ||
193 | return(NULL); | ||
194 | } | ||
195 | return(sym); | ||
196 | } | ||
197 | |||
198 | static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname) | ||
199 | { | ||
200 | shl_t ptr; | ||
201 | void *sym; | ||
202 | |||
203 | if((dso == NULL) || (symname == NULL)) | ||
204 | { | ||
205 | DSOerr(DSO_F_DL_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); | ||
206 | return(NULL); | ||
207 | } | ||
208 | if(sk_num(dso->meth_data) < 1) | ||
209 | { | ||
210 | DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_STACK_ERROR); | ||
211 | return(NULL); | ||
212 | } | ||
213 | ptr = (shl_t)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | ||
214 | if(ptr == NULL) | ||
215 | { | ||
216 | DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_NULL_HANDLE); | ||
217 | return(NULL); | ||
218 | } | ||
219 | if (shl_findsym(ptr, symname, TYPE_UNDEFINED, &sym) < 0) | ||
220 | { | ||
221 | DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_SYM_FAILURE); | ||
222 | return(NULL); | ||
223 | } | ||
224 | return((DSO_FUNC_TYPE)sym); | ||
225 | } | ||
226 | |||
227 | static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg) | ||
228 | { | ||
229 | if(dso == NULL) | ||
230 | { | ||
231 | DSOerr(DSO_F_DL_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
232 | return(-1); | ||
233 | } | ||
234 | switch(cmd) | ||
235 | { | ||
236 | case DSO_CTRL_GET_FLAGS: | ||
237 | return dso->flags; | ||
238 | case DSO_CTRL_SET_FLAGS: | ||
239 | dso->flags = (int)larg; | ||
240 | return(0); | ||
241 | case DSO_CTRL_OR_FLAGS: | ||
242 | dso->flags |= (int)larg; | ||
243 | return(0); | ||
244 | default: | ||
245 | break; | ||
246 | } | ||
247 | DSOerr(DSO_F_DL_CTRL,DSO_R_UNKNOWN_COMMAND); | ||
248 | return(-1); | ||
249 | } | ||
250 | |||
251 | #endif /* DSO_DL */ | ||
diff --git a/src/lib/libcrypto/dso/dso_dlfcn.c b/src/lib/libcrypto/dso/dso_dlfcn.c new file mode 100644 index 0000000000..e709c721cc --- /dev/null +++ b/src/lib/libcrypto/dso/dso_dlfcn.c | |||
@@ -0,0 +1,276 @@ | |||
1 | /* dso_dlfcn.c */ | ||
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 "cryptlib.h" | ||
61 | #include <openssl/dso.h> | ||
62 | |||
63 | #ifndef DSO_DLFCN | ||
64 | DSO_METHOD *DSO_METHOD_dlfcn(void) | ||
65 | { | ||
66 | return NULL; | ||
67 | } | ||
68 | #else | ||
69 | |||
70 | #ifdef HAVE_DLFCN_H | ||
71 | #include <dlfcn.h> | ||
72 | #endif | ||
73 | |||
74 | /* Part of the hack in "dlfcn_load" ... */ | ||
75 | #define DSO_MAX_TRANSLATED_SIZE 256 | ||
76 | |||
77 | static int dlfcn_load(DSO *dso, const char *filename); | ||
78 | static int dlfcn_unload(DSO *dso); | ||
79 | static void *dlfcn_bind_var(DSO *dso, const char *symname); | ||
80 | static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname); | ||
81 | #if 0 | ||
82 | static int dlfcn_unbind(DSO *dso, char *symname, void *symptr); | ||
83 | static int dlfcn_init(DSO *dso); | ||
84 | static int dlfcn_finish(DSO *dso); | ||
85 | #endif | ||
86 | static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg); | ||
87 | |||
88 | static DSO_METHOD dso_meth_dlfcn = { | ||
89 | "OpenSSL 'dlfcn' shared library method", | ||
90 | dlfcn_load, | ||
91 | dlfcn_unload, | ||
92 | dlfcn_bind_var, | ||
93 | dlfcn_bind_func, | ||
94 | /* For now, "unbind" doesn't exist */ | ||
95 | #if 0 | ||
96 | NULL, /* unbind_var */ | ||
97 | NULL, /* unbind_func */ | ||
98 | #endif | ||
99 | dlfcn_ctrl, | ||
100 | NULL, /* init */ | ||
101 | NULL /* finish */ | ||
102 | }; | ||
103 | |||
104 | DSO_METHOD *DSO_METHOD_dlfcn(void) | ||
105 | { | ||
106 | return(&dso_meth_dlfcn); | ||
107 | } | ||
108 | |||
109 | /* Prior to using the dlopen() function, we should decide on the flag | ||
110 | * we send. There's a few different ways of doing this and it's a | ||
111 | * messy venn-diagram to match up which platforms support what. So | ||
112 | * as we don't have autoconf yet, I'm implementing a hack that could | ||
113 | * be hacked further relatively easily to deal with cases as we find | ||
114 | * them. Initially this is to cope with OpenBSD. */ | ||
115 | #ifdef __OpenBSD__ | ||
116 | # ifdef DL_LAZY | ||
117 | # define DLOPEN_FLAG DL_LAZY | ||
118 | # else | ||
119 | # ifdef RTLD_NOW | ||
120 | # define DLOPEN_FLAG RTLD_NOW | ||
121 | # else | ||
122 | # define DLOPEN_FLAG 0 | ||
123 | # endif | ||
124 | # endif | ||
125 | #else | ||
126 | # define DLOPEN_FLAG RTLD_NOW /* Hope this works everywhere else */ | ||
127 | #endif | ||
128 | |||
129 | /* For this DSO_METHOD, our meth_data STACK will contain; | ||
130 | * (i) the handle (void*) returned from dlopen(). | ||
131 | */ | ||
132 | |||
133 | static int dlfcn_load(DSO *dso, const char *filename) | ||
134 | { | ||
135 | void *ptr; | ||
136 | char translated[DSO_MAX_TRANSLATED_SIZE]; | ||
137 | int len; | ||
138 | |||
139 | /* NB: This is a hideous hack, but I'm not yet sure what | ||
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 | { | ||
148 | sprintf(translated, "lib%s.so", filename); | ||
149 | ptr = dlopen(translated, DLOPEN_FLAG); | ||
150 | } | ||
151 | else | ||
152 | { | ||
153 | ptr = dlopen(filename, DLOPEN_FLAG); | ||
154 | } | ||
155 | if(ptr == NULL) | ||
156 | { | ||
157 | DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED); | ||
158 | return(0); | ||
159 | } | ||
160 | if(!sk_push(dso->meth_data, (char *)ptr)) | ||
161 | { | ||
162 | DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR); | ||
163 | dlclose(ptr); | ||
164 | return(0); | ||
165 | } | ||
166 | return(1); | ||
167 | } | ||
168 | |||
169 | static int dlfcn_unload(DSO *dso) | ||
170 | { | ||
171 | void *ptr; | ||
172 | if(dso == NULL) | ||
173 | { | ||
174 | DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); | ||
175 | return(0); | ||
176 | } | ||
177 | if(sk_num(dso->meth_data) < 1) | ||
178 | return(1); | ||
179 | ptr = (void *)sk_pop(dso->meth_data); | ||
180 | if(ptr == NULL) | ||
181 | { | ||
182 | DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE); | ||
183 | /* Should push the value back onto the stack in | ||
184 | * case of a retry. */ | ||
185 | sk_push(dso->meth_data, (char *)ptr); | ||
186 | return(0); | ||
187 | } | ||
188 | /* For now I'm not aware of any errors associated with dlclose() */ | ||
189 | dlclose(ptr); | ||
190 | return(1); | ||
191 | } | ||
192 | |||
193 | static void *dlfcn_bind_var(DSO *dso, const char *symname) | ||
194 | { | ||
195 | void *ptr, *sym; | ||
196 | |||
197 | if((dso == NULL) || (symname == NULL)) | ||
198 | { | ||
199 | DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | ||
200 | return(NULL); | ||
201 | } | ||
202 | if(sk_num(dso->meth_data) < 1) | ||
203 | { | ||
204 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR); | ||
205 | return(NULL); | ||
206 | } | ||
207 | ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | ||
208 | if(ptr == NULL) | ||
209 | { | ||
210 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE); | ||
211 | return(NULL); | ||
212 | } | ||
213 | sym = dlsym(ptr, symname); | ||
214 | if(sym == NULL) | ||
215 | { | ||
216 | DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_SYM_FAILURE); | ||
217 | return(NULL); | ||
218 | } | ||
219 | return(sym); | ||
220 | } | ||
221 | |||
222 | static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname) | ||
223 | { | ||
224 | void *ptr; | ||
225 | DSO_FUNC_TYPE sym; | ||
226 | |||
227 | if((dso == NULL) || (symname == NULL)) | ||
228 | { | ||
229 | DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); | ||
230 | return(NULL); | ||
231 | } | ||
232 | if(sk_num(dso->meth_data) < 1) | ||
233 | { | ||
234 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR); | ||
235 | return(NULL); | ||
236 | } | ||
237 | ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | ||
238 | if(ptr == NULL) | ||
239 | { | ||
240 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE); | ||
241 | return(NULL); | ||
242 | } | ||
243 | sym = (DSO_FUNC_TYPE)dlsym(ptr, symname); | ||
244 | if(sym == NULL) | ||
245 | { | ||
246 | DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE); | ||
247 | return(NULL); | ||
248 | } | ||
249 | return(sym); | ||
250 | } | ||
251 | |||
252 | static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg) | ||
253 | { | ||
254 | if(dso == NULL) | ||
255 | { | ||
256 | DSOerr(DSO_F_DLFCN_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
257 | return(-1); | ||
258 | } | ||
259 | switch(cmd) | ||
260 | { | ||
261 | case DSO_CTRL_GET_FLAGS: | ||
262 | return dso->flags; | ||
263 | case DSO_CTRL_SET_FLAGS: | ||
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 | } | ||
272 | DSOerr(DSO_F_DLFCN_CTRL,DSO_R_UNKNOWN_COMMAND); | ||
273 | return(-1); | ||
274 | } | ||
275 | |||
276 | #endif /* DSO_DLFCN */ | ||
diff --git a/src/lib/libcrypto/dso/dso_err.c b/src/lib/libcrypto/dso/dso_err.c new file mode 100644 index 0000000000..a3d7321c9b --- /dev/null +++ b/src/lib/libcrypto/dso/dso_err.c | |||
@@ -0,0 +1,128 @@ | |||
1 | /* crypto/dso/dso_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/dso.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef NO_ERR | ||
67 | static ERR_STRING_DATA DSO_str_functs[]= | ||
68 | { | ||
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"}, | ||
71 | {ERR_PACK(0,DSO_F_DLFCN_CTRL,0), "DLFCN_CTRL"}, | ||
72 | {ERR_PACK(0,DSO_F_DLFCN_LOAD,0), "DLFCN_LOAD"}, | ||
73 | {ERR_PACK(0,DSO_F_DLFCN_UNLOAD,0), "DLFCN_UNLOAD"}, | ||
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"}, | ||
76 | {ERR_PACK(0,DSO_F_DL_CTRL,0), "DL_CTRL"}, | ||
77 | {ERR_PACK(0,DSO_F_DL_LOAD,0), "DL_LOAD"}, | ||
78 | {ERR_PACK(0,DSO_F_DL_UNLOAD,0), "DL_UNLOAD"}, | ||
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"}, | ||
81 | {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_LOAD,0), "DSO_load"}, | ||
84 | {ERR_PACK(0,DSO_F_DSO_NEW_METHOD,0), "DSO_new_method"}, | ||
85 | {ERR_PACK(0,DSO_F_DSO_UP,0), "DSO_up"}, | ||
86 | {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"}, | ||
89 | {ERR_PACK(0,DSO_F_VMS_UNLOAD,0), "VMS_UNLOAD"}, | ||
90 | {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"}, | ||
92 | {ERR_PACK(0,DSO_F_WIN32_CTRL,0), "WIN32_CTRL"}, | ||
93 | {ERR_PACK(0,DSO_F_WIN32_LOAD,0), "WIN32_LOAD"}, | ||
94 | {ERR_PACK(0,DSO_F_WIN32_UNLOAD,0), "WIN32_UNLOAD"}, | ||
95 | {0,NULL} | ||
96 | }; | ||
97 | |||
98 | static ERR_STRING_DATA DSO_str_reasons[]= | ||
99 | { | ||
100 | {DSO_R_CTRL_FAILED ,"control command failed"}, | ||
101 | {DSO_R_FILENAME_TOO_BIG ,"filename too big"}, | ||
102 | {DSO_R_FINISH_FAILED ,"cleanup method function failed"}, | ||
103 | {DSO_R_LOAD_FAILED ,"could not load the shared library"}, | ||
104 | {DSO_R_NULL_HANDLE ,"a null shared library handle was used"}, | ||
105 | {DSO_R_STACK_ERROR ,"the meth_data stack is corrupt"}, | ||
106 | {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"}, | ||
109 | {DSO_R_UNSUPPORTED ,"functionality not supported"}, | ||
110 | {0,NULL} | ||
111 | }; | ||
112 | |||
113 | #endif | ||
114 | |||
115 | void ERR_load_DSO_strings(void) | ||
116 | { | ||
117 | static int init=1; | ||
118 | |||
119 | if (init) | ||
120 | { | ||
121 | init=0; | ||
122 | #ifndef NO_ERR | ||
123 | ERR_load_strings(ERR_LIB_DSO,DSO_str_functs); | ||
124 | ERR_load_strings(ERR_LIB_DSO,DSO_str_reasons); | ||
125 | #endif | ||
126 | |||
127 | } | ||
128 | } | ||
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c new file mode 100644 index 0000000000..acd166697e --- /dev/null +++ b/src/lib/libcrypto/dso/dso_lib.c | |||
@@ -0,0 +1,306 @@ | |||
1 | /* dso_lib.c */ | ||
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 <openssl/crypto.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/dso.h> | ||
63 | |||
64 | static DSO_METHOD *default_DSO_meth = NULL; | ||
65 | |||
66 | DSO *DSO_new(void) | ||
67 | { | ||
68 | return(DSO_new_method(NULL)); | ||
69 | } | ||
70 | |||
71 | void DSO_set_default_method(DSO_METHOD *meth) | ||
72 | { | ||
73 | default_DSO_meth = meth; | ||
74 | } | ||
75 | |||
76 | DSO_METHOD *DSO_get_default_method(void) | ||
77 | { | ||
78 | return(default_DSO_meth); | ||
79 | } | ||
80 | |||
81 | DSO_METHOD *DSO_get_method(DSO *dso) | ||
82 | { | ||
83 | return(dso->meth); | ||
84 | } | ||
85 | |||
86 | DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth) | ||
87 | { | ||
88 | DSO_METHOD *mtmp; | ||
89 | mtmp = dso->meth; | ||
90 | dso->meth = meth; | ||
91 | return(mtmp); | ||
92 | } | ||
93 | |||
94 | DSO *DSO_new_method(DSO_METHOD *meth) | ||
95 | { | ||
96 | DSO *ret; | ||
97 | |||
98 | if(default_DSO_meth == NULL) | ||
99 | /* We default to DSO_METH_openssl() which in turn defaults | ||
100 | * to stealing the "best available" method. Will fallback | ||
101 | * to DSO_METH_null() in the worst case. */ | ||
102 | default_DSO_meth = DSO_METHOD_openssl(); | ||
103 | ret = (DSO *)OPENSSL_malloc(sizeof(DSO)); | ||
104 | if(ret == NULL) | ||
105 | { | ||
106 | DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); | ||
107 | return(NULL); | ||
108 | } | ||
109 | memset(ret, 0, sizeof(DSO)); | ||
110 | ret->meth_data = sk_new_null(); | ||
111 | if((ret->meth_data = sk_new_null()) == NULL) | ||
112 | { | ||
113 | /* sk_new doesn't generate any errors so we do */ | ||
114 | DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); | ||
115 | OPENSSL_free(ret); | ||
116 | return(NULL); | ||
117 | } | ||
118 | if(meth == NULL) | ||
119 | ret->meth = default_DSO_meth; | ||
120 | else | ||
121 | ret->meth = meth; | ||
122 | ret->references = 1; | ||
123 | if((ret->meth->init != NULL) && !ret->meth->init(ret)) | ||
124 | { | ||
125 | OPENSSL_free(ret); | ||
126 | ret=NULL; | ||
127 | } | ||
128 | return(ret); | ||
129 | } | ||
130 | |||
131 | int DSO_free(DSO *dso) | ||
132 | { | ||
133 | int i; | ||
134 | |||
135 | if(dso == NULL) | ||
136 | { | ||
137 | DSOerr(DSO_F_DSO_FREE,ERR_R_PASSED_NULL_PARAMETER); | ||
138 | return(0); | ||
139 | } | ||
140 | |||
141 | i=CRYPTO_add(&dso->references,-1,CRYPTO_LOCK_DSO); | ||
142 | #ifdef REF_PRINT | ||
143 | REF_PRINT("DSO",dso); | ||
144 | #endif | ||
145 | if(i > 0) return(1); | ||
146 | #ifdef REF_CHECK | ||
147 | if(i < 0) | ||
148 | { | ||
149 | fprintf(stderr,"DSO_free, bad reference count\n"); | ||
150 | abort(); | ||
151 | } | ||
152 | #endif | ||
153 | |||
154 | if((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) | ||
155 | { | ||
156 | DSOerr(DSO_F_DSO_FREE,DSO_R_UNLOAD_FAILED); | ||
157 | return(0); | ||
158 | } | ||
159 | |||
160 | if((dso->meth->finish != NULL) && !dso->meth->finish(dso)) | ||
161 | { | ||
162 | DSOerr(DSO_F_DSO_FREE,DSO_R_FINISH_FAILED); | ||
163 | return(0); | ||
164 | } | ||
165 | |||
166 | sk_free(dso->meth_data); | ||
167 | |||
168 | OPENSSL_free(dso); | ||
169 | return(1); | ||
170 | } | ||
171 | |||
172 | int DSO_flags(DSO *dso) | ||
173 | { | ||
174 | return((dso == NULL) ? 0 : dso->flags); | ||
175 | } | ||
176 | |||
177 | |||
178 | int DSO_up(DSO *dso) | ||
179 | { | ||
180 | if (dso == NULL) | ||
181 | { | ||
182 | DSOerr(DSO_F_DSO_UP,ERR_R_PASSED_NULL_PARAMETER); | ||
183 | return(0); | ||
184 | } | ||
185 | |||
186 | CRYPTO_add(&dso->references,1,CRYPTO_LOCK_DSO); | ||
187 | return(1); | ||
188 | } | ||
189 | |||
190 | DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags) | ||
191 | { | ||
192 | DSO *ret; | ||
193 | int allocated = 0; | ||
194 | |||
195 | if(filename == NULL) | ||
196 | { | ||
197 | DSOerr(DSO_F_DSO_LOAD,ERR_R_PASSED_NULL_PARAMETER); | ||
198 | return(NULL); | ||
199 | } | ||
200 | if(dso == NULL) | ||
201 | { | ||
202 | ret = DSO_new_method(meth); | ||
203 | if(ret == NULL) | ||
204 | { | ||
205 | DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE); | ||
206 | return(NULL); | ||
207 | } | ||
208 | allocated = 1; | ||
209 | } | ||
210 | else | ||
211 | ret = dso; | ||
212 | /* Bleurgh ... have to check for negative return values for | ||
213 | * errors. <grimace> */ | ||
214 | if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) | ||
215 | { | ||
216 | DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED); | ||
217 | if(allocated) | ||
218 | DSO_free(ret); | ||
219 | return(NULL); | ||
220 | } | ||
221 | if(ret->meth->dso_load == NULL) | ||
222 | { | ||
223 | DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED); | ||
224 | if(allocated) | ||
225 | DSO_free(ret); | ||
226 | return(NULL); | ||
227 | } | ||
228 | if(!ret->meth->dso_load(ret, filename)) | ||
229 | { | ||
230 | DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED); | ||
231 | if(allocated) | ||
232 | DSO_free(ret); | ||
233 | return(NULL); | ||
234 | } | ||
235 | /* Load succeeded */ | ||
236 | return(ret); | ||
237 | } | ||
238 | |||
239 | void *DSO_bind_var(DSO *dso, const char *symname) | ||
240 | { | ||
241 | void *ret = NULL; | ||
242 | |||
243 | if((dso == NULL) || (symname == NULL)) | ||
244 | { | ||
245 | DSOerr(DSO_F_DSO_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | ||
246 | return(NULL); | ||
247 | } | ||
248 | if(dso->meth->dso_bind_var == NULL) | ||
249 | { | ||
250 | DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_UNSUPPORTED); | ||
251 | return(NULL); | ||
252 | } | ||
253 | if((ret = dso->meth->dso_bind_var(dso, symname)) == NULL) | ||
254 | { | ||
255 | DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_SYM_FAILURE); | ||
256 | return(NULL); | ||
257 | } | ||
258 | /* Success */ | ||
259 | return(ret); | ||
260 | } | ||
261 | |||
262 | DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname) | ||
263 | { | ||
264 | DSO_FUNC_TYPE ret = NULL; | ||
265 | |||
266 | if((dso == NULL) || (symname == NULL)) | ||
267 | { | ||
268 | DSOerr(DSO_F_DSO_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); | ||
269 | return(NULL); | ||
270 | } | ||
271 | if(dso->meth->dso_bind_func == NULL) | ||
272 | { | ||
273 | DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_UNSUPPORTED); | ||
274 | return(NULL); | ||
275 | } | ||
276 | if((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) | ||
277 | { | ||
278 | DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_SYM_FAILURE); | ||
279 | return(NULL); | ||
280 | } | ||
281 | /* Success */ | ||
282 | return(ret); | ||
283 | } | ||
284 | |||
285 | /* I don't really like these *_ctrl functions very much to be perfectly | ||
286 | * honest. For one thing, I think I have to return a negative value for | ||
287 | * any error because possible DSO_ctrl() commands may return values | ||
288 | * such as "size"s that can legitimately be zero (making the standard | ||
289 | * "if(DSO_cmd(...))" form that works almost everywhere else fail at | ||
290 | * odd times. I'd prefer "output" values to be passed by reference and | ||
291 | * the return value as success/failure like usual ... but we conform | ||
292 | * when we must... :-) */ | ||
293 | long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) | ||
294 | { | ||
295 | if(dso == NULL) | ||
296 | { | ||
297 | DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
298 | return(-1); | ||
299 | } | ||
300 | if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) | ||
301 | { | ||
302 | DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED); | ||
303 | return(-1); | ||
304 | } | ||
305 | return(dso->meth->dso_ctrl(dso,cmd,larg,parg)); | ||
306 | } | ||
diff --git a/src/lib/libcrypto/dso/dso_null.c b/src/lib/libcrypto/dso/dso_null.c new file mode 100644 index 0000000000..fa13a7cb0f --- /dev/null +++ b/src/lib/libcrypto/dso/dso_null.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* dso_null.c */ | ||
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 | /* This "NULL" method is provided as the fallback for systems that have | ||
60 | * no appropriate support for "shared-libraries". */ | ||
61 | |||
62 | #include <stdio.h> | ||
63 | #include "cryptlib.h" | ||
64 | #include <openssl/dso.h> | ||
65 | |||
66 | static DSO_METHOD dso_meth_null = { | ||
67 | "NULL shared library method", | ||
68 | NULL, /* load */ | ||
69 | NULL, /* unload */ | ||
70 | NULL, /* bind_var */ | ||
71 | NULL, /* bind_func */ | ||
72 | /* For now, "unbind" doesn't exist */ | ||
73 | #if 0 | ||
74 | NULL, /* unbind_var */ | ||
75 | NULL, /* unbind_func */ | ||
76 | #endif | ||
77 | NULL, /* ctrl */ | ||
78 | NULL, /* init */ | ||
79 | NULL /* finish */ | ||
80 | }; | ||
81 | |||
82 | DSO_METHOD *DSO_METHOD_null(void) | ||
83 | { | ||
84 | return(&dso_meth_null); | ||
85 | } | ||
86 | |||
diff --git a/src/lib/libcrypto/dso/dso_openssl.c b/src/lib/libcrypto/dso/dso_openssl.c new file mode 100644 index 0000000000..a4395ebffe --- /dev/null +++ b/src/lib/libcrypto/dso/dso_openssl.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* dso_openssl.c */ | ||
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 "cryptlib.h" | ||
61 | #include <openssl/dso.h> | ||
62 | |||
63 | /* We just pinch the method from an appropriate "default" method. */ | ||
64 | |||
65 | DSO_METHOD *DSO_METHOD_openssl(void) | ||
66 | { | ||
67 | #ifdef DEF_DSO_METHOD | ||
68 | return(DEF_DSO_METHOD()); | ||
69 | #elif defined(DSO_DLFCN) | ||
70 | return(DSO_METHOD_dlfcn()); | ||
71 | #elif defined(DSO_DL) | ||
72 | return(DSO_METHOD_dl()); | ||
73 | #elif defined(DSO_WIN32) | ||
74 | return(DSO_METHOD_win32()); | ||
75 | #elif defined(DSO_VMS) | ||
76 | return(DSO_METHOD_vms()); | ||
77 | #else | ||
78 | return(DSO_METHOD_null()); | ||
79 | #endif | ||
80 | } | ||
81 | |||
diff --git a/src/lib/libcrypto/dso/dso_vms.c b/src/lib/libcrypto/dso/dso_vms.c new file mode 100644 index 0000000000..8ff7090129 --- /dev/null +++ b/src/lib/libcrypto/dso/dso_vms.c | |||
@@ -0,0 +1,371 @@ | |||
1 | /* dso_vms.c */ | ||
2 | /* Written by Richard Levitte (richard@levitte.org) 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 | #include <errno.h> | ||
62 | #ifdef VMS | ||
63 | #pragma message disable DOLLARID | ||
64 | #include <lib$routines.h> | ||
65 | #include <libfisdef.h> | ||
66 | #include <stsdef.h> | ||
67 | #include <descrip.h> | ||
68 | #include <starlet.h> | ||
69 | #endif | ||
70 | #include "cryptlib.h" | ||
71 | #include <openssl/dso.h> | ||
72 | |||
73 | #ifndef VMS | ||
74 | DSO_METHOD *DSO_METHOD_vms(void) | ||
75 | { | ||
76 | return NULL; | ||
77 | } | ||
78 | #else | ||
79 | #pragma message disable DOLLARID | ||
80 | |||
81 | static int vms_load(DSO *dso, const char *filename); | ||
82 | static int vms_unload(DSO *dso); | ||
83 | static void *vms_bind_var(DSO *dso, const char *symname); | ||
84 | static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname); | ||
85 | #if 0 | ||
86 | static int vms_unbind_var(DSO *dso, char *symname, void *symptr); | ||
87 | static int vms_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); | ||
88 | static int vms_init(DSO *dso); | ||
89 | static int vms_finish(DSO *dso); | ||
90 | #endif | ||
91 | static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg); | ||
92 | |||
93 | static DSO_METHOD dso_meth_vms = { | ||
94 | "OpenSSL 'VMS' shared library method", | ||
95 | vms_load, | ||
96 | NULL, /* unload */ | ||
97 | vms_bind_var, | ||
98 | vms_bind_func, | ||
99 | /* For now, "unbind" doesn't exist */ | ||
100 | #if 0 | ||
101 | NULL, /* unbind_var */ | ||
102 | NULL, /* unbind_func */ | ||
103 | #endif | ||
104 | vms_ctrl, | ||
105 | NULL, /* init */ | ||
106 | NULL /* finish */ | ||
107 | }; | ||
108 | |||
109 | /* On VMS, the only "handle" is the file name. LIB$FIND_IMAGE_SYMBOL depends | ||
110 | * on the reference to the file name being the same for all calls regarding | ||
111 | * one shared image, so we'll just store it in an instance of the following | ||
112 | * structure and put a pointer to that instance in the meth_data stack. | ||
113 | */ | ||
114 | typedef struct dso_internal_st | ||
115 | { | ||
116 | /* This should contain the name only, no directory, | ||
117 | * no extension, nothing but a name. */ | ||
118 | struct dsc$descriptor_s filename_dsc; | ||
119 | char filename[FILENAME_MAX+1]; | ||
120 | /* This contains whatever is not in filename, if needed. | ||
121 | * Normally not defined. */ | ||
122 | struct dsc$descriptor_s imagename_dsc; | ||
123 | char imagename[FILENAME_MAX+1]; | ||
124 | } DSO_VMS_INTERNAL; | ||
125 | |||
126 | |||
127 | DSO_METHOD *DSO_METHOD_vms(void) | ||
128 | { | ||
129 | return(&dso_meth_vms); | ||
130 | } | ||
131 | |||
132 | static int vms_load(DSO *dso, const char *filename) | ||
133 | { | ||
134 | DSO_VMS_INTERNAL *p; | ||
135 | const char *sp1, *sp2; /* Search result */ | ||
136 | |||
137 | /* A file specification may look like this: | ||
138 | * | ||
139 | * node::dev:[dir-spec]name.type;ver | ||
140 | * | ||
141 | * or (for compatibility with TOPS-20): | ||
142 | * | ||
143 | * node::dev:<dir-spec>name.type;ver | ||
144 | * | ||
145 | * and the dir-spec uses '.' as separator. Also, a dir-spec | ||
146 | * may consist of several parts, with mixed use of [] and <>: | ||
147 | * | ||
148 | * [dir1.]<dir2> | ||
149 | * | ||
150 | * We need to split the file specification into the name and | ||
151 | * the rest (both before and after the name itself). | ||
152 | */ | ||
153 | /* Start with trying to find the end of a dir-spec, and save the | ||
154 | position of the byte after in sp1 */ | ||
155 | sp1 = strrchr(filename, ']'); | ||
156 | sp2 = strrchr(filename, '>'); | ||
157 | if (sp1 == NULL) sp1 = sp2; | ||
158 | if (sp2 != NULL && sp2 > sp1) sp1 = sp2; | ||
159 | if (sp1 == NULL) sp1 = strrchr(filename, ':'); | ||
160 | if (sp1 == NULL) | ||
161 | sp1 = filename; | ||
162 | else | ||
163 | sp1++; /* The byte after the found character */ | ||
164 | /* Now, let's see if there's a type, and save the position in sp2 */ | ||
165 | sp2 = strchr(sp1, '.'); | ||
166 | /* If we found it, that's where we'll cut. Otherwise, look for a | ||
167 | version number and save the position in sp2 */ | ||
168 | if (sp2 == NULL) sp2 = strchr(sp1, ';'); | ||
169 | /* If there was still nothing to find, set sp2 to point at the end of | ||
170 | the string */ | ||
171 | if (sp2 == NULL) sp2 = sp1 + strlen(sp1); | ||
172 | |||
173 | /* Check that we won't get buffer overflows */ | ||
174 | if (sp2 - sp1 > FILENAME_MAX | ||
175 | || (sp1 - filename) + strlen(sp2) > FILENAME_MAX) | ||
176 | { | ||
177 | DSOerr(DSO_F_VMS_LOAD,DSO_R_FILENAME_TOO_BIG); | ||
178 | return(0); | ||
179 | } | ||
180 | |||
181 | p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL)); | ||
182 | if(p == NULL) | ||
183 | { | ||
184 | DSOerr(DSO_F_VMS_LOAD,ERR_R_MALLOC_FAILURE); | ||
185 | return(0); | ||
186 | } | ||
187 | |||
188 | strncpy(p->filename, sp1, sp2-sp1); | ||
189 | p->filename[sp2-sp1] = '\0'; | ||
190 | |||
191 | strncpy(p->imagename, filename, sp1-filename); | ||
192 | p->imagename[sp1-filename] = '\0'; | ||
193 | strcat(p->imagename, sp2); | ||
194 | |||
195 | p->filename_dsc.dsc$w_length = strlen(p->filename); | ||
196 | p->filename_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | ||
197 | p->filename_dsc.dsc$b_class = DSC$K_CLASS_S; | ||
198 | p->filename_dsc.dsc$a_pointer = p->filename; | ||
199 | p->imagename_dsc.dsc$w_length = strlen(p->imagename); | ||
200 | p->imagename_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | ||
201 | p->imagename_dsc.dsc$b_class = DSC$K_CLASS_S; | ||
202 | p->imagename_dsc.dsc$a_pointer = p->imagename; | ||
203 | |||
204 | if(!sk_push(dso->meth_data, (char *)p)) | ||
205 | { | ||
206 | DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR); | ||
207 | OPENSSL_free(p); | ||
208 | return(0); | ||
209 | } | ||
210 | return(1); | ||
211 | } | ||
212 | |||
213 | /* Note that this doesn't actually unload the shared image, as there is no | ||
214 | * such thing in VMS. Next time it get loaded again, a new copy will | ||
215 | * actually be loaded. | ||
216 | */ | ||
217 | static int vms_unload(DSO *dso) | ||
218 | { | ||
219 | DSO_VMS_INTERNAL *p; | ||
220 | if(dso == NULL) | ||
221 | { | ||
222 | DSOerr(DSO_F_VMS_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); | ||
223 | return(0); | ||
224 | } | ||
225 | if(sk_num(dso->meth_data) < 1) | ||
226 | return(1); | ||
227 | p = (DSO_VMS_INTERNAL *)sk_pop(dso->meth_data); | ||
228 | if(p == NULL) | ||
229 | { | ||
230 | DSOerr(DSO_F_VMS_UNLOAD,DSO_R_NULL_HANDLE); | ||
231 | return(0); | ||
232 | } | ||
233 | /* Cleanup */ | ||
234 | OPENSSL_free(p); | ||
235 | return(1); | ||
236 | } | ||
237 | |||
238 | /* We must do this in a separate function because of the way the exception | ||
239 | handler works (it makes this function return */ | ||
240 | static int do_find_symbol(DSO_VMS_INTERNAL *ptr, | ||
241 | struct dsc$descriptor_s *symname_dsc, void **sym, | ||
242 | unsigned long flags) | ||
243 | { | ||
244 | /* Make sure that signals are caught and returned instead of | ||
245 | aborting the program. The exception handler gets unestablished | ||
246 | automatically on return from this function. */ | ||
247 | lib$establish(lib$sig_to_ret); | ||
248 | |||
249 | if(ptr->imagename_dsc.dsc$w_length) | ||
250 | return lib$find_image_symbol(&ptr->filename_dsc, | ||
251 | symname_dsc, sym, | ||
252 | &ptr->imagename_dsc, flags); | ||
253 | else | ||
254 | return lib$find_image_symbol(&ptr->filename_dsc, | ||
255 | symname_dsc, sym, | ||
256 | 0, flags); | ||
257 | } | ||
258 | |||
259 | void vms_bind_sym(DSO *dso, const char *symname, void **sym) | ||
260 | { | ||
261 | DSO_VMS_INTERNAL *ptr; | ||
262 | int status; | ||
263 | int flags = LIB$M_FIS_MIXEDCASE; | ||
264 | struct dsc$descriptor_s symname_dsc; | ||
265 | *sym = NULL; | ||
266 | |||
267 | symname_dsc.dsc$w_length = strlen(symname); | ||
268 | symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | ||
269 | symname_dsc.dsc$b_class = DSC$K_CLASS_S; | ||
270 | symname_dsc.dsc$a_pointer = (char *)symname; /* The cast is needed */ | ||
271 | |||
272 | if((dso == NULL) || (symname == NULL)) | ||
273 | { | ||
274 | DSOerr(DSO_F_VMS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | ||
275 | return; | ||
276 | } | ||
277 | if(sk_num(dso->meth_data) < 1) | ||
278 | { | ||
279 | DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_STACK_ERROR); | ||
280 | return; | ||
281 | } | ||
282 | ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data, | ||
283 | sk_num(dso->meth_data) - 1); | ||
284 | if(ptr == NULL) | ||
285 | { | ||
286 | DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_NULL_HANDLE); | ||
287 | return; | ||
288 | } | ||
289 | |||
290 | if(dso->flags & DSO_FLAG_UPCASE_SYMBOL) flags = 0; | ||
291 | |||
292 | status = do_find_symbol(ptr, &symname_dsc, sym, flags); | ||
293 | |||
294 | if(!$VMS_STATUS_SUCCESS(status)) | ||
295 | { | ||
296 | unsigned short length; | ||
297 | char errstring[257]; | ||
298 | struct dsc$descriptor_s errstring_dsc; | ||
299 | |||
300 | errstring_dsc.dsc$w_length = sizeof(errstring); | ||
301 | errstring_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | ||
302 | errstring_dsc.dsc$b_class = DSC$K_CLASS_S; | ||
303 | errstring_dsc.dsc$a_pointer = errstring; | ||
304 | |||
305 | *sym = NULL; | ||
306 | |||
307 | status = sys$getmsg(status, &length, &errstring_dsc, 1, 0); | ||
308 | |||
309 | if (!$VMS_STATUS_SUCCESS(status)) | ||
310 | lib$signal(status); /* This is really bad. Abort! */ | ||
311 | else | ||
312 | { | ||
313 | errstring[length] = '\0'; | ||
314 | |||
315 | DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_SYM_FAILURE); | ||
316 | if (ptr->imagename_dsc.dsc$w_length) | ||
317 | ERR_add_error_data(9, | ||
318 | "Symbol ", symname, | ||
319 | " in ", ptr->filename, | ||
320 | " (", ptr->imagename, ")", | ||
321 | ": ", errstring); | ||
322 | else | ||
323 | ERR_add_error_data(6, | ||
324 | "Symbol ", symname, | ||
325 | " in ", ptr->filename, | ||
326 | ": ", errstring); | ||
327 | } | ||
328 | return; | ||
329 | } | ||
330 | return; | ||
331 | } | ||
332 | |||
333 | static void *vms_bind_var(DSO *dso, const char *symname) | ||
334 | { | ||
335 | void *sym = 0; | ||
336 | vms_bind_sym(dso, symname, &sym); | ||
337 | return sym; | ||
338 | } | ||
339 | |||
340 | static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname) | ||
341 | { | ||
342 | DSO_FUNC_TYPE sym = 0; | ||
343 | vms_bind_sym(dso, symname, (void **)&sym); | ||
344 | return sym; | ||
345 | } | ||
346 | |||
347 | static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg) | ||
348 | { | ||
349 | if(dso == NULL) | ||
350 | { | ||
351 | DSOerr(DSO_F_VMS_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
352 | return(-1); | ||
353 | } | ||
354 | switch(cmd) | ||
355 | { | ||
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 new file mode 100644 index 0000000000..7f1d904806 --- /dev/null +++ b/src/lib/libcrypto/dso/dso_win32.c | |||
@@ -0,0 +1,273 @@ | |||
1 | /* dso_win32.c */ | ||
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 | #include "cryptlib.h" | ||
62 | #include <openssl/dso.h> | ||
63 | |||
64 | #ifndef WIN32 | ||
65 | DSO_METHOD *DSO_METHOD_win32(void) | ||
66 | { | ||
67 | return NULL; | ||
68 | } | ||
69 | #else | ||
70 | |||
71 | /* Part of the hack in "win32_load" ... */ | ||
72 | #define DSO_MAX_TRANSLATED_SIZE 256 | ||
73 | |||
74 | static int win32_load(DSO *dso, const char *filename); | ||
75 | static int win32_unload(DSO *dso); | ||
76 | static void *win32_bind_var(DSO *dso, const char *symname); | ||
77 | static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname); | ||
78 | #if 0 | ||
79 | static int win32_unbind_var(DSO *dso, char *symname, void *symptr); | ||
80 | static int win32_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); | ||
81 | static int win32_init(DSO *dso); | ||
82 | static int win32_finish(DSO *dso); | ||
83 | #endif | ||
84 | static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg); | ||
85 | |||
86 | static DSO_METHOD dso_meth_win32 = { | ||
87 | "OpenSSL 'win32' shared library method", | ||
88 | win32_load, | ||
89 | win32_unload, | ||
90 | win32_bind_var, | ||
91 | win32_bind_func, | ||
92 | /* For now, "unbind" doesn't exist */ | ||
93 | #if 0 | ||
94 | NULL, /* unbind_var */ | ||
95 | NULL, /* unbind_func */ | ||
96 | #endif | ||
97 | win32_ctrl, | ||
98 | NULL, /* init */ | ||
99 | NULL /* finish */ | ||
100 | }; | ||
101 | |||
102 | DSO_METHOD *DSO_METHOD_win32(void) | ||
103 | { | ||
104 | return(&dso_meth_win32); | ||
105 | } | ||
106 | |||
107 | /* For this DSO_METHOD, our meth_data STACK will contain; | ||
108 | * (i) a pointer to the handle (HINSTANCE) returned from | ||
109 | * LoadLibrary(), and copied. | ||
110 | */ | ||
111 | |||
112 | static int win32_load(DSO *dso, const char *filename) | ||
113 | { | ||
114 | HINSTANCE h, *p; | ||
115 | char translated[DSO_MAX_TRANSLATED_SIZE]; | ||
116 | int len; | ||
117 | |||
118 | /* NB: This is a hideous hack, but I'm not yet sure what | ||
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 | { | ||
130 | sprintf(translated, "%s.dll", filename); | ||
131 | h = LoadLibrary(translated); | ||
132 | } | ||
133 | else | ||
134 | h = LoadLibrary(filename); | ||
135 | if(h == NULL) | ||
136 | { | ||
137 | DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED); | ||
138 | return(0); | ||
139 | } | ||
140 | p = (HINSTANCE *)OPENSSL_malloc(sizeof(HINSTANCE)); | ||
141 | if(p == NULL) | ||
142 | { | ||
143 | DSOerr(DSO_F_WIN32_LOAD,ERR_R_MALLOC_FAILURE); | ||
144 | FreeLibrary(h); | ||
145 | return(0); | ||
146 | } | ||
147 | *p = h; | ||
148 | if(!sk_push(dso->meth_data, (char *)p)) | ||
149 | { | ||
150 | DSOerr(DSO_F_WIN32_LOAD,DSO_R_STACK_ERROR); | ||
151 | FreeLibrary(h); | ||
152 | OPENSSL_free(p); | ||
153 | return(0); | ||
154 | } | ||
155 | return(1); | ||
156 | } | ||
157 | |||
158 | static int win32_unload(DSO *dso) | ||
159 | { | ||
160 | HINSTANCE *p; | ||
161 | if(dso == NULL) | ||
162 | { | ||
163 | DSOerr(DSO_F_WIN32_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); | ||
164 | return(0); | ||
165 | } | ||
166 | if(sk_num(dso->meth_data) < 1) | ||
167 | return(1); | ||
168 | p = (HINSTANCE *)sk_pop(dso->meth_data); | ||
169 | if(p == NULL) | ||
170 | { | ||
171 | DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_NULL_HANDLE); | ||
172 | return(0); | ||
173 | } | ||
174 | if(!FreeLibrary(*p)) | ||
175 | { | ||
176 | DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_UNLOAD_FAILED); | ||
177 | /* We should push the value back onto the stack in | ||
178 | * case of a retry. */ | ||
179 | sk_push(dso->meth_data, (char *)p); | ||
180 | return(0); | ||
181 | } | ||
182 | /* Cleanup */ | ||
183 | OPENSSL_free(p); | ||
184 | return(1); | ||
185 | } | ||
186 | |||
187 | /* Using GetProcAddress for variables? TODO: Check this out in | ||
188 | * the Win32 API docs, there's probably a variant for variables. */ | ||
189 | static void *win32_bind_var(DSO *dso, const char *symname) | ||
190 | { | ||
191 | HINSTANCE *ptr; | ||
192 | void *sym; | ||
193 | |||
194 | if((dso == NULL) || (symname == NULL)) | ||
195 | { | ||
196 | DSOerr(DSO_F_WIN32_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | ||
197 | return(NULL); | ||
198 | } | ||
199 | if(sk_num(dso->meth_data) < 1) | ||
200 | { | ||
201 | DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_STACK_ERROR); | ||
202 | return(NULL); | ||
203 | } | ||
204 | ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | ||
205 | if(ptr == NULL) | ||
206 | { | ||
207 | DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_NULL_HANDLE); | ||
208 | return(NULL); | ||
209 | } | ||
210 | sym = GetProcAddress(*ptr, symname); | ||
211 | if(sym == NULL) | ||
212 | { | ||
213 | DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_SYM_FAILURE); | ||
214 | return(NULL); | ||
215 | } | ||
216 | return(sym); | ||
217 | } | ||
218 | |||
219 | static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname) | ||
220 | { | ||
221 | HINSTANCE *ptr; | ||
222 | void *sym; | ||
223 | |||
224 | if((dso == NULL) || (symname == NULL)) | ||
225 | { | ||
226 | DSOerr(DSO_F_WIN32_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); | ||
227 | return(NULL); | ||
228 | } | ||
229 | if(sk_num(dso->meth_data) < 1) | ||
230 | { | ||
231 | DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_STACK_ERROR); | ||
232 | return(NULL); | ||
233 | } | ||
234 | ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | ||
235 | if(ptr == NULL) | ||
236 | { | ||
237 | DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_NULL_HANDLE); | ||
238 | return(NULL); | ||
239 | } | ||
240 | sym = GetProcAddress(*ptr, symname); | ||
241 | if(sym == NULL) | ||
242 | { | ||
243 | DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_SYM_FAILURE); | ||
244 | return(NULL); | ||
245 | } | ||
246 | return((DSO_FUNC_TYPE)sym); | ||
247 | } | ||
248 | |||
249 | static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg) | ||
250 | { | ||
251 | if(dso == NULL) | ||
252 | { | ||
253 | DSOerr(DSO_F_WIN32_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
254 | return(-1); | ||
255 | } | ||
256 | switch(cmd) | ||
257 | { | ||
258 | case DSO_CTRL_GET_FLAGS: | ||
259 | return dso->flags; | ||
260 | case DSO_CTRL_SET_FLAGS: | ||
261 | dso->flags = (int)larg; | ||
262 | return(0); | ||
263 | case DSO_CTRL_OR_FLAGS: | ||
264 | dso->flags |= (int)larg; | ||
265 | return(0); | ||
266 | default: | ||
267 | break; | ||
268 | } | ||
269 | DSOerr(DSO_F_WIN32_CTRL,DSO_R_UNKNOWN_COMMAND); | ||
270 | return(-1); | ||
271 | } | ||
272 | |||
273 | #endif /* WIN32 */ | ||