- if(!ctx->DYNAMIC_LIBNAME || ((ctx->dynamic_dso = DSO_load(NULL,
- ctx->DYNAMIC_LIBNAME, NULL, 0)) == NULL))
- {
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
- ENGINE_R_DSO_NOT_FOUND);
- return 0;
- }
- /* We have to find a bind function otherwise it'll always end badly */
- if(!(ctx->bind_engine = (dynamic_bind_engine)DSO_bind_func(
- ctx->dynamic_dso, ctx->DYNAMIC_F2)))
- {
- ctx->bind_engine = NULL;
- DSO_free(ctx->dynamic_dso);
- ctx->dynamic_dso = NULL;
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
- ENGINE_R_DSO_FAILURE);
- return 0;
- }
- /* Do we perform version checking? */
- if(!ctx->no_vcheck)
- {
- unsigned long vcheck_res = 0;
- /* Now we try to find a version checking function and decide how
- * to cope with failure if/when it fails. */
- ctx->v_check = (dynamic_v_check_fn)DSO_bind_func(
- ctx->dynamic_dso, ctx->DYNAMIC_F1);
- if(ctx->v_check)
- vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION);
- /* We fail if the version checker veto'd the load *or* if it is
- * deferring to us (by returning its version) and we think it is
- * too old. */
- if(vcheck_res < OSSL_DYNAMIC_OLDEST)
- {
- /* Fail */
- ctx->bind_engine = NULL;
- ctx->v_check = NULL;
- DSO_free(ctx->dynamic_dso);
- ctx->dynamic_dso = NULL;
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
- ENGINE_R_VERSION_INCOMPATIBILITY);
- return 0;
- }
- }
- /* First binary copy the ENGINE structure so that we can roll back if
- * the hand-over fails */
- memcpy(&cpy, e, sizeof(ENGINE));
- /* Provide the ERR, "ex_data", memory, and locking callbacks so the
- * loaded library uses our state rather than its own. FIXME: As noted in
- * engine.h, much of this would be simplified if each area of code
- * provided its own "summary" structure of all related callbacks. It
- * would also increase opaqueness. */
- fns.err_fns = ERR_get_implementation();
- fns.ex_data_fns = CRYPTO_get_ex_data_implementation();
- CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb,
- &fns.mem_fns.realloc_cb,
- &fns.mem_fns.free_cb);
- fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback();
- fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback();
- fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback();
- fns.lock_fns.dynlock_lock_cb = CRYPTO_get_dynlock_lock_callback();
- fns.lock_fns.dynlock_destroy_cb = CRYPTO_get_dynlock_destroy_callback();
- /* Try to bind the ENGINE onto our own ENGINE structure */
- if(!ctx->bind_engine(e, ctx->engine_id, &fns))
- {
- ctx->bind_engine = NULL;
- ctx->v_check = NULL;
- DSO_free(ctx->dynamic_dso);
- ctx->dynamic_dso = NULL;
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD,ENGINE_R_INIT_FAILED);
- /* Copy the original ENGINE structure back */
- memcpy(e, &cpy, sizeof(ENGINE));
- return 0;
- }
- /* Do we try to add this ENGINE to the internal list too? */
- if(ctx->list_add_value > 0)
- {
- if(!ENGINE_add(e))
- {
- /* Do we tolerate this or fail? */
- if(ctx->list_add_value > 1)
- {
- /* Fail - NB: By this time, it's too late to
- * rollback, and trying to do so allows the
- * bind_engine() code to have created leaks. We
- * just have to fail where we are, after the
- * ENGINE has changed. */
- ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
- ENGINE_R_CONFLICTING_ENGINE_ID);
- return 0;
- }
- /* Tolerate */
- ERR_clear_error();
- }
- }
- return 1;
- }
+ /* Try to bind the ENGINE onto our own ENGINE structure */
+ if (!ctx->bind_engine(e, ctx->engine_id, &fns)) {
+ ctx->bind_engine = NULL;
+ ctx->v_check = NULL;
+ DSO_free(ctx->dynamic_dso);
+ ctx->dynamic_dso = NULL;
+ ENGINEerr(ENGINE_F_DYNAMIC_LOAD, ENGINE_R_INIT_FAILED);
+ /* Copy the original ENGINE structure back */
+ memcpy(e, &cpy, sizeof(ENGINE));
+ return 0;
+ }
+ /* Do we try to add this ENGINE to the internal list too? */
+ if (ctx->list_add_value > 0) {
+ if (!ENGINE_add(e)) {
+ /* Do we tolerate this or fail? */
+ if (ctx->list_add_value > 1) {
+ /*
+ * Fail - NB: By this time, it's too late to rollback, and
+ * trying to do so allows the bind_engine() code to have
+ * created leaks. We just have to fail where we are, after
+ * the ENGINE has changed.
+ */
+ ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
+ ENGINE_R_CONFLICTING_ENGINE_ID);
+ return 0;
+ }
+ /* Tolerate */
+ ERR_clear_error();
+ }
+ }
+ return 1;
+}