diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/dso/dso_win32.c | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/dso/dso_win32.c')
-rw-r--r-- | src/lib/libcrypto/dso/dso_win32.c | 112 |
1 files changed, 59 insertions, 53 deletions
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 |
65 | DSO_METHOD *DSO_METHOD_win32(void) | 65 | DSO_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 | ||
74 | static int win32_load(DSO *dso, const char *filename); | 74 | static int win32_load(DSO *dso); |
75 | static int win32_unload(DSO *dso); | 75 | static int win32_unload(DSO *dso); |
76 | static void *win32_bind_var(DSO *dso, const char *symname); | 76 | static void *win32_bind_var(DSO *dso, const char *symname); |
77 | static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname); | 77 | static 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); | |||
80 | static int win32_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); | 80 | static int win32_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); |
81 | static int win32_init(DSO *dso); | 81 | static int win32_init(DSO *dso); |
82 | static int win32_finish(DSO *dso); | 82 | static int win32_finish(DSO *dso); |
83 | #endif | ||
84 | static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg); | 83 | static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg); |
84 | #endif | ||
85 | static char *win32_name_converter(DSO *dso, const char *filename); | ||
85 | 86 | ||
86 | static DSO_METHOD dso_meth_win32 = { | 87 | static 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 | ||
112 | static int win32_load(DSO *dso, const char *filename) | 114 | static 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); |
147 | err: | ||
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 | ||
158 | static int win32_unload(DSO *dso) | 158 | static 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 | ||
249 | static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg) | 251 | static 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 */ |