]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
credential_factory: Store name of plugin registering a builder
authorAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 30 May 2021 04:32:50 +0000 (06:32 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 1 Jun 2021 19:12:46 +0000 (21:12 +0200)
src/libstrongswan/credentials/credential_factory.c
src/libstrongswan/credentials/credential_factory.h
src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c
src/libstrongswan/plugins/plugin_feature.c

index fd3ecb8faba644d976f722268f898b320089ff31..c15e5712223098a2fa68c4faabd85050f84f32a2 100644 (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);
        }
index a03dd1abc28798feff4d93284b19e72183ec0094..c10f8fc7a85d3ed78ebba3dc8c0a0a0ea274917b 100644 (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.
         *
index d6bf4de4226609edb77671ac76598f9c95679c12..a181bb3cbad25c698685ce8d86fefab0fbb4d08f 100644 (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
        {
index fa3d1f31b68cabb23683638ab533b7c1954e31e6..4b3f0ebb3ef7901bd0a2b707ece1493988268855 100644 (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);