/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdlib.h>
#include <string.h>
#include "metaGlobal.h"
/*
* The list and the list lock are global for two external uses:
* 1) C_CloseAllSessions need to close the head (repeatedly,
* until no more sessions exist).
* 2) meta_object_find_by_handle needs to walk all sessions,
* searching each session object list for matching objects.
*/
/*
* The following 2 variables are used for tracking the number of
* sessions and number of rw sessios that are currently open
*
* They are being manipulated in the metaSession.c file, and being
* referenced in the metaSlotToken.c file
*/
/*
* meta_sessionManager_initialize
*
* Called from meta_Initialize. Initializes all the variables used
* by the session manager.
*/
{
return (CKR_FUNCTION_FAILED);
}
(void) pthread_rwlock_destroy(&meta_sessionlist_lock);
return (CKR_FUNCTION_FAILED);
}
num_meta_sessions = 0;
num_rw_meta_sessions = 0;
return (CKR_OK);
}
/*
* meta_sessionManager_finalize
*
* Close all sessions, and destroy all the locks
*/
void
{
/*
* Close any remaining metasessions, can just simply call
* meta_CloseAllSessions. The METASLOT_SLOTID argument is
* not used, but need to be passed in.
*/
(void) meta_CloseAllSessions(METASLOT_SLOTID);
(void) pthread_rwlock_destroy(&meta_sessionclose_lock);
(void) pthread_rwlock_destroy(&meta_sessionlist_lock);
}
/*
* meta_handle2session
*
* Convert a CK_SESSION_HANDLE to the corresponding metasession. If
* successful, a write-lock on the session will be held to indicate
* that it's in use. Call REFRELEASE() when finished.
*
*/
{
/* Check for bad args (eg CK_INVALID_HANDLE, which is 0/NULL). */
if (tmp_session == NULL ||
return (CKR_SESSION_HANDLE_INVALID);
}
/*
* sessions can only be used by a single thread at a time.
* So, we need to get a write-lock.
*/
/* Make sure this session is not in the process of being deleted */
if (tmp_session->isClosingSession) {
(void) pthread_mutex_unlock(
return (CKR_SESSION_HANDLE_INVALID);
}
*session = tmp_session;
return (CKR_OK);
}
/*
* meta_session_alloc
*/
{
/* Allocate memory for the session. */
if (new_session == NULL)
return (CKR_HOST_MEMORY);
return (CKR_HOST_MEMORY);
}
*session = new_session;
return (CKR_OK);
}
/*
* meta_session_activate
*
* Create and add a session to the list of active meta sessions.
*/
{
/* Add session to the list of sessions. */
(void) pthread_rwlock_wrlock(&meta_sessionlist_lock);
(void) pthread_rwlock_unlock(&meta_sessionlist_lock);
return (rv);
}
/*
* meta_session_deactivate
*
*
*/
{
/* Safely resolve attempts of concurrent-close */
if (session->isClosingSession) {
/* Lost a delete race. */
return (CKR_SESSION_HANDLE_INVALID);
}
/*
* Remove session from the session list. Once removed, it will not
* be possible for another thread to begin using the session.
*/
(void) pthread_rwlock_wrlock(&meta_sessionclose_lock);
if (!have_sessionlist_lock) {
(void) pthread_rwlock_wrlock(&meta_sessionlist_lock);
}
if (meta_sessionlist_head == NULL) {
}
if (!have_sessionlist_lock) {
(void) pthread_rwlock_unlock(&meta_sessionlist_lock);
}
(void) pthread_rwlock_unlock(&meta_sessionclose_lock);
/* Cleanup any in-progress operations. */
}
}
/* Remove all the session metaobjects created in this session. */
/* Basically, emulate C_DestroyObject, including safety h2s */
/* Can only happen if someone else just closed it. */
continue;
}
continue;
}
continue;
}
}
if ((isLastSession) && (metaslot_logged_in())) {
return (rv);
/* if C_Logout fails, just ignore the error */
return (rv);
/* need to deactivate all the PRIVATE token objects */
return (rv);
}
}
return (CKR_OK);
}
/*
* meta_session_dealloc
*
* Release the resources held by a metasession. If the session has been
* activated, it must be deactivated first.
*/
void
{
}
/*
* If there were active operations, cleanup the slot session so that
* it can be reused (otherwise provider might complain that an
* operation is active).
*/
/* Final object cleanup. */
}
/*
* This function adds the to-be-freed meta session to a linked list.
* When the number of sessions queued in the linked list reaches the
* maximum threshold MAX_SESSION_TO_BE_FREED, it will free the first
* session (FIFO) in the list.
*/
void
{
/* Add the newly deleted session at the end of the list */
} else {
}
/*
* Free the first session in the list only if
* the total count reaches maximum threshold.
*/
}
}