This change facilitates name translation for shared libraries. The
[openssl.git] / crypto / dso / dso_win32.c
index f04cb58a52761b34a54d07deb7a52f1c10f0c885..edf5d75b0f6a7e78c9087ae457ededc9d605a03a 100644 (file)
@@ -67,14 +67,18 @@ DSO_METHOD *DSO_METHOD_win32(void)
        }
 #else
 
-static int win32_load(DSO *dso, char *filename);
+/* Part of the hack in "win32_load" ... */
+#define DSO_MAX_TRANSLATED_SIZE 256
+
+static int win32_load(DSO *dso, const char *filename);
 static int win32_unload(DSO *dso);
-static int win32_bind(DSO *dso, char *symname, void **symptr);
+static int win32_bind(DSO *dso, const char *symname, void **symptr);
 #if 0
 static int win32_unbind(DSO *dso, char *symname, void *symptr);
 static int win32_init(DSO *dso);
 static int win32_finish(DSO *dso);
 #endif
+static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg);
 
 static DSO_METHOD dso_meth_win32 = {
        "OpenSSL 'win32' shared library method",
@@ -85,6 +89,7 @@ static DSO_METHOD dso_meth_win32 = {
 #if 0
        NULL, /* unbind */
 #endif
+       win32_ctrl,
        NULL, /* init */
        NULL  /* finish */
        };
@@ -96,14 +101,32 @@ DSO_METHOD *DSO_METHOD_win32(void)
 
 /* For this DSO_METHOD, our meth_data STACK will contain;
  * (i) a pointer to the handle (HINSTANCE) returned from
- *      LoadLibrary(), and copied.
+ *     LoadLibrary(), and copied.
  */
 
-static int win32_load(DSO *dso, char *filename)
+static int win32_load(DSO *dso, const char *filename)
        {
        HINSTANCE h, *p;
+       char translated[DSO_MAX_TRANSLATED_SIZE];
+       int len;
 
-       h = LoadLibrary(filename);
+       /* NB: This is a hideous hack, but I'm not yet sure what
+        * to replace it with. This attempts to convert any filename,
+        * that looks like it has no path information, into a
+        * translated form, e. "blah" -> "blah.dll" ... I'm more
+        * comfortable putting hacks into win32 code though ;-) */
+       len = strlen(filename);
+       if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
+                       (len + 4 < DSO_MAX_TRANSLATED_SIZE) &&
+                       (strstr(filename, "/") == NULL)
+                       (strstr(filename, "\\") == NULL)
+                       (strstr(filename, ":") == NULL))
+               {
+               sprintf(translated, "%s.dll", filename);
+               h = LoadLibrary(translated);
+               }
+       else
+               h = LoadLibrary(filename);
        if(h == NULL)
                {
                DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED);
@@ -159,7 +182,7 @@ static int win32_unload(DSO *dso)
        return(1);
        }
 
-static int win32_bind(DSO *dso, char *symname, void **symptr)
+static int win32_bind(DSO *dso, const char *symname, void **symptr)
        {
        HINSTANCE *ptr;
        void *sym;
@@ -190,4 +213,28 @@ static int win32_bind(DSO *dso, char *symname, void **symptr)
        return(1);
        }
 
+static int win32_ctrl(DSO *dso, int cmd, long larg, void *parg)
+        {
+        if(dso == NULL)
+                {
+                DSOerr(DSO_F_WIN32_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_WIN32_CTRL,DSO_R_UNKNOWN_COMMAND);
+        return(-1);
+        }
+
 #endif /* WIN32 */