kernelSession.c revision 01223cbad606a31eb5d446226266d8bcde160fc9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <pthread.h>
#include <errno.h>
#include <security/cryptoki.h>
#include "kernelGlobal.h"
#include "kernelSession.h"
#include "kernelSlot.h"
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* For legacy reasons, the CKF_SERIAL_SESSION bit must always
* be set.
*/
if (!(flags & CKF_SERIAL_SESSION))
return (CKR_SESSION_PARALLEL_NOT_SUPPORTED);
return (CKR_ARGUMENTS_BAD);
if (slotID >= slot_count) {
return (CKR_SLOT_ID_INVALID);
}
/*
* Acquire the slot lock to protect sl_state and sl_sess_list.
* These two fields need to be protected atomically, even though
* "sl_sess_list" is updated in kernel_add_session().
*/
/* If SO is logged in the slot, only the RW session is allowed. */
return (CKR_SESSION_READ_WRITE_SO_EXISTS);
}
/* Create a new session */
return (rv);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/*
* Set SESSION_IS_CLOSING flag so any access to this
* session will be rejected.
*/
return (CKR_SESSION_CLOSED);
}
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
/*
* Delete a session by calling kernel_delete_session() with
* a session pointer and two boolean arguments. The 3rd argument
* boolean value FALSE indicates that the caller does not
* hold the slot lock. The 4th argument boolean value B_FALSE
* indicates that we want to delete all the objects completely.
*
* kernel_delete_session() will reset SESSION_IS_CLOSING
* flag after it is done.
*/
B_FALSE);
return (rv);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/* Delete all the sessions and release the allocated resources */
return (CKR_OK);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
return (CKR_ARGUMENTS_BAD);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Provide information for the specified session */
pInfo->ulDeviceError = 0;
}
/*
* Decrement the session reference count.
*/
return (CKR_OK);
}
/*ARGSUSED*/
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
return (CKR_FUNCTION_NOT_SUPPORTED);
}
/*ARGSUSED*/
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
return (CKR_FUNCTION_NOT_SUPPORTED);
}
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
return (CKR_USER_TYPE_INVALID);
}
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Acquire the slot lock */
/* Check if the slot is logged in already */
goto clean_exit;
}
/* To login as SO, every session in this slot needs to be R/W */
while (sp) {
/*
* Need not to lock individual sessions before
* accessing their "ses_RO" and "next" fields,
* because they are always accessed under the
* slot's mutex protection.
*/
break;
}
}
if (found) {
goto clean_exit;
}
}
/* Now make the ioctl call; no need to acquire the session lock. */
break;
}
if (r < 0) {
} else {
}
/* Set the slot's session state. */
}
return (rv);
}
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Acquire the slot lock. */
/* Check if the user or SO was logged in */
goto clean_exit;
}
/* Now make the ioctl call. No need to acquire the session lock. */
break;
}
if (r < 0) {
} else {
}
goto clean_exit;
}
/*
* If this slot was logged in as USER previously, we need to clean up
* all private object wrappers in library for this slot.
*/
/* Reset the slot's session state. */
}
return (rv);
}