metaSlotManager.c revision 94f411eba162a20a3c25d34447c4edb85737f4c3
1472N/A * The contents of this file are subject to the terms of the 0N/A * Common Development and Distribution License (the "License"). 0N/A * You may not use this file except in compliance with the License. 0N/A * See the License for the specific language governing permissions 0N/A * and limitations under the License. 0N/A * When distributing Covered Code, include this CDDL HEADER in each 0N/A * If applicable, add the following below this CDDL HEADER, with the 0N/A * fields enclosed by brackets "[]" replaced with your own identifying 0N/A * information: Portions Copyright [yyyy] [name of copyright owner] 1472N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 1472N/A * Use is subject to license terms. 0N/A#
pragma ident "%Z%%M% %I% %E% SMI" 0N/A * Functions for dealing with provider sessions 0N/A * This is just a **WILD** guess for the maximum idle sessions to 0N/A * keep for each slot. This number should probably be adjusted 0N/A * when there's more data from actual application use 0N/A * The following 5 variables are initialized at the time metaslot 0N/A * is initialized. They are not modified after they are initialized * During initialization time, they are protected by the "initmutex" /* protects the "metaslotLoggedIn" variable */ * meta_slotManager_initialize * Called from C_Initialize. Allocates and initializes the storage needed /* Initialize the static variables */ * Count the number of slots in the framework. * We start at ((slottable->st_first) + 1) instead of * slottable->st_first because when we are here, metaslot is * enabled, and st_first is always metaslot, which doesn't * This shouldn't happen, because there should at least * be 1 other slot besides metaslot. * Store the slot IDs. Adjust for the fact that the first slot is * actually us (metaslot). * meta_slotManager_finalize * Called from C_Finalize. Deallocates any storage held by the slot manager. /* If no slots to free, return */ * No need to lock pool, we assume all meta sessions are closed. * Close all sessions in the idle and persist list. * The active list is empty. It doesn't need to be checked. * The slotobjects associated with the session should have * been closed when the metaobjects were closed. Thus, no * need to do anything here. * meta_slotManager_find_object_token() * Called from meta_Initialize. Searches for the "object token," which is used * for storing token objects and loging into. * We do the search using the following algorithm. * If either ${METASLOT_OBJECTSTORE_SLOT} or ${METASLOT_OBJECTSTORE_TOKEN} * environment variable is defined, the value of the defined variable(s) * will be used for the match. All token and slot values defined system-wide * If neither variables above are defined, the system-wide values defined * If neither environment variables or system-wide values are defined, * or if none of the existing slots/tokens match the defined * values, the first slot after metaslot will be used as the default. * pad slot description from user/system configuration * The PKCS#11 strings are not null-terminated, so, * we just compare SLOT_DESCRIPTION_SIZE bytes * pad slot description from user/system configuration * The PKCS#11 strings are not null-terminated. * So, just compare TOKEN_LABEL_SIZE bytes * Currently this is the only time that * the write_protected state is set, and * it is never cleared. The token could * clear (or set!) this flag later on. * We might want to adjust the state * of metaslot, but there's know way to know * when a token changes this flag. * if slot and/or token is not defined for the keystore, * just use the first available slot as keystore * This is only used internally, and so the slotnum should always * Find a session in the given list that matches the specified flags. * If such a session is found, it will be removed from the list, and * returned to the caller. If such a session is not found, will * Call to get a session with a specific slot/token. * NOTE - We assume the slot allows an unlimited number of sessions. We * could look at what's reported in the token info, but that information is * not always set. It's also unclear when we should (A) wait for one to become * available, (B) skip the slot for now or (C) return a fatal error. The * extra complexity is not worth it. * Try to reuse an existing session. /* initialize slotsession */ /* Retry with a RO session. */ /* Insert session into active list */ * meta_release_slot_session * Call to release a session obtained via meta_get_slot_session() /* Note that the active_list must have >= 1 entry (this session) */ * If the session has session objects, we need to retain it. Also * retain it if it's the only session holding login state (or handles * to public token objects) /* remove from active list */ /* insert into persist list */ /* insert into idle list */ * Returns whether metaslot has directly logged in