2 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
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).
63 #pragma message disable DOLLARID
64 #include <lib$routines.h>
65 #include <libfisdef.h>
71 #include <openssl/dso.h>
74 DSO_METHOD *DSO_METHOD_vms(void)
79 #pragma message disable DOLLARID
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);
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);
91 static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
93 static DSO_METHOD dso_meth_vms = {
94 "OpenSSL 'VMS' shared library method",
99 /* For now, "unbind" doesn't exist */
101 NULL, /* unbind_var */
102 NULL, /* unbind_func */
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.
114 typedef struct dso_internal_st
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];
127 DSO_METHOD *DSO_METHOD_vms(void)
129 return(&dso_meth_vms);
132 static int vms_load(DSO *dso, const char *filename)
135 const char *sp1, *sp2; /* Search result */
137 /* A file specification may look like this:
139 * node::dev:[dir-spec]name.type;ver
141 * or (for compatibility with TOPS-20):
143 * node::dev:<dir-spec>name.type;ver
145 * and the dir-spec uses '.' as separator. Also, a dir-spec
146 * may consist of several parts, with mixed use of [] and <>:
150 * We need to split the file specification into the name and
151 * the rest (both before and after the name itself).
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, ':');
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
171 if (sp2 == NULL) sp2 = sp1 + strlen(sp1);
173 /* Check that we won't get buffer overflows */
174 if (sp2 - sp1 > FILENAME_MAX
175 || (sp1 - filename) + strlen(sp2) > FILENAME_MAX)
177 DSOerr(DSO_F_VMS_LOAD,DSO_R_FILENAME_TOO_BIG);
181 p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL));
184 DSOerr(DSO_F_VMS_LOAD,ERR_R_MALLOC_FAILURE);
188 strncpy(p->filename, sp1, sp2-sp1);
189 p->filename[sp2-sp1] = '\0';
191 strncpy(p->imagename, filename, sp1-filename);
192 p->imagename[sp1-filename] = '\0';
193 strcat(p->imagename, sp2);
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;
204 if(!sk_push(dso->meth_data, (char *)p))
206 DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR);
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.
217 static int vms_unload(DSO *dso)
222 DSOerr(DSO_F_VMS_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
225 if(sk_num(dso->meth_data) < 1)
227 p = (DSO_VMS_INTERNAL *)sk_pop(dso->meth_data);
230 DSOerr(DSO_F_VMS_UNLOAD,DSO_R_NULL_HANDLE);
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,
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);
249 if(ptr->imagename_dsc.dsc$w_length)
250 return lib$find_image_symbol(&ptr->filename_dsc,
252 &ptr->imagename_dsc, flags);
254 return lib$find_image_symbol(&ptr->filename_dsc,
259 void vms_bind_sym(DSO *dso, const char *symname, void **sym)
261 DSO_VMS_INTERNAL *ptr;
263 int flags = LIB$M_FIS_MIXEDCASE;
264 struct dsc$descriptor_s symname_dsc;
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 */
272 if((dso == NULL) || (symname == NULL))
274 DSOerr(DSO_F_VMS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
277 if(sk_num(dso->meth_data) < 1)
279 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_STACK_ERROR);
282 ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data,
283 sk_num(dso->meth_data) - 1);
286 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_NULL_HANDLE);
290 if(dso->flags & DSO_FLAG_UPCASE_SYMBOL) flags = 0;
292 status = do_find_symbol(ptr, &symname_dsc, sym, flags);
294 if(!$VMS_STATUS_SUCCESS(status))
296 unsigned short length;
298 struct dsc$descriptor_s errstring_dsc;
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;
307 status = sys$getmsg(status, &length, &errstring_dsc, 1, 0);
309 if (!$VMS_STATUS_SUCCESS(status))
310 lib$signal(status); /* This is really bad. Abort! */
313 errstring[length] = '\0';
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,
319 " in ", ptr->filename,
320 " (", ptr->imagename, ")",
323 ERR_add_error_data(6,
325 " in ", ptr->filename,
333 static void *vms_bind_var(DSO *dso, const char *symname)
336 vms_bind_sym(dso, symname, &sym);
340 static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
342 DSO_FUNC_TYPE sym = 0;
343 vms_bind_sym(dso, symname, (void **)&sym);
347 static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg)
351 DSOerr(DSO_F_VMS_CTRL,ERR_R_PASSED_NULL_PARAMETER);
356 case DSO_CTRL_GET_FLAGS:
358 case DSO_CTRL_SET_FLAGS:
359 dso->flags = (int)larg;
361 case DSO_CTRL_OR_FLAGS:
362 dso->flags |= (int)larg;
367 DSOerr(DSO_F_VMS_CTRL,DSO_R_UNKNOWN_COMMAND);