1 /* dso_vms.c -*- mode:C; c-file-style: "eay" -*- */
3 * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project
6 /* ====================================================================
7 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
35 * 6. Redistributions of any form whatsoever must retain the following
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
64 #include <openssl/dso.h>
65 #ifdef OPENSSL_SYS_VMS
66 # pragma message disable DOLLARID
68 # include <lib$routines.h>
74 #ifndef OPENSSL_SYS_VMS
75 DSO_METHOD
*DSO_METHOD_vms(void)
80 # pragma message disable DOLLARID
82 static int vms_load(DSO
*dso
);
83 static int vms_unload(DSO
*dso
);
84 static void *vms_bind_var(DSO
*dso
, const char *symname
);
85 static DSO_FUNC_TYPE
vms_bind_func(DSO
*dso
, const char *symname
);
87 static int vms_unbind_var(DSO
*dso
, char *symname
, void *symptr
);
88 static int vms_unbind_func(DSO
*dso
, char *symname
, DSO_FUNC_TYPE symptr
);
89 static int vms_init(DSO
*dso
);
90 static int vms_finish(DSO
*dso
);
91 static long vms_ctrl(DSO
*dso
, int cmd
, long larg
, void *parg
);
93 static char *vms_name_converter(DSO
*dso
, const char *filename
);
94 static char *vms_merger(DSO
*dso
, const char *filespec1
,
95 const char *filespec2
);
97 static DSO_METHOD dso_meth_vms
= {
98 "OpenSSL 'VMS' shared library method",
103 /* For now, "unbind" doesn't exist */
105 NULL
, /* unbind_var */
106 NULL
, /* unbind_func */
116 * On VMS, the only "handle" is the file name. LIB$FIND_IMAGE_SYMBOL depends
117 * on the reference to the file name being the same for all calls regarding
118 * one shared image, so we'll just store it in an instance of the following
119 * structure and put a pointer to that instance in the meth_data stack.
121 typedef struct dso_internal_st
{
123 * This should contain the name only, no directory, no extension, nothing
126 struct dsc$descriptor_s filename_dsc
;
127 char filename
[FILENAME_MAX
+ 1];
129 * This contains whatever is not in filename, if needed. Normally not
132 struct dsc$descriptor_s imagename_dsc
;
133 char imagename
[FILENAME_MAX
+ 1];
136 DSO_METHOD
*DSO_METHOD_vms(void)
138 return (&dso_meth_vms
);
141 static int vms_load(DSO
*dso
)
144 /* See applicable comments in dso_dl.c */
145 char *filename
= DSO_convert_filename(dso
, NULL
);
147 const char *sp1
, *sp2
; /* Search result */
149 if (filename
== NULL
) {
150 DSOerr(DSO_F_VMS_LOAD
, DSO_R_NO_FILENAME
);
155 * A file specification may look like this:
157 * node::dev:[dir-spec]name.type;ver
159 * or (for compatibility with TOPS-20):
161 * node::dev:<dir-spec>name.type;ver
163 * and the dir-spec uses '.' as separator. Also, a dir-spec
164 * may consist of several parts, with mixed use of [] and <>:
168 * We need to split the file specification into the name and
169 * the rest (both before and after the name itself).
172 * Start with trying to find the end of a dir-spec, and save the position
173 * of the byte after in sp1
175 sp1
= strrchr(filename
, ']');
176 sp2
= strrchr(filename
, '>');
179 if (sp2
!= NULL
&& sp2
> sp1
)
182 sp1
= strrchr(filename
, ':');
186 sp1
++; /* The byte after the found character */
187 /* Now, let's see if there's a type, and save the position in sp2 */
188 sp2
= strchr(sp1
, '.');
190 * If we found it, that's where we'll cut. Otherwise, look for a version
191 * number and save the position in sp2
194 sp2
= strchr(sp1
, ';');
196 * If there was still nothing to find, set sp2 to point at the end of the
200 sp2
= sp1
+ strlen(sp1
);
202 /* Check that we won't get buffer overflows */
203 if (sp2
- sp1
> FILENAME_MAX
204 || (sp1
- filename
) + strlen(sp2
) > FILENAME_MAX
) {
205 DSOerr(DSO_F_VMS_LOAD
, DSO_R_FILENAME_TOO_BIG
);
209 p
= (DSO_VMS_INTERNAL
*)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL
));
211 DSOerr(DSO_F_VMS_LOAD
, ERR_R_MALLOC_FAILURE
);
215 strncpy(p
->filename
, sp1
, sp2
- sp1
);
216 p
->filename
[sp2
- sp1
] = '\0';
218 strncpy(p
->imagename
, filename
, sp1
- filename
);
219 p
->imagename
[sp1
- filename
] = '\0';
220 strcat(p
->imagename
, sp2
);
222 p
->filename_dsc
.dsc$w_length
= strlen(p
->filename
);
223 p
->filename_dsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
224 p
->filename_dsc
.dsc$b_class
= DSC$K_CLASS_S
;
225 p
->filename_dsc
.dsc$a_pointer
= p
->filename
;
226 p
->imagename_dsc
.dsc$w_length
= strlen(p
->imagename
);
227 p
->imagename_dsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
228 p
->imagename_dsc
.dsc$b_class
= DSC$K_CLASS_S
;
229 p
->imagename_dsc
.dsc$a_pointer
= p
->imagename
;
231 if (!sk_push(dso
->meth_data
, (char *)p
)) {
232 DSOerr(DSO_F_VMS_LOAD
, DSO_R_STACK_ERROR
);
236 /* Success (for now, we lie. We actually do not know...) */
237 dso
->loaded_filename
= filename
;
243 if (filename
!= NULL
)
244 OPENSSL_free(filename
);
249 * Note that this doesn't actually unload the shared image, as there is no
250 * such thing in VMS. Next time it get loaded again, a new copy will
251 * actually be loaded.
253 static int vms_unload(DSO
*dso
)
257 DSOerr(DSO_F_VMS_UNLOAD
, ERR_R_PASSED_NULL_PARAMETER
);
260 if (sk_num(dso
->meth_data
) < 1)
262 p
= (DSO_VMS_INTERNAL
*)sk_pop(dso
->meth_data
);
264 DSOerr(DSO_F_VMS_UNLOAD
, DSO_R_NULL_HANDLE
);
273 * We must do this in a separate function because of the way the exception
274 * handler works (it makes this function return
276 static int do_find_symbol(DSO_VMS_INTERNAL
*ptr
,
277 struct dsc$descriptor_s
*symname_dsc
, void **sym
,
281 * Make sure that signals are caught and returned instead of aborting the
282 * program. The exception handler gets unestablished automatically on
283 * return from this function.
285 lib$
establish(lib$sig_to_ret
);
287 if (ptr
->imagename_dsc
.dsc$w_length
)
288 return lib$
find_image_symbol(&ptr
->filename_dsc
,
290 &ptr
->imagename_dsc
, flags
);
292 return lib$
find_image_symbol(&ptr
->filename_dsc
,
293 symname_dsc
, sym
, 0, flags
);
296 void vms_bind_sym(DSO
*dso
, const char *symname
, void **sym
)
298 DSO_VMS_INTERNAL
*ptr
;
301 int flags
= (1 << 4); /* LIB$M_FIS_MIXEDCASE, but this symbol isn't
302 * defined in VMS older than 7.0 or so */
306 struct dsc$descriptor_s symname_dsc
;
309 symname_dsc
.dsc$w_length
= strlen(symname
);
310 symname_dsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
311 symname_dsc
.dsc$b_class
= DSC$K_CLASS_S
;
312 symname_dsc
.dsc$a_pointer
= (char *)symname
; /* The cast is needed */
314 if ((dso
== NULL
) || (symname
== NULL
)) {
315 DSOerr(DSO_F_VMS_BIND_SYM
, ERR_R_PASSED_NULL_PARAMETER
);
318 if (sk_num(dso
->meth_data
) < 1) {
319 DSOerr(DSO_F_VMS_BIND_SYM
, DSO_R_STACK_ERROR
);
322 ptr
= (DSO_VMS_INTERNAL
*)sk_value(dso
->meth_data
,
323 sk_num(dso
->meth_data
) - 1);
325 DSOerr(DSO_F_VMS_BIND_SYM
, DSO_R_NULL_HANDLE
);
329 if (dso
->flags
& DSO_FLAG_UPCASE_SYMBOL
)
332 status
= do_find_symbol(ptr
, &symname_dsc
, sym
, flags
);
334 if (!$
VMS_STATUS_SUCCESS(status
)) {
335 unsigned short length
;
337 struct dsc$descriptor_s errstring_dsc
;
339 errstring_dsc
.dsc$w_length
= sizeof(errstring
);
340 errstring_dsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
341 errstring_dsc
.dsc$b_class
= DSC$K_CLASS_S
;
342 errstring_dsc
.dsc$a_pointer
= errstring
;
346 status
= sys$
getmsg(status
, &length
, &errstring_dsc
, 1, 0);
348 if (!$
VMS_STATUS_SUCCESS(status
))
349 lib$
signal(status
); /* This is really bad. Abort! */
351 errstring
[length
] = '\0';
353 DSOerr(DSO_F_VMS_BIND_SYM
, DSO_R_SYM_FAILURE
);
354 if (ptr
->imagename_dsc
.dsc$w_length
)
355 ERR_add_error_data(9,
357 " in ", ptr
->filename
,
358 " (", ptr
->imagename
, ")",
361 ERR_add_error_data(6,
363 " in ", ptr
->filename
, ": ", errstring
);
370 static void *vms_bind_var(DSO
*dso
, const char *symname
)
373 vms_bind_sym(dso
, symname
, &sym
);
377 static DSO_FUNC_TYPE
vms_bind_func(DSO
*dso
, const char *symname
)
379 DSO_FUNC_TYPE sym
= 0;
380 vms_bind_sym(dso
, symname
, (void **)&sym
);
384 static char *vms_merger(DSO
*dso
, const char *filespec1
,
385 const char *filespec2
)
388 int filespec1len
, filespec2len
;
390 # ifdef NAML$C_MAXRSS
392 char esa
[NAML$C_MAXRSS
];
395 char esa
[NAM$C_MAXRSS
];
403 filespec1len
= strlen(filespec1
);
404 filespec2len
= strlen(filespec2
);
407 # ifdef NAML$C_MAXRSS
413 fab
.fab$l_fna
= (char *)filespec1
;
414 fab
.fab$b_fns
= filespec1len
;
415 fab
.fab$l_dna
= (char *)filespec2
;
416 fab
.fab$b_dns
= filespec2len
;
417 # ifdef NAML$C_MAXRSS
418 if (filespec1len
> NAM$C_MAXRSS
) {
421 nam
.naml$l_long_filename
= (char *)filespec1
;
422 nam
.naml$l_long_filename_size
= filespec1len
;
424 if (filespec2len
> NAM$C_MAXRSS
) {
427 nam
.naml$l_long_defname
= (char *)filespec2
;
428 nam
.naml$l_long_defname_size
= filespec2len
;
430 nam
.naml$l_esa
= esa
;
431 nam
.naml$b_ess
= NAM$C_MAXRSS
;
432 nam
.naml$l_long_expand
= esa
;
433 nam
.naml$l_long_expand_alloc
= sizeof(esa
);
434 nam
.naml$b_nop
= NAM$M_SYNCHK
| NAM$M_PWD
;
435 nam
.naml$v_no_short_upcase
= 1;
436 fab
.fab$l_naml
= &nam
;
439 nam
.nam$b_ess
= NAM$C_MAXRSS
;
440 nam
.nam$b_nop
= NAM$M_SYNCHK
| NAM$M_PWD
;
441 fab
.fab$l_nam
= &nam
;
444 status
= sys$
parse(&fab
, 0, 0);
446 if (!$
VMS_STATUS_SUCCESS(status
)) {
447 unsigned short length
;
449 struct dsc$descriptor_s errstring_dsc
;
451 errstring_dsc
.dsc$w_length
= sizeof(errstring
);
452 errstring_dsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
453 errstring_dsc
.dsc$b_class
= DSC$K_CLASS_S
;
454 errstring_dsc
.dsc$a_pointer
= errstring
;
456 status
= sys$
getmsg(status
, &length
, &errstring_dsc
, 1, 0);
458 if (!$
VMS_STATUS_SUCCESS(status
))
459 lib$
signal(status
); /* This is really bad. Abort! */
461 errstring
[length
] = '\0';
463 DSOerr(DSO_F_VMS_MERGER
, DSO_R_FAILURE
);
464 ERR_add_error_data(7,
465 "filespec \"", filespec1
, "\", ",
466 "defaults \"", filespec2
, "\": ", errstring
);
470 # ifdef NAML$C_MAXRSS
471 if (nam
.naml$l_long_expand_size
) {
472 merged
= OPENSSL_malloc(nam
.naml$l_long_expand_size
+ 1);
475 strncpy(merged
, nam
.naml$l_long_expand
, nam
.naml$l_long_expand_size
);
476 merged
[nam
.naml$l_long_expand_size
] = '\0';
478 merged
= OPENSSL_malloc(nam
.naml$b_esl
+ 1);
481 strncpy(merged
, nam
.naml$l_esa
, nam
.naml$b_esl
);
482 merged
[nam
.naml$b_esl
] = '\0';
485 merged
= OPENSSL_malloc(nam
.nam$b_esl
+ 1);
488 strncpy(merged
, nam
.nam$l_esa
, nam
.nam$b_esl
);
489 merged
[nam
.nam$b_esl
] = '\0';
493 DSOerr(DSO_F_VMS_MERGER
, ERR_R_MALLOC_FAILURE
);
496 static char *vms_name_converter(DSO
*dso
, const char *filename
)
498 int len
= strlen(filename
);
499 char *not_translated
= OPENSSL_malloc(len
+ 1);
500 strcpy(not_translated
, filename
);
501 return (not_translated
);
504 #endif /* OPENSSL_SYS_VMS */