diff options
-rw-r--r-- | p11util.c | 25 | ||||
-rw-r--r-- | pkcs11.c | 17 |
2 files changed, 29 insertions, 13 deletions
@@ -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; } @@ -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; |