Exemple #1
0
CK_RV C_Logout(CK_SESSION_HANDLE hSession) /* the session's handle */
{
int ret = CKR_OK;
P11_SESSION *pSession = NULL;
P11_SLOT *pSlot = NULL;
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: Logout (session %d)", hSession);

ret = p11_get_session(hSession, &pSession);
if (ret)
   {
   log_trace(WHERE, "E: Invalid session handle (%d)", hSession);
   goto cleanup;
   }

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;
   }

if (pSlot->login_type >= 0)
   {
   pSlot->login_type = -1;
	//printf("We ask for cal_logout...\n");
   ret = cal_logout(pSession->hslot);
	//printf("We are done!\n");
   }
else
   ret = CKR_USER_NOT_LOGGED_IN;

/* TODO  cleanup all active operations (see standard) */
/* TODO: invalidate all private objects */
/* TODO: destroy all private session objects (we only have private token objects and they are unreadable anyway) */

cleanup:
   p11_unlock();
   log_trace(WHERE, "I: leave, ret = %i",ret);
   return ret;
}
Exemple #2
0
CK_RV p11_close_all_sessions(CK_SLOT_ID slotID)
{
    int ret = 0;
    unsigned int i = 0;
    P11_SLOT    *pSlot = NULL;
    P11_SESSION *pSession = NULL;

    pSlot = p11_get_slot(slotID);
    if (pSlot == NULL)
    {
        log_trace(WHERE, "E: Invalid slot (%d)", slotID);
        ret = CKR_SLOT_ID_INVALID;
        goto cleanup;
    }

    if (pSlot->nsessions == 0)
    {
        ret = CKR_OK;
        goto cleanup;
    }

//walk through all sessions and clean the ones related to this slot
    for (i=0; (i < nSessions) && (pSession = &gpSessions[i]) ; i++)
    {
        if ( (pSession->inuse) && (pSession->hslot == slotID) )
        {
            if (pSlot->nsessions > 0)
                pSlot->nsessions--;

            if ((pSlot->nsessions == 0) && (pSlot->login_type >= 0) )
            {
                cal_logout(slotID);
                pSlot->login_type = -1;
            }

            //clear data so it can be reused
            pSession->inuse = 0;
            pSession->flags = 0;
            pSession->hslot = 0;
            pSession->pdNotify = NULL;
            pSession->pfNotify = NULL;
            pSession->state = 0;
        }
    }

cleanup:

    return (ret);
}
Exemple #3
0
CK_RV p11_close_session(P11_SLOT* pSlot, P11_SESSION* pSession)
{
	CK_RV ret = CKR_OK;

	if (pSlot == NULL)
		return ret;

	if (pSlot->nsessions > 0)
		pSlot->nsessions--;

	if ((pSlot->nsessions < 1) && (pSlot->login_type >= 0) )
	{
		cal_logout(pSession->hslot);
		pSlot->login_type = -1;
	}

	//disconnect this session to device
	ret = cal_disconnect(pSession->hslot);
	//clear data so it can be reused
	if(pSession->Operation[P11_OPERATION_FIND].active) {
		p11_clean_finddata(pSession->Operation[P11_OPERATION_FIND].pData);
		free(pSession->Operation[P11_OPERATION_FIND].pData);
		pSession->Operation[P11_OPERATION_FIND].pData = NULL;
		pSession->Operation[P11_OPERATION_FIND].active = 0;
	}
	if(pSession->Operation[P11_OPERATION_DIGEST].active) {
		free(pSession->Operation[P11_OPERATION_DIGEST].pData);
		pSession->Operation[P11_OPERATION_DIGEST].pData = NULL;
		pSession->Operation[P11_OPERATION_DIGEST].active = 0;
	}
	if(pSession->Operation[P11_OPERATION_SIGN].active) {
		free(pSession->Operation[P11_OPERATION_SIGN].pData);
		pSession->Operation[P11_OPERATION_SIGN].pData = NULL;
		pSession->Operation[P11_OPERATION_SIGN].active = 0;
	}
	pSession->state = 0;
	pSession->inuse = 0;
	pSession->flags = 0;
	pSession->hslot = 0;
	pSession->pdNotify = NULL;
	pSession->pfNotify = NULL;

	return ret;
}