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) 2010, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <errno.h>
2N/A#include <security/cryptoki.h>
2N/A#include "kmsGlobal.h"
2N/A#include "kmsSlot.h"
2N/A
2N/Astatic kms_slot_t *slotinfo = NULL;
2N/A
2N/A/*
2N/A * Initialize the slotinfo record.
2N/A *
2N/A * This function is called from C_Initialize() only. Since C_Initialize()
2N/A * holds the global mutex lock, there is no need to acquire another lock
2N/A * in this routine to protect the slot table.
2N/A */
2N/ACK_RV
2N/Akms_slottable_init()
2N/A{
2N/A CK_RV rv = CKR_OK;
2N/A
2N/A /* Allocate space for the slot table */
2N/A slotinfo = calloc(KMS_SLOTS, sizeof (kms_slot_t));
2N/A if (slotinfo == NULL)
2N/A return (CKR_HOST_MEMORY);
2N/A
2N/A slotinfo->sl_sess_list = NULL;
2N/A slotinfo->sl_tobj_list = NULL;
2N/A slotinfo->sl_state = CKU_PUBLIC;
2N/A
2N/A /* Initialize this slot's mutex */
2N/A if (pthread_mutex_init(&slotinfo->sl_mutex, NULL) != 0) {
2N/A (void) free(slotinfo);
2N/A slotinfo = NULL;
2N/A return (CKR_FUNCTION_FAILED);
2N/A }
2N/A
2N/A return (rv);
2N/A}
2N/A
2N/Avoid
2N/Acleanup_slottable()
2N/A{
2N/A if (slotinfo != NULL) {
2N/A (void) pthread_mutex_destroy(&slotinfo->sl_mutex);
2N/A (void) free(slotinfo);
2N/A slotinfo = NULL;
2N/A }
2N/A}
2N/A
2N/Akms_slot_t *
2N/Aget_slotinfo()
2N/A{
2N/A return (slotinfo);
2N/A}