mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-08 00:02:03 -04:00
Merged the monolithic and non-monolithic plugin loaders into one.
This allows to add additional plugins even when the original build was monolithic. Also fixes the pluto/xauth bug with the monolithic build.
This commit is contained in:
parent
c38877b395
commit
6302f49754
@ -50,62 +50,77 @@ struct private_plugin_loader_t {
|
|||||||
linked_list_t *names;
|
linked_list_t *names;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MONOLITHIC
|
|
||||||
/**
|
/**
|
||||||
* load a single plugin in monolithic mode
|
* create a plugin
|
||||||
|
* returns: NOT_FOUND, if the constructor was not found
|
||||||
|
* FAILED, if the plugin could not be constructed
|
||||||
*/
|
*/
|
||||||
static plugin_t* load_plugin(private_plugin_loader_t *this,
|
static status_t create_plugin(private_plugin_loader_t *this, void *handle,
|
||||||
char *path, char *name)
|
char *name, bool integrity, plugin_t **plugin)
|
||||||
{
|
{
|
||||||
char create[128];
|
char create[128];
|
||||||
plugin_t *plugin;
|
|
||||||
plugin_constructor_t constructor;
|
plugin_constructor_t constructor;
|
||||||
|
|
||||||
if (snprintf(create, sizeof(create), "%s_plugin_create",
|
if (snprintf(create, sizeof(create), "%s_plugin_create",
|
||||||
name) >= sizeof(create))
|
name) >= sizeof(create))
|
||||||
{
|
{
|
||||||
return NULL;
|
return FAILED;
|
||||||
}
|
}
|
||||||
translate(create, "-", "_");
|
translate(create, "-", "_");
|
||||||
constructor = dlsym(RTLD_DEFAULT, create);
|
constructor = dlsym(handle, create);
|
||||||
if (constructor == NULL)
|
if (constructor == NULL)
|
||||||
{
|
{
|
||||||
DBG1(DBG_LIB, "plugin '%s': failed to load - %s not found", name,
|
DBG2(DBG_LIB, "plugin '%s': failed to load - %s not found", name,
|
||||||
create);
|
create);
|
||||||
return NULL;
|
return NOT_FOUND;
|
||||||
}
|
}
|
||||||
plugin = constructor();
|
if (integrity && lib->integrity)
|
||||||
if (plugin == NULL)
|
{
|
||||||
|
if (!lib->integrity->check_segment(lib->integrity, name, constructor))
|
||||||
|
{
|
||||||
|
DBG1(DBG_LIB, "plugin '%s': failed segment integrity test", name);
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
DBG1(DBG_LIB, "plugin '%s': passed file and segment integrity tests",
|
||||||
|
name);
|
||||||
|
}
|
||||||
|
*plugin = constructor();
|
||||||
|
if (*plugin == NULL)
|
||||||
{
|
{
|
||||||
DBG1(DBG_LIB, "plugin '%s': failed to load - %s returned NULL", name,
|
DBG1(DBG_LIB, "plugin '%s': failed to load - %s returned NULL", name,
|
||||||
create);
|
create);
|
||||||
return NULL;
|
return FAILED;
|
||||||
}
|
}
|
||||||
DBG2(DBG_LIB, "plugin '%s': loaded successfully", name);
|
DBG2(DBG_LIB, "plugin '%s': loaded successfully", name);
|
||||||
|
return SUCCESS;
|
||||||
return plugin;
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
/**
|
/**
|
||||||
* load a single plugin
|
* load a single plugin
|
||||||
*/
|
*/
|
||||||
static plugin_t* load_plugin(private_plugin_loader_t *this,
|
static plugin_t* load_plugin(private_plugin_loader_t *this,
|
||||||
char *path, char *name)
|
char *path, char *name)
|
||||||
{
|
{
|
||||||
char create[128];
|
|
||||||
char file[PATH_MAX];
|
char file[PATH_MAX];
|
||||||
void *handle;
|
void *handle;
|
||||||
plugin_t *plugin;
|
plugin_t *plugin;
|
||||||
plugin_constructor_t constructor;
|
|
||||||
|
switch (create_plugin(this, RTLD_DEFAULT, name, FALSE, &plugin))
|
||||||
|
{
|
||||||
|
case SUCCESS:
|
||||||
|
return plugin;
|
||||||
|
case NOT_FOUND:
|
||||||
|
/* try to load the plugin from a file */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (snprintf(file, sizeof(file), "%s/libstrongswan-%s.so", path,
|
if (snprintf(file, sizeof(file), "%s/libstrongswan-%s.so", path,
|
||||||
name) >= sizeof(file) ||
|
name) >= sizeof(file))
|
||||||
snprintf(create, sizeof(create), "%s_plugin_create",
|
|
||||||
name) >= sizeof(create))
|
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
translate(create, "-", "_");
|
|
||||||
if (lib->integrity)
|
if (lib->integrity)
|
||||||
{
|
{
|
||||||
if (!lib->integrity->check_file(lib->integrity, name, file))
|
if (!lib->integrity->check_file(lib->integrity, name, file))
|
||||||
@ -121,40 +136,15 @@ static plugin_t* load_plugin(private_plugin_loader_t *this,
|
|||||||
DBG1(DBG_LIB, "plugin '%s' failed to load: %s", name, dlerror());
|
DBG1(DBG_LIB, "plugin '%s' failed to load: %s", name, dlerror());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
constructor = dlsym(handle, create);
|
if (create_plugin(this, handle, name, TRUE, &plugin) != SUCCESS)
|
||||||
if (constructor == NULL)
|
|
||||||
{
|
{
|
||||||
DBG1(DBG_LIB, "plugin '%s': failed to load - %s not found", name,
|
|
||||||
create);
|
|
||||||
dlclose(handle);
|
dlclose(handle);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (lib->integrity)
|
|
||||||
{
|
|
||||||
if (!lib->integrity->check_segment(lib->integrity, name, constructor))
|
|
||||||
{
|
|
||||||
DBG1(DBG_LIB, "plugin '%s': failed segment integrity test", name);
|
|
||||||
dlclose(handle);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
DBG1(DBG_LIB, "plugin '%s': passed file and segment integrity tests",
|
|
||||||
name);
|
|
||||||
}
|
|
||||||
plugin = constructor();
|
|
||||||
if (plugin == NULL)
|
|
||||||
{
|
|
||||||
DBG1(DBG_LIB, "plugin '%s': failed to load - %s returned NULL", name,
|
|
||||||
create);
|
|
||||||
dlclose(handle);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
DBG2(DBG_LIB, "plugin '%s': loaded successfully", name);
|
|
||||||
|
|
||||||
/* we do not store or free dlopen() handles, leak_detective requires
|
/* we do not store or free dlopen() handles, leak_detective requires
|
||||||
* the modules to keep loaded until leak report */
|
* the modules to keep loaded until leak report */
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a plugin is already loaded
|
* Check if a plugin is already loaded
|
||||||
@ -187,12 +177,10 @@ static bool load(private_plugin_loader_t *this, char *path, char *list)
|
|||||||
char *token;
|
char *token;
|
||||||
bool critical_failed = FALSE;
|
bool critical_failed = FALSE;
|
||||||
|
|
||||||
#ifndef MONOLITHIC
|
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
{
|
{
|
||||||
path = PLUGINDIR;
|
path = PLUGINDIR;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
enumerator = enumerator_create_token(list, " ", " ");
|
enumerator = enumerator_create_token(list, " ", " ");
|
||||||
while (!critical_failed && enumerator->enumerate(enumerator, &token))
|
while (!critical_failed && enumerator->enumerate(enumerator, &token))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user