Step 11c of move of engines: Time to make the changes to support
authorRichard Levitte <levitte@openssl.org>
Fri, 11 Oct 2002 18:49:55 +0000 (18:49 +0000)
committerRichard Levitte <levitte@openssl.org>
Fri, 11 Oct 2002 18:49:55 +0000 (18:49 +0000)
automatic load of dynamic engines.  Change the iterator to try to load
the requested engine dynamically.  The environment variable
OPENSSL_ENGINES can be used to override the internal default directory
where one can expect to find dynamically loadable engines.

Note: The changes in step 11 have all been made by Geoff Thorpe.
Credit where credit is due.

crypto/engine/eng_list.c

index 50188567814d274ccbd3a9e98b392ded9e3bc8ee..b41e6ba0f79032f457b87ea78d63ca5ea527672e 100644 (file)
@@ -351,6 +351,7 @@ static void engine_cpy(ENGINE *dest, const ENGINE *src)
 ENGINE *ENGINE_by_id(const char *id)
        {
        ENGINE *iterator;
+       char *load_dir = NULL;
        if(id == NULL)
                {
                ENGINEerr(ENGINE_F_ENGINE_BY_ID,
@@ -384,6 +385,7 @@ ENGINE *ENGINE_by_id(const char *id)
                        }
                }
        CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
+#if 0
        if(iterator == NULL)
                {
                ENGINEerr(ENGINE_F_ENGINE_BY_ID,
@@ -391,4 +393,26 @@ ENGINE *ENGINE_by_id(const char *id)
                ERR_add_error_data(2, "id=", id);
                }
        return iterator;
+#else
+       /* EEK! Experimental code starts */
+       if(iterator) return iterator;
+#ifdef OPENSSL_SYS_VMS
+       if((load_dir = getenv("OPENSSL_ENGINES")) == 0) load_dir = "SSLROOT:[ENGINES]";
+#else
+       if((load_dir = getenv("OPENSSL_ENGINES")) == 0) load_dir = OPENSSLDIR "/engines";
+#endif
+       iterator = ENGINE_by_id("dynamic");
+       if(!iterator || !ENGINE_ctrl_cmd_string(iterator, "ID", id, 0) ||
+                       !ENGINE_ctrl_cmd_string(iterator, "DIR_LOAD", "2", 0) ||
+                       !ENGINE_ctrl_cmd_string(iterator, "DIR_ADD",
+                               load_dir, 0) ||
+                       !ENGINE_ctrl_cmd_string(iterator, "LOAD", NULL, 0))
+               goto notfound;
+       return iterator;
+notfound:
+       ENGINEerr(ENGINE_F_ENGINE_BY_ID,ENGINE_R_NO_SUCH_ENGINE);
+       ERR_add_error_data(2, "id=", id);
+       return NULL;
+       /* EEK! Experimental code ends */
+#endif
        }