diff options
Diffstat (limited to 'p11-kit')
-rw-r--r-- | p11-kit/proxy.c | 40 | ||||
-rw-r--r-- | p11-kit/proxy.h | 3 |
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__ */ |