aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/plugin_loader.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2013-06-25 19:40:52 +0200
committerTobias Brunner <tobias@strongswan.org>2013-06-27 10:27:24 +0200
commitf2086e42ff9c1eaf643449da375e72dc75927ab6 (patch)
treef6c5635138d7a054bffe52951e92da9573f23faf /src/libstrongswan/plugins/plugin_loader.c
parent71c7b43541c946a728fcf34a73a82b0a6632b448 (diff)
downloadstrongswan-f2086e42ff9c1eaf643449da375e72dc75927ab6.tar.bz2
strongswan-f2086e42ff9c1eaf643449da375e72dc75927ab6.tar.xz
plugin-loader: Method added to provide additional search paths for plugins
Diffstat (limited to 'src/libstrongswan/plugins/plugin_loader.c')
-rw-r--r--src/libstrongswan/plugins/plugin_loader.c59
1 files changed, 49 insertions, 10 deletions
diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c
index e08b12306..025e97adb 100644
--- a/src/libstrongswan/plugins/plugin_loader.c
+++ b/src/libstrongswan/plugins/plugin_loader.c
@@ -17,6 +17,9 @@
#define _GNU_SOURCE
#include "plugin_loader.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <string.h>
#include <dlfcn.h>
#include <limits.h>
@@ -60,6 +63,11 @@ struct private_plugin_loader_t {
linked_list_t *loaded;
/**
+ * List of paths to search for plugins
+ */
+ linked_list_t *paths;
+
+ /**
* List of names of loaded plugins
*/
char *loaded_plugins;
@@ -909,17 +917,36 @@ METHOD(plugin_loader_t, add_static_features, void,
register_features(this, entry);
}
+/**
+ * Tries to find the plugin with the given name in the given path.
+ */
+static bool find_plugin(char *path, char *name, char *buf, char **file)
+{
+ struct stat stb;
+
+ if (path && snprintf(buf, PATH_MAX, "%s/libstrongswan-%s.so",
+ path, name) < PATH_MAX)
+ {
+ if (stat(buf, &stb) == 0)
+ {
+ *file = buf;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
METHOD(plugin_loader_t, load_plugins, bool,
- private_plugin_loader_t *this, char *path, char *list)
+ private_plugin_loader_t *this, char *default_path, char *list)
{
enumerator_t *enumerator;
char *token;
bool critical_failed = FALSE;
#ifdef PLUGINDIR
- if (path == NULL)
+ if (default_path == NULL)
{
- path = PLUGINDIR;
+ default_path = PLUGINDIR;
}
#endif /* PLUGINDIR */
@@ -943,14 +970,14 @@ METHOD(plugin_loader_t, load_plugins, bool,
free(token);
continue;
}
- if (path)
+ if (this->paths)
{
- if (snprintf(buf, sizeof(buf), "%s/libstrongswan-%s.so",
- path, token) >= sizeof(buf))
- {
- return FALSE;
- }
- file = buf;
+ this->paths->find_first(this->paths, (void*)find_plugin, NULL,
+ token, buf, &file);
+ }
+ if (!file)
+ {
+ find_plugin(default_path, token, buf, &file);
}
entry = load_plugin(this, token, file, critical);
if (entry)
@@ -1027,6 +1054,16 @@ METHOD(plugin_loader_t, unload, void,
memset(&this->stats, 0, sizeof(this->stats));
}
+METHOD(plugin_loader_t, add_path, void,
+ private_plugin_loader_t *this, char *path)
+{
+ if (!this->paths)
+ {
+ this->paths = linked_list_create();
+ }
+ this->paths->insert_last(this->paths, strdupnull(path));
+}
+
/**
* Reload a plugin by name, NULL for all
*/
@@ -1102,6 +1139,7 @@ METHOD(plugin_loader_t, destroy, void,
this->features->destroy(this->features);
this->loaded->destroy(this->loaded);
this->plugins->destroy(this->plugins);
+ DESTROY_FUNCTION_IF(this->paths, free);
free(this->loaded_plugins);
free(this);
}
@@ -1117,6 +1155,7 @@ plugin_loader_t *plugin_loader_create()
.public = {
.add_static_features = _add_static_features,
.load = _load_plugins,
+ .add_path = _add_path,
.reload = _reload,
.unload = _unload,
.create_plugin_enumerator = _create_plugin_enumerator,