summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2018-06-25 17:17:41 +0200
committerDaiki Ueno <ueno@gnu.org>2018-07-16 16:19:42 +0200
commit8d8bff0a2edf4659b641dde1333eb6a7c695671c (patch)
tree5b93aa0460e3b6acefa4ff50f681243637e34e9a
parenta65696b3e79acb602bd0c000f8524d3cc8998187 (diff)
proxy: Allow proxy to be created from the library
Previously, to aggregate multiple modules into one, there was no other way than loading the proxy module. From the p11-kit applications, however, it is not possible to load that module because of the recursive loading check (p11_proxy_module_check). This patch adds another means to aggregate modules, through a library function p11_proxy_module_create.
-rw-r--r--p11-kit/proxy.c40
-rw-r--r--p11-kit/proxy.h3
2 files changed, 42 insertions, 1 deletions
diff --git a/p11-kit/proxy.c b/p11-kit/proxy.c
index 5cd49bc..916ee92 100644
--- a/p11-kit/proxy.c
+++ b/p11-kit/proxy.c
@@ -95,7 +95,7 @@ typedef struct _State {
} State;
static State *all_instances = NULL;
-static State global = { { { { -1, -1 }, NULL, }, }, NULL, NULL, FIRST_HANDLE, NULL };
+static State global = { { { { -1, -1 }, NULL, }, }, NULL, NULL, NULL, FIRST_HANDLE, NULL };
#define PROXY_VALID(px) ((px) && (px)->forkid == p11_forkid)
#define PROXY_FORKED(px) ((px) && (px)->forkid != p11_forkid)
@@ -1728,3 +1728,41 @@ p11_proxy_module_check (CK_FUNCTION_LIST_PTR module)
{
return (module->C_WaitForSlotEvent == module_C_WaitForSlotEvent);
}
+
+static void
+proxy_module_free (p11_virtual *virt)
+{
+ State *state = (State *)virt;
+
+ p11_virtual_unwrap (state->wrapped);
+ p11_kit_modules_release (state->loaded);
+ free (state);
+}
+
+CK_RV
+p11_proxy_module_create (CK_FUNCTION_LIST_PTR *module,
+ CK_FUNCTION_LIST_PTR *modules)
+{
+ State *state;
+ CK_RV rv = CKR_OK;
+
+ assert (module != NULL);
+ assert (modules != NULL);
+
+ state = calloc (1, sizeof (State));
+ if (!state)
+ return CKR_HOST_MEMORY;
+
+ p11_virtual_init (&state->virt, &proxy_functions, state, NULL);
+ state->last_handle = FIRST_HANDLE;
+ state->loaded = modules_dup (modules);
+ state->wrapped = p11_virtual_wrap (&state->virt, (p11_destroyer)proxy_module_free);
+ if (state->wrapped == NULL) {
+ proxy_module_free (&state->virt);
+ return CKR_GENERAL_ERROR;
+ }
+
+ *module = state->wrapped;
+
+ return rv;
+}
diff --git a/p11-kit/proxy.h b/p11-kit/proxy.h
index f3d56d7..81926bd 100644
--- a/p11-kit/proxy.h
+++ b/p11-kit/proxy.h
@@ -39,5 +39,8 @@ bool p11_proxy_module_check (CK_FUNCTION_LIST_PTR modul
void p11_proxy_module_cleanup (void);
+CK_RV p11_proxy_module_create (CK_FUNCTION_LIST_PTR *module,
+ CK_FUNCTION_LIST_PTR *modules);
+
#endif /* __P11_PROXY_H__ */