On VMS, the norm is still that symbols are uppercased, so for now it's better
[openssl.git] / crypto / dso / dso_vms.c
index 58b9027..1674619 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #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 <lib$routines.h>
 #include <lib$routines.h>
-#include <libfisdef.h>
 #include <stsdef.h>
 #include <descrip.h>
 #include <starlet.h>
 #endif
 #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;
 DSO_METHOD *DSO_METHOD_vms(void)
        {
        return NULL;
@@ -77,7 +77,7 @@ DSO_METHOD *DSO_METHOD_vms(void)
 #else
 #pragma message disable DOLLARID
 
 #else
 #pragma message disable DOLLARID
 
-static int vms_load(DSO *dso, const char *filename);
+static int vms_load(DSO *dso);
 static int vms_unload(DSO *dso);
 static void *vms_bind_var(DSO *dso, const char *symname);
 static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname);
 static int vms_unload(DSO *dso);
 static void *vms_bind_var(DSO *dso, const char *symname);
 static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname);
@@ -86,8 +86,9 @@ static int vms_unbind_var(DSO *dso, char *symname, void *symptr);
 static int vms_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
 static int vms_init(DSO *dso);
 static int vms_finish(DSO *dso);
 static int vms_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
 static int vms_init(DSO *dso);
 static int vms_finish(DSO *dso);
-#endif
 static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
 static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
+#endif
+static char *vms_name_converter(DSO *dso, const char *filename);
 
 static DSO_METHOD dso_meth_vms = {
        "OpenSSL 'VMS' shared library method",
 
 static DSO_METHOD dso_meth_vms = {
        "OpenSSL 'VMS' shared library method",
@@ -100,7 +101,8 @@ static DSO_METHOD dso_meth_vms = {
        NULL, /* unbind_var */
        NULL, /* unbind_func */
 #endif
        NULL, /* unbind_var */
        NULL, /* unbind_func */
 #endif
-       vms_ctrl,
+       NULL, /* ctrl */
+       vms_name_converter,
        NULL, /* init */
        NULL  /* finish */
        };
        NULL, /* init */
        NULL  /* finish */
        };
@@ -128,11 +130,20 @@ DSO_METHOD *DSO_METHOD_vms(void)
        return(&dso_meth_vms);
        }
 
        return(&dso_meth_vms);
        }
 
-static int vms_load(DSO *dso, const char *filename)
+static int vms_load(DSO *dso)
        {
        {
+       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 */
 
        DSO_VMS_INTERNAL *p;
        const char *sp1, *sp2;  /* Search result */
 
+       if(filename == NULL)
+               {
+               DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME);
+               goto err;
+               }
+
        /* A file specification may look like this:
         *
         *      node::dev:[dir-spec]name.type;ver
        /* A file specification may look like this:
         *
         *      node::dev:[dir-spec]name.type;ver
@@ -174,14 +185,14 @@ static int vms_load(DSO *dso, const char *filename)
                || (sp1 - filename) + strlen(sp2) > FILENAME_MAX)
                {
                DSOerr(DSO_F_VMS_LOAD,DSO_R_FILENAME_TOO_BIG);
                || (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);
                }
 
        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);
                }
 
        strncpy(p->filename, sp1, sp2-sp1);
@@ -203,10 +214,19 @@ static int vms_load(DSO *dso, const char *filename)
        if(!sk_push(dso->meth_data, (char *)p))
                {
                DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR);
        if(!sk_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);
        return(1);
+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
        }
 
 /* Note that this doesn't actually unload the shared image, as there is no
@@ -255,13 +275,18 @@ static int do_find_symbol(DSO_VMS_INTERNAL *ptr,
                        0, flags);
        }
 
                        0, flags);
        }
 
-static void *vms_bind_sym(DSO *dso, const char *symname)
+void vms_bind_sym(DSO *dso, const char *symname, void **sym)
        {
        DSO_VMS_INTERNAL *ptr;
        {
        DSO_VMS_INTERNAL *ptr;
-       void *sym = 0;
        int status;
        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;
        struct dsc$descriptor_s symname_dsc;
+       *sym = NULL;
 
        symname_dsc.dsc$w_length = strlen(symname);
        symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
 
        symname_dsc.dsc$w_length = strlen(symname);
        symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
@@ -271,24 +296,24 @@ static void *vms_bind_sym(DSO *dso, const char *symname)
        if((dso == NULL) || (symname == NULL))
                {
                DSOerr(DSO_F_VMS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
        if((dso == NULL) || (symname == NULL))
                {
                DSOerr(DSO_F_VMS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
-               return(NULL);
+               return;
                }
        if(sk_num(dso->meth_data) < 1)
                {
                DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_STACK_ERROR);
                }
        if(sk_num(dso->meth_data) < 1)
                {
                DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_STACK_ERROR);
-               return(NULL);
+               return;
                }
        ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data,
                sk_num(dso->meth_data) - 1);
        if(ptr == NULL)
                {
                DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_NULL_HANDLE);
                }
        ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data,
                sk_num(dso->meth_data) - 1);
        if(ptr == NULL)
                {
                DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_NULL_HANDLE);
-               return(NULL);
+               return;
                }
 
        if(dso->flags & DSO_FLAG_UPCASE_SYMBOL) flags = 0;
 
                }
 
        if(dso->flags & DSO_FLAG_UPCASE_SYMBOL) flags = 0;
 
-       status = do_find_symbol(ptr, &symname_dsc, &sym, flags);
+       status = do_find_symbol(ptr, &symname_dsc, sym, flags);
 
        if(!$VMS_STATUS_SUCCESS(status))
                {
 
        if(!$VMS_STATUS_SUCCESS(status))
                {
@@ -301,6 +326,8 @@ static void *vms_bind_sym(DSO *dso, const char *symname)
                errstring_dsc.dsc$b_class = DSC$K_CLASS_S;
                errstring_dsc.dsc$a_pointer = errstring;
 
                errstring_dsc.dsc$b_class = DSC$K_CLASS_S;
                errstring_dsc.dsc$a_pointer = errstring;
 
+               *sym = NULL;
+
                status = sys$getmsg(status, &length, &errstring_dsc, 1, 0);
 
                if (!$VMS_STATUS_SUCCESS(status))
                status = sys$getmsg(status, &length, &errstring_dsc, 1, 0);
 
                if (!$VMS_STATUS_SUCCESS(status))
@@ -322,43 +349,31 @@ static void *vms_bind_sym(DSO *dso, const char *symname)
                                        " in ", ptr->filename,
                                        ": ", errstring);
                        }
                                        " in ", ptr->filename,
                                        ": ", errstring);
                        }
-               return(NULL);
+               return;
                }
                }
-       return(sym);
+       return;
        }
 
 static void *vms_bind_var(DSO *dso, const char *symname)
        {
        }
 
 static void *vms_bind_var(DSO *dso, const char *symname)
        {
-       return vms_bind_sym(dso, symname);
+       void *sym = 0;
+       vms_bind_sym(dso, symname, &sym);
+       return sym;
        }
 
 static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
        {
        }
 
 static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
        {
-       return (DSO_FUNC_TYPE)vms_bind_sym(dso, symname);
+       DSO_FUNC_TYPE sym = 0;
+       vms_bind_sym(dso, symname, (void **)&sym);
+       return sym;
+       }
+
+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);
        }
 
        }
 
-static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg)
-        {
-        if(dso == NULL)
-                {
-                DSOerr(DSO_F_VMS_CTRL,ERR_R_PASSED_NULL_PARAMETER);
-                return(-1);
-                }
-        switch(cmd)
-                {
-        case DSO_CTRL_GET_FLAGS:
-                return dso->flags;
-        case DSO_CTRL_SET_FLAGS:
-                dso->flags = (int)larg;
-                return(0);
-        case DSO_CTRL_OR_FLAGS:
-                dso->flags |= (int)larg;
-                return(0);
-        default:
-                break;
-                }
-        DSOerr(DSO_F_VMS_CTRL,DSO_R_UNKNOWN_COMMAND);
-        return(-1);
-        }
-
-#endif /* VMS */
+#endif /* OPENSSL_SYS_VMS */