17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*d3a28a55Sdinak  * Common Development and Distribution License (the "License").
6*d3a28a55Sdinak  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d3a28a55Sdinak  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Slot and Token Management functions
287c478bd9Sstevel@tonic-gate  * (as defined in PKCS#11 spec section 11.5)
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <stdio.h>
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <string.h>
347c478bd9Sstevel@tonic-gate #include "metaGlobal.h"
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate extern CK_ULONG num_meta_sessions;
377c478bd9Sstevel@tonic-gate extern CK_ULONG num_rw_meta_sessions;
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * meta_GetSlotList
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * For the metaslot, this is a trivial function. The metaslot module,
437c478bd9Sstevel@tonic-gate  * by defination, provides exactly one slot. The token is always present.
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * This function is actually not called.
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate /* ARGSUSED */
487c478bd9Sstevel@tonic-gate CK_RV
meta_GetSlotList(CK_BBOOL tokenPresent,CK_SLOT_ID_PTR pSlotList,CK_ULONG_PTR pulCount)497c478bd9Sstevel@tonic-gate meta_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList,
507c478bd9Sstevel@tonic-gate     CK_ULONG_PTR pulCount)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	CK_RV rv;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	if (pulCount == NULL)
557c478bd9Sstevel@tonic-gate 		return (CKR_ARGUMENTS_BAD);
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	if (pSlotList == NULL) {
587c478bd9Sstevel@tonic-gate 		*pulCount = 1;
597c478bd9Sstevel@tonic-gate 		return (CKR_OK);
607c478bd9Sstevel@tonic-gate 	}
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	if (*pulCount < 1) {
637c478bd9Sstevel@tonic-gate 		rv = CKR_BUFFER_TOO_SMALL;
647c478bd9Sstevel@tonic-gate 	} else {
657c478bd9Sstevel@tonic-gate 		pSlotList[0] = METASLOT_SLOTID;
667c478bd9Sstevel@tonic-gate 		rv = CKR_OK;
677c478bd9Sstevel@tonic-gate 	}
687c478bd9Sstevel@tonic-gate 	*pulCount = 1;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	return (rv);
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * meta_GetSlotInfo
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * Returns basic information about the metaslot.
787c478bd9Sstevel@tonic-gate  *
797c478bd9Sstevel@tonic-gate  * The slotID argument is ignored.
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate /*ARGSUSED*/
827c478bd9Sstevel@tonic-gate CK_RV
meta_GetSlotInfo(CK_SLOT_ID slotID,CK_SLOT_INFO_PTR pInfo)837c478bd9Sstevel@tonic-gate meta_GetSlotInfo(CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo)
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate 	CK_SLOT_INFO slotinfo;
867c478bd9Sstevel@tonic-gate 	CK_SLOT_ID true_id;
877c478bd9Sstevel@tonic-gate 	CK_RV rv;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	if (!metaslot_enabled) {
907c478bd9Sstevel@tonic-gate 		return (CKR_SLOT_ID_INVALID);
917c478bd9Sstevel@tonic-gate 	}
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	if (pInfo == NULL) {
947c478bd9Sstevel@tonic-gate 		return (CKR_ARGUMENTS_BAD);
957c478bd9Sstevel@tonic-gate 	}
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	/* Provide information about the slot in the provided buffer */
987c478bd9Sstevel@tonic-gate 	(void) memcpy(pInfo->slotDescription, METASLOT_SLOT_DESCRIPTION, 64);
997c478bd9Sstevel@tonic-gate 	(void) memcpy(pInfo->manufacturerID, METASLOT_MANUFACTURER_ID, 32);
1007c478bd9Sstevel@tonic-gate 	pInfo->hardwareVersion.major = METASLOT_HARDWARE_VERSION_MAJOR;
1017c478bd9Sstevel@tonic-gate 	pInfo->hardwareVersion.minor = METASLOT_HARDWARE_VERSION_MINOR;
1027c478bd9Sstevel@tonic-gate 	pInfo->firmwareVersion.major = METASLOT_FIRMWARE_VERSION_MAJOR;
1037c478bd9Sstevel@tonic-gate 	pInfo->firmwareVersion.minor = METASLOT_FIRMWARE_VERSION_MINOR;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	/* Find out token is present in the underlying keystore */
1067c478bd9Sstevel@tonic-gate 	true_id = TRUEID(metaslot_keystore_slotid);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(metaslot_keystore_slotid)->C_GetSlotInfo(true_id,
1097c478bd9Sstevel@tonic-gate 	    &slotinfo);
1107c478bd9Sstevel@tonic-gate 	if ((rv == CKR_OK) && (slotinfo.flags & CKF_TOKEN_PRESENT)) {
1117c478bd9Sstevel@tonic-gate 		/*
1127c478bd9Sstevel@tonic-gate 		 * store the token present flag if it is successfully
1137c478bd9Sstevel@tonic-gate 		 * received from the keystore slot.
1147c478bd9Sstevel@tonic-gate 		 * If not, this flag will not be set.
1157c478bd9Sstevel@tonic-gate 		 */
1167c478bd9Sstevel@tonic-gate 		pInfo->flags = CKF_TOKEN_PRESENT;
1177c478bd9Sstevel@tonic-gate 	}
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	return (CKR_OK);
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * meta_GetTokenInfo
1257c478bd9Sstevel@tonic-gate  *
1267c478bd9Sstevel@tonic-gate  * Returns basic information about the metaslot "token."
1277c478bd9Sstevel@tonic-gate  *
1287c478bd9Sstevel@tonic-gate  * The slotID argument is ignored.
1297c478bd9Sstevel@tonic-gate  *
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1327c478bd9Sstevel@tonic-gate CK_RV
meta_GetTokenInfo(CK_SLOT_ID slotID,CK_TOKEN_INFO_PTR pInfo)1337c478bd9Sstevel@tonic-gate meta_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
1347c478bd9Sstevel@tonic-gate {
1357c478bd9Sstevel@tonic-gate 	CK_RV rv;
1367c478bd9Sstevel@tonic-gate 	CK_TOKEN_INFO metainfo;
1377c478bd9Sstevel@tonic-gate 	CK_SLOT_ID true_id;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	if (!metaslot_enabled) {
1407c478bd9Sstevel@tonic-gate 		return (CKR_SLOT_ID_INVALID);
1417c478bd9Sstevel@tonic-gate 	}
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	if (pInfo == NULL)
1447c478bd9Sstevel@tonic-gate 		return (CKR_ARGUMENTS_BAD);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	true_id = TRUEID(metaslot_keystore_slotid);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(metaslot_keystore_slotid)->C_GetTokenInfo(true_id,
1497c478bd9Sstevel@tonic-gate 	    &metainfo);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	/*
1527c478bd9Sstevel@tonic-gate 	 * If we could not get information about the object token, use
1537c478bd9Sstevel@tonic-gate 	 * default values. This allows metaslot to be used even if there
1547c478bd9Sstevel@tonic-gate 	 * are problems with the object token (eg, it's not present).
1557c478bd9Sstevel@tonic-gate 	 */
1567c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
1577c478bd9Sstevel@tonic-gate 		metainfo.ulTotalPublicMemory	= CK_UNAVAILABLE_INFORMATION;
1587c478bd9Sstevel@tonic-gate 		metainfo.ulFreePublicMemory	= CK_UNAVAILABLE_INFORMATION;
1597c478bd9Sstevel@tonic-gate 		metainfo.ulTotalPrivateMemory	= CK_UNAVAILABLE_INFORMATION;
1607c478bd9Sstevel@tonic-gate 		metainfo.ulFreePrivateMemory	= CK_UNAVAILABLE_INFORMATION;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 		metainfo.flags = CKF_WRITE_PROTECTED;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 		metainfo.ulMaxPinLen = 0;
1657c478bd9Sstevel@tonic-gate 		metainfo.ulMinPinLen = 0;
1667c478bd9Sstevel@tonic-gate 		metainfo.hardwareVersion.major =
1677c478bd9Sstevel@tonic-gate 		    METASLOT_HARDWARE_VERSION_MAJOR;
1687c478bd9Sstevel@tonic-gate 		metainfo.hardwareVersion.minor =
1697c478bd9Sstevel@tonic-gate 		    METASLOT_HARDWARE_VERSION_MINOR;
1707c478bd9Sstevel@tonic-gate 		metainfo.firmwareVersion.major =
1717c478bd9Sstevel@tonic-gate 		    METASLOT_FIRMWARE_VERSION_MAJOR;
1727c478bd9Sstevel@tonic-gate 		metainfo.firmwareVersion.minor =
1737c478bd9Sstevel@tonic-gate 		    METASLOT_FIRMWARE_VERSION_MINOR;
1747c478bd9Sstevel@tonic-gate 	}
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	/*
1777c478bd9Sstevel@tonic-gate 	 * Override some values that the object token may have set. They
1787c478bd9Sstevel@tonic-gate 	 * can be inappropriate/misleading when used in the context of
1797c478bd9Sstevel@tonic-gate 	 * metaslot.
1807c478bd9Sstevel@tonic-gate 	 */
1817c478bd9Sstevel@tonic-gate 	(void) memcpy(metainfo.label, METASLOT_TOKEN_LABEL, 32);
1827c478bd9Sstevel@tonic-gate 	(void) memcpy(metainfo.manufacturerID,
1837c478bd9Sstevel@tonic-gate 	    METASLOT_MANUFACTURER_ID, 32);
1847c478bd9Sstevel@tonic-gate 	(void) memcpy(metainfo.model, METASLOT_TOKEN_MODEL, 16);
1857c478bd9Sstevel@tonic-gate 	(void) memset(metainfo.serialNumber, ' ', 16);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	metainfo.ulMaxSessionCount	= CK_EFFECTIVELY_INFINITE;
1887c478bd9Sstevel@tonic-gate 	metainfo.ulSessionCount		= num_meta_sessions;
1897c478bd9Sstevel@tonic-gate 	metainfo.ulMaxRwSessionCount	= CK_EFFECTIVELY_INFINITE;
1907c478bd9Sstevel@tonic-gate 	metainfo.ulRwSessionCount	= num_rw_meta_sessions;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	metainfo.flags |= CKF_RNG;
1937c478bd9Sstevel@tonic-gate 	metainfo.flags &= ~CKF_RESTORE_KEY_NOT_NEEDED;
1947c478bd9Sstevel@tonic-gate 	metainfo.flags |= CKF_TOKEN_INITIALIZED;
1957c478bd9Sstevel@tonic-gate 	metainfo.flags &= ~CKF_SECONDARY_AUTHENTICATION;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	/* Clear the time field if the token does not have a clock. */
1987c478bd9Sstevel@tonic-gate 	if (!(metainfo.flags & CKF_CLOCK_ON_TOKEN))
1997c478bd9Sstevel@tonic-gate 		(void) memset(metainfo.utcTime, ' ', 16);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	*pInfo = metainfo;
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	return (CKR_OK);
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * meta_WaitForSlotEvent
2097c478bd9Sstevel@tonic-gate  *
2107c478bd9Sstevel@tonic-gate  * The metaslot never generates events, so this function doesn't do anything
2117c478bd9Sstevel@tonic-gate  * useful. We do not pass on provider events because we want to hide details
2127c478bd9Sstevel@tonic-gate  * of the providers.
2137c478bd9Sstevel@tonic-gate  *
2147c478bd9Sstevel@tonic-gate  * If CKF_DONT_BLOCK flag is turned on, CKR_NO_EVENT will be return.
2157c478bd9Sstevel@tonic-gate  * Otherwise, return CKR_FUNCTION_FAILED.
2167c478bd9Sstevel@tonic-gate  *
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate /* ARGSUSED */
2197c478bd9Sstevel@tonic-gate CK_RV
meta_WaitForSlotEvent(CK_FLAGS flags,CK_SLOT_ID_PTR pSlot,CK_VOID_PTR pReserved)2207c478bd9Sstevel@tonic-gate meta_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot,
2217c478bd9Sstevel@tonic-gate     CK_VOID_PTR pReserved)
2227c478bd9Sstevel@tonic-gate {
2237c478bd9Sstevel@tonic-gate 	if (flags & CKF_DONT_BLOCK) {
2247c478bd9Sstevel@tonic-gate 		return (CKR_NO_EVENT);
2257c478bd9Sstevel@tonic-gate 	} else {
2267c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
2277c478bd9Sstevel@tonic-gate 	}
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate  * meta_GetMechanismList
2337c478bd9Sstevel@tonic-gate  *
2347c478bd9Sstevel@tonic-gate  * The slotID argument is not used.
2357c478bd9Sstevel@tonic-gate  *
2367c478bd9Sstevel@tonic-gate  */
2377c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2387c478bd9Sstevel@tonic-gate CK_RV
meta_GetMechanismList(CK_SLOT_ID slotID,CK_MECHANISM_TYPE_PTR pMechanismList,CK_ULONG_PTR pulCount)2397c478bd9Sstevel@tonic-gate meta_GetMechanismList(CK_SLOT_ID slotID, CK_MECHANISM_TYPE_PTR pMechanismList,
2407c478bd9Sstevel@tonic-gate     CK_ULONG_PTR pulCount)
2417c478bd9Sstevel@tonic-gate {
2427c478bd9Sstevel@tonic-gate 	CK_RV rv;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	if (!metaslot_enabled) {
2457c478bd9Sstevel@tonic-gate 		return (CKR_SLOT_ID_INVALID);
2467c478bd9Sstevel@tonic-gate 	}
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	if (pulCount == NULL)
2497c478bd9Sstevel@tonic-gate 		return (CKR_ARGUMENTS_BAD);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	rv = meta_mechManager_get_mechs(pMechanismList, pulCount);
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	if ((rv == CKR_BUFFER_TOO_SMALL) && (pMechanismList == NULL)) {
2547c478bd9Sstevel@tonic-gate 		/*
2557c478bd9Sstevel@tonic-gate 		 * if pMechanismList is not provided, just need to
2567c478bd9Sstevel@tonic-gate 		 * return count
2577c478bd9Sstevel@tonic-gate 		 */
2587c478bd9Sstevel@tonic-gate 		rv = CKR_OK;
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 	return (rv);
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate /*
2657c478bd9Sstevel@tonic-gate  * meta_GetMechanismInfo
2667c478bd9Sstevel@tonic-gate  *
2677c478bd9Sstevel@tonic-gate  * The slotID argument is not used.
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2707c478bd9Sstevel@tonic-gate CK_RV
meta_GetMechanismInfo(CK_SLOT_ID slotID,CK_MECHANISM_TYPE type,CK_MECHANISM_INFO_PTR pInfo)2717c478bd9Sstevel@tonic-gate meta_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type,
2727c478bd9Sstevel@tonic-gate     CK_MECHANISM_INFO_PTR pInfo)
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate 	CK_RV rv;
2757c478bd9Sstevel@tonic-gate 	mechinfo_t **slots = NULL;
2767c478bd9Sstevel@tonic-gate 	unsigned long i, slotCount = 0;
2777c478bd9Sstevel@tonic-gate 	mech_support_info_t  mech_support_info;
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	if (!metaslot_enabled) {
2807c478bd9Sstevel@tonic-gate 		return (CKR_SLOT_ID_INVALID);
2817c478bd9Sstevel@tonic-gate 	}
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	if (pInfo == NULL) {
2847c478bd9Sstevel@tonic-gate 		return (CKR_ARGUMENTS_BAD);
2857c478bd9Sstevel@tonic-gate 	}
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	mech_support_info.supporting_slots =
2887c478bd9Sstevel@tonic-gate 	    malloc(meta_slotManager_get_slotcount() * sizeof (mechinfo_t *));
2897c478bd9Sstevel@tonic-gate 	if (mech_support_info.supporting_slots == NULL) {
2907c478bd9Sstevel@tonic-gate 		return (CKR_HOST_MEMORY);
2917c478bd9Sstevel@tonic-gate 	}
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	mech_support_info.mech = type;
2947c478bd9Sstevel@tonic-gate 
295*d3a28a55Sdinak 	rv = meta_mechManager_get_slots(&mech_support_info, TRUE, NULL);
2967c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
2977c478bd9Sstevel@tonic-gate 		free(mech_support_info.supporting_slots);
2987c478bd9Sstevel@tonic-gate 		return (rv);
2997c478bd9Sstevel@tonic-gate 	}
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	slotCount = mech_support_info.num_supporting_slots;
3027c478bd9Sstevel@tonic-gate 	slots = mech_support_info.supporting_slots;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	/* Merge mechanism info from all slots. */
3057c478bd9Sstevel@tonic-gate 	(void) memcpy(pInfo, &(slots[0]->mechanism_info),
3067c478bd9Sstevel@tonic-gate 	    sizeof (CK_MECHANISM_INFO));
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	/* no need to look at index 0, since that's what we started with */
3097c478bd9Sstevel@tonic-gate 	for (i = 1; i < slotCount; i++) {
3107c478bd9Sstevel@tonic-gate 		CK_ULONG thisValue;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 		/* MinKeySize should be smallest of all slots. */
3137c478bd9Sstevel@tonic-gate 		thisValue = slots[i]->mechanism_info.ulMinKeySize;
3147c478bd9Sstevel@tonic-gate 		if (thisValue < pInfo->ulMinKeySize) {
3157c478bd9Sstevel@tonic-gate 			pInfo->ulMinKeySize = thisValue;
3167c478bd9Sstevel@tonic-gate 		}
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 		/* MaxKeySize should be largest of all slots. */
3197c478bd9Sstevel@tonic-gate 		thisValue = slots[i]->mechanism_info.ulMaxKeySize;
3207c478bd9Sstevel@tonic-gate 		if (thisValue > pInfo->ulMaxKeySize) {
3217c478bd9Sstevel@tonic-gate 			pInfo->ulMaxKeySize = thisValue;
3227c478bd9Sstevel@tonic-gate 		}
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 		pInfo->flags |= slots[i]->mechanism_info.flags;
3257c478bd9Sstevel@tonic-gate 	}
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	/* Clear the CKF_HW flag. We might select a software provider later. */
3287c478bd9Sstevel@tonic-gate 	pInfo->flags &= ~CKF_HW;
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	/* Clear the extenstion flag. Spec says is should never even be set. */
3317c478bd9Sstevel@tonic-gate 	pInfo->flags &= ~CKF_EXTENSION;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	free(mech_support_info.supporting_slots);
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	return (CKR_OK);
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate /*
3407c478bd9Sstevel@tonic-gate  * meta_InitToken
3417c478bd9Sstevel@tonic-gate  *
3427c478bd9Sstevel@tonic-gate  * Not supported. The metaslot "token" is always initialized. The token object
3437c478bd9Sstevel@tonic-gate  * token must already be initialized. Other vendors don't seem to support
3447c478bd9Sstevel@tonic-gate  * this anyway.
3457c478bd9Sstevel@tonic-gate  */
3467c478bd9Sstevel@tonic-gate /* ARGSUSED */
3477c478bd9Sstevel@tonic-gate CK_RV
meta_InitToken(CK_SLOT_ID slotID,CK_UTF8CHAR_PTR pPin,CK_ULONG ulPinLen,CK_UTF8CHAR_PTR pLabel)3487c478bd9Sstevel@tonic-gate meta_InitToken(CK_SLOT_ID slotID, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen,
3497c478bd9Sstevel@tonic-gate     CK_UTF8CHAR_PTR pLabel)
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate 	return (CKR_FUNCTION_NOT_SUPPORTED);
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate /*
3567c478bd9Sstevel@tonic-gate  * meta_InitPIN
3577c478bd9Sstevel@tonic-gate  *
3587c478bd9Sstevel@tonic-gate  * Not supported. Same reason as C_InitToken.
3597c478bd9Sstevel@tonic-gate  */
3607c478bd9Sstevel@tonic-gate /* ARGSUSED */
3617c478bd9Sstevel@tonic-gate CK_RV
meta_InitPIN(CK_SESSION_HANDLE hSession,CK_UTF8CHAR_PTR pPin,CK_ULONG ulPinLen)3627c478bd9Sstevel@tonic-gate meta_InitPIN(CK_SESSION_HANDLE hSession,
3637c478bd9Sstevel@tonic-gate     CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen)
3647c478bd9Sstevel@tonic-gate {
3657c478bd9Sstevel@tonic-gate 	return (CKR_FUNCTION_NOT_SUPPORTED);
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate  * meta_SetPIN
3717c478bd9Sstevel@tonic-gate  *
3727c478bd9Sstevel@tonic-gate  * This is basically just a pass-thru to the object token. No need to
3737c478bd9Sstevel@tonic-gate  * even check the arguments, since we don't use them.
3747c478bd9Sstevel@tonic-gate  */
3757c478bd9Sstevel@tonic-gate CK_RV
meta_SetPIN(CK_SESSION_HANDLE hSession,CK_UTF8CHAR_PTR pOldPin,CK_ULONG ulOldPinLen,CK_UTF8CHAR_PTR pNewPin,CK_ULONG ulNewPinLen)3767c478bd9Sstevel@tonic-gate meta_SetPIN(CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin,
3777c478bd9Sstevel@tonic-gate     CK_ULONG ulOldPinLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewPinLen)
3787c478bd9Sstevel@tonic-gate {
3797c478bd9Sstevel@tonic-gate 	CK_RV rv;
3807c478bd9Sstevel@tonic-gate 	meta_session_t *session;
3817c478bd9Sstevel@tonic-gate 	slot_session_t *slot_session;
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 	rv = meta_handle2session(hSession, &session);
3847c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK)
3857c478bd9Sstevel@tonic-gate 		return (rv);
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 	if (IS_READ_ONLY_SESSION(session->session_flags)) {
3887c478bd9Sstevel@tonic-gate 		REFRELEASE(session);
3897c478bd9Sstevel@tonic-gate 		return (CKR_SESSION_READ_ONLY);
3907c478bd9Sstevel@tonic-gate 	}
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	rv = meta_get_slot_session(get_keystore_slotnum(), &slot_session,
3937c478bd9Sstevel@tonic-gate 	    session->session_flags);
3947c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
3957c478bd9Sstevel@tonic-gate 		REFRELEASE(session);
3967c478bd9Sstevel@tonic-gate 		return (rv);
3977c478bd9Sstevel@tonic-gate 	}
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(slot_session->fw_st_id)->C_SetPIN(slot_session->hSession,
4007c478bd9Sstevel@tonic-gate 	    pOldPin, ulOldPinLen, pNewPin, ulNewPinLen);
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	meta_release_slot_session(slot_session);
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 	REFRELEASE(session);
4057c478bd9Sstevel@tonic-gate 	return (rv);
4067c478bd9Sstevel@tonic-gate }
407