From: Richard Levitte Date: Mon, 25 Feb 2019 00:53:34 +0000 (+0100) Subject: Replumbing: Add an OSSL_PROVIDER iterator with callback X-Git-Tag: openssl-3.0.0-alpha1~2385 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=85e2417c0d81cfe97586b74c410ef37595aea72d;p=oweals%2Fopenssl.git Replumbing: Add an OSSL_PROVIDER iterator with callback Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/8340) --- diff --git a/crypto/provider_core.c b/crypto/provider_core.c index 05a6bfff49..e7cbee2e43 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -328,6 +328,30 @@ int ossl_provider_activate(OSSL_PROVIDER *prov) return 1; } +int ossl_provider_forall_loaded(OPENSSL_CTX *ctx, + int (*cb)(OSSL_PROVIDER *provider, + void *cbdata), + void *cbdata) +{ + int ret = 1; + int i; + struct provider_store_st *store = get_provider_store(ctx); + + if (store != NULL) { + CRYPTO_THREAD_read_lock(store->lock); + for (i = 0; i < sk_OSSL_PROVIDER_num(store->providers); i++) { + OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(store->providers, i); + + if (prov->flag_initialized + && !(ret = cb(prov, cbdata))) + break; + } + CRYPTO_THREAD_unlock(store->lock); + } + + return ret; +} + /* Getters of Provider Object data */ const char *ossl_provider_name(OSSL_PROVIDER *prov) { diff --git a/doc/internal/man3/ossl_provider_new.pod b/doc/internal/man3/ossl_provider_new.pod index 79964d6548..c21012bf19 100644 --- a/doc/internal/man3/ossl_provider_new.pod +++ b/doc/internal/man3/ossl_provider_new.pod @@ -4,7 +4,8 @@ ossl_provider_find, ossl_provider_new, ossl_provider_upref, ossl_provider_free, ossl_provider_add_module_location, -ossl_provider_activate, ossl_provider_name, ossl_provider_dso, +ossl_provider_activate, ossl_provider_forall_loaded, +ossl_provider_name, ossl_provider_dso, ossl_provider_module_name, ossl_provider_module_path, ossl_provider_teardown, ossl_provider_get_param_types, ossl_provider_get_params - internal provider routines @@ -25,6 +26,12 @@ ossl_provider_get_params - internal provider routines /* Load and initialize the Provider */ int ossl_provider_activate(OSSL_PROVIDER *prov); + /* Iterate over all loaded providers */ + int ossl_provider_forall_loaded(OPENSSL_CTX *, + int (*cb)(OSSL_PROVIDER *provider, + void *cbdata), + void *cbdata); + /* Getters for other library functions */ const char *ossl_provider_name(OSSL_PROVIDER *prov); const DSO *ossl_provider_dso(OSSL_PROVIDER *prov); @@ -102,6 +109,9 @@ be located in that module, and called. =back +ossl_provider_forall_loaded() iterates over all the currently +"activated" providers, and calls C for each of them. + ossl_provider_name() returns the name that was given with ossl_provider_new(). diff --git a/include/internal/provider.h b/include/internal/provider.h index 44d1d70461..dee5ee6b9f 100644 --- a/include/internal/provider.h +++ b/include/internal/provider.h @@ -42,6 +42,12 @@ int ossl_provider_add_module_location(OSSL_PROVIDER *prov, const char *loc); */ int ossl_provider_activate(OSSL_PROVIDER *prov); +/* Iterate over all loaded providers */ +int ossl_provider_forall_loaded(OPENSSL_CTX *, + int (*cb)(OSSL_PROVIDER *provider, + void *cbdata), + void *cbdata); + /* Getters for other library functions */ const char *ossl_provider_name(OSSL_PROVIDER *prov); const DSO *ossl_provider_dso(OSSL_PROVIDER *prov);