Include OpenSSL header files earlier so macros like OPENSSL_SYS_VMS
[openssl.git] / crypto / dso / dso_vms.c
index bd284535f1a2c1fd943f948f56fa1094404e1e9c..703b19ed69aaaadbd9cf0e1b5d8d6073c42d207b 100644 (file)
@@ -59,7 +59,9 @@
 #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 <libfisdef.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,7 @@ 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 DSO_METHOD dso_meth_vms = {
        "OpenSSL 'VMS' shared library method",
@@ -133,10 +133,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_DLFCN_LOAD,DSO_R_NO_FILENAME);
+               goto err;
+               }
+
        /* A file specification may look like this:
         *
         *      node::dev:[dir-spec]name.type;ver
@@ -178,14 +186,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);
@@ -207,16 +215,19 @@ static int vms_load(DSO *dso)
        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);
-#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
@@ -353,26 +364,12 @@ static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
        return sym;
        }
 
-static char *vms_name_converter(DSO *dso)
+static char *vms_name_converter(DSO *dso, const char *filename)
        {
-       /* 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 len = strlen(filename);
+        char *not_translated = OPENSSL_malloc(len+1);
+        strcpy(not_translated,filename);
+       return(not_translated);
        }
 
-#endif /* VMS */
+#endif /* OPENSSL_SYS_VMS */