2 * Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL project
5 /* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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/)"
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.
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.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
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 * ====================================================================
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).
62 # include <openssl/crypto.h>
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
74 * By default, DSO_load() will translate the provided filename into a form
75 * typical for the platform using the dso_name_converter function of the
76 * method. Eg. win32 will transform "blah" into "blah.dll", and dlfcn will
77 * transform it into "libblah.so". This callback could even utilise the
78 * DSO_METHOD's converter too if it only wants to override behaviour for
79 * one or two possible DSO methods. However, the following flag can be
80 * set in a DSO to prevent *any* native name-translation at all - eg. if
81 * the caller has prompted the user for a path to a driver library so the
82 * filename should be interpreted as-is.
84 # define DSO_FLAG_NO_NAME_TRANSLATION 0x01
86 * An extra flag to give if only the extension should be added as
87 * translation. This is obviously only of importance on Unix and other
88 * operating systems where the translation also may prefix the name with
89 * something, like 'lib', and ignored everywhere else. This flag is also
90 * ignored if DSO_FLAG_NO_NAME_TRANSLATION is used at the same time.
92 # define DSO_FLAG_NAME_TRANSLATION_EXT_ONLY 0x02
95 * The following flag controls the translation of symbol names to upper case.
96 * This is currently only being implemented for OpenVMS.
98 # define DSO_FLAG_UPCASE_SYMBOL 0x10
101 * This flag loads the library with public symbols. Meaning: The exported
102 * symbols of this library are public to all libraries loaded after this
103 * library. At the moment only implemented in unix.
105 # define DSO_FLAG_GLOBAL_SYMBOLS 0x20
107 typedef void (*DSO_FUNC_TYPE) (void);
109 typedef struct dso_st DSO;
110 typedef struct dso_meth_st DSO_METHOD;
113 * The function prototype used for method functions (or caller-provided
114 * callbacks) that transform filenames. They are passed a DSO structure
115 * pointer (or NULL if they are to be used independently of a DSO object) and
116 * a filename to transform. They should either return NULL (if there is an
117 * error condition) or a newly allocated string containing the transformed
118 * form that the caller will need to free with OPENSSL_free() when done.
120 typedef char *(*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *);
122 * The function prototype used for method functions (or caller-provided
123 * callbacks) that merge two file specifications. They are passed a DSO
124 * structure pointer (or NULL if they are to be used independently of a DSO
125 * object) and two file specifications to merge. They should either return
126 * NULL (if there is an error condition) or a newly allocated string
127 * containing the result of merging that the caller will need to free with
128 * OPENSSL_free() when done. Here, merging means that bits and pieces are
129 * taken from each of the file specifications and added together in whatever
130 * fashion that is sensible for the DSO method in question. The only rule
131 * that really applies is that if the two specification contain pieces of the
132 * same type, the copy from the first string takes priority. One could see
133 * it as the first specification is the one given by the user and the second
134 * being a bunch of defaults to add on if they're missing in the first.
136 typedef char *(*DSO_MERGER_FUNC)(DSO *, const char *, const char *);
139 int DSO_free(DSO *dso);
140 int DSO_flags(DSO *dso);
141 int DSO_up_ref(DSO *dso);
142 long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg);
145 * These functions can be used to get/set the platform-independent filename
146 * used for a DSO. NB: set will fail if the DSO is already loaded.
148 const char *DSO_get_filename(DSO *dso);
149 int DSO_set_filename(DSO *dso, const char *filename);
151 * This function will invoke the DSO's name_converter callback to translate a
152 * filename, or if the callback isn't set it will instead use the DSO_METHOD's
153 * converter. If "filename" is NULL, the "filename" in the DSO itself will be
154 * used. If the DSO_FLAG_NO_NAME_TRANSLATION flag is set, then the filename is
155 * simply duplicated. NB: This function is usually called from within a
156 * DSO_METHOD during the processing of a DSO_load() call, and is exposed so
157 * that caller-created DSO_METHODs can do the same thing. A non-NULL return
158 * value will need to be OPENSSL_free()'d.
160 char *DSO_convert_filename(DSO *dso, const char *filename);
162 * This function will invoke the DSO's merger callback to merge two file
163 * specifications, or if the callback isn't set it will instead use the
164 * DSO_METHOD's merger. A non-NULL return value will need to be
167 char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2);
170 * The all-singing all-dancing load function, you normally pass NULL for the
171 * first and third parameters. Use DSO_up_ref and DSO_free for subsequent
172 * reference count handling. Any flags passed in will be set in the
173 * constructed DSO after its init() function but before the load operation.
174 * If 'dso' is non-NULL, 'flags' is ignored.
176 DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags);
178 /* This function binds to a function inside a shared library. */
179 DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname);
182 * This method is the default, but will beg, borrow, or steal whatever method
183 * should be the default on any particular platform (including
184 * DSO_METH_null() if necessary).
186 DSO_METHOD *DSO_METHOD_openssl(void);
189 * This function should be used with caution! It looks up symbols in *all*
190 * loaded modules and if module gets unloaded by somebody else attempt to
191 * dereference the pointer is doomed to have fatal consequences. Primary
192 * usage for this function is to probe *core* system functionality, e.g.
193 * check if getnameinfo(3) is available at run-time without bothering about
194 * OS-specific details such as libc.so.versioning or where does it actually
195 * reside: in libc itself or libsocket.
197 void *DSO_global_lookup(const char *name);
199 /* BEGIN ERROR CODES */
201 * The following lines are auto generated by the script mkerr.pl. Any changes
202 * made after this point may be overwritten when the script is next run.
204 void ERR_load_DSO_strings(void);
206 /* Error codes for the DSO functions. */
208 /* Function codes. */
209 # define DSO_F_BEOS_BIND_FUNC 144
210 # define DSO_F_BEOS_BIND_VAR 145
211 # define DSO_F_BEOS_LOAD 146
212 # define DSO_F_BEOS_NAME_CONVERTER 147
213 # define DSO_F_BEOS_UNLOAD 148
214 # define DSO_F_DLFCN_BIND_FUNC 100
215 # define DSO_F_DLFCN_BIND_VAR 101
216 # define DSO_F_DLFCN_LOAD 102
217 # define DSO_F_DLFCN_MERGER 130
218 # define DSO_F_DLFCN_NAME_CONVERTER 123
219 # define DSO_F_DLFCN_UNLOAD 103
220 # define DSO_F_DL_BIND_FUNC 104
221 # define DSO_F_DL_BIND_VAR 105
222 # define DSO_F_DL_LOAD 106
223 # define DSO_F_DL_MERGER 131
224 # define DSO_F_DL_NAME_CONVERTER 124
225 # define DSO_F_DL_UNLOAD 107
226 # define DSO_F_DSO_BIND_FUNC 108
227 # define DSO_F_DSO_CONVERT_FILENAME 126
228 # define DSO_F_DSO_CTRL 110
229 # define DSO_F_DSO_FREE 111
230 # define DSO_F_DSO_GET_FILENAME 127
231 # define DSO_F_DSO_GET_LOADED_FILENAME 128
232 # define DSO_F_DSO_GLOBAL_LOOKUP 139
233 # define DSO_F_DSO_LOAD 112
234 # define DSO_F_DSO_MERGE 132
235 # define DSO_F_DSO_NEW_METHOD 113
236 # define DSO_F_DSO_SET_FILENAME 129
237 # define DSO_F_DSO_UP_REF 114
238 # define DSO_F_GLOBAL_LOOKUP_FUNC 138
239 # define DSO_F_VMS_BIND_SYM 115
240 # define DSO_F_VMS_LOAD 116
241 # define DSO_F_VMS_MERGER 133
242 # define DSO_F_VMS_UNLOAD 117
243 # define DSO_F_WIN32_BIND_FUNC 118
244 # define DSO_F_WIN32_BIND_VAR 119
245 # define DSO_F_WIN32_GLOBALLOOKUP 142
246 # define DSO_F_WIN32_GLOBALLOOKUP_FUNC 143
247 # define DSO_F_WIN32_JOINER 135
248 # define DSO_F_WIN32_LOAD 120
249 # define DSO_F_WIN32_MERGER 134
250 # define DSO_F_WIN32_NAME_CONVERTER 125
251 # define DSO_F_WIN32_SPLITTER 136
252 # define DSO_F_WIN32_UNLOAD 121
255 # define DSO_R_CTRL_FAILED 100
256 # define DSO_R_DSO_ALREADY_LOADED 110
257 # define DSO_R_EMPTY_FILE_STRUCTURE 113
258 # define DSO_R_FAILURE 114
259 # define DSO_R_FILENAME_TOO_BIG 101
260 # define DSO_R_FINISH_FAILED 102
261 # define DSO_R_INCORRECT_FILE_SYNTAX 115
262 # define DSO_R_LOAD_FAILED 103
263 # define DSO_R_NAME_TRANSLATION_FAILED 109
264 # define DSO_R_NO_FILENAME 111
265 # define DSO_R_NO_FILE_SPECIFICATION 116
266 # define DSO_R_NULL_HANDLE 104
267 # define DSO_R_SET_FILENAME_FAILED 112
268 # define DSO_R_STACK_ERROR 105
269 # define DSO_R_SYM_FAILURE 106
270 # define DSO_R_UNLOAD_FAILED 107
271 # define DSO_R_UNSUPPORTED 108