metaSession.c revision d288ba7491829a622697c947c3f1a30aec18c133
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * CDDL HEADER START
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms of the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Common Development and Distribution License (the "License").
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You may not use this file except in compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing permissions
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL HEADER in each
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below this CDDL HEADER, with the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * fields enclosed by brackets "[]" replaced with your own identifying
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * information: Portions Copyright [yyyy] [name of copyright owner]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * CDDL HEADER END
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Use is subject to license terms.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * Session Management Functions
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (as defined in PKCS#11 spec spection 11.6)
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonextern meta_session_t *meta_sessionlist_head;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonextern pthread_rwlock_t meta_sessionlist_lock;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * meta_OpenSession
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * 1) The pApplication and Notify args are not used, as the metaslot does not
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * support application callbacks.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * 2) the slotID argument is not checked or used because this function
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is only called from the framework.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/* ARGSUSED */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostermeta_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication,
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington CK_NOTIFY Notify, CK_SESSION_HANDLE_PTR phSession)
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington /* Check for any unknown flags. */
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington if (flags & ~(CKF_SERIAL_SESSION | CKF_RW_SESSION)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (meta_slotManager_token_write_protected() &&
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * meta_CloseSession
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonmeta_CloseSession(CK_SESSION_HANDLE hSession)
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington rv = meta_handle2session(hSession, &session);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington /* save info about session flags before they are destroyed */
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington rv = meta_session_deactivate(session, B_FALSE);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * meta_CloseAllSessions
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * This is a simple loop that closes the sessionlist head (resulting in a
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * new list head) until the list is empty.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington (void) pthread_rwlock_wrlock(&meta_sessionlist_lock);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington while ((session = meta_sessionlist_head) != NULL) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington rv = meta_handle2session((CK_SESSION_HANDLE)session, &session);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington /*NOTREACHED*/
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington (void) pthread_rwlock_unlock(&meta_sessionlist_lock);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington (void) meta_session_deactivate(session, B_TRUE);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington (void) pthread_rwlock_unlock(&meta_sessionlist_lock);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington /* All open sessions should be closed, just reset the variables */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * meta_GetSessionInfo
return (CKR_ARGUMENTS_BAD);
return (rv);
if (metaslot_logged_in()) {
return (CKR_OK);
return (rv);
return (CKR_ARGUMENTS_BAD);
return (rv);
goto endgetopstate;
return (rv);
goto endgetopstate;
sizeof (meta_opstate_t);
goto endgetopstate;
sizeof (meta_opstate_t));
return (rv);
static CK_RV
return (rv);
return (rv);
return (rv);
return (CKR_ARGUMENTS_BAD);
return (CKR_SAVED_STATE_INVALID);
return (CKR_SAVED_STATE_INVALID);
return (rv);
goto cleanup;
goto cleanup;
B_FALSE);
goto cleanup;
FALSE);
goto cleanup;
return (rv);
return (rv);
if (metaslot_logged_in()) {
goto finish;
goto finish;
goto finish;
goto finish;
* For some slots (eg: the pkcs11_softtoken.so), C_Login()
* successful. For pkcs11_softtoken.so, the CKF_USER_PIN_TO_BE_CHANGED
* behave like pkcs11_softtoken.so.
goto finish;
if (login_session)
return (rv);
return (rv);
if (!metaslot_logged_in()) {
goto finish;
goto finish;
if (logout_session)
return (rv);