credential_factory: Store name of plugin registering a builder

This commit is contained in:
Andreas Steffen 2021-05-30 06:32:50 +02:00
parent 62c5ef035c
commit e0044e5f48
4 changed files with 31 additions and 24 deletions

View File

@ -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);
}

View File

@ -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.
*

View File

@ -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
{

View File

@ -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);