diff options
-rw-r--r-- | src/libstrongswan/plugins/plugin_loader.c | 21 | ||||
-rw-r--r-- | src/libstrongswan/utils.c | 22 | ||||
-rw-r--r-- | src/libstrongswan/utils.h | 8 |
3 files changed, 32 insertions, 19 deletions
diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c index 5dfeb873f..abcb84440 100644 --- a/src/libstrongswan/plugins/plugin_loader.c +++ b/src/libstrongswan/plugins/plugin_loader.c @@ -50,23 +50,6 @@ struct private_plugin_loader_t { linked_list_t *names; }; -/** - * Replace '-' with '_' to use str as identifier. - */ -static char* sanitize(char *str) -{ - char *pos = str; - while (pos && *pos) - { - if (*pos == '-') - { - *pos = '_'; - } - pos++; - } - return str; -} - #ifdef MONOLITHIC /** * load a single plugin in monolithic mode @@ -83,7 +66,7 @@ static plugin_t* load_plugin(private_plugin_loader_t *this, { return NULL; } - sanitize(create); + translate(create, "-", "_"); constructor = dlsym(RTLD_DEFAULT, create); if (constructor == NULL) { @@ -120,7 +103,7 @@ static plugin_t* load_plugin(private_plugin_loader_t *this, { return NULL; } - sanitize(create); + translate(create, "-", "_"); if (lib->integrity) { if (!lib->integrity->check_file(lib->integrity, name, file)) diff --git a/src/libstrongswan/utils.c b/src/libstrongswan/utils.c index b1b860351..fd313843e 100644 --- a/src/libstrongswan/utils.c +++ b/src/libstrongswan/utils.c @@ -119,6 +119,28 @@ void *memstr(const void *haystack, const char *needle, size_t n) /** * Described in header. */ +char* translate(char *str, const char *from, const char *to) +{ + char *pos = str; + if (strlen(from) != strlen(to)) + { + return str; + } + while (pos && *pos) + { + char *match; + if ((match = strchr(from, *pos)) != NULL) + { + *pos = to[match - from]; + } + pos++; + } + return str; +} + +/** + * Described in header. + */ bool mkdir_p(const char *path, mode_t mode) { int len; diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h index d3500258f..607d077f7 100644 --- a/src/libstrongswan/utils.h +++ b/src/libstrongswan/utils.h @@ -311,6 +311,14 @@ void memxor(u_int8_t dest[], u_int8_t src[], size_t n); void *memstr(const void *haystack, const char *needle, size_t n); /** + * Translates the characters in the given string, searching for characters + * in 'from' and mapping them to characters in 'to'. + * The two characters sets 'from' and 'to' must contain the same number of + * characters. + */ +char *translate(char *str, const char *from, const char *to); + +/** * Creates a directory and all required parent directories. * * @param path path to the new directory |