diff options
Diffstat (limited to 'src/lib/libcrypto/dso/dso.h')
-rw-r--r-- | src/lib/libcrypto/dso/dso.h | 168 |
1 files changed, 120 insertions, 48 deletions
diff --git a/src/lib/libcrypto/dso/dso.h b/src/lib/libcrypto/dso/dso.h index bed7c464a6..aa721f7feb 100644 --- a/src/lib/libcrypto/dso/dso.h +++ b/src/lib/libcrypto/dso/dso.h | |||
@@ -70,31 +70,51 @@ extern "C" { | |||
70 | #define DSO_CTRL_SET_FLAGS 2 | 70 | #define DSO_CTRL_SET_FLAGS 2 |
71 | #define DSO_CTRL_OR_FLAGS 3 | 71 | #define DSO_CTRL_OR_FLAGS 3 |
72 | 72 | ||
73 | /* These flags control the translation of file-names from canonical to | 73 | /* By default, DSO_load() will translate the provided filename into a form |
74 | * native. Eg. in the CryptoSwift support, the "dl" and "dlfcn" | 74 | * typical for the platform (more specifically the DSO_METHOD) using the |
75 | * methods will translate "swift" -> "libswift.so" whereas the "win32" | 75 | * dso_name_converter function of the method. Eg. win32 will transform "blah" |
76 | * method will translate "swift" -> "swift.dll". NB: Until I can figure | 76 | * into "blah.dll", and dlfcn will transform it into "libblah.so". The |
77 | * out how to be more "conventional" with this, the methods will only | 77 | * behaviour can be overriden by setting the name_converter callback in the DSO |
78 | * honour this flag if it looks like it was passed a file without any | 78 | * object (using DSO_set_name_converter()). This callback could even utilise |
79 | * path and if the filename is small enough. | 79 | * the DSO_METHOD's converter too if it only wants to override behaviour for |
80 | */ | 80 | * one or two possible DSO methods. However, the following flag can be set in a |
81 | #define DSO_FLAG_NAME_TRANSLATION 0x01 | 81 | * DSO to prevent *any* native name-translation at all - eg. if the caller has |
82 | * prompted the user for a path to a driver library so the filename should be | ||
83 | * interpreted as-is. */ | ||
84 | #define DSO_FLAG_NO_NAME_TRANSLATION 0x01 | ||
85 | /* An extra flag to give if only the extension should be added as | ||
86 | * translation. This is obviously only of importance on Unix and | ||
87 | * other operating systems where the translation also may prefix | ||
88 | * the name with something, like 'lib', and ignored everywhere else. | ||
89 | * This flag is also ignored if DSO_FLAG_NO_NAME_TRANSLATION is used | ||
90 | * at the same time. */ | ||
91 | #define DSO_FLAG_NAME_TRANSLATION_EXT_ONLY 0x02 | ||
82 | 92 | ||
83 | /* The following flag controls the translation of symbol names to upper | 93 | /* The following flag controls the translation of symbol names to upper |
84 | * case. This is currently only being implemented for OpenVMS. | 94 | * case. This is currently only being implemented for OpenVMS. |
85 | */ | 95 | */ |
86 | #define DSO_FLAG_UPCASE_SYMBOL 0x02 | 96 | #define DSO_FLAG_UPCASE_SYMBOL 0x10 |
87 | 97 | ||
88 | 98 | ||
89 | typedef void (*DSO_FUNC_TYPE)(void); | 99 | typedef void (*DSO_FUNC_TYPE)(void); |
90 | 100 | ||
91 | typedef struct dso_st DSO; | 101 | typedef struct dso_st DSO; |
92 | 102 | ||
103 | /* The function prototype used for method functions (or caller-provided | ||
104 | * callbacks) that transform filenames. They are passed a DSO structure pointer | ||
105 | * (or NULL if they are to be used independantly of a DSO object) and a | ||
106 | * filename to transform. They should either return NULL (if there is an error | ||
107 | * condition) or a newly allocated string containing the transformed form that | ||
108 | * the caller will need to free with OPENSSL_free() when done. */ | ||
109 | typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *); | ||
110 | |||
93 | typedef struct dso_meth_st | 111 | typedef struct dso_meth_st |
94 | { | 112 | { |
95 | const char *name; | 113 | const char *name; |
96 | /* Loads a shared library */ | 114 | /* Loads a shared library, NB: new DSO_METHODs must ensure that a |
97 | int (*dso_load)(DSO *dso, const char *filename); | 115 | * successful load populates the loaded_filename field, and likewise a |
116 | * successful unload OPENSSL_frees and NULLs it out. */ | ||
117 | int (*dso_load)(DSO *dso); | ||
98 | /* Unloads a shared library */ | 118 | /* Unloads a shared library */ |
99 | int (*dso_unload)(DSO *dso); | 119 | int (*dso_unload)(DSO *dso); |
100 | /* Binds a variable */ | 120 | /* Binds a variable */ |
@@ -117,6 +137,9 @@ typedef struct dso_meth_st | |||
117 | /* The generic (yuck) "ctrl()" function. NB: Negative return | 137 | /* The generic (yuck) "ctrl()" function. NB: Negative return |
118 | * values (rather than zero) indicate errors. */ | 138 | * values (rather than zero) indicate errors. */ |
119 | long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg); | 139 | long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg); |
140 | /* The default DSO_METHOD-specific function for converting filenames to | ||
141 | * a canonical native form. */ | ||
142 | DSO_NAME_CONVERTER_FUNC dso_name_converter; | ||
120 | 143 | ||
121 | /* [De]Initialisation handlers. */ | 144 | /* [De]Initialisation handlers. */ |
122 | int (*init)(DSO *dso); | 145 | int (*init)(DSO *dso); |
@@ -140,6 +163,23 @@ struct dso_st | |||
140 | /* For use by applications etc ... use this for your bits'n'pieces, | 163 | /* For use by applications etc ... use this for your bits'n'pieces, |
141 | * don't touch meth_data! */ | 164 | * don't touch meth_data! */ |
142 | CRYPTO_EX_DATA ex_data; | 165 | CRYPTO_EX_DATA ex_data; |
166 | /* If this callback function pointer is set to non-NULL, then it will | ||
167 | * be used on DSO_load() in place of meth->dso_name_converter. NB: This | ||
168 | * should normally set using DSO_set_name_converter(). */ | ||
169 | DSO_NAME_CONVERTER_FUNC name_converter; | ||
170 | /* This is populated with (a copy of) the platform-independant | ||
171 | * filename used for this DSO. */ | ||
172 | char *filename; | ||
173 | /* This is populated with (a copy of) the translated filename by which | ||
174 | * the DSO was actually loaded. It is NULL iff the DSO is not currently | ||
175 | * loaded. NB: This is here because the filename translation process | ||
176 | * may involve a callback being invoked more than once not only to | ||
177 | * convert to a platform-specific form, but also to try different | ||
178 | * filenames in the process of trying to perform a load. As such, this | ||
179 | * variable can be used to indicate (a) whether this DSO structure | ||
180 | * corresponds to a loaded library or not, and (b) the filename with | ||
181 | * which it was actually loaded. */ | ||
182 | char *loaded_filename; | ||
143 | }; | 183 | }; |
144 | 184 | ||
145 | 185 | ||
@@ -147,10 +187,38 @@ DSO * DSO_new(void); | |||
147 | DSO * DSO_new_method(DSO_METHOD *method); | 187 | DSO * DSO_new_method(DSO_METHOD *method); |
148 | int DSO_free(DSO *dso); | 188 | int DSO_free(DSO *dso); |
149 | int DSO_flags(DSO *dso); | 189 | int DSO_flags(DSO *dso); |
150 | int DSO_up(DSO *dso); | 190 | int DSO_up_ref(DSO *dso); |
151 | long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg); | 191 | long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg); |
152 | 192 | ||
153 | void DSO_set_default_method(DSO_METHOD *meth); | 193 | /* This function sets the DSO's name_converter callback. If it is non-NULL, |
194 | * then it will be used instead of the associated DSO_METHOD's function. If | ||
195 | * oldcb is non-NULL then it is set to the function pointer value being | ||
196 | * replaced. Return value is non-zero for success. */ | ||
197 | int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb, | ||
198 | DSO_NAME_CONVERTER_FUNC *oldcb); | ||
199 | /* These functions can be used to get/set the platform-independant filename | ||
200 | * used for a DSO. NB: set will fail if the DSO is already loaded. */ | ||
201 | const char *DSO_get_filename(DSO *dso); | ||
202 | int DSO_set_filename(DSO *dso, const char *filename); | ||
203 | /* This function will invoke the DSO's name_converter callback to translate a | ||
204 | * filename, or if the callback isn't set it will instead use the DSO_METHOD's | ||
205 | * converter. If "filename" is NULL, the "filename" in the DSO itself will be | ||
206 | * used. If the DSO_FLAG_NO_NAME_TRANSLATION flag is set, then the filename is | ||
207 | * simply duplicated. NB: This function is usually called from within a | ||
208 | * DSO_METHOD during the processing of a DSO_load() call, and is exposed so that | ||
209 | * caller-created DSO_METHODs can do the same thing. A non-NULL return value | ||
210 | * will need to be OPENSSL_free()'d. */ | ||
211 | char *DSO_convert_filename(DSO *dso, const char *filename); | ||
212 | /* If the DSO is currently loaded, this returns the filename that it was loaded | ||
213 | * under, otherwise it returns NULL. So it is also useful as a test as to | ||
214 | * whether the DSO is currently loaded. NB: This will not necessarily return | ||
215 | * the same value as DSO_convert_filename(dso, dso->filename), because the | ||
216 | * DSO_METHOD's load function may have tried a variety of filenames (with | ||
217 | * and/or without the aid of the converters) before settling on the one it | ||
218 | * actually loaded. */ | ||
219 | const char *DSO_get_loaded_filename(DSO *dso); | ||
220 | |||
221 | void DSO_set_default_method(DSO_METHOD *meth); | ||
154 | DSO_METHOD *DSO_get_default_method(void); | 222 | DSO_METHOD *DSO_get_default_method(void); |
155 | DSO_METHOD *DSO_get_method(DSO *dso); | 223 | DSO_METHOD *DSO_get_method(DSO *dso); |
156 | DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth); | 224 | DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth); |
@@ -159,8 +227,7 @@ DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth); | |||
159 | * for the first and third parameters. Use DSO_up and DSO_free for | 227 | * for the first and third parameters. Use DSO_up and DSO_free for |
160 | * subsequent reference count handling. Any flags passed in will be set | 228 | * subsequent reference count handling. Any flags passed in will be set |
161 | * in the constructed DSO after its init() function but before the | 229 | * in the constructed DSO after its init() function but before the |
162 | * load operation. This will be done with; | 230 | * load operation. If 'dso' is non-NULL, 'flags' is ignored. */ |
163 | * DSO_ctrl(dso, DSO_CTRL_SET_FLAGS, flags, NULL); */ | ||
164 | DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags); | 231 | DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags); |
165 | 232 | ||
166 | /* This function binds to a variable inside a shared library. */ | 233 | /* This function binds to a variable inside a shared library. */ |
@@ -194,52 +261,58 @@ DSO_METHOD *DSO_METHOD_win32(void); | |||
194 | /* If VMS is defined, use shared images. If not, return NULL. */ | 261 | /* If VMS is defined, use shared images. If not, return NULL. */ |
195 | DSO_METHOD *DSO_METHOD_vms(void); | 262 | DSO_METHOD *DSO_METHOD_vms(void); |
196 | 263 | ||
197 | void ERR_load_DSO_strings(void); | ||
198 | |||
199 | /* BEGIN ERROR CODES */ | 264 | /* BEGIN ERROR CODES */ |
200 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 265 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
201 | * made after this point may be overwritten when the script is next run. | 266 | * made after this point may be overwritten when the script is next run. |
202 | */ | 267 | */ |
268 | void ERR_load_DSO_strings(void); | ||
203 | 269 | ||
204 | /* Error codes for the DSO functions. */ | 270 | /* Error codes for the DSO functions. */ |
205 | 271 | ||
206 | /* Function codes. */ | 272 | /* Function codes. */ |
207 | #define DSO_F_DLFCN_BIND_FUNC 100 | 273 | #define DSO_F_DLFCN_BIND_FUNC 100 |
208 | #define DSO_F_DLFCN_BIND_VAR 101 | 274 | #define DSO_F_DLFCN_BIND_VAR 101 |
209 | #define DSO_F_DLFCN_CTRL 102 | 275 | #define DSO_F_DLFCN_LOAD 102 |
210 | #define DSO_F_DLFCN_LOAD 103 | 276 | #define DSO_F_DLFCN_NAME_CONVERTER 123 |
211 | #define DSO_F_DLFCN_UNLOAD 104 | 277 | #define DSO_F_DLFCN_UNLOAD 103 |
212 | #define DSO_F_DL_BIND_FUNC 105 | 278 | #define DSO_F_DL_BIND_FUNC 104 |
213 | #define DSO_F_DL_BIND_VAR 106 | 279 | #define DSO_F_DL_BIND_VAR 105 |
214 | #define DSO_F_DL_CTRL 107 | 280 | #define DSO_F_DL_LOAD 106 |
215 | #define DSO_F_DL_LOAD 108 | 281 | #define DSO_F_DL_NAME_CONVERTER 124 |
216 | #define DSO_F_DL_UNLOAD 109 | 282 | #define DSO_F_DL_UNLOAD 107 |
217 | #define DSO_F_DSO_BIND_FUNC 110 | 283 | #define DSO_F_DSO_BIND_FUNC 108 |
218 | #define DSO_F_DSO_BIND_VAR 111 | 284 | #define DSO_F_DSO_BIND_VAR 109 |
219 | #define DSO_F_DSO_CTRL 112 | 285 | #define DSO_F_DSO_CONVERT_FILENAME 126 |
220 | #define DSO_F_DSO_FREE 113 | 286 | #define DSO_F_DSO_CTRL 110 |
221 | #define DSO_F_DSO_LOAD 114 | 287 | #define DSO_F_DSO_FREE 111 |
222 | #define DSO_F_DSO_NEW_METHOD 115 | 288 | #define DSO_F_DSO_GET_FILENAME 127 |
223 | #define DSO_F_DSO_UP 116 | 289 | #define DSO_F_DSO_GET_LOADED_FILENAME 128 |
224 | #define DSO_F_VMS_BIND_VAR 122 | 290 | #define DSO_F_DSO_LOAD 112 |
225 | #define DSO_F_VMS_CTRL 123 | 291 | #define DSO_F_DSO_NEW_METHOD 113 |
226 | #define DSO_F_VMS_LOAD 124 | 292 | #define DSO_F_DSO_SET_FILENAME 129 |
227 | #define DSO_F_VMS_UNLOAD 125 | 293 | #define DSO_F_DSO_SET_NAME_CONVERTER 122 |
228 | #define DSO_F_WIN32_BIND_FUNC 117 | 294 | #define DSO_F_DSO_UP_REF 114 |
229 | #define DSO_F_WIN32_BIND_VAR 118 | 295 | #define DSO_F_VMS_BIND_VAR 115 |
230 | #define DSO_F_WIN32_CTRL 119 | 296 | #define DSO_F_VMS_LOAD 116 |
297 | #define DSO_F_VMS_UNLOAD 117 | ||
298 | #define DSO_F_WIN32_BIND_FUNC 118 | ||
299 | #define DSO_F_WIN32_BIND_VAR 119 | ||
231 | #define DSO_F_WIN32_LOAD 120 | 300 | #define DSO_F_WIN32_LOAD 120 |
301 | #define DSO_F_WIN32_NAME_CONVERTER 125 | ||
232 | #define DSO_F_WIN32_UNLOAD 121 | 302 | #define DSO_F_WIN32_UNLOAD 121 |
233 | 303 | ||
234 | /* Reason codes. */ | 304 | /* Reason codes. */ |
235 | #define DSO_R_CTRL_FAILED 100 | 305 | #define DSO_R_CTRL_FAILED 100 |
236 | #define DSO_R_FILENAME_TOO_BIG 109 | 306 | #define DSO_R_DSO_ALREADY_LOADED 110 |
237 | #define DSO_R_FINISH_FAILED 101 | 307 | #define DSO_R_FILENAME_TOO_BIG 101 |
238 | #define DSO_R_LOAD_FAILED 102 | 308 | #define DSO_R_FINISH_FAILED 102 |
239 | #define DSO_R_NULL_HANDLE 103 | 309 | #define DSO_R_LOAD_FAILED 103 |
240 | #define DSO_R_STACK_ERROR 104 | 310 | #define DSO_R_NAME_TRANSLATION_FAILED 109 |
241 | #define DSO_R_SYM_FAILURE 105 | 311 | #define DSO_R_NO_FILENAME 111 |
242 | #define DSO_R_UNKNOWN_COMMAND 106 | 312 | #define DSO_R_NULL_HANDLE 104 |
313 | #define DSO_R_SET_FILENAME_FAILED 112 | ||
314 | #define DSO_R_STACK_ERROR 105 | ||
315 | #define DSO_R_SYM_FAILURE 106 | ||
243 | #define DSO_R_UNLOAD_FAILED 107 | 316 | #define DSO_R_UNLOAD_FAILED 107 |
244 | #define DSO_R_UNSUPPORTED 108 | 317 | #define DSO_R_UNSUPPORTED 108 |
245 | 318 | ||
@@ -247,4 +320,3 @@ void ERR_load_DSO_strings(void); | |||
247 | } | 320 | } |
248 | #endif | 321 | #endif |
249 | #endif | 322 | #endif |
250 | |||