From: Andreas Steffen Date: Sun, 30 May 2021 04:32:50 +0000 (+0200) Subject: credential_factory: Store name of plugin registering a builder X-Git-Tag: 5.9.3dr3~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e0044e5f48ef87bbd4fdee5fadcee1152bb26117;p=thirdparty%2Fstrongswan.git credential_factory: Store name of plugin registering a builder --- diff --git a/src/libstrongswan/credentials/credential_factory.c b/src/libstrongswan/credentials/credential_factory.c index fd3ecb8fab..c15e571222 100644 --- a/src/libstrongswan/credentials/credential_factory.c +++ b/src/libstrongswan/credentials/credential_factory.c @@ -67,19 +67,22 @@ struct entry_t { int subtype; /** registered with final flag? */ bool final; + /** plugin that registered this algorithm */ + const char *plugin_name; /** builder function */ builder_function_t constructor; }; METHOD(credential_factory_t, add_builder, void, private_credential_factory_t *this, credential_type_t type, int subtype, - bool final, builder_function_t constructor) + bool final, const char *plugin_name, builder_function_t constructor) { entry_t *entry = malloc_thing(entry_t); entry->type = type; entry->subtype = subtype; entry->final = final; + entry->plugin_name = plugin_name; entry->constructor = constructor; this->lock->write_lock(this->lock); this->constructors->insert_last(this->constructors, entry); @@ -115,6 +118,22 @@ METHOD(credential_factory_t, create, void*, void *construct = NULL; int failures = 0; uintptr_t level; + enum_name_t *names; + + switch (type) + { + case CRED_CERTIFICATE: + names = certificate_type_names; + break; + case CRED_CONTAINER: + names = container_type_names; + break; + case CRED_PRIVATE_KEY: + case CRED_PUBLIC_KEY: + default: + names = key_type_names; + break; + } level = (uintptr_t)this->recursive->get(this->recursive); this->recursive->set(this->recursive, (void*)level + 1); @@ -125,6 +144,9 @@ METHOD(credential_factory_t, create, void*, { if (entry->type == type && entry->subtype == subtype) { + DBG2(DBG_LIB, "builder L%d %N - %N of plugin '%s'", + (int)level, credential_type_names, type, names, subtype, + entry->plugin_name); va_start(args, subtype); construct = entry->constructor(subtype, args); va_end(args); @@ -140,22 +162,6 @@ METHOD(credential_factory_t, create, void*, if (!construct && !level) { - enum_name_t *names; - - switch (type) - { - case CRED_CERTIFICATE: - names = certificate_type_names; - break; - case CRED_CONTAINER: - names = container_type_names; - break; - case CRED_PRIVATE_KEY: - case CRED_PUBLIC_KEY: - default: - names = key_type_names; - break; - } DBG1(DBG_LIB, "building %N - %N failed, tried %d builders", credential_type_names, type, names, subtype, failures); } diff --git a/src/libstrongswan/credentials/credential_factory.h b/src/libstrongswan/credentials/credential_factory.h index a03dd1abc2..c10f8fc7a8 100644 --- a/src/libstrongswan/credentials/credential_factory.h +++ b/src/libstrongswan/credentials/credential_factory.h @@ -80,11 +80,12 @@ struct credential_factory_t { * @param type type of credential the builder creates * @param subtype subtype of the credential, type specific * @param final TRUE if this build does not invoke other builders + * @param plugin_name plugin that registered this builder * @param constructor builder constructor function to register */ void (*add_builder)(credential_factory_t *this, credential_type_t type, int subtype, bool final, - builder_function_t constructor); + const char *plugin_name, builder_function_t constructor); /** * Unregister a credential builder function. * diff --git a/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c b/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c index d6bf4de422..a181bb3cba 100644 --- a/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c +++ b/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c @@ -153,8 +153,8 @@ static bool handle_certs(private_pkcs11_plugin_t *this, } enumerator->destroy(enumerator); - lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, - CERT_X509, FALSE, (void*)pkcs11_creds_load); + lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509, FALSE, + get_name(this), (void*)pkcs11_creds_load); } else { diff --git a/src/libstrongswan/plugins/plugin_feature.c b/src/libstrongswan/plugins/plugin_feature.c index fa3d1f31b6..4b3f0ebb3e 100644 --- a/src/libstrongswan/plugins/plugin_feature.c +++ b/src/libstrongswan/plugins/plugin_feature.c @@ -518,24 +518,24 @@ bool plugin_feature_load(plugin_t *plugin, plugin_feature_t *feature, case FEATURE_PRIVKEY_GEN: lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, feature->arg.privkey, reg->arg.reg.final, - reg->arg.reg.f); + name, reg->arg.reg.f); break; case FEATURE_PUBKEY: lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, feature->arg.pubkey, reg->arg.reg.final, - reg->arg.reg.f); + name, reg->arg.reg.f); break; case FEATURE_CERT_DECODE: case FEATURE_CERT_ENCODE: lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, feature->arg.cert, reg->arg.reg.final, - reg->arg.reg.f); + name, reg->arg.reg.f); break; case FEATURE_CONTAINER_DECODE: case FEATURE_CONTAINER_ENCODE: lib->creds->add_builder(lib->creds, CRED_CONTAINER, feature->arg.container, reg->arg.reg.final, - reg->arg.reg.f); + name, reg->arg.reg.f); break; case FEATURE_DATABASE: lib->db->add_database(lib->db, reg->arg.reg.f);