summaryrefslogtreecommitdiff
path: root/p11-kit
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2017-09-26 16:37:34 +0200
committerDaiki Ueno <ueno@gnu.org>2017-09-27 11:55:02 +0200
commitdcd932786c970fc50922ec4f19786b177481570a (patch)
treeb7a5800ad57c4726632d338eda2e32543321e8d6 /p11-kit
parent26312a8774b5d113f6e7f904f7b6654449ab7b2e (diff)
server: Make it work only when token URI is provided
Previously, when "p11-kit server" started only with a token URI, it couldn't properly find and initialize the module which provides the token. This was because of the wrong order of cleanup of the modules.
Diffstat (limited to 'p11-kit')
-rw-r--r--p11-kit/rpc-server.c88
1 files changed, 41 insertions, 47 deletions
diff --git a/p11-kit/rpc-server.c b/p11-kit/rpc-server.c
index fcf837b..6f504dc 100644
--- a/p11-kit/rpc-server.c
+++ b/p11-kit/rpc-server.c
@@ -2085,49 +2085,6 @@ p11_kit_remote_serve_token (CK_FUNCTION_LIST *module,
return ret;
}
-/* Find a module providing a token */
-static CK_FUNCTION_LIST *
-find_module (const char *token)
-{
- CK_FUNCTION_LIST **modules = NULL, *module = NULL;
- P11KitUri *uri = NULL;
- P11KitIter *iter = NULL;
- CK_RV rv;
-
- modules = p11_kit_modules_load_and_initialize (0);
- if (modules == NULL)
- goto out;
-
- uri = p11_kit_uri_new ();
- if (uri == NULL)
- goto out;
-
- if (p11_kit_uri_parse (token, P11_KIT_URI_FOR_TOKEN, uri) !=
- P11_KIT_URI_OK)
- goto out;
-
- iter = p11_kit_iter_new (uri,
- P11_KIT_ITER_WITH_TOKENS |
- P11_KIT_ITER_WITHOUT_OBJECTS);
- p11_kit_uri_free (uri);
- uri = NULL;
- if (iter == NULL)
- goto out;
-
- p11_kit_iter_begin (iter, modules);
- rv = p11_kit_iter_next (iter);
- if (rv != CKR_OK)
- goto out;
-
- module = p11_kit_iter_get_module (iter);
-
- out:
- p11_kit_iter_free (iter);
- p11_kit_modules_release (modules);
-
- return module;
-}
-
/**
* p11_kit_remote_serve_tokens:
* @tokens: a list of token URIs
@@ -2150,7 +2107,9 @@ p11_kit_remote_serve_tokens (const char **tokens,
{
p11_virtual virt;
p11_virtual *filter = NULL;
- CK_FUNCTION_LIST *filtered = NULL;
+ CK_FUNCTION_LIST **modules = NULL, *filtered = NULL;
+ P11KitIter *iter;
+ P11KitUri *uri;
int ret = 1;
size_t i;
@@ -2159,8 +2118,42 @@ p11_kit_remote_serve_tokens (const char **tokens,
return_val_if_fail (in_fd >= 0, 2);
return_val_if_fail (out_fd >= 0, 2);
- if (!module)
- module = find_module (tokens[0]);
+ if (!module) {
+ modules = p11_kit_modules_load_and_initialize (0);
+ if (modules == NULL)
+ goto out;
+
+ /* Find a module that provides the first token */
+ uri = p11_kit_uri_new ();
+ if (uri == NULL)
+ goto out;
+
+ if (p11_kit_uri_parse (tokens[0], P11_KIT_URI_FOR_TOKEN, uri) !=
+ P11_KIT_URI_OK)
+ goto out;
+
+ iter = p11_kit_iter_new (uri,
+ P11_KIT_ITER_WITH_TOKENS |
+ P11_KIT_ITER_WITHOUT_OBJECTS);
+ p11_kit_uri_free (uri);
+ if (iter == NULL)
+ goto out;
+
+ p11_kit_iter_begin (iter, modules);
+ if (p11_kit_iter_next (iter) != CKR_OK) {
+ p11_kit_iter_free (iter);
+ goto out;
+ }
+
+ module = p11_kit_iter_get_module (iter);
+ assert (module != NULL);
+
+ p11_kit_iter_free (iter);
+
+ /* Call C_Finalize on modules as C_Initialize on the
+ * found module will be called later */
+ p11_kit_modules_finalize (modules);
+ }
/* Create a virtual module that provides only the specified tokens */
p11_virtual_init (&virt, &p11_virtual_base, module, NULL);
@@ -2169,7 +2162,6 @@ p11_kit_remote_serve_tokens (const char **tokens,
goto out;
for (i = 0; i < n_tokens; i++) {
- P11KitUri *uri;
CK_TOKEN_INFO *token;
uri = p11_kit_uri_new ();
@@ -2198,6 +2190,8 @@ p11_kit_remote_serve_tokens (const char **tokens,
p11_virtual_unwrap (filtered);
if (filter != NULL)
p11_filter_release (filter);
+ if (modules != NULL)
+ p11_kit_modules_release (modules);
return ret;
}