summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/plugin_loader.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/plugins/plugin_loader.c')
-rw-r--r--src/libstrongswan/plugins/plugin_loader.c74
1 files changed, 63 insertions, 11 deletions
diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c
index d4513f25a..cad279a9d 100644
--- a/src/libstrongswan/plugins/plugin_loader.c
+++ b/src/libstrongswan/plugins/plugin_loader.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2010 Tobias Brunner
* Copyright (C) 2007 Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -49,37 +50,83 @@ struct private_plugin_loader_t {
linked_list_t *names;
};
+#ifdef MONOLITHIC
+/**
+ * load a single plugin in monolithic mode
+ */
+static plugin_t* load_plugin(private_plugin_loader_t *this,
+ char *path, char *name)
+{
+ char create[128];
+ plugin_t *plugin;
+ plugin_constructor_t constructor;
+
+ if (snprintf(create, sizeof(create), "%s_plugin_create",
+ name) >= sizeof(create))
+ {
+ return NULL;
+ }
+ translate(create, "-", "_");
+ constructor = dlsym(RTLD_DEFAULT, create);
+ if (constructor == NULL)
+ {
+ DBG1(DBG_LIB, "plugin '%s': failed to load - %s not found", name,
+ create);
+ return NULL;
+ }
+ plugin = constructor();
+ if (plugin == NULL)
+ {
+ DBG1(DBG_LIB, "plugin '%s': failed to load - %s returned NULL", name,
+ create);
+ return NULL;
+ }
+ DBG2(DBG_LIB, "plugin '%s': loaded successfully", name);
+
+ return plugin;
+}
+#else
/**
* load a single plugin
*/
static plugin_t* load_plugin(private_plugin_loader_t *this,
char *path, char *name)
{
+ char create[128];
char file[PATH_MAX];
void *handle;
plugin_t *plugin;
plugin_constructor_t constructor;
- snprintf(file, sizeof(file), "%s/libstrongswan-%s.so", path, name);
-
+ if (snprintf(file, sizeof(file), "%s/libstrongswan-%s.so", path,
+ name) >= sizeof(file) ||
+ snprintf(create, sizeof(create), "%s_plugin_create",
+ name) >= sizeof(create))
+ {
+ return NULL;
+ }
+ translate(create, "-", "_");
if (lib->integrity)
{
if (!lib->integrity->check_file(lib->integrity, name, file))
{
- DBG1("plugin '%s': failed file integrity test of '%s'", name, file);
+ DBG1(DBG_LIB, "plugin '%s': failed file integrity test of '%s'",
+ name, file);
return NULL;
}
}
handle = dlopen(file, RTLD_LAZY);
if (handle == NULL)
{
- DBG1("plugin '%s': failed to load '%s' - %s", name, file, dlerror());
+ DBG1(DBG_LIB, "plugin '%s': failed to load '%s' - %s", name, file,
+ dlerror());
return NULL;
}
- constructor = dlsym(handle, "plugin_create");
+ constructor = dlsym(handle, create);
if (constructor == NULL)
{
- DBG1("plugin '%s': failed to load - no plugin_create() function", name);
+ DBG1(DBG_LIB, "plugin '%s': failed to load - %s not found", name,
+ create);
dlclose(handle);
return NULL;
}
@@ -87,25 +134,28 @@ static plugin_t* load_plugin(private_plugin_loader_t *this,
{
if (!lib->integrity->check_segment(lib->integrity, name, constructor))
{
- DBG1("plugin '%s': failed segment integrity test", name);
+ DBG1(DBG_LIB, "plugin '%s': failed segment integrity test", name);
dlclose(handle);
return NULL;
}
- DBG1("plugin '%s': passed file and segment integrity tests", name);
+ DBG1(DBG_LIB, "plugin '%s': passed file and segment integrity tests",
+ name);
}
plugin = constructor();
if (plugin == NULL)
{
- DBG1("plugin '%s': failed to load - plugin_create() returned NULL", name);
+ DBG1(DBG_LIB, "plugin '%s': failed to load - %s returned NULL", name,
+ create);
dlclose(handle);
return NULL;
}
- DBG2("plugin '%s': loaded successfully", name);
+ DBG2(DBG_LIB, "plugin '%s': loaded successfully", name);
/* we do not store or free dlopen() handles, leak_detective requires
* the modules to keep loaded until leak report */
return plugin;
}
+#endif
/**
* Implementation of plugin_loader_t.load_plugins.
@@ -116,10 +166,12 @@ static bool load(private_plugin_loader_t *this, char *path, char *list)
char *token;
bool critical_failed = FALSE;
+#ifndef MONOLITHIC
if (path == NULL)
{
path = PLUGINDIR;
}
+#endif
enumerator = enumerator_create_token(list, " ", " ");
while (!critical_failed && enumerator->enumerate(enumerator, &token))
@@ -147,7 +199,7 @@ static bool load(private_plugin_loader_t *this, char *path, char *list)
if (critical)
{
critical_failed = TRUE;
- DBG1("loading critical plugin '%s' failed", token);
+ DBG1(DBG_LIB, "loading critical plugin '%s' failed", token);
}
free(token);
}