Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "ckdbm.h" |
michael@0 | 6 | |
michael@0 | 7 | static CK_RV |
michael@0 | 8 | nss_dbm_mdSlot_Initialize |
michael@0 | 9 | ( |
michael@0 | 10 | NSSCKMDSlot *mdSlot, |
michael@0 | 11 | NSSCKFWSlot *fwSlot, |
michael@0 | 12 | NSSCKMDInstance *mdInstance, |
michael@0 | 13 | NSSCKFWInstance *fwInstance |
michael@0 | 14 | ) |
michael@0 | 15 | { |
michael@0 | 16 | nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc; |
michael@0 | 17 | nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc; |
michael@0 | 18 | CK_RV rv = CKR_OK; |
michael@0 | 19 | |
michael@0 | 20 | slot->token_db = nss_dbm_db_open(instance->arena, fwInstance, slot->filename, |
michael@0 | 21 | slot->flags, &rv); |
michael@0 | 22 | if( (nss_dbm_db_t *)NULL == slot->token_db ) { |
michael@0 | 23 | if( CKR_TOKEN_NOT_PRESENT == rv ) { |
michael@0 | 24 | /* This is not an error-- just means "the token isn't there" */ |
michael@0 | 25 | rv = CKR_OK; |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | return rv; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | static void |
michael@0 | 33 | nss_dbm_mdSlot_Destroy |
michael@0 | 34 | ( |
michael@0 | 35 | NSSCKMDSlot *mdSlot, |
michael@0 | 36 | NSSCKFWSlot *fwSlot, |
michael@0 | 37 | NSSCKMDInstance *mdInstance, |
michael@0 | 38 | NSSCKFWInstance *fwInstance |
michael@0 | 39 | ) |
michael@0 | 40 | { |
michael@0 | 41 | nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc; |
michael@0 | 42 | |
michael@0 | 43 | if( (nss_dbm_db_t *)NULL != slot->token_db ) { |
michael@0 | 44 | nss_dbm_db_close(slot->token_db); |
michael@0 | 45 | slot->token_db = (nss_dbm_db_t *)NULL; |
michael@0 | 46 | } |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | static NSSUTF8 * |
michael@0 | 50 | nss_dbm_mdSlot_GetSlotDescription |
michael@0 | 51 | ( |
michael@0 | 52 | NSSCKMDSlot *mdSlot, |
michael@0 | 53 | NSSCKFWSlot *fwSlot, |
michael@0 | 54 | NSSCKMDInstance *mdInstance, |
michael@0 | 55 | NSSCKFWInstance *fwInstance, |
michael@0 | 56 | CK_RV *pError |
michael@0 | 57 | ) |
michael@0 | 58 | { |
michael@0 | 59 | return "Database"; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | static NSSUTF8 * |
michael@0 | 63 | nss_dbm_mdSlot_GetManufacturerID |
michael@0 | 64 | ( |
michael@0 | 65 | NSSCKMDSlot *mdSlot, |
michael@0 | 66 | NSSCKFWSlot *fwSlot, |
michael@0 | 67 | NSSCKMDInstance *mdInstance, |
michael@0 | 68 | NSSCKFWInstance *fwInstance, |
michael@0 | 69 | CK_RV *pError |
michael@0 | 70 | ) |
michael@0 | 71 | { |
michael@0 | 72 | return "Berkeley"; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | static CK_BBOOL |
michael@0 | 76 | nss_dbm_mdSlot_GetTokenPresent |
michael@0 | 77 | ( |
michael@0 | 78 | NSSCKMDSlot *mdSlot, |
michael@0 | 79 | NSSCKFWSlot *fwSlot, |
michael@0 | 80 | NSSCKMDInstance *mdInstance, |
michael@0 | 81 | NSSCKFWInstance *fwInstance |
michael@0 | 82 | ) |
michael@0 | 83 | { |
michael@0 | 84 | nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc; |
michael@0 | 85 | |
michael@0 | 86 | if( (nss_dbm_db_t *)NULL == slot->token_db ) { |
michael@0 | 87 | return CK_FALSE; |
michael@0 | 88 | } else { |
michael@0 | 89 | return CK_TRUE; |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | static CK_BBOOL |
michael@0 | 94 | nss_dbm_mdSlot_GetRemovableDevice |
michael@0 | 95 | ( |
michael@0 | 96 | NSSCKMDSlot *mdSlot, |
michael@0 | 97 | NSSCKFWSlot *fwSlot, |
michael@0 | 98 | NSSCKMDInstance *mdInstance, |
michael@0 | 99 | NSSCKFWInstance *fwInstance |
michael@0 | 100 | ) |
michael@0 | 101 | { |
michael@0 | 102 | /* |
michael@0 | 103 | * Well, this supports "tokens" (databases) that aren't there, so in |
michael@0 | 104 | * that sense they're removable. It'd be nice to handle databases |
michael@0 | 105 | * that suddenly disappear (NFS-mounted home directories and network |
michael@0 | 106 | * errors, for instance) but that's a harder problem. We'll say |
michael@0 | 107 | * we support removable devices, badly. |
michael@0 | 108 | */ |
michael@0 | 109 | |
michael@0 | 110 | return CK_TRUE; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | /* nss_dbm_mdSlot_GetHardwareSlot defaults to CK_FALSE */ |
michael@0 | 114 | /* |
michael@0 | 115 | * nss_dbm_mdSlot_GetHardwareVersion |
michael@0 | 116 | * nss_dbm_mdSlot_GetFirmwareVersion |
michael@0 | 117 | * |
michael@0 | 118 | * These are kinda fuzzy concepts here. I suppose we could return the |
michael@0 | 119 | * Berkeley DB version for one of them, if we had an actual number we |
michael@0 | 120 | * were confident in. But mcom's "dbm" has been hacked enough that I |
michael@0 | 121 | * don't really know from what "real" version it stems.. |
michael@0 | 122 | */ |
michael@0 | 123 | |
michael@0 | 124 | static NSSCKMDToken * |
michael@0 | 125 | nss_dbm_mdSlot_GetToken |
michael@0 | 126 | ( |
michael@0 | 127 | NSSCKMDSlot *mdSlot, |
michael@0 | 128 | NSSCKFWSlot *fwSlot, |
michael@0 | 129 | NSSCKMDInstance *mdInstance, |
michael@0 | 130 | NSSCKFWInstance *fwInstance, |
michael@0 | 131 | CK_RV *pError |
michael@0 | 132 | ) |
michael@0 | 133 | { |
michael@0 | 134 | nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc; |
michael@0 | 135 | return nss_dbm_mdToken_factory(slot, pError); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | NSS_IMPLEMENT NSSCKMDSlot * |
michael@0 | 139 | nss_dbm_mdSlot_factory |
michael@0 | 140 | ( |
michael@0 | 141 | nss_dbm_instance_t *instance, |
michael@0 | 142 | char *filename, |
michael@0 | 143 | int flags, |
michael@0 | 144 | CK_RV *pError |
michael@0 | 145 | ) |
michael@0 | 146 | { |
michael@0 | 147 | nss_dbm_slot_t *slot; |
michael@0 | 148 | NSSCKMDSlot *rv; |
michael@0 | 149 | |
michael@0 | 150 | slot = nss_ZNEW(instance->arena, nss_dbm_slot_t); |
michael@0 | 151 | if( (nss_dbm_slot_t *)NULL == slot ) { |
michael@0 | 152 | *pError = CKR_HOST_MEMORY; |
michael@0 | 153 | return (NSSCKMDSlot *)NULL; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | slot->instance = instance; |
michael@0 | 157 | slot->filename = filename; |
michael@0 | 158 | slot->flags = flags; |
michael@0 | 159 | slot->token_db = (nss_dbm_db_t *)NULL; |
michael@0 | 160 | |
michael@0 | 161 | rv = nss_ZNEW(instance->arena, NSSCKMDSlot); |
michael@0 | 162 | if( (NSSCKMDSlot *)NULL == rv ) { |
michael@0 | 163 | *pError = CKR_HOST_MEMORY; |
michael@0 | 164 | return (NSSCKMDSlot *)NULL; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | rv->etc = (void *)slot; |
michael@0 | 168 | rv->Initialize = nss_dbm_mdSlot_Initialize; |
michael@0 | 169 | rv->Destroy = nss_dbm_mdSlot_Destroy; |
michael@0 | 170 | rv->GetSlotDescription = nss_dbm_mdSlot_GetSlotDescription; |
michael@0 | 171 | rv->GetManufacturerID = nss_dbm_mdSlot_GetManufacturerID; |
michael@0 | 172 | rv->GetTokenPresent = nss_dbm_mdSlot_GetTokenPresent; |
michael@0 | 173 | rv->GetRemovableDevice = nss_dbm_mdSlot_GetRemovableDevice; |
michael@0 | 174 | /* GetHardwareSlot */ |
michael@0 | 175 | /* GetHardwareVersion */ |
michael@0 | 176 | /* GetFirmwareVersion */ |
michael@0 | 177 | rv->GetToken = nss_dbm_mdSlot_GetToken; |
michael@0 | 178 | rv->null = (void *)NULL; |
michael@0 | 179 | |
michael@0 | 180 | return rv; |
michael@0 | 181 | } |