credential_factory: Store name of plugin registering a builder

This commit is contained in:
Andreas Steffen
2021-06-01 21:12:46 +02:00
parent 62c5ef035c
commit e0044e5f48
4 changed files with 31 additions and 24 deletions
@@ -67,19 +67,22 @@ struct entry_t {
int subtype; int subtype;
/** registered with final flag? */ /** registered with final flag? */
bool final; bool final;
/** plugin that registered this algorithm */
const char *plugin_name;
/** builder function */ /** builder function */
builder_function_t constructor; builder_function_t constructor;
}; };
METHOD(credential_factory_t, add_builder, void, METHOD(credential_factory_t, add_builder, void,
private_credential_factory_t *this, credential_type_t type, int subtype, 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_t *entry = malloc_thing(entry_t);
entry->type = type; entry->type = type;
entry->subtype = subtype; entry->subtype = subtype;
entry->final = final; entry->final = final;
entry->plugin_name = plugin_name;
entry->constructor = constructor; entry->constructor = constructor;
this->lock->write_lock(this->lock); this->lock->write_lock(this->lock);
this->constructors->insert_last(this->constructors, entry); this->constructors->insert_last(this->constructors, entry);
@@ -115,6 +118,22 @@ METHOD(credential_factory_t, create, void*,
void *construct = NULL; void *construct = NULL;
int failures = 0; int failures = 0;
uintptr_t level; 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); level = (uintptr_t)this->recursive->get(this->recursive);
this->recursive->set(this->recursive, (void*)level + 1); 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) 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); va_start(args, subtype);
construct = entry->constructor(subtype, args); construct = entry->constructor(subtype, args);
va_end(args); va_end(args);
@@ -140,22 +162,6 @@ METHOD(credential_factory_t, create, void*,
if (!construct && !level) 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", DBG1(DBG_LIB, "building %N - %N failed, tried %d builders",
credential_type_names, type, names, subtype, failures); credential_type_names, type, names, subtype, failures);
} }
@@ -80,11 +80,12 @@ struct credential_factory_t {
* @param type type of credential the builder creates * @param type type of credential the builder creates
* @param subtype subtype of the credential, type specific * @param subtype subtype of the credential, type specific
* @param final TRUE if this build does not invoke other builders * @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 * @param constructor builder constructor function to register
*/ */
void (*add_builder)(credential_factory_t *this, void (*add_builder)(credential_factory_t *this,
credential_type_t type, int subtype, bool final, 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. * Unregister a credential builder function.
* *
@@ -153,8 +153,8 @@ static bool handle_certs(private_pkcs11_plugin_t *this,
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509, FALSE,
CERT_X509, FALSE, (void*)pkcs11_creds_load); get_name(this), (void*)pkcs11_creds_load);
} }
else else
{ {
+4 -4
View File
@@ -518,24 +518,24 @@ bool plugin_feature_load(plugin_t *plugin, plugin_feature_t *feature,
case FEATURE_PRIVKEY_GEN: case FEATURE_PRIVKEY_GEN:
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY,
feature->arg.privkey, reg->arg.reg.final, feature->arg.privkey, reg->arg.reg.final,
reg->arg.reg.f); name, reg->arg.reg.f);
break; break;
case FEATURE_PUBKEY: case FEATURE_PUBKEY:
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY,
feature->arg.pubkey, reg->arg.reg.final, feature->arg.pubkey, reg->arg.reg.final,
reg->arg.reg.f); name, reg->arg.reg.f);
break; break;
case FEATURE_CERT_DECODE: case FEATURE_CERT_DECODE:
case FEATURE_CERT_ENCODE: case FEATURE_CERT_ENCODE:
lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, lib->creds->add_builder(lib->creds, CRED_CERTIFICATE,
feature->arg.cert, reg->arg.reg.final, feature->arg.cert, reg->arg.reg.final,
reg->arg.reg.f); name, reg->arg.reg.f);
break; break;
case FEATURE_CONTAINER_DECODE: case FEATURE_CONTAINER_DECODE:
case FEATURE_CONTAINER_ENCODE: case FEATURE_CONTAINER_ENCODE:
lib->creds->add_builder(lib->creds, CRED_CONTAINER, lib->creds->add_builder(lib->creds, CRED_CONTAINER,
feature->arg.container, reg->arg.reg.final, feature->arg.container, reg->arg.reg.final,
reg->arg.reg.f); name, reg->arg.reg.f);
break; break;
case FEATURE_DATABASE: case FEATURE_DATABASE:
lib->db->add_database(lib->db, reg->arg.reg.f); lib->db->add_database(lib->db, reg->arg.reg.f);