summaryrefslogtreecommitdiff
path: root/p11-kit
diff options
context:
space:
mode:
authorKalev Lember <kalevlember@gmail.com>2011-09-14 08:10:46 +0300
committerStef Walter <stefw@collabora.co.uk>2011-09-14 16:05:24 +0200
commit927d2e5927ddad1eafe94c0bcadd76cd73d6297a (patch)
tree597b41e8403f593273cca2f03256cfdc879343da /p11-kit
parent138c1efa9af4893536fb7c3a90d3cb1ac24cea89 (diff)
When a module has a relative path, load it from $libdir/pkcs11
So far we have only supported full paths to the pkcs11 modules in config files. This change adds relative path support, so that for modules installed under the standard $libdir/pkcs11, the config file won't have to spell out the full path.
Diffstat (limited to 'p11-kit')
-rw-r--r--p11-kit/modules.c61
-rw-r--r--p11-kit/p11-kit-1.pc.in1
2 files changed, 59 insertions, 3 deletions
diff --git a/p11-kit/modules.c b/p11-kit/modules.c
index 1e2095b..3f1eae1 100644
--- a/p11-kit/modules.c
+++ b/p11-kit/modules.c
@@ -244,6 +244,35 @@ alloc_module_unlocked (void)
return mod;
}
+static int
+is_relative_path (const char *path)
+{
+ assert (path);
+
+ return (*path != '/');
+}
+
+static char*
+build_path (const char *dir, const char *filename)
+{
+ char *path;
+ int len;
+
+ assert (dir);
+ assert (filename);
+
+ len = snprintf (NULL, 0, "%s/%s", dir, filename) + 1;
+ if (len <= 0 || len > PATH_MAX)
+ return NULL;
+
+ if (!(path = malloc (len)))
+ return NULL;
+
+ sprintf (path, "%s/%s", dir, filename);
+
+ return path;
+}
+
static CK_RV
dlopen_and_get_function_list (Module *mod, const char *path)
{
@@ -312,11 +341,27 @@ load_module_from_file_unlocked (const char *path, Module **result)
return CKR_OK;
}
+static char*
+expand_module_path (const char *filename)
+{
+ char *path;
+
+ if (is_relative_path (filename)) {
+ debug ("module path is relative, loading from: %s", P11_MODULE_PATH);
+ path = build_path (P11_MODULE_PATH, filename);
+ } else {
+ path = strdup (filename);
+ }
+
+ return path;
+}
+
static CK_RV
take_config_and_load_module_unlocked (char **name, hashmap **config)
{
Module *mod, *prev;
- const char *path;
+ const char *module_filename;
+ char *path;
CK_RV rv;
assert (name);
@@ -324,12 +369,22 @@ take_config_and_load_module_unlocked (char **name, hashmap **config)
assert (config);
assert (*config);
- path = hash_get (*config, "module");
- if (path == NULL) {
+ module_filename = hash_get (*config, "module");
+ if (module_filename == NULL) {
debug ("no module path for module, skipping: %s", *name);
return CKR_OK;
}
+ path = expand_module_path (module_filename);
+ if (!path)
+ return CKR_HOST_MEMORY;
+
+ /* The hash map will take ownership of the variable */
+ if (!hash_set (*config, "module", path)) {
+ free (path);
+ return CKR_HOST_MEMORY;
+ }
+
mod = alloc_module_unlocked ();
if (!mod)
return CKR_HOST_MEMORY;
diff --git a/p11-kit/p11-kit-1.pc.in b/p11-kit/p11-kit-1.pc.in
index 0f596fa..7180497 100644
--- a/p11-kit/p11-kit-1.pc.in
+++ b/p11-kit/p11-kit-1.pc.in
@@ -11,6 +11,7 @@ p11_system_config_modules=@p11_system_config_modules@
p11_user_config=@p11_user_config@
p11_user_config_file=@p11_user_config_file@
p11_user_config_modules=@p11_user_config_modules@
+p11_module_path=@p11_module_path@
proxy_module=@libdir@/p11-kit-proxy.so
Name: p11-kit