michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "ckdbm.h" michael@0: michael@0: static CK_RV michael@0: nss_dbm_mdSlot_Initialize michael@0: ( michael@0: NSSCKMDSlot *mdSlot, michael@0: NSSCKFWSlot *fwSlot, michael@0: NSSCKMDInstance *mdInstance, michael@0: NSSCKFWInstance *fwInstance michael@0: ) michael@0: { michael@0: nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc; michael@0: nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc; michael@0: CK_RV rv = CKR_OK; michael@0: michael@0: slot->token_db = nss_dbm_db_open(instance->arena, fwInstance, slot->filename, michael@0: slot->flags, &rv); michael@0: if( (nss_dbm_db_t *)NULL == slot->token_db ) { michael@0: if( CKR_TOKEN_NOT_PRESENT == rv ) { michael@0: /* This is not an error-- just means "the token isn't there" */ michael@0: rv = CKR_OK; michael@0: } michael@0: } michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: static void michael@0: nss_dbm_mdSlot_Destroy michael@0: ( michael@0: NSSCKMDSlot *mdSlot, michael@0: NSSCKFWSlot *fwSlot, michael@0: NSSCKMDInstance *mdInstance, michael@0: NSSCKFWInstance *fwInstance michael@0: ) michael@0: { michael@0: nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc; michael@0: michael@0: if( (nss_dbm_db_t *)NULL != slot->token_db ) { michael@0: nss_dbm_db_close(slot->token_db); michael@0: slot->token_db = (nss_dbm_db_t *)NULL; michael@0: } michael@0: } michael@0: michael@0: static NSSUTF8 * michael@0: nss_dbm_mdSlot_GetSlotDescription michael@0: ( michael@0: NSSCKMDSlot *mdSlot, michael@0: NSSCKFWSlot *fwSlot, michael@0: NSSCKMDInstance *mdInstance, michael@0: NSSCKFWInstance *fwInstance, michael@0: CK_RV *pError michael@0: ) michael@0: { michael@0: return "Database"; michael@0: } michael@0: michael@0: static NSSUTF8 * michael@0: nss_dbm_mdSlot_GetManufacturerID michael@0: ( michael@0: NSSCKMDSlot *mdSlot, michael@0: NSSCKFWSlot *fwSlot, michael@0: NSSCKMDInstance *mdInstance, michael@0: NSSCKFWInstance *fwInstance, michael@0: CK_RV *pError michael@0: ) michael@0: { michael@0: return "Berkeley"; michael@0: } michael@0: michael@0: static CK_BBOOL michael@0: nss_dbm_mdSlot_GetTokenPresent michael@0: ( michael@0: NSSCKMDSlot *mdSlot, michael@0: NSSCKFWSlot *fwSlot, michael@0: NSSCKMDInstance *mdInstance, michael@0: NSSCKFWInstance *fwInstance michael@0: ) michael@0: { michael@0: nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc; michael@0: michael@0: if( (nss_dbm_db_t *)NULL == slot->token_db ) { michael@0: return CK_FALSE; michael@0: } else { michael@0: return CK_TRUE; michael@0: } michael@0: } michael@0: michael@0: static CK_BBOOL michael@0: nss_dbm_mdSlot_GetRemovableDevice michael@0: ( michael@0: NSSCKMDSlot *mdSlot, michael@0: NSSCKFWSlot *fwSlot, michael@0: NSSCKMDInstance *mdInstance, michael@0: NSSCKFWInstance *fwInstance michael@0: ) michael@0: { michael@0: /* michael@0: * Well, this supports "tokens" (databases) that aren't there, so in michael@0: * that sense they're removable. It'd be nice to handle databases michael@0: * that suddenly disappear (NFS-mounted home directories and network michael@0: * errors, for instance) but that's a harder problem. We'll say michael@0: * we support removable devices, badly. michael@0: */ michael@0: michael@0: return CK_TRUE; michael@0: } michael@0: michael@0: /* nss_dbm_mdSlot_GetHardwareSlot defaults to CK_FALSE */ michael@0: /* michael@0: * nss_dbm_mdSlot_GetHardwareVersion michael@0: * nss_dbm_mdSlot_GetFirmwareVersion michael@0: * michael@0: * These are kinda fuzzy concepts here. I suppose we could return the michael@0: * Berkeley DB version for one of them, if we had an actual number we michael@0: * were confident in. But mcom's "dbm" has been hacked enough that I michael@0: * don't really know from what "real" version it stems.. michael@0: */ michael@0: michael@0: static NSSCKMDToken * michael@0: nss_dbm_mdSlot_GetToken michael@0: ( michael@0: NSSCKMDSlot *mdSlot, michael@0: NSSCKFWSlot *fwSlot, michael@0: NSSCKMDInstance *mdInstance, michael@0: NSSCKFWInstance *fwInstance, michael@0: CK_RV *pError michael@0: ) michael@0: { michael@0: nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc; michael@0: return nss_dbm_mdToken_factory(slot, pError); michael@0: } michael@0: michael@0: NSS_IMPLEMENT NSSCKMDSlot * michael@0: nss_dbm_mdSlot_factory michael@0: ( michael@0: nss_dbm_instance_t *instance, michael@0: char *filename, michael@0: int flags, michael@0: CK_RV *pError michael@0: ) michael@0: { michael@0: nss_dbm_slot_t *slot; michael@0: NSSCKMDSlot *rv; michael@0: michael@0: slot = nss_ZNEW(instance->arena, nss_dbm_slot_t); michael@0: if( (nss_dbm_slot_t *)NULL == slot ) { michael@0: *pError = CKR_HOST_MEMORY; michael@0: return (NSSCKMDSlot *)NULL; michael@0: } michael@0: michael@0: slot->instance = instance; michael@0: slot->filename = filename; michael@0: slot->flags = flags; michael@0: slot->token_db = (nss_dbm_db_t *)NULL; michael@0: michael@0: rv = nss_ZNEW(instance->arena, NSSCKMDSlot); michael@0: if( (NSSCKMDSlot *)NULL == rv ) { michael@0: *pError = CKR_HOST_MEMORY; michael@0: return (NSSCKMDSlot *)NULL; michael@0: } michael@0: michael@0: rv->etc = (void *)slot; michael@0: rv->Initialize = nss_dbm_mdSlot_Initialize; michael@0: rv->Destroy = nss_dbm_mdSlot_Destroy; michael@0: rv->GetSlotDescription = nss_dbm_mdSlot_GetSlotDescription; michael@0: rv->GetManufacturerID = nss_dbm_mdSlot_GetManufacturerID; michael@0: rv->GetTokenPresent = nss_dbm_mdSlot_GetTokenPresent; michael@0: rv->GetRemovableDevice = nss_dbm_mdSlot_GetRemovableDevice; michael@0: /* GetHardwareSlot */ michael@0: /* GetHardwareVersion */ michael@0: /* GetFirmwareVersion */ michael@0: rv->GetToken = nss_dbm_mdSlot_GetToken; michael@0: rv->null = (void *)NULL; michael@0: michael@0: return rv; michael@0: }