Stack changes made dso_vms.c not compile properly.
[openssl.git] / crypto / dso / dso_vms.c
index bd284535f1a2c1fd943f948f56fa1094404e1e9c..321512772aa79a84c3b0dfa5956e7ef0466fbed2 100644 (file)
@@ -1,4 +1,4 @@
-/* dso_vms.c */
+/* dso_vms.c -*- mode:C; c-file-style: "eay" -*- */
 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
  * project 2000.
  */
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
-#ifdef VMS
+#include "cryptlib.h"
+#include <openssl/dso.h>
+#ifdef OPENSSL_SYS_VMS
 #pragma message disable DOLLARID
+#include <rms.h>
 #include <lib$routines.h>
-#include <libfisdef.h>
 #include <stsdef.h>
 #include <descrip.h>
 #include <starlet.h>
 #endif
-#include "cryptlib.h"
-#include <openssl/dso.h>
 
-#ifndef VMS
+#ifndef OPENSSL_SYS_VMS
 DSO_METHOD *DSO_METHOD_vms(void)
        {
        return NULL;
@@ -89,7 +89,9 @@ static int vms_init(DSO *dso);
 static int vms_finish(DSO *dso);
 static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
 #endif
-static char *vms_name_converter(DSO *dso);
+static char *vms_name_converter(DSO *dso, const char *filename);
+static char *vms_merger(DSO *dso, const char *filespec1,
+       const char *filespec2);
 
 static DSO_METHOD dso_meth_vms = {
        "OpenSSL 'VMS' shared library method",
@@ -104,6 +106,7 @@ static DSO_METHOD dso_meth_vms = {
 #endif
        NULL, /* ctrl */
        vms_name_converter,
+       vms_merger,
        NULL, /* init */
        NULL  /* finish */
        };
@@ -133,10 +136,18 @@ DSO_METHOD *DSO_METHOD_vms(void)
 
 static int vms_load(DSO *dso)
        {
-#if 0
+       void *ptr = NULL;
+       /* See applicable comments in dso_dl.c */
+       char *filename = DSO_convert_filename(dso, NULL);
        DSO_VMS_INTERNAL *p;
        const char *sp1, *sp2;  /* Search result */
 
+       if(filename == NULL)
+               {
+               DSOerr(DSO_F_VMS_LOAD,DSO_R_NO_FILENAME);
+               goto err;
+               }
+
        /* A file specification may look like this:
         *
         *      node::dev:[dir-spec]name.type;ver
@@ -178,14 +189,14 @@ static int vms_load(DSO *dso)
                || (sp1 - filename) + strlen(sp2) > FILENAME_MAX)
                {
                DSOerr(DSO_F_VMS_LOAD,DSO_R_FILENAME_TOO_BIG);
-               return(0);
+               goto err;
                }
 
        p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL));
        if(p == NULL)
                {
                DSOerr(DSO_F_VMS_LOAD,ERR_R_MALLOC_FAILURE);
-               return(0);
+               goto err;
                }
 
        strncpy(p->filename, sp1, sp2-sp1);
@@ -204,19 +215,22 @@ static int vms_load(DSO *dso)
        p->imagename_dsc.dsc$b_class = DSC$K_CLASS_S;
        p->imagename_dsc.dsc$a_pointer = p->imagename;
 
-       if(!sk_push(dso->meth_data, (char *)p))
+       if(!sk_void_push(dso->meth_data, (char *)p))
                {
                DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR);
-               OPENSSL_free(p);
-               return(0);
+               goto err;
                }
+
+       /* Success (for now, we lie.  We actually do not know...) */
+       dso->loaded_filename = filename;
        return(1);
-#else
-       /* See the comments lower down in the vms_name_converter
-        * "implementation" :-) */
-       please_break_compilation();
-       return(bother_richard);
-#endif
+err:
+       /* Cleanup! */
+       if(p != NULL)
+               OPENSSL_free(p);
+       if(filename != NULL)
+               OPENSSL_free(filename);
+       return(0);
        }
 
 /* Note that this doesn't actually unload the shared image, as there is no
@@ -231,9 +245,9 @@ static int vms_unload(DSO *dso)
                DSOerr(DSO_F_VMS_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
                return(0);
                }
-       if(sk_num(dso->meth_data) < 1)
+       if(sk_void_num(dso->meth_data) < 1)
                return(1);
-       p = (DSO_VMS_INTERNAL *)sk_pop(dso->meth_data);
+       p = (DSO_VMS_INTERNAL *)sk_void_pop(dso->meth_data);
        if(p == NULL)
                {
                DSOerr(DSO_F_VMS_UNLOAD,DSO_R_NULL_HANDLE);
@@ -269,7 +283,12 @@ void vms_bind_sym(DSO *dso, const char *symname, void **sym)
        {
        DSO_VMS_INTERNAL *ptr;
        int status;
-       int flags = LIB$M_FIS_MIXEDCASE;
+#if 0
+       int flags = (1<<4); /* LIB$M_FIS_MIXEDCASE, but this symbol isn't
+                               defined in VMS older than 7.0 or so */
+#else
+       int flags = 0;
+#endif
        struct dsc$descriptor_s symname_dsc;
        *sym = NULL;
 
@@ -280,19 +299,19 @@ void vms_bind_sym(DSO *dso, const char *symname, void **sym)
 
        if((dso == NULL) || (symname == NULL))
                {
-               DSOerr(DSO_F_VMS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
+               DSOerr(DSO_F_VMS_BIND_SYM,ERR_R_PASSED_NULL_PARAMETER);
                return;
                }
-       if(sk_num(dso->meth_data) < 1)
+       if(sk_void_num(dso->meth_data) < 1)
                {
-               DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_STACK_ERROR);
+               DSOerr(DSO_F_VMS_BIND_SYM,DSO_R_STACK_ERROR);
                return;
                }
-       ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data,
-               sk_num(dso->meth_data) - 1);
+       ptr = (DSO_VMS_INTERNAL *)sk_void_value(dso->meth_data,
+               sk_void_num(dso->meth_data) - 1);
        if(ptr == NULL)
                {
-               DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_NULL_HANDLE);
+               DSOerr(DSO_F_VMS_BIND_SYM,DSO_R_NULL_HANDLE);
                return;
                }
 
@@ -321,7 +340,7 @@ void vms_bind_sym(DSO *dso, const char *symname, void **sym)
                        {
                        errstring[length] = '\0';
 
-                       DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_SYM_FAILURE);
+                       DSOerr(DSO_F_VMS_BIND_SYM,DSO_R_SYM_FAILURE);
                        if (ptr->imagename_dsc.dsc$w_length)
                                ERR_add_error_data(9,
                                        "Symbol ", symname,
@@ -353,26 +372,133 @@ static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
        return sym;
        }
 
-static char *vms_name_converter(DSO *dso)
+static char *vms_merger(DSO *dso, const char *filespec1, const char *filespec2)
        {
-       /* Implementation note: on VMS is it preferable to do real conversions
-        * here, or to actually have it performed in-line with the bind calls
-        * (given that VMS never actually does a load except implicitly within
-        * the bind functions). Another note: normally (eg. dlfcn), the
-        * DSO_load call will either load, put the loaded filename into the DSO
-        * (which marks it effectively as "read-only"), and return success - or
-        * it will fail. VMS needs to work out what to do - otherwise DSO_load
-        * will always succeed, but leave the DSO looking unloaded (because the
-        * loaded_filename will be NULL still) and then real loading (and
-        * setting of loaded_filename) will only happen during the first bind
-        * call (which should have error checking anyway to prevent you calling
-        * it on an "unloaded" DSO - thus giving VMS *serious* grief). Richard,
-        * what do you think? Is it worth having DSO_load() try to find and pin
-        * itself to a library file (and populate loaded_filename) even though
-        * it's unecessary to actually do a load prior to the first bind call?
-        * I leave it to you ... :-) */
-       deliberately_break_compilation_here();
-       return(1);
+       int status;
+       int filespec1len, filespec2len;
+       struct FAB fab;
+#ifdef NAML$C_MAXRSS
+       struct NAML nam;
+       char esa[NAML$C_MAXRSS];
+#else
+       struct NAM nam;
+       char esa[NAM$C_MAXRSS];
+#endif
+       char *merged;
+
+       if (!filespec1) filespec1 = "";
+       if (!filespec2) filespec2 = "";
+       filespec1len = strlen(filespec1);
+       filespec2len = strlen(filespec2);
+
+       fab = cc$rms_fab;
+#ifdef NAML$C_MAXRSS
+       nam = cc$rms_naml;
+#else
+       nam = cc$rms_nam;
+#endif
+
+       fab.fab$l_fna = (char *)filespec1;
+       fab.fab$b_fns = filespec1len;
+       fab.fab$l_dna = (char *)filespec2;
+       fab.fab$b_dns = filespec2len;
+#ifdef NAML$C_MAXRSS
+       if (filespec1len > NAM$C_MAXRSS)
+               {
+               fab.fab$l_fna = 0;
+               fab.fab$b_fns = 0;
+               nam.naml$l_long_filename = (char *)filespec1;
+               nam.naml$l_long_filename_size = filespec1len;
+               }
+       if (filespec2len > NAM$C_MAXRSS)
+               {
+               fab.fab$l_dna = 0;
+               fab.fab$b_dns = 0;
+               nam.naml$l_long_defname = (char *)filespec2;
+               nam.naml$l_long_defname_size = filespec2len;
+               }
+       nam.naml$l_esa = esa;
+       nam.naml$b_ess = NAM$C_MAXRSS;
+       nam.naml$l_long_expand = esa;
+       nam.naml$l_long_expand_alloc = sizeof(esa);
+       nam.naml$b_nop = NAM$M_SYNCHK | NAM$M_PWD;
+       nam.naml$v_no_short_upcase = 1;
+       fab.fab$l_naml = &nam;
+#else
+       nam.nam$l_esa = esa;
+       nam.nam$b_ess = NAM$C_MAXRSS;
+       nam.nam$b_nop = NAM$M_SYNCHK | NAM$M_PWD;
+       fab.fab$l_nam = &nam;
+#endif
+
+       status = sys$parse(&fab, 0, 0);
+
+       if(!$VMS_STATUS_SUCCESS(status))
+               {
+               unsigned short length;
+               char errstring[257];
+               struct dsc$descriptor_s errstring_dsc;
+
+               errstring_dsc.dsc$w_length = sizeof(errstring);
+               errstring_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
+               errstring_dsc.dsc$b_class = DSC$K_CLASS_S;
+               errstring_dsc.dsc$a_pointer = errstring;
+
+               status = sys$getmsg(status, &length, &errstring_dsc, 1, 0);
+
+               if (!$VMS_STATUS_SUCCESS(status))
+                       lib$signal(status); /* This is really bad.  Abort!  */
+               else
+                       {
+                       errstring[length] = '\0';
+
+                       DSOerr(DSO_F_VMS_MERGER,DSO_R_FAILURE);
+                       ERR_add_error_data(7,
+                                          "filespec \"", filespec1, "\", ",
+                                          "defaults \"", filespec2, "\": ",
+                                          errstring);
+                       }
+               return(NULL);
+               }
+#ifdef NAML$C_MAXRSS
+       if (nam.naml$l_long_expand_size)
+               {
+               merged = OPENSSL_malloc(nam.naml$l_long_expand_size + 1);
+               if(!merged)
+                       goto malloc_err;
+               strncpy(merged, nam.naml$l_long_expand,
+                       nam.naml$l_long_expand_size);
+               merged[nam.naml$l_long_expand_size] = '\0';
+               }
+       else
+               {
+               merged = OPENSSL_malloc(nam.naml$b_esl + 1);
+               if(!merged)
+                       goto malloc_err;
+               strncpy(merged, nam.naml$l_esa,
+                       nam.naml$b_esl);
+               merged[nam.naml$b_esl] = '\0';
+               }
+#else
+       merged = OPENSSL_malloc(nam.nam$b_esl + 1);
+       if(!merged)
+               goto malloc_err;
+       strncpy(merged, nam.nam$l_esa,
+               nam.nam$b_esl);
+       merged[nam.nam$b_esl] = '\0';
+#endif
+       return(merged);
+ malloc_err:
+       DSOerr(DSO_F_VMS_MERGER,
+               ERR_R_MALLOC_FAILURE);
+       }
+
+static char *vms_name_converter(DSO *dso, const char *filename)
+       {
+        int len = strlen(filename);
+        char *not_translated = OPENSSL_malloc(len+1);
+        strcpy(not_translated,filename);
+       return(not_translated);
        }
 
-#endif /* VMS */
+#endif /* OPENSSL_SYS_VMS */