From: Tobias Brunner Date: Thu, 5 May 2022 08:21:10 +0000 (+0200) Subject: plugin-loader: Print an error message if plugin constructor is not found X-Git-Tag: 5.9.7dr1~10 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=af9c78d393882f8732f5ba558029d28e4882f0b0;p=thirdparty%2Fstrongswan.git plugin-loader: Print an error message if plugin constructor is not found --- diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c index 538de2abec..7834c6797c 100644 --- a/src/libstrongswan/plugins/plugin_loader.c +++ b/src/libstrongswan/plugins/plugin_loader.c @@ -357,19 +357,12 @@ void plugin_constructor_register(char *name, void *constructor) * FAILED, if the plugin could not be constructed */ static status_t create_plugin(private_plugin_loader_t *this, void *handle, - char *name, bool integrity, bool critical, - plugin_entry_t **entry) + char *name, char *create, bool integrity, + bool critical, plugin_entry_t **entry) { - char create[128]; plugin_t *plugin; plugin_constructor_t constructor = NULL; - if (snprintf(create, sizeof(create), "%s_plugin_create", - name) >= sizeof(create)) - { - return FAILED; - } - translate(create, "-", "_"); #ifdef STATIC_PLUGIN_CONSTRUCTORS if (plugin_constructors) { @@ -416,11 +409,19 @@ static status_t create_plugin(private_plugin_loader_t *this, void *handle, static plugin_entry_t *load_plugin(private_plugin_loader_t *this, char *name, char *file, bool critical) { + char create[128]; plugin_entry_t *entry; void *handle; int flag = RTLD_LAZY; - switch (create_plugin(this, RTLD_DEFAULT, name, FALSE, critical, &entry)) + if (snprintf(create, sizeof(create), "%s_plugin_create", + name) >= sizeof(create)) + { + return NULL; + } + translate(create, "-", "_"); + switch (create_plugin(this, RTLD_DEFAULT, name, create, FALSE, critical, + &entry)) { case SUCCESS: this->plugins->insert_last(this->plugins, entry); @@ -430,6 +431,8 @@ static plugin_entry_t *load_plugin(private_plugin_loader_t *this, char *name, { /* try to load the plugin from a file */ break; } + DBG1(DBG_LIB, "plugin '%s': failed to load - %s not found and no " + "plugin file available", name, create); /* fall-through */ default: return NULL; @@ -461,10 +464,17 @@ static plugin_entry_t *load_plugin(private_plugin_loader_t *this, char *name, DBG1(DBG_LIB, "plugin '%s' failed to load: %s", name, dlerror()); return NULL; } - if (create_plugin(this, handle, name, TRUE, critical, &entry) != SUCCESS) + switch (create_plugin(this, handle, name, create, TRUE, critical, &entry)) { - dlclose(handle); - return NULL; + case SUCCESS: + break; + case NOT_FOUND: + DBG1(DBG_LIB, "plugin '%s': failed to load - %s not found", name, + create); + /* fall-through */ + default: + dlclose(handle); + return NULL; } entry->handle = handle; this->plugins->insert_last(this->plugins, entry);