1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 #include <errno.h> 26 #include <security/cryptoki.h> 27 #include "kmsGlobal.h" 28 #include "kmsSlot.h" 29 30 static kms_slot_t *slotinfo = NULL; 31 32 /* 33 * Initialize the slotinfo record. 34 * 35 * This function is called from C_Initialize() only. Since C_Initialize() 36 * holds the global mutex lock, there is no need to acquire another lock 37 * in this routine to protect the slot table. 38 */ 39 CK_RV kms_slottable_init()40kms_slottable_init() 41 { 42 CK_RV rv = CKR_OK; 43 44 /* Allocate space for the slot table */ 45 slotinfo = calloc(KMS_SLOTS, sizeof (kms_slot_t)); 46 if (slotinfo == NULL) 47 return (CKR_HOST_MEMORY); 48 49 slotinfo->sl_sess_list = NULL; 50 slotinfo->sl_tobj_list = NULL; 51 slotinfo->sl_state = CKU_PUBLIC; 52 53 /* Initialize this slot's mutex */ 54 if (pthread_mutex_init(&slotinfo->sl_mutex, NULL) != 0) { 55 (void) free(slotinfo); 56 slotinfo = NULL; 57 return (CKR_FUNCTION_FAILED); 58 } 59 60 return (rv); 61 } 62 63 void cleanup_slottable()64cleanup_slottable() 65 { 66 if (slotinfo != NULL) { 67 (void) pthread_mutex_destroy(&slotinfo->sl_mutex); 68 (void) free(slotinfo); 69 slotinfo = NULL; 70 } 71 } 72 73 kms_slot_t * get_slotinfo()74get_slotinfo() 75 { 76 return (slotinfo); 77 } 78