[Cryptech-Commits] [sw/pkcs11] 01/04: The libhal RPC channel works better when one remembers to initialize it.

git at cryptech.is git at cryptech.is
Sat May 14 07:12:34 UTC 2016


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch rpc
in repository sw/pkcs11.

commit 441990d176ff6df7032ef812efb2ac35f4d76388
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Fri May 13 17:00:44 2016 -0400

    The libhal RPC channel works better when one remembers to initialize it.
---
 p11util.c | 25 +++++++++++++------------
 pkcs11.c  | 17 ++++++++++++++++-
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/p11util.c b/p11util.c
index 606e40c..db36888 100644
--- a/p11util.c
+++ b/p11util.c
@@ -265,23 +265,24 @@ static int set_pin(const hal_user_t user, const int read_from_stdin)
 int main(int argc, char *argv[])
 {
   int do_set_so_pin = 0, do_set_user_pin = 0, do_set_wheel_pin = 0, read_from_stdin = 0;
+  hal_error_t err;
 
   parse_args(argc, argv, &do_set_so_pin, &do_set_user_pin, &do_set_wheel_pin, &read_from_stdin);
 
-  if (do_set_wheel_pin && !set_pin(HAL_USER_WHEEL, read_from_stdin)) {
-    fprintf(stderr, "Couldn't set wheel PIN\n");
-    return 1;
-  }
+  if ((err = hal_rpc_client_init()) != HAL_OK)
+    return fprintf(stderr, "Couldn't initialize RPC: %s\n", hal_error_string(err)), 1;
 
-  if (do_set_so_pin && !set_pin(HAL_USER_SO, read_from_stdin)) {
-    fprintf(stderr, "Couldn't set SO PIN\n");
-    return 2;
-  }
+  if (do_set_wheel_pin && !set_pin(HAL_USER_WHEEL, read_from_stdin))
+    return fprintf(stderr, "Couldn't set wheel PIN\n"), 2;
 
-  if (do_set_user_pin && !set_pin(HAL_USER_NORMAL, read_from_stdin)) {
-    fprintf(stderr, "Couldn't set user PIN\n");
-    return 3;
-  }
+  if (do_set_so_pin && !set_pin(HAL_USER_SO, read_from_stdin))
+    return fprintf(stderr, "Couldn't set SO PIN\n"), 3;
+
+  if (do_set_user_pin && !set_pin(HAL_USER_NORMAL, read_from_stdin))
+    return fprintf(stderr, "Couldn't set user PIN\n"), 4;
+
+  if ((err = hal_rpc_client_close()) != HAL_OK)
+    return fprintf(stderr, "Couldn't shut down RPC: %s\n", hal_error_string(err)), 5;
 
   return 0;
 }
diff --git a/pkcs11.c b/pkcs11.c
index dc14fd9..10b9034 100644
--- a/pkcs11.c
+++ b/pkcs11.c
@@ -2361,6 +2361,7 @@ CK_RV C_Initialize(CK_VOID_PTR pInitArgs)
 
   CK_C_INITIALIZE_ARGS_PTR a = pInitArgs;
   int initialized_sql = 0;
+  int initialized_rpc = 0;
   CK_RV rv;
 
   /*
@@ -2454,6 +2455,15 @@ CK_RV C_Initialize(CK_VOID_PTR pInitArgs)
     goto fail;
 
   /*
+   * Initialize libhal RPC channel.
+   */
+
+  if (!hal_check(hal_rpc_client_init()))
+    lose(CKR_GENERAL_ERROR);
+
+  initialized_rpc = 1;
+
+  /*
    * Initialize SQLite3, opening the database(s) and loading the
    * schema and views.
    */
@@ -2474,6 +2484,9 @@ CK_RV C_Initialize(CK_VOID_PTR pInitArgs)
   if (initialized_sql)
     sql_fini();
 
+  if (initialized_rpc)
+    hal_rpc_client_close();
+
   return rv;
 }
 
@@ -2503,9 +2516,11 @@ CK_RV C_Finalize(CK_VOID_PTR pReserved)
 
   /*
    * By this point we're pretty well committed to shutting down, so
-   * there's not much to be done if these mutex operations fail.
+   * there's not much to be done if any of the rest of this fails.
    */
 
+  hal_rpc_client_close();
+
   rv =  mutex_unlock(p11_global_mutex);
   (void) mutex_destroy(p11_global_mutex);
   p11_global_mutex = NULL;



More information about the Commits mailing list