diff options
author | Rob Austein <sra@hactrn.net> | 2015-12-24 13:55:55 -0500 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2015-12-24 13:55:55 -0500 |
commit | 1a7b3c31095762afebeab1cc1717259c0e3c5cc9 (patch) | |
tree | 77753c21bf6510ccadcb96684004a9808f6f9ae6 /rpc_misc.c | |
parent | 7dfad9f2b40f32fb2f2d38c4637ae9faad4228d9 (diff) |
hal_rpc_logout_all(), hal_rpc_is_logged_in().
Diffstat (limited to 'rpc_misc.c')
-rw-r--r-- | rpc_misc.c | 31 |
1 files changed, 25 insertions, 6 deletions
@@ -64,10 +64,6 @@ static hal_error_t get_random(void *buffer, const size_t length) * * More interesting question is whether we should ever allow the WHEEL * PIN to be changed a second time without toasting the keystore. - * - * We also need a function which the rest of the library can use to - * check current login status for a particular hal_client_t. Don't - * know yet whether we need anything else. */ #warning PIN code not yet fully implemented @@ -180,7 +176,7 @@ static hal_error_t login(const hal_client_handle_t client, client_slot_t *slot = find_handle(client); - if (slot != NULL && (slot = alloc_slot()) == NULL) + if (slot == NULL && (slot = alloc_slot()) == NULL) return HAL_ERROR_NO_CLIENT_SLOTS_AVAILABLE; slot->handle = client; @@ -189,6 +185,19 @@ static hal_error_t login(const hal_client_handle_t client, return HAL_OK; } +static hal_error_t is_logged_in(const hal_client_handle_t client, + const hal_user_t user) +{ + assert(user == HAL_USER_NORMAL || user == HAL_USER_SO || user == HAL_USER_WHEEL); + + client_slot_t *slot = find_handle(client); + + if (slot == NULL || slot->logged_in != user) + return HAL_ERROR_FORBIDDEN; + + return HAL_OK; +} + static hal_error_t logout(const hal_client_handle_t client) { client_slot_t *slot = find_handle(client); @@ -199,8 +208,18 @@ static hal_error_t logout(const hal_client_handle_t client) return HAL_OK; } +static hal_error_t logout_all(void) +{ +#if HAL_STATIC_CLIENT_STATE_BLOCKS > 0 + for (int i = 0; i < sizeof(client_handle)/sizeof(*client_handle); i++) + client_handle[i].logged_in = HAL_USER_NONE; +#endif + + return HAL_OK; +} + const hal_rpc_misc_dispatch_t hal_rpc_remote_misc_dispatch = { - set_pin, login, logout, get_random + set_pin, login, logout, logout_all, is_logged_in, get_random }; /* |