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_mdInstance_Initialize |
michael@0 | 9 | ( |
michael@0 | 10 | NSSCKMDInstance *mdInstance, |
michael@0 | 11 | NSSCKFWInstance *fwInstance, |
michael@0 | 12 | NSSUTF8 *configurationData |
michael@0 | 13 | ) |
michael@0 | 14 | { |
michael@0 | 15 | CK_RV rv = CKR_OK; |
michael@0 | 16 | NSSArena *arena; |
michael@0 | 17 | nss_dbm_instance_t *instance; |
michael@0 | 18 | |
michael@0 | 19 | arena = NSSCKFWInstance_GetArena(fwInstance, &rv); |
michael@0 | 20 | if( ((NSSArena *)NULL == arena) && (CKR_OK != rv) ) { |
michael@0 | 21 | return rv; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | instance = nss_ZNEW(arena, nss_dbm_instance_t); |
michael@0 | 25 | if( (nss_dbm_instance_t *)NULL == instance ) { |
michael@0 | 26 | return CKR_HOST_MEMORY; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | instance->arena = arena; |
michael@0 | 30 | |
michael@0 | 31 | /* |
michael@0 | 32 | * This should parse the configuration data for information on |
michael@0 | 33 | * number and locations of databases, modes (e.g. readonly), etc. |
michael@0 | 34 | * But for now, we'll have one slot with a creatable read-write |
michael@0 | 35 | * database called "cert8.db." |
michael@0 | 36 | */ |
michael@0 | 37 | |
michael@0 | 38 | instance->nSlots = 1; |
michael@0 | 39 | instance->filenames = nss_ZNEWARRAY(arena, char *, instance->nSlots); |
michael@0 | 40 | if( (char **)NULL == instance->filenames ) { |
michael@0 | 41 | return CKR_HOST_MEMORY; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | instance->flags = nss_ZNEWARRAY(arena, int, instance->nSlots); |
michael@0 | 45 | if( (int *)NULL == instance->flags ) { |
michael@0 | 46 | return CKR_HOST_MEMORY; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | instance->filenames[0] = "cert8.db"; |
michael@0 | 50 | instance->flags[0] = O_RDWR|O_CREAT; |
michael@0 | 51 | |
michael@0 | 52 | mdInstance->etc = (void *)instance; |
michael@0 | 53 | return CKR_OK; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | /* nss_dbm_mdInstance_Finalize is not required */ |
michael@0 | 57 | |
michael@0 | 58 | static CK_ULONG |
michael@0 | 59 | nss_dbm_mdInstance_GetNSlots |
michael@0 | 60 | ( |
michael@0 | 61 | NSSCKMDInstance *mdInstance, |
michael@0 | 62 | NSSCKFWInstance *fwInstance, |
michael@0 | 63 | CK_RV *pError |
michael@0 | 64 | ) |
michael@0 | 65 | { |
michael@0 | 66 | nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc; |
michael@0 | 67 | return instance->nSlots; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | static CK_VERSION |
michael@0 | 71 | nss_dbm_mdInstance_GetCryptokiVersion |
michael@0 | 72 | ( |
michael@0 | 73 | NSSCKMDInstance *mdInstance, |
michael@0 | 74 | NSSCKFWInstance *fwInstance |
michael@0 | 75 | ) |
michael@0 | 76 | { |
michael@0 | 77 | static CK_VERSION rv = { 2, 1 }; |
michael@0 | 78 | return rv; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | static NSSUTF8 * |
michael@0 | 82 | nss_dbm_mdInstance_GetManufacturerID |
michael@0 | 83 | ( |
michael@0 | 84 | NSSCKMDInstance *mdInstance, |
michael@0 | 85 | NSSCKFWInstance *fwInstance, |
michael@0 | 86 | CK_RV *pError |
michael@0 | 87 | ) |
michael@0 | 88 | { |
michael@0 | 89 | return "Mozilla Foundation"; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | static NSSUTF8 * |
michael@0 | 93 | nss_dbm_mdInstance_GetLibraryDescription |
michael@0 | 94 | ( |
michael@0 | 95 | NSSCKMDInstance *mdInstance, |
michael@0 | 96 | NSSCKFWInstance *fwInstance, |
michael@0 | 97 | CK_RV *pError |
michael@0 | 98 | ) |
michael@0 | 99 | { |
michael@0 | 100 | return "Berkeley Database Module"; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | static CK_VERSION |
michael@0 | 104 | nss_dbm_mdInstance_GetLibraryVersion |
michael@0 | 105 | ( |
michael@0 | 106 | NSSCKMDInstance *mdInstance, |
michael@0 | 107 | NSSCKFWInstance *fwInstance |
michael@0 | 108 | ) |
michael@0 | 109 | { |
michael@0 | 110 | static CK_VERSION rv = { 1, 0 }; /* My own version number */ |
michael@0 | 111 | return rv; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | static CK_BBOOL |
michael@0 | 115 | nss_dbm_mdInstance_ModuleHandlesSessionObjects |
michael@0 | 116 | ( |
michael@0 | 117 | NSSCKMDInstance *mdInstance, |
michael@0 | 118 | NSSCKFWInstance *fwInstance |
michael@0 | 119 | ) |
michael@0 | 120 | { |
michael@0 | 121 | return CK_TRUE; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | static CK_RV |
michael@0 | 125 | nss_dbm_mdInstance_GetSlots |
michael@0 | 126 | ( |
michael@0 | 127 | NSSCKMDInstance *mdInstance, |
michael@0 | 128 | NSSCKFWInstance *fwInstance, |
michael@0 | 129 | NSSCKMDSlot *slots[] |
michael@0 | 130 | ) |
michael@0 | 131 | { |
michael@0 | 132 | nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc; |
michael@0 | 133 | CK_ULONG i; |
michael@0 | 134 | CK_RV rv = CKR_OK; |
michael@0 | 135 | |
michael@0 | 136 | for( i = 0; i < instance->nSlots; i++ ) { |
michael@0 | 137 | slots[i] = nss_dbm_mdSlot_factory(instance, instance->filenames[i], |
michael@0 | 138 | instance->flags[i], &rv); |
michael@0 | 139 | if( (NSSCKMDSlot *)NULL == slots[i] ) { |
michael@0 | 140 | return rv; |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | return rv; |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | /* nss_dbm_mdInstance_WaitForSlotEvent is not relevant */ |
michael@0 | 148 | |
michael@0 | 149 | NSS_IMPLEMENT_DATA NSSCKMDInstance |
michael@0 | 150 | nss_dbm_mdInstance = { |
michael@0 | 151 | NULL, /* etc; filled in later */ |
michael@0 | 152 | nss_dbm_mdInstance_Initialize, |
michael@0 | 153 | NULL, /* nss_dbm_mdInstance_Finalize */ |
michael@0 | 154 | nss_dbm_mdInstance_GetNSlots, |
michael@0 | 155 | nss_dbm_mdInstance_GetCryptokiVersion, |
michael@0 | 156 | nss_dbm_mdInstance_GetManufacturerID, |
michael@0 | 157 | nss_dbm_mdInstance_GetLibraryDescription, |
michael@0 | 158 | nss_dbm_mdInstance_GetLibraryVersion, |
michael@0 | 159 | nss_dbm_mdInstance_ModuleHandlesSessionObjects, |
michael@0 | 160 | nss_dbm_mdInstance_GetSlots, |
michael@0 | 161 | NULL, /* nss_dbm_mdInstance_WaitForSlotEvent */ |
michael@0 | 162 | NULL /* terminator */ |
michael@0 | 163 | }; |