2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <pthread.h>
2N/A#include <stdlib.h>
2N/A#include <security/cryptoki.h>
2N/A#include "softGlobal.h"
2N/A#include "softObject.h"
2N/A#include "softSession.h"
2N/A#include "softKeystore.h"
2N/A#include "softKeystoreUtil.h"
2N/A
2N/A
2N/ACK_RV
2N/AC_CreateObject(CK_SESSION_HANDLE hSession,
2N/A CK_ATTRIBUTE_PTR pTemplate,
2N/A CK_ULONG ulCount,
2N/A CK_OBJECT_HANDLE_PTR phObject)
2N/A{
2N/A
2N/A CK_RV rv;
2N/A soft_session_t *session_p;
2N/A boolean_t lock_held = B_FALSE;
2N/A
2N/A if (!softtoken_initialized)
2N/A return (CKR_CRYPTOKI_NOT_INITIALIZED);
2N/A
2N/A /*
2N/A * Obtain the session pointer. Also, increment the session
2N/A * reference count.
2N/A */
2N/A rv = handle2session(hSession, &session_p);
2N/A if (rv != CKR_OK)
2N/A return (rv);
2N/A
2N/A if ((pTemplate == NULL) || (ulCount == 0) ||
2N/A (phObject == NULL)) {
2N/A rv = CKR_ARGUMENTS_BAD;
2N/A goto clean_exit;
2N/A }
2N/A
2N/A /* Create a new object. */
2N/A rv = soft_add_object(pTemplate, ulCount, phObject, session_p);
2N/A
2N/Aclean_exit:
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A}
2N/A
2N/ACK_RV
2N/AC_CopyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
2N/A CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
2N/A CK_OBJECT_HANDLE_PTR phNewObject)
2N/A{
2N/A
2N/A CK_RV rv;
2N/A soft_session_t *session_p;
2N/A boolean_t lock_held = B_FALSE;
2N/A soft_object_t *old_object, *new_object = NULL;
2N/A ulong_t i;
2N/A
2N/A if (!softtoken_initialized)
2N/A return (CKR_CRYPTOKI_NOT_INITIALIZED);
2N/A
2N/A /*
2N/A * Obtain the session pointer. Also, increment the session
2N/A * reference count.
2N/A */
2N/A rv = handle2session(hSession, &session_p);
2N/A if (rv != CKR_OK)
2N/A return (rv);
2N/A
2N/A /* Check arguments */
2N/A if (((ulCount > 0) && (pTemplate == NULL)) ||
2N/A (phNewObject == NULL)) {
2N/A rv = CKR_ARGUMENTS_BAD;
2N/A goto clean_exit;
2N/A }
2N/A
2N/A /* Obtain the object pointer. */
2N/A HANDLE2OBJECT(hObject, old_object, rv);
2N/A if (rv != CKR_OK) {
2N/A goto clean_exit;
2N/A }
2N/A
2N/A /*
2N/A * Copy the old object to a new object.
2N/A * The 3rd argument with SOFT_COPY_OBJ value indicates that
2N/A * everything in the object will be duplicated for C_CopyObject.
2N/A * The 4th argument has the session pointer that will be
2N/A * saved in the new copy of the session object.
2N/A */
2N/A (void) pthread_rwlock_rdlock(&old_object->object_rwlock);
2N/A rv = soft_copy_object(old_object, &new_object, SOFT_COPY_OBJECT,
2N/A session_p);
2N/A
2N/A if ((rv != CKR_OK) || (new_object == NULL)) {
2N/A /* Most likely we ran out of space. */
2N/A (void) pthread_rwlock_unlock(&old_object->object_rwlock);
2N/A goto clean_exit1;
2N/A }
2N/A
2N/A /* No need to hold the lock on the old object. */
2N/A (void) pthread_rwlock_unlock(&old_object->object_rwlock);
2N/A
2N/A /* Modifiy the objects if requested */
2N/A for (i = 0; i < ulCount; i++) {
2N/A /* Set the requested attribute into the new object. */
2N/A rv = soft_set_attribute(new_object, &pTemplate[i], B_TRUE);
2N/A if (rv != CKR_OK) {
2N/A goto fail;
2N/A }
2N/A }
2N/A
2N/A rv = soft_pin_expired_check(new_object);
2N/A if (rv != CKR_OK) {
2N/A goto fail;
2N/A }
2N/A
2N/A /*
2N/A * Does the new object violate the creation rule or access rule?
2N/A */
2N/A rv = soft_object_write_access_check(session_p, new_object);
2N/A if (rv != CKR_OK) {
2N/A goto fail;
2N/A }
2N/A
2N/A /*
2N/A * If the new object is a token object, it will be added
2N/A * to token object list and write to disk.
2N/A */
2N/A if (IS_TOKEN_OBJECT(new_object)) {
2N/A new_object->version = 1;
2N/A /*
2N/A * Write to the keystore file.
2N/A */
2N/A rv = soft_put_object_to_keystore(new_object);
2N/A if (rv != CKR_OK) {
2N/A goto fail;
2N/A }
2N/A
2N/A new_object->session_handle = (CK_SESSION_HANDLE)NULL;
2N/A /*
2N/A * Add the newly created token object to the global
2N/A * token object list in the slot struct.
2N/A */
2N/A soft_add_token_object_to_slot(new_object);
2N/A OBJ_REFRELE(old_object);
2N/A SES_REFRELE(session_p, lock_held);
2N/A *phNewObject = (CK_ULONG)new_object;
2N/A
2N/A return (CKR_OK);
2N/A }
2N/A
2N/A /* Insert new object into this session's object list */
2N/A soft_add_object_to_session(new_object, session_p);
2N/A
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A OBJ_REFRELE(old_object);
2N/A SES_REFRELE(session_p, lock_held);
2N/A
2N/A /* set handle of the new object */
2N/A *phNewObject = (CK_ULONG)new_object;
2N/A
2N/A return (rv);
2N/A
2N/Afail:
2N/A soft_cleanup_object(new_object);
2N/A free(new_object);
2N/A
2N/Aclean_exit1:
2N/A OBJ_REFRELE(old_object);
2N/Aclean_exit:
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A}
2N/A
2N/ACK_RV
2N/AC_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject)
2N/A{
2N/A
2N/A CK_RV rv;
2N/A soft_object_t *object_p;
2N/A soft_session_t *session_p = (soft_session_t *)(hSession);
2N/A boolean_t lock_held = B_FALSE;
2N/A CK_SESSION_HANDLE creating_session;
2N/A
2N/A
2N/A if (!softtoken_initialized)
2N/A return (CKR_CRYPTOKI_NOT_INITIALIZED);
2N/A
2N/A /*
2N/A * The reason that we don't call handle2session is because
2N/A * the argument hSession may not be the creating_session of
2N/A * the object to be destroyed, and we want to avoid the lock
2N/A * contention. The handle2session will be called later for
2N/A * the creating_session.
2N/A */
2N/A if ((session_p == NULL) ||
2N/A (session_p->magic_marker != SOFTTOKEN_SESSION_MAGIC)) {
2N/A return (CKR_SESSION_HANDLE_INVALID);
2N/A }
2N/A
2N/A /* Obtain the object pointer. */
2N/A HANDLE2OBJECT_DESTROY(hObject, object_p, rv);
2N/A if (rv != CKR_OK) {
2N/A return (rv);
2N/A }
2N/A
2N/A /* Obtain the session handle which object belongs to. */
2N/A creating_session = object_p->session_handle;
2N/A
2N/A if (creating_session == NULL) {
2N/A /*
2N/A * This is a token object to be deleted.
2N/A * For token object, there is no creating session concept,
2N/A * therefore, creating_session is always NULL.
2N/A */
2N/A rv = soft_pin_expired_check(object_p);
2N/A if (rv != CKR_OK) {
2N/A return (rv);
2N/A }
2N/A
2N/A /* Obtain the session pointer just for validity check. */
2N/A rv = handle2session(hSession, &session_p);
2N/A if (rv != CKR_OK) {
2N/A return (rv);
2N/A }
2N/A
2N/A rv = soft_object_write_access_check(session_p, object_p);
2N/A if (rv != CKR_OK) {
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A }
2N/A
2N/A /*
2N/A * Set OBJECT_IS_DELETING flag so any access to this
2N/A * object will be rejected.
2N/A */
2N/A (void) pthread_mutex_lock(&object_p->object_mutex);
2N/A if (object_p->obj_delete_sync & OBJECT_IS_DELETING) {
2N/A (void) pthread_mutex_unlock(&object_p->object_mutex);
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_OBJECT_HANDLE_INVALID);
2N/A }
2N/A object_p->obj_delete_sync |= OBJECT_IS_DELETING;
2N/A (void) pthread_mutex_unlock(&object_p->object_mutex);
2N/A SES_REFRELE(session_p, lock_held);
2N/A
2N/A /*
2N/A * Delete a token object by calling soft_delete_token_object()
2N/A * with the second argument B_TRUE indicating to delete the
2N/A * object from keystore and the third argument B_FALSE
2N/A * indicating that the caller does not hold the slot mutex.
2N/A */
2N/A soft_delete_token_object(object_p, B_TRUE, B_FALSE);
2N/A return (CKR_OK);
2N/A }
2N/A
2N/A /*
2N/A * Obtain the session pointer. Also, increment the session
2N/A * reference count.
2N/A */
2N/A rv = handle2session(creating_session, &session_p);
2N/A if (rv != CKR_OK) {
2N/A return (rv);
2N/A }
2N/A
2N/A /*
2N/A * Set OBJECT_IS_DELETING flag so any access to this
2N/A * object will be rejected.
2N/A */
2N/A (void) pthread_mutex_lock(&object_p->object_mutex);
2N/A if (object_p->obj_delete_sync & OBJECT_IS_DELETING) {
2N/A (void) pthread_mutex_unlock(&object_p->object_mutex);
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_OBJECT_HANDLE_INVALID);
2N/A }
2N/A object_p->obj_delete_sync |= OBJECT_IS_DELETING;
2N/A (void) pthread_mutex_unlock(&object_p->object_mutex);
2N/A
2N/A /*
2N/A * Delete an object by calling soft_delete_object()
2N/A * with a FALSE boolean argument indicating that
2N/A * the caller does not hold the session lock.
2N/A */
2N/A soft_delete_object(session_p, object_p, B_FALSE, B_FALSE);
2N/A
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A SES_REFRELE(session_p, lock_held);
2N/A
2N/A return (rv);
2N/A}
2N/A
2N/A
2N/ACK_RV
2N/AC_GetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
2N/A CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
2N/A{
2N/A
2N/A CK_RV rv = CKR_OK, rv1 = CKR_OK;
2N/A soft_object_t *object_p;
2N/A soft_session_t *session_p;
2N/A boolean_t lock_held = B_FALSE;
2N/A ulong_t i;
2N/A
2N/A if (!softtoken_initialized)
2N/A return (CKR_CRYPTOKI_NOT_INITIALIZED);
2N/A
2N/A /*
2N/A * Obtain the session pointer. Also, increment the session
2N/A * reference count.
2N/A */
2N/A rv = handle2session(hSession, &session_p);
2N/A if (rv != CKR_OK)
2N/A return (rv);
2N/A
2N/A if ((pTemplate == NULL) || (ulCount == 0)) {
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_ARGUMENTS_BAD);
2N/A }
2N/A
2N/A /* Obtain the object pointer. */
2N/A HANDLE2OBJECT(hObject, object_p, rv);
2N/A if (rv != CKR_OK) {
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A }
2N/A
2N/A if (IS_TOKEN_OBJECT(object_p)) {
2N/A
2N/A rv = soft_keystore_load_latest_object(object_p);
2N/A if (rv != CKR_OK) {
2N/A OBJ_REFRELE(object_p);
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A }
2N/A }
2N/A
2N/A /* Acquire the lock on the object. */
2N/A (void) pthread_rwlock_rdlock(&object_p->object_rwlock);
2N/A
2N/A for (i = 0; i < ulCount; i++) {
2N/A /*
2N/A * Get the value of each attribute in the template.
2N/A * (We must process EVERY attribute in the template.)
2N/A */
2N/A rv = soft_get_attribute(object_p, &pTemplate[i]);
2N/A if (rv != CKR_OK)
2N/A /* At least we catch some type of error. */
2N/A rv1 = rv;
2N/A }
2N/A
2N/A /* Release the object lock */
2N/A (void) pthread_rwlock_unlock(&object_p->object_rwlock);
2N/A
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A OBJ_REFRELE(object_p);
2N/A SES_REFRELE(session_p, lock_held);
2N/A
2N/A rv = rv1;
2N/A return (rv);
2N/A}
2N/A
2N/A
2N/ACK_RV
2N/AC_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
2N/A CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
2N/A{
2N/A CK_RV rv = CKR_OK;
2N/A soft_object_t *object_p;
2N/A soft_object_t *new_object = NULL;
2N/A soft_session_t *session_p;
2N/A boolean_t lock_held = B_FALSE;
2N/A ulong_t i;
2N/A
2N/A if (!softtoken_initialized)
2N/A return (CKR_CRYPTOKI_NOT_INITIALIZED);
2N/A
2N/A /*
2N/A * Obtain the session pointer. Also, increment the session
2N/A * reference count.
2N/A */
2N/A rv = handle2session(hSession, &session_p);
2N/A if (rv != CKR_OK)
2N/A return (rv);
2N/A
2N/A if ((pTemplate == NULL) || (ulCount == 0)) {
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_ARGUMENTS_BAD);
2N/A }
2N/A
2N/A /* Obtain the object pointer. */
2N/A HANDLE2OBJECT(hObject, object_p, rv);
2N/A if (rv != CKR_OK) {
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A }
2N/A
2N/A if (object_p->bool_attr_mask & NOT_MODIFIABLE_BOOL_ON) {
2N/A rv = CKR_ATTRIBUTE_READ_ONLY;
2N/A goto fail_1;
2N/A }
2N/A
2N/A /*
2N/A * Start working on the object, so we need to set the write lock so that
2N/A * no one can write to it but still can read it.
2N/A */
2N/A if (IS_TOKEN_OBJECT(object_p)) {
2N/A rv = soft_keystore_load_latest_object(object_p);
2N/A if (rv != CKR_OK) {
2N/A goto fail_1;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Copy the old object to a new object. We work on the copied
2N/A * version because in case of error we still keep the old one
2N/A * intact.
2N/A * The 3rd argument with SOFT_SET_ATTR_VALUE value indicates that
2N/A * not everything will be duplicated for C_SetAttributeValue.
2N/A * Information not duplicated are those attributes that are not
2N/A * modifiable.
2N/A */
2N/A (void) pthread_rwlock_rdlock(&object_p->object_rwlock);
2N/A rv = soft_copy_object(object_p, &new_object, SOFT_SET_ATTR_VALUE, NULL);
2N/A
2N/A if ((rv != CKR_OK) || (new_object == NULL)) {
2N/A /* Most likely we ran out of space. */
2N/A (void) pthread_rwlock_unlock(&object_p->object_rwlock);
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A goto fail_1;
2N/A }
2N/A
2N/A /*
2N/A * No need to hold the lock on the old object, because we
2N/A * will be working on the new scratch object.
2N/A */
2N/A (void) pthread_rwlock_unlock(&object_p->object_rwlock);
2N/A
2N/A rv = soft_object_write_access_check(session_p, new_object);
2N/A if (rv != CKR_OK) {
2N/A goto fail;
2N/A }
2N/A
2N/A for (i = 0; i < ulCount; i++) {
2N/A /* Set the requested attribute into the new object. */
2N/A rv = soft_set_attribute(new_object, &pTemplate[i], B_FALSE);
2N/A
2N/A if (rv != CKR_OK) {
2N/A goto fail;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * We've successfully set all the requested attributes.
2N/A * Merge the new object with the old object, then destroy
2N/A * the new one. The reason to do the merging is because we
2N/A * have to keep the original object handle (address of object).
2N/A */
2N/A (void) pthread_rwlock_wrlock(&object_p->object_rwlock);
2N/A
2N/A soft_merge_object(object_p, new_object);
2N/A
2N/A /*
2N/A * The object has been modified, so we write it back to keystore.
2N/A */
2N/A if (IS_TOKEN_OBJECT(object_p)) {
2N/A object_p->version++;
2N/A rv = soft_modify_object_to_keystore(object_p);
2N/A }
2N/A
2N/A (void) pthread_rwlock_unlock(&object_p->object_rwlock);
2N/A free(new_object);
2N/A
2N/A /*
2N/A * Decrement the session reference count.
2N/A * We do not hold the session lock.
2N/A */
2N/A OBJ_REFRELE(object_p);
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A
2N/Afail:
2N/A soft_cleanup_object(new_object);
2N/A free(new_object);
2N/A
2N/Afail_1:
2N/A OBJ_REFRELE(object_p);
2N/A SES_REFRELE(session_p, lock_held);
2N/A
2N/A return (rv);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/ACK_RV
2N/AC_GetObjectSize(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
2N/A CK_ULONG_PTR pulSize)
2N/A{
2N/A if (!softtoken_initialized)
2N/A return (CKR_CRYPTOKI_NOT_INITIALIZED);
2N/A
2N/A return (CKR_FUNCTION_NOT_SUPPORTED);
2N/A}
2N/A
2N/ACK_RV
2N/AC_FindObjectsInit(CK_SESSION_HANDLE sh, CK_ATTRIBUTE_PTR pTemplate,
2N/A CK_ULONG ulCount)
2N/A{
2N/A
2N/A CK_RV rv;
2N/A soft_session_t *session_p;
2N/A boolean_t lock_held = B_TRUE;
2N/A
2N/A if (!softtoken_initialized)
2N/A return (CKR_CRYPTOKI_NOT_INITIALIZED);
2N/A
2N/A /*
2N/A * Obtain the session pointer. Also, increment the session
2N/A * reference count.
2N/A */
2N/A rv = handle2session(sh, &session_p);
2N/A if (rv != CKR_OK)
2N/A return (rv);
2N/A
2N/A /* Check the arguments */
2N/A if ((ulCount > 0) && (pTemplate == NULL)) {
2N/A /* decrement the session count, we do not hold the lock */
2N/A lock_held = B_FALSE;
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_ARGUMENTS_BAD);
2N/A }
2N/A
2N/A /* Acquire the session lock */
2N/A (void) pthread_mutex_lock(&session_p->session_mutex);
2N/A
2N/A /* Check to see if find operation is already active */
2N/A if (session_p->find_objects.flags & CRYPTO_OPERATION_ACTIVE) {
2N/A /* decrement the session count, and unlock the mutex */
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_OPERATION_ACTIVE);
2N/A } else {
2N/A /*
2N/A * This active flag will remain ON until application calls
2N/A * C_FindObjectsFinal.
2N/A */
2N/A session_p->find_objects.flags = CRYPTO_OPERATION_ACTIVE;
2N/A }
2N/A
2N/A (void) pthread_mutex_unlock(&session_p->session_mutex);
2N/A
2N/A rv = soft_find_objects_init(session_p, pTemplate, ulCount);
2N/A
2N/A if (rv != CKR_OK) {
2N/A (void) pthread_mutex_lock(&session_p->session_mutex);
2N/A session_p->find_objects.flags = 0;
2N/A (void) pthread_mutex_unlock(&session_p->session_mutex);
2N/A }
2N/A
2N/A /* decrement the session count, and unlock the mutex */
2N/A lock_held = B_FALSE;
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A}
2N/A
2N/ACK_RV
2N/AC_FindObjects(CK_SESSION_HANDLE sh,
2N/A CK_OBJECT_HANDLE_PTR phObject,
2N/A CK_ULONG ulMaxObjectCount,
2N/A CK_ULONG_PTR pulObjectCount)
2N/A{
2N/A soft_session_t *session_p;
2N/A CK_RV rv = CKR_OK;
2N/A boolean_t lock_held = B_TRUE;
2N/A
2N/A if (!softtoken_initialized)
2N/A return (CKR_CRYPTOKI_NOT_INITIALIZED);
2N/A
2N/A /*
2N/A * Obtain the session pointer. Also, increment the session
2N/A * reference count.
2N/A */
2N/A rv = handle2session(sh, &session_p);
2N/A if (rv != CKR_OK)
2N/A return (rv);
2N/A
2N/A /* check for invalid arguments */
2N/A if (((phObject == NULL) && (ulMaxObjectCount != 0)) ||
2N/A (pulObjectCount == NULL)) {
2N/A /* decrement the session count, we do not hold the lock */
2N/A lock_held = B_FALSE;
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_ARGUMENTS_BAD);
2N/A }
2N/A
2N/A if (ulMaxObjectCount == 0) {
2N/A /* don't need to do anything, just return */
2N/A *pulObjectCount = 0;
2N/A /* decrement the session count, we do not hold the lock */
2N/A lock_held = B_FALSE;
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_OK);
2N/A }
2N/A
2N/A /* Acquire the session lock */
2N/A (void) pthread_mutex_lock(&session_p->session_mutex);
2N/A
2N/A /* Check to see if find operation is active */
2N/A if (!(session_p->find_objects.flags & CRYPTO_OPERATION_ACTIVE)) {
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_OPERATION_NOT_INITIALIZED);
2N/A }
2N/A
2N/A soft_find_objects(session_p, phObject, ulMaxObjectCount,
2N/A pulObjectCount);
2N/A
2N/A /* decrement the session count, and release the lock */
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A}
2N/A
2N/ACK_RV
2N/AC_FindObjectsFinal(CK_SESSION_HANDLE sh)
2N/A{
2N/A soft_session_t *session_p;
2N/A CK_RV rv;
2N/A boolean_t lock_held = B_TRUE;
2N/A
2N/A if (!softtoken_initialized)
2N/A return (CKR_CRYPTOKI_NOT_INITIALIZED);
2N/A
2N/A /*
2N/A * Obtain the session pointer. Also, increment the session
2N/A * reference count.
2N/A */
2N/A rv = handle2session(sh, &session_p);
2N/A if (rv != CKR_OK)
2N/A return (rv);
2N/A
2N/A /* Acquire the session lock */
2N/A (void) pthread_mutex_lock(&session_p->session_mutex);
2N/A
2N/A /* Check to see if find operation is active */
2N/A if (!(session_p->find_objects.flags & CRYPTO_OPERATION_ACTIVE)) {
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (CKR_OPERATION_NOT_INITIALIZED);
2N/A }
2N/A
2N/A soft_find_objects_final(session_p);
2N/A
2N/A /* decrement the session count, and release the lock */
2N/A SES_REFRELE(session_p, lock_held);
2N/A return (rv);
2N/A}