diff options
author | Tobias Brunner <tobias@strongswan.org> | 2010-02-23 16:20:38 +0100 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2010-03-02 09:10:26 +0100 |
commit | 9ce567f89591a3856d29db00d83eb5ce6d9f6f9e (patch) | |
tree | 6ef47b9f7599f7dacc1b3868d3e8b02ceee37798 /src/libstrongswan/plugins/plugin_loader.c | |
parent | 6cc13cd9c57bc7016f6d352bf6fbbe42d23b5513 (diff) | |
download | strongswan-9ce567f89591a3856d29db00d83eb5ce6d9f6f9e.tar.bz2 strongswan-9ce567f89591a3856d29db00d83eb5ce6d9f6f9e.tar.xz |
Changed plugin constructors from plugin_create to plugin_name_plugin_create.
Diffstat (limited to 'src/libstrongswan/plugins/plugin_loader.c')
-rw-r--r-- | src/libstrongswan/plugins/plugin_loader.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c index d4513f25a..fb970b4d7 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 * @@ -50,18 +51,42 @@ struct private_plugin_loader_t { }; /** + * Replace '-' with '_' to use str as identifier. + */ +static char* sanitize(char *str) +{ + char *pos = str; + while (pos && *pos) + { + if (*pos == '-') + { + *pos = '_'; + } + pos++; + } + return str; +} + +/** * 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; + } + sanitize(create); if (lib->integrity) { if (!lib->integrity->check_file(lib->integrity, name, file)) @@ -76,10 +101,10 @@ static plugin_t* load_plugin(private_plugin_loader_t *this, DBG1("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("plugin '%s': failed to load - %s not found", name, create); dlclose(handle); return NULL; } @@ -96,7 +121,7 @@ static plugin_t* load_plugin(private_plugin_loader_t *this, plugin = constructor(); if (plugin == NULL) { - DBG1("plugin '%s': failed to load - plugin_create() returned NULL", name); + DBG1("plugin '%s': failed to load - %s returned NULL", name, create); dlclose(handle); return NULL; } |