pkcs11Slottable.c revision d288ba7491829a622697c947c3f1a30aec18c133
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <dlfcn.h>
#include <stdlib.h>
#include <pthread.h>
#include <strings.h>
#include <security/cryptoki.h>
#include "pkcs11Global.h"
#include "pkcs11Slot.h"
#include "metaGlobal.h"
/*
* pkcs11_slottable_initialize initizializes the global slottable.
* This slottable will contain information about the plugged in
* slots, including their mapped slotID. This function should only
* be called by C_Intialize.
*/
return (CKR_HOST_MEMORY);
stmp->st_cur_size = 0;
return (CKR_FUNCTION_FAILED);
}
/* Set up for possible threads later */
stmp->st_event_slot = 0;
stmp->st_thr_count = 0;
return (CKR_OK);
}
/*
* pkcs11_slottable_increase should only be called from C_Initialize().
* It is called after the first call to C_GetSlotList() and is used to
* increase the size of the slottable, as needed, to contain the next
* set of slots that C_Initialize() is currently mapping into the framework.
*/
/* Add 1 to cover space for the metaslot */
/* Check to see if we already have enough space */
return (CKR_OK);
}
return (CKR_HOST_MEMORY);
}
return (CKR_OK);
}
/*
* pkcs11_slot_allocate should only be called from C_Initialize().
* We won't know if the metaslot will be used until after all of
* the other slots have been allocated.
*/
return (CKR_HOST_MEMORY);
/* Initialize this slot's mutex */
return (CKR_FUNCTION_FAILED);
}
return (CKR_OK);
}
/*
* pkcs11_slottable_delete should only be called by C_Finalize(),
* or by C_Initialize() in error conditions.
*/
ulong_t i;
/*
* For the first slot from this provider, do
* extra cleanup.
*/
if (prov_id != last_prov_id) {
(void) pthread_cancel
}
/*
* Only call C_Finalize of plug-in if we
* get here from an explicit C_Finalize
* call from an application. Otherwise,
* there is a risk that the application may
* have directly dlopened this provider and
* we could interrupt their work. Plug-ins
* should have their own _fini function to
* clean up when they are no longer referenced.
*/
(!fini_called)) {
(void) cur_slot->
}
/*
* Each provider maintains one disabled
* mechanism list for each of its slots to use.
*/
}
}
/*
* Cleanup the session list. This must
* happen after the mutext is unlocked
* because session_delete tries to lock it
* again.
*/
}
}
return (CKR_OK);
}
/*
* pkcs11_is_valid_slot verifies that the slot ID passed to the
* framework is valid.
*/
return (CKR_SLOT_ID_INVALID);
return (CKR_OK);
} else {
return (CKR_SLOT_ID_INVALID);
}
}
/*
* pkcs11_validate_and_convert_slotid verifies whether the slot ID
* passed to the framework is valid, and convert it to the
* true slot ID maintained in the framework data structures
* accordingly.
*
* This is necessary because when metaslot is enabled, the slot
* providing persistent object storage is "hidden".
*
* The real ID is returned in the "real_slot_id" argument regardless conversion
* is done or not.
*/
if (!metaslot_enabled) {
*real_slot_id = slot_id;
} else {
/* need to do conversion */
if (slot_id >= metaslot_keystore_slotid) {
} else {
*real_slot_id = slot_id;
}
}
return (pkcs11_is_valid_slot(*real_slot_id));
}