CK_RV C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) { CK_RV ret; log_trace(WHERE, "I: enter"); if (p11_get_init() != BEIDP11_INITIALIZED) { log_trace(WHERE, "I: leave, CKR_CRYPTOKI_NOT_INITIALIZED"); return (CKR_CRYPTOKI_NOT_INITIALIZED); } ret = p11_lock(); if (ret != CKR_OK) { log_trace(WHERE, "I: leave, p11_lock failed with %i",ret); return ret; } log_trace(WHERE, "S: C_GetTokenInfo(slot %d)", slotID); if (pInfo == NULL_PTR) { log_trace(WHERE, "E: pInfo = NULL"); CLEANUP(CKR_ARGUMENTS_BAD); } ret = cal_get_token_info(slotID, pInfo); if (ret != CKR_OK) { log_trace(WHERE, "E: p11_get_token_info returns %d", ret); goto cleanup; } cleanup: p11_unlock(); log_trace(WHERE, "I: leave, ret = %i",ret); return ret; }
CK_RV C_GetSessionInfo(CK_SESSION_HANDLE hSession, /* the session's handle */ CK_SESSION_INFO_PTR pInfo) /* receives session information */ { int ret; char buf[256]; P11_SESSION *pSession = NULL; P11_SLOT *pSlot = NULL; CK_TOKEN_INFO tokeninfo; log_trace(WHERE, "I: enter"); ret = p11_lock(); if (ret != CKR_OK) { log_trace(WHERE, "I: leave, p11_lock failed with %i",ret); return ret; } log_trace(WHERE, "S: C_GetSessionInfo(session %d)", hSession); if (pInfo == NULL_PTR) { ret = CKR_ARGUMENTS_BAD; goto cleanup; } ret = p11_get_session(hSession, &pSession); if (ret) { log_trace(WHERE, "E: Invalid session handle (%d) (%s)", hSession, log_map_error(ret)); goto cleanup; } pInfo->slotID = pSession->hslot; pInfo->flags = pSession->flags; pInfo->ulDeviceError = 0; pSlot = p11_get_slot(pSession->hslot); if (pSlot == NULL) { log_trace(WHERE, "E: slot not found for session %d", hSession); ret = CKR_SESSION_HANDLE_INVALID; goto cleanup; } //SO only can create RW_SO sessions if (pSlot->login_type == CKU_SO) { pInfo->state = CKS_RW_SO_FUNCTIONS; } //USER can create RW or RO sessions else if (pSlot->login_type == CKU_USER) { pInfo->state = (pSession->flags & CKF_RW_SESSION)? CKS_RW_USER_FUNCTIONS : CKS_RO_USER_FUNCTIONS; } //if login not required => we can also get USER sessions without being logged on else { ret = cal_get_token_info(pSession->hslot, &tokeninfo); if ( (ret == CKR_OK) && !(tokeninfo.flags & CKF_LOGIN_REQUIRED) ) pInfo->state = (pSession->flags & CKF_RW_SESSION)? CKS_RW_USER_FUNCTIONS : CKS_RO_USER_FUNCTIONS; else pInfo->state = (pSession->flags & CKF_RW_SESSION) ? CKS_RW_PUBLIC_SESSION : CKS_RO_PUBLIC_SESSION; } cleanup: p11_unlock(); log_trace(WHERE, "I: leave, ret = %i",ret); return ret; }