Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: nss/lib/ckfw/instance.c

Issue 1843333003: Update NSPR to 4.12 and NSS to 3.23 on iOS (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 /* 5 /*
6 * instance.c 6 * instance.c
7 * 7 *
8 * This file implements the NSSCKFWInstance type and methods. 8 * This file implements the NSSCKFWInstance type and methods.
9 */ 9 */
10 10
(...skipping 15 matching lines...) Expand all
26 * NSSCKFWInstance_CreateMutex 26 * NSSCKFWInstance_CreateMutex
27 * NSSCKFWInstance_GetConfigurationData 27 * NSSCKFWInstance_GetConfigurationData
28 * NSSCKFWInstance_GetInitArgs 28 * NSSCKFWInstance_GetInitArgs
29 * 29 *
30 * -- implement public accessors -- 30 * -- implement public accessors --
31 * nssCKFWInstance_GetMDInstance 31 * nssCKFWInstance_GetMDInstance
32 * nssCKFWInstance_GetArena 32 * nssCKFWInstance_GetArena
33 * nssCKFWInstance_MayCreatePthreads 33 * nssCKFWInstance_MayCreatePthreads
34 * nssCKFWInstance_CreateMutex 34 * nssCKFWInstance_CreateMutex
35 * nssCKFWInstance_GetConfigurationData 35 * nssCKFWInstance_GetConfigurationData
36 * nssCKFWInstance_GetInitArgs 36 * nssCKFWInstance_GetInitArgs
37 * 37 *
38 * -- private accessors -- 38 * -- private accessors --
39 * nssCKFWInstance_CreateSessionHandle 39 * nssCKFWInstance_CreateSessionHandle
40 * nssCKFWInstance_ResolveSessionHandle 40 * nssCKFWInstance_ResolveSessionHandle
41 * nssCKFWInstance_DestroySessionHandle 41 * nssCKFWInstance_DestroySessionHandle
42 * nssCKFWInstance_FindSessionHandle 42 * nssCKFWInstance_FindSessionHandle
43 * nssCKFWInstance_CreateObjectHandle 43 * nssCKFWInstance_CreateObjectHandle
44 * nssCKFWInstance_ResolveObjectHandle 44 * nssCKFWInstance_ResolveObjectHandle
45 * nssCKFWInstance_DestroyObjectHandle 45 * nssCKFWInstance_DestroyObjectHandle
46 * 46 *
47 * -- module fronts -- 47 * -- module fronts --
48 * nssCKFWInstance_GetNSlots 48 * nssCKFWInstance_GetNSlots
49 * nssCKFWInstance_GetCryptokiVersion 49 * nssCKFWInstance_GetCryptokiVersion
50 * nssCKFWInstance_GetManufacturerID 50 * nssCKFWInstance_GetManufacturerID
51 * nssCKFWInstance_GetFlags 51 * nssCKFWInstance_GetFlags
52 * nssCKFWInstance_GetLibraryDescription 52 * nssCKFWInstance_GetLibraryDescription
53 * nssCKFWInstance_GetLibraryVersion 53 * nssCKFWInstance_GetLibraryVersion
54 * nssCKFWInstance_GetModuleHandlesSessionObjects 54 * nssCKFWInstance_GetModuleHandlesSessionObjects
55 * nssCKFWInstance_GetSlots 55 * nssCKFWInstance_GetSlots
56 * nssCKFWInstance_WaitForSlotEvent 56 * nssCKFWInstance_WaitForSlotEvent
57 * 57 *
58 * -- debugging versions only -- 58 * -- debugging versions only --
59 * nssCKFWInstance_verifyPointer 59 * nssCKFWInstance_verifyPointer
60 */ 60 */
61 61
62 struct NSSCKFWInstanceStr { 62 struct NSSCKFWInstanceStr {
63 NSSCKFWMutex *mutex; 63 NSSCKFWMutex *mutex;
64 NSSArena *arena; 64 NSSArena *arena;
65 NSSCKMDInstance *mdInstance; 65 NSSCKMDInstance *mdInstance;
66 CK_C_INITIALIZE_ARGS_PTR pInitArgs; 66 CK_C_INITIALIZE_ARGS_PTR pInitArgs;
67 CK_C_INITIALIZE_ARGS initArgs; 67 CK_C_INITIALIZE_ARGS initArgs;
68 CryptokiLockingState LockingState; 68 CryptokiLockingState LockingState;
69 CK_BBOOL mayCreatePthreads; 69 CK_BBOOL mayCreatePthreads;
70 NSSUTF8 *configurationData; 70 NSSUTF8 *configurationData;
71 CK_ULONG nSlots; 71 CK_ULONG nSlots;
72 NSSCKFWSlot **fwSlotList; 72 NSSCKFWSlot **fwSlotList;
73 NSSCKMDSlot **mdSlotList; 73 NSSCKMDSlot **mdSlotList;
74 CK_BBOOL moduleHandlesSessionObjects; 74 CK_BBOOL moduleHandlesSessionObjects;
75 75
76 /* 76 /*
77 * Everything above is set at creation time, and then not modified. 77 * Everything above is set at creation time, and then not modified.
78 * The invariants the mutex protects are: 78 * The invariants the mutex protects are:
79 * 79 *
80 * 1) Each of the cached descriptions (versions, etc.) are in an 80 * 1) Each of the cached descriptions (versions, etc.) are in an
81 * internally consistant state. 81 * internally consistant state.
82 * 82 *
83 * 2) The session handle hashes and count are consistant 83 * 2) The session handle hashes and count are consistant
84 * 84 *
85 * 3) The object handle hashes and count are consistant. 85 * 3) The object handle hashes and count are consistant.
86 * 86 *
87 * I could use multiple locks, but let's wait to see if that's 87 * I could use multiple locks, but let's wait to see if that's
88 * really necessary. 88 * really necessary.
89 * 89 *
90 * Note that the calls accessing the cached descriptions will 90 * Note that the calls accessing the cached descriptions will
91 * call the NSSCKMDInstance methods with the mutex locked. Those 91 * call the NSSCKMDInstance methods with the mutex locked. Those
92 * methods may then call the public NSSCKFWInstance routines. 92 * methods may then call the public NSSCKFWInstance routines.
93 * Those public routines only access the constant data above, so 93 * Those public routines only access the constant data above, so
94 * there's no problem. But be careful if you add to this object; 94 * there's no problem. But be careful if you add to this object;
95 * mutexes are in general not reentrant, so don't create deadlock 95 * mutexes are in general not reentrant, so don't create deadlock
96 * situations. 96 * situations.
97 */ 97 */
98 98
99 CK_VERSION cryptokiVersion; 99 CK_VERSION cryptokiVersion;
100 NSSUTF8 *manufacturerID; 100 NSSUTF8 *manufacturerID;
101 NSSUTF8 *libraryDescription; 101 NSSUTF8 *libraryDescription;
102 CK_VERSION libraryVersion; 102 CK_VERSION libraryVersion;
103 103
104 CK_ULONG lastSessionHandle; 104 CK_ULONG lastSessionHandle;
105 nssCKFWHash *sessionHandleHash; 105 nssCKFWHash *sessionHandleHash;
106 106
107 CK_ULONG lastObjectHandle; 107 CK_ULONG lastObjectHandle;
108 nssCKFWHash *objectHandleHash; 108 nssCKFWHash *objectHandleHash;
109 }; 109 };
110 110
111 #ifdef DEBUG 111 #ifdef DEBUG
112 /* 112 /*
113 * But first, the pointer-tracking stuff. 113 * But first, the pointer-tracking stuff.
114 * 114 *
115 * NOTE: the pointer-tracking support in NSS/base currently relies 115 * NOTE: the pointer-tracking support in NSS/base currently relies
116 * upon NSPR's CallOnce support. That, however, relies upon NSPR's 116 * upon NSPR's CallOnce support. That, however, relies upon NSPR's
117 * locking, which is tied into the runtime. We need a pointer-tracker 117 * locking, which is tied into the runtime. We need a pointer-tracker
118 * implementation that uses the locks supplied through C_Initialize. 118 * implementation that uses the locks supplied through C_Initialize.
119 * That support, however, can be filled in later. So for now, I'll 119 * That support, however, can be filled in later. So for now, I'll
120 * just do this routines as no-ops. 120 * just do this routines as no-ops.
121 */ 121 */
122 122
123 static CK_RV 123 static CK_RV
124 instance_add_pointer 124 instance_add_pointer(
125 ( 125 const NSSCKFWInstance *fwInstance)
126 const NSSCKFWInstance *fwInstance
127 )
128 { 126 {
129 return CKR_OK; 127 return CKR_OK;
130 } 128 }
131 129
132 static CK_RV 130 static CK_RV
133 instance_remove_pointer 131 instance_remove_pointer(
134 ( 132 const NSSCKFWInstance *fwInstance)
135 const NSSCKFWInstance *fwInstance
136 )
137 { 133 {
138 return CKR_OK; 134 return CKR_OK;
139 } 135 }
140 136
141 NSS_IMPLEMENT CK_RV 137 NSS_IMPLEMENT CK_RV
142 nssCKFWInstance_verifyPointer 138 nssCKFWInstance_verifyPointer(
143 ( 139 const NSSCKFWInstance *fwInstance)
144 const NSSCKFWInstance *fwInstance
145 )
146 { 140 {
147 return CKR_OK; 141 return CKR_OK;
148 } 142 }
149 143
150 #endif /* DEBUG */ 144 #endif /* DEBUG */
151 145
152 /* 146 /*
153 * nssCKFWInstance_Create 147 * nssCKFWInstance_Create
154 * 148 *
155 */ 149 */
156 NSS_IMPLEMENT NSSCKFWInstance * 150 NSS_IMPLEMENT NSSCKFWInstance *
157 nssCKFWInstance_Create 151 nssCKFWInstance_Create(
158 ( 152 CK_C_INITIALIZE_ARGS_PTR pInitArgs,
159 CK_C_INITIALIZE_ARGS_PTR pInitArgs, 153 CryptokiLockingState LockingState,
160 CryptokiLockingState LockingState, 154 NSSCKMDInstance *mdInstance,
161 NSSCKMDInstance *mdInstance, 155 CK_RV *pError)
162 CK_RV *pError
163 )
164 { 156 {
165 NSSCKFWInstance *fwInstance; 157 NSSCKFWInstance *fwInstance;
166 NSSArena *arena = (NSSArena *)NULL; 158 NSSArena *arena = (NSSArena *)NULL;
167 CK_ULONG i; 159 CK_ULONG i;
168 CK_BBOOL called_Initialize = CK_FALSE; 160 CK_BBOOL called_Initialize = CK_FALSE;
169 161
170 #ifdef NSSDEBUG 162 #ifdef NSSDEBUG
171 if( (CK_RV)NULL == pError ) { 163 if ((CK_RV)NULL == pError) {
172 return (NSSCKFWInstance *)NULL; 164 return (NSSCKFWInstance *)NULL;
173 } 165 }
174 166
175 if (!mdInstance) { 167 if (!mdInstance) {
176 *pError = CKR_ARGUMENTS_BAD; 168 *pError = CKR_ARGUMENTS_BAD;
177 return (NSSCKFWInstance *)NULL; 169 return (NSSCKFWInstance *)NULL;
178 } 170 }
179 #endif /* NSSDEBUG */ 171 #endif /* NSSDEBUG */
180 172
181 arena = NSSArena_Create(); 173 arena = NSSArena_Create();
182 if (!arena) { 174 if (!arena) {
183 *pError = CKR_HOST_MEMORY; 175 *pError = CKR_HOST_MEMORY;
184 return (NSSCKFWInstance *)NULL; 176 return (NSSCKFWInstance *)NULL;
185 }
186
187 fwInstance = nss_ZNEW(arena, NSSCKFWInstance);
188 if (!fwInstance) {
189 goto nomem;
190 }
191
192 fwInstance->arena = arena;
193 fwInstance->mdInstance = mdInstance;
194
195 fwInstance->LockingState = LockingState;
196 if( (CK_C_INITIALIZE_ARGS_PTR)NULL != pInitArgs ) {
197 fwInstance->initArgs = *pInitArgs;
198 fwInstance->pInitArgs = &fwInstance->initArgs;
199 if( pInitArgs->flags & CKF_LIBRARY_CANT_CREATE_OS_THREADS ) {
200 fwInstance->mayCreatePthreads = CK_FALSE;
201 } else {
202 fwInstance->mayCreatePthreads = CK_TRUE;
203 }
204 fwInstance->configurationData = (NSSUTF8 *)(pInitArgs->pReserved);
205 } else {
206 fwInstance->mayCreatePthreads = CK_TRUE;
207 }
208
209 fwInstance->mutex = nssCKFWMutex_Create(pInitArgs, LockingState, arena,
210 pError);
211 if (!fwInstance->mutex) {
212 if( CKR_OK == *pError ) {
213 *pError = CKR_GENERAL_ERROR;
214 }
215 goto loser;
216 }
217
218 if (mdInstance->Initialize) {
219 *pError = mdInstance->Initialize(mdInstance, fwInstance, fwInstance->configu rationData);
220 if( CKR_OK != *pError ) {
221 goto loser;
222 } 177 }
223 178
224 called_Initialize = CK_TRUE; 179 fwInstance = nss_ZNEW(arena, NSSCKFWInstance);
225 } 180 if (!fwInstance) {
226 181 goto nomem;
227 if (mdInstance->ModuleHandlesSessionObjects) {
228 fwInstance->moduleHandlesSessionObjects =
229 mdInstance->ModuleHandlesSessionObjects(mdInstance, fwInstance);
230 } else {
231 fwInstance->moduleHandlesSessionObjects = CK_FALSE;
232 }
233
234 if (!mdInstance->GetNSlots) {
235 /* That routine is required */
236 *pError = CKR_GENERAL_ERROR;
237 goto loser;
238 }
239
240 fwInstance->nSlots = mdInstance->GetNSlots(mdInstance, fwInstance, pError);
241 if( (CK_ULONG)0 == fwInstance->nSlots ) {
242 if( CKR_OK == *pError ) {
243 /* Zero is not a legitimate answer */
244 *pError = CKR_GENERAL_ERROR;
245 }
246 goto loser;
247 }
248
249 fwInstance->fwSlotList = nss_ZNEWARRAY(arena, NSSCKFWSlot *, fwInstance->nSlot s);
250 if( (NSSCKFWSlot **)NULL == fwInstance->fwSlotList ) {
251 goto nomem;
252 }
253
254 fwInstance->mdSlotList = nss_ZNEWARRAY(arena, NSSCKMDSlot *, fwInstance->nSlot s);
255 if( (NSSCKMDSlot **)NULL == fwInstance->mdSlotList ) {
256 goto nomem;
257 }
258
259 fwInstance->sessionHandleHash = nssCKFWHash_Create(fwInstance,
260 fwInstance->arena, pError);
261 if (!fwInstance->sessionHandleHash) {
262 goto loser;
263 }
264
265 fwInstance->objectHandleHash = nssCKFWHash_Create(fwInstance,
266 fwInstance->arena, pError);
267 if (!fwInstance->objectHandleHash) {
268 goto loser;
269 }
270
271 if (!mdInstance->GetSlots) {
272 /* That routine is required */
273 *pError = CKR_GENERAL_ERROR;
274 goto loser;
275 }
276
277 *pError = mdInstance->GetSlots(mdInstance, fwInstance, fwInstance->mdSlotList) ;
278 if( CKR_OK != *pError ) {
279 goto loser;
280 }
281
282 for( i = 0; i < fwInstance->nSlots; i++ ) {
283 NSSCKMDSlot *mdSlot = fwInstance->mdSlotList[i];
284
285 if (!mdSlot) {
286 *pError = CKR_GENERAL_ERROR;
287 goto loser;
288 } 182 }
289 183
290 fwInstance->fwSlotList[i] = nssCKFWSlot_Create(fwInstance, mdSlot, i, pError ); 184 fwInstance->arena = arena;
291 if( CKR_OK != *pError ) { 185 fwInstance->mdInstance = mdInstance;
292 CK_ULONG j;
293 186
294 for( j = 0; j < i; j++ ) { 187 fwInstance->LockingState = LockingState;
295 (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[j]); 188 if ((CK_C_INITIALIZE_ARGS_PTR)NULL != pInitArgs) {
296 } 189 fwInstance->initArgs = *pInitArgs;
190 fwInstance->pInitArgs = &fwInstance->initArgs;
191 if (pInitArgs->flags & CKF_LIBRARY_CANT_CREATE_OS_THREADS) {
192 fwInstance->mayCreatePthreads = CK_FALSE;
193 } else {
194 fwInstance->mayCreatePthreads = CK_TRUE;
195 }
196 fwInstance->configurationData = (NSSUTF8 *)(pInitArgs->pReserved);
197 } else {
198 fwInstance->mayCreatePthreads = CK_TRUE;
199 }
297 200
298 for( j = i; j < fwInstance->nSlots; j++ ) { 201 fwInstance->mutex = nssCKFWMutex_Create(pInitArgs, LockingState, arena,
299 NSSCKMDSlot *mds = fwInstance->mdSlotList[j]; 202 pError);
300 if (mds->Destroy) { 203 if (!fwInstance->mutex) {
301 mds->Destroy(mds, (NSSCKFWSlot *)NULL, mdInstance, fwInstance); 204 if (CKR_OK == *pError) {
205 *pError = CKR_GENERAL_ERROR;
302 } 206 }
303 } 207 goto loser;
208 }
304 209
305 goto loser; 210 if (mdInstance->Initialize) {
211 *pError = mdInstance->Initialize(mdInstance, fwInstance, fwInstance->con figurationData);
212 if (CKR_OK != *pError) {
213 goto loser;
214 }
215
216 called_Initialize = CK_TRUE;
306 } 217 }
307 } 218
219 if (mdInstance->ModuleHandlesSessionObjects) {
220 fwInstance->moduleHandlesSessionObjects =
221 mdInstance->ModuleHandlesSessionObjects(mdInstance, fwInstance);
222 } else {
223 fwInstance->moduleHandlesSessionObjects = CK_FALSE;
224 }
225
226 if (!mdInstance->GetNSlots) {
227 /* That routine is required */
228 *pError = CKR_GENERAL_ERROR;
229 goto loser;
230 }
231
232 fwInstance->nSlots = mdInstance->GetNSlots(mdInstance, fwInstance, pError);
233 if ((CK_ULONG)0 == fwInstance->nSlots) {
234 if (CKR_OK == *pError) {
235 /* Zero is not a legitimate answer */
236 *pError = CKR_GENERAL_ERROR;
237 }
238 goto loser;
239 }
240
241 fwInstance->fwSlotList = nss_ZNEWARRAY(arena, NSSCKFWSlot *, fwInstance->nSl ots);
242 if ((NSSCKFWSlot **)NULL == fwInstance->fwSlotList) {
243 goto nomem;
244 }
245
246 fwInstance->mdSlotList = nss_ZNEWARRAY(arena, NSSCKMDSlot *, fwInstance->nSl ots);
247 if ((NSSCKMDSlot **)NULL == fwInstance->mdSlotList) {
248 goto nomem;
249 }
250
251 fwInstance->sessionHandleHash = nssCKFWHash_Create(fwInstance,
252 fwInstance->arena, pError );
253 if (!fwInstance->sessionHandleHash) {
254 goto loser;
255 }
256
257 fwInstance->objectHandleHash = nssCKFWHash_Create(fwInstance,
258 fwInstance->arena, pError) ;
259 if (!fwInstance->objectHandleHash) {
260 goto loser;
261 }
262
263 if (!mdInstance->GetSlots) {
264 /* That routine is required */
265 *pError = CKR_GENERAL_ERROR;
266 goto loser;
267 }
268
269 *pError = mdInstance->GetSlots(mdInstance, fwInstance, fwInstance->mdSlotLis t);
270 if (CKR_OK != *pError) {
271 goto loser;
272 }
273
274 for (i = 0; i < fwInstance->nSlots; i++) {
275 NSSCKMDSlot *mdSlot = fwInstance->mdSlotList[i];
276
277 if (!mdSlot) {
278 *pError = CKR_GENERAL_ERROR;
279 goto loser;
280 }
281
282 fwInstance->fwSlotList[i] = nssCKFWSlot_Create(fwInstance, mdSlot, i, pE rror);
283 if (CKR_OK != *pError) {
284 CK_ULONG j;
285
286 for (j = 0; j < i; j++) {
287 (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[j]);
288 }
289
290 for (j = i; j < fwInstance->nSlots; j++) {
291 NSSCKMDSlot *mds = fwInstance->mdSlotList[j];
292 if (mds->Destroy) {
293 mds->Destroy(mds, (NSSCKFWSlot *)NULL, mdInstance, fwInstanc e);
294 }
295 }
296
297 goto loser;
298 }
299 }
308 300
309 #ifdef DEBUG 301 #ifdef DEBUG
310 *pError = instance_add_pointer(fwInstance); 302 *pError = instance_add_pointer(fwInstance);
311 if( CKR_OK != *pError ) { 303 if (CKR_OK != *pError) {
312 for( i = 0; i < fwInstance->nSlots; i++ ) { 304 for (i = 0; i < fwInstance->nSlots; i++) {
313 (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]); 305 (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]);
306 }
307
308 goto loser;
314 } 309 }
315
316 goto loser;
317 }
318 #endif /* DEBUG */ 310 #endif /* DEBUG */
319 311
320 *pError = CKR_OK; 312 *pError = CKR_OK;
321 return fwInstance; 313 return fwInstance;
322 314
323 nomem: 315 nomem:
324 *pError = CKR_HOST_MEMORY; 316 *pError = CKR_HOST_MEMORY;
325 /*FALLTHROUGH*/ 317 /*FALLTHROUGH*/
326 loser: 318 loser:
327 319
328 if( CK_TRUE == called_Initialize ) { 320 if (CK_TRUE == called_Initialize) {
329 if (mdInstance->Finalize) { 321 if (mdInstance->Finalize) {
330 mdInstance->Finalize(mdInstance, fwInstance); 322 mdInstance->Finalize(mdInstance, fwInstance);
323 }
331 } 324 }
332 }
333 325
334 if (fwInstance && fwInstance->mutex) { 326 if (fwInstance && fwInstance->mutex) {
335 nssCKFWMutex_Destroy(fwInstance->mutex); 327 nssCKFWMutex_Destroy(fwInstance->mutex);
336 } 328 }
337 329
338 if (arena) { 330 if (arena) {
339 (void)NSSArena_Destroy(arena); 331 (void)NSSArena_Destroy(arena);
340 } 332 }
341 return (NSSCKFWInstance *)NULL; 333 return (NSSCKFWInstance *)NULL;
342 } 334 }
343 335
344 /* 336 /*
345 * nssCKFWInstance_Destroy 337 * nssCKFWInstance_Destroy
346 * 338 *
347 */ 339 */
348 NSS_IMPLEMENT CK_RV 340 NSS_IMPLEMENT CK_RV
349 nssCKFWInstance_Destroy 341 nssCKFWInstance_Destroy(
350 ( 342 NSSCKFWInstance *fwInstance)
351 NSSCKFWInstance *fwInstance
352 )
353 { 343 {
354 #ifdef NSSDEBUG 344 #ifdef NSSDEBUG
355 CK_RV error = CKR_OK; 345 CK_RV error = CKR_OK;
356 #endif /* NSSDEBUG */ 346 #endif /* NSSDEBUG */
357 CK_ULONG i; 347 CK_ULONG i;
358 348
359 #ifdef NSSDEBUG 349 #ifdef NSSDEBUG
360 error = nssCKFWInstance_verifyPointer(fwInstance); 350 error = nssCKFWInstance_verifyPointer(fwInstance);
361 if( CKR_OK != error ) { 351 if (CKR_OK != error) {
362 return error; 352 return error;
363 } 353 }
364 #endif /* NSSDEBUG */ 354 #endif /* NSSDEBUG */
365 355
366 nssCKFWMutex_Destroy(fwInstance->mutex); 356 nssCKFWMutex_Destroy(fwInstance->mutex);
367 357
368 for( i = 0; i < fwInstance->nSlots; i++ ) { 358 for (i = 0; i < fwInstance->nSlots; i++) {
369 (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]); 359 (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]);
370 } 360 }
371 361
372 if (fwInstance->mdInstance->Finalize) { 362 if (fwInstance->mdInstance->Finalize) {
373 fwInstance->mdInstance->Finalize(fwInstance->mdInstance, fwInstance); 363 fwInstance->mdInstance->Finalize(fwInstance->mdInstance, fwInstance);
374 } 364 }
375 365
376 if (fwInstance->sessionHandleHash) { 366 if (fwInstance->sessionHandleHash) {
377 nssCKFWHash_Destroy(fwInstance->sessionHandleHash); 367 nssCKFWHash_Destroy(fwInstance->sessionHandleHash);
378 } 368 }
379 369
380 if (fwInstance->objectHandleHash) { 370 if (fwInstance->objectHandleHash) {
381 nssCKFWHash_Destroy(fwInstance->objectHandleHash); 371 nssCKFWHash_Destroy(fwInstance->objectHandleHash);
382 } 372 }
383 373
384 #ifdef DEBUG 374 #ifdef DEBUG
385 (void)instance_remove_pointer(fwInstance); 375 (void)instance_remove_pointer(fwInstance);
386 #endif /* DEBUG */ 376 #endif /* DEBUG */
387 377
388 (void)NSSArena_Destroy(fwInstance->arena); 378 (void)NSSArena_Destroy(fwInstance->arena);
389 return CKR_OK; 379 return CKR_OK;
390 } 380 }
391 381
392 /* 382 /*
393 * nssCKFWInstance_GetMDInstance 383 * nssCKFWInstance_GetMDInstance
394 * 384 *
395 */ 385 */
396 NSS_IMPLEMENT NSSCKMDInstance * 386 NSS_IMPLEMENT NSSCKMDInstance *
397 nssCKFWInstance_GetMDInstance 387 nssCKFWInstance_GetMDInstance(
398 ( 388 NSSCKFWInstance *fwInstance)
399 NSSCKFWInstance *fwInstance
400 )
401 { 389 {
402 #ifdef NSSDEBUG 390 #ifdef NSSDEBUG
403 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 391 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
404 return (NSSCKMDInstance *)NULL; 392 return (NSSCKMDInstance *)NULL;
405 } 393 }
406 #endif /* NSSDEBUG */ 394 #endif /* NSSDEBUG */
407 395
408 return fwInstance->mdInstance; 396 return fwInstance->mdInstance;
409 } 397 }
410 398
411 /* 399 /*
412 * nssCKFWInstance_GetArena 400 * nssCKFWInstance_GetArena
413 * 401 *
414 */ 402 */
415 NSS_IMPLEMENT NSSArena * 403 NSS_IMPLEMENT NSSArena *
416 nssCKFWInstance_GetArena 404 nssCKFWInstance_GetArena(
417 ( 405 NSSCKFWInstance *fwInstance,
418 NSSCKFWInstance *fwInstance, 406 CK_RV *pError)
419 CK_RV *pError
420 )
421 { 407 {
422 #ifdef NSSDEBUG 408 #ifdef NSSDEBUG
423 if (!pError) { 409 if (!pError) {
424 return (NSSArena *)NULL; 410 return (NSSArena *)NULL;
425 } 411 }
426 412
427 *pError = nssCKFWInstance_verifyPointer(fwInstance); 413 *pError = nssCKFWInstance_verifyPointer(fwInstance);
428 if( CKR_OK != *pError ) { 414 if (CKR_OK != *pError) {
429 return (NSSArena *)NULL; 415 return (NSSArena *)NULL;
430 } 416 }
431 #endif /* NSSDEBUG */ 417 #endif /* NSSDEBUG */
432 418
433 *pError = CKR_OK; 419 *pError = CKR_OK;
434 return fwInstance->arena; 420 return fwInstance->arena;
435 } 421 }
436 422
437 /* 423 /*
438 * nssCKFWInstance_MayCreatePthreads 424 * nssCKFWInstance_MayCreatePthreads
439 * 425 *
440 */ 426 */
441 NSS_IMPLEMENT CK_BBOOL 427 NSS_IMPLEMENT CK_BBOOL
442 nssCKFWInstance_MayCreatePthreads 428 nssCKFWInstance_MayCreatePthreads(
443 ( 429 NSSCKFWInstance *fwInstance)
444 NSSCKFWInstance *fwInstance
445 )
446 { 430 {
447 #ifdef NSSDEBUG 431 #ifdef NSSDEBUG
448 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 432 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
449 return CK_FALSE; 433 return CK_FALSE;
450 } 434 }
451 #endif /* NSSDEBUG */ 435 #endif /* NSSDEBUG */
452 436
453 return fwInstance->mayCreatePthreads; 437 return fwInstance->mayCreatePthreads;
454 } 438 }
455 439
456 /* 440 /*
457 * nssCKFWInstance_CreateMutex 441 * nssCKFWInstance_CreateMutex
458 * 442 *
459 */ 443 */
460 NSS_IMPLEMENT NSSCKFWMutex * 444 NSS_IMPLEMENT NSSCKFWMutex *
461 nssCKFWInstance_CreateMutex 445 nssCKFWInstance_CreateMutex(
462 ( 446 NSSCKFWInstance *fwInstance,
463 NSSCKFWInstance *fwInstance, 447 NSSArena *arena,
464 NSSArena *arena, 448 CK_RV *pError)
465 CK_RV *pError
466 )
467 { 449 {
468 NSSCKFWMutex *mutex; 450 NSSCKFWMutex *mutex;
469 451
470 #ifdef NSSDEBUG 452 #ifdef NSSDEBUG
471 if (!pError) { 453 if (!pError) {
472 return (NSSCKFWMutex *)NULL; 454 return (NSSCKFWMutex *)NULL;
473 } 455 }
474 456
475 *pError = nssCKFWInstance_verifyPointer(fwInstance); 457 *pError = nssCKFWInstance_verifyPointer(fwInstance);
476 if( CKR_OK != *pError ) { 458 if (CKR_OK != *pError) {
477 return (NSSCKFWMutex *)NULL; 459 return (NSSCKFWMutex *)NULL;
478 } 460 }
479 #endif /* NSSDEBUG */ 461 #endif /* NSSDEBUG */
480 462
481 mutex = nssCKFWMutex_Create(fwInstance->pInitArgs, fwInstance->LockingState, 463 mutex = nssCKFWMutex_Create(fwInstance->pInitArgs, fwInstance->LockingState,
482 arena, pError); 464 arena, pError);
483 if (!mutex) { 465 if (!mutex) {
484 if( CKR_OK == *pError ) { 466 if (CKR_OK == *pError) {
485 *pError = CKR_GENERAL_ERROR; 467 *pError = CKR_GENERAL_ERROR;
468 }
469
470 return (NSSCKFWMutex *)NULL;
486 } 471 }
487 472
488 return (NSSCKFWMutex *)NULL; 473 return mutex;
489 }
490
491 return mutex;
492 } 474 }
493 475
494 /* 476 /*
495 * nssCKFWInstance_GetConfigurationData 477 * nssCKFWInstance_GetConfigurationData
496 * 478 *
497 */ 479 */
498 NSS_IMPLEMENT NSSUTF8 * 480 NSS_IMPLEMENT NSSUTF8 *
499 nssCKFWInstance_GetConfigurationData 481 nssCKFWInstance_GetConfigurationData(
500 ( 482 NSSCKFWInstance *fwInstance)
501 NSSCKFWInstance *fwInstance
502 )
503 { 483 {
504 #ifdef NSSDEBUG 484 #ifdef NSSDEBUG
505 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 485 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
506 return (NSSUTF8 *)NULL; 486 return (NSSUTF8 *)NULL;
507 } 487 }
508 #endif /* NSSDEBUG */ 488 #endif /* NSSDEBUG */
509 489
510 return fwInstance->configurationData; 490 return fwInstance->configurationData;
511 } 491 }
512 492
513 /* 493 /*
514 * nssCKFWInstance_GetInitArgs 494 * nssCKFWInstance_GetInitArgs
515 * 495 *
516 */ 496 */
517 CK_C_INITIALIZE_ARGS_PTR 497 CK_C_INITIALIZE_ARGS_PTR
518 nssCKFWInstance_GetInitArgs 498 nssCKFWInstance_GetInitArgs(
519 ( 499 NSSCKFWInstance *fwInstance)
520 NSSCKFWInstance *fwInstance
521 )
522 { 500 {
523 #ifdef NSSDEBUG 501 #ifdef NSSDEBUG
524 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 502 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
525 return (CK_C_INITIALIZE_ARGS_PTR)NULL; 503 return (CK_C_INITIALIZE_ARGS_PTR)NULL;
526 } 504 }
527 #endif /* NSSDEBUG */ 505 #endif /* NSSDEBUG */
528 506
529 return fwInstance->pInitArgs; 507 return fwInstance->pInitArgs;
530 } 508 }
531 509
532 /* 510 /*
533 * nssCKFWInstance_CreateSessionHandle 511 * nssCKFWInstance_CreateSessionHandle
534 * 512 *
535 */ 513 */
536 NSS_IMPLEMENT CK_SESSION_HANDLE 514 NSS_IMPLEMENT CK_SESSION_HANDLE
537 nssCKFWInstance_CreateSessionHandle 515 nssCKFWInstance_CreateSessionHandle(
538 ( 516 NSSCKFWInstance *fwInstance,
539 NSSCKFWInstance *fwInstance, 517 NSSCKFWSession *fwSession,
540 NSSCKFWSession *fwSession, 518 CK_RV *pError)
541 CK_RV *pError
542 )
543 { 519 {
544 CK_SESSION_HANDLE hSession; 520 CK_SESSION_HANDLE hSession;
545 521
546 #ifdef NSSDEBUG 522 #ifdef NSSDEBUG
547 if (!pError) { 523 if (!pError) {
548 return (CK_SESSION_HANDLE)0; 524 return (CK_SESSION_HANDLE)0;
549 } 525 }
550 526
551 *pError = nssCKFWInstance_verifyPointer(fwInstance); 527 *pError = nssCKFWInstance_verifyPointer(fwInstance);
552 if( CKR_OK != *pError ) { 528 if (CKR_OK != *pError) {
553 return (CK_SESSION_HANDLE)0; 529 return (CK_SESSION_HANDLE)0;
554 } 530 }
555 #endif /* NSSDEBUG */ 531 #endif /* NSSDEBUG */
556 532
557 *pError = nssCKFWMutex_Lock(fwInstance->mutex); 533 *pError = nssCKFWMutex_Lock(fwInstance->mutex);
558 if( CKR_OK != *pError ) { 534 if (CKR_OK != *pError) {
559 return (CK_SESSION_HANDLE)0; 535 return (CK_SESSION_HANDLE)0;
560 } 536 }
561 537
562 hSession = ++(fwInstance->lastSessionHandle); 538 hSession = ++(fwInstance->lastSessionHandle);
563 539
564 /* Alan would say I should unlock for this call. */ 540 /* Alan would say I should unlock for this call. */
565
566 *pError = nssCKFWSession_SetHandle(fwSession, hSession);
567 if( CKR_OK != *pError ) {
568 goto done;
569 }
570 541
571 *pError = nssCKFWHash_Add(fwInstance->sessionHandleHash, 542 *pError = nssCKFWSession_SetHandle(fwSession, hSession);
572 (const void *)hSession, (const void *)fwSession); 543 if (CKR_OK != *pError) {
573 if( CKR_OK != *pError ) { 544 goto done;
574 hSession = (CK_SESSION_HANDLE)0; 545 }
575 goto done;
576 }
577 546
578 done: 547 *pError = nssCKFWHash_Add(fwInstance->sessionHandleHash,
579 nssCKFWMutex_Unlock(fwInstance->mutex); 548 (const void *)hSession, (const void *)fwSession);
580 return hSession; 549 if (CKR_OK != *pError) {
550 hSession = (CK_SESSION_HANDLE)0;
551 goto done;
552 }
553
554 done:
555 nssCKFWMutex_Unlock(fwInstance->mutex);
556 return hSession;
581 } 557 }
582 558
583 /* 559 /*
584 * nssCKFWInstance_ResolveSessionHandle 560 * nssCKFWInstance_ResolveSessionHandle
585 * 561 *
586 */ 562 */
587 NSS_IMPLEMENT NSSCKFWSession * 563 NSS_IMPLEMENT NSSCKFWSession *
588 nssCKFWInstance_ResolveSessionHandle 564 nssCKFWInstance_ResolveSessionHandle(
589 ( 565 NSSCKFWInstance *fwInstance,
590 NSSCKFWInstance *fwInstance, 566 CK_SESSION_HANDLE hSession)
591 CK_SESSION_HANDLE hSession
592 )
593 { 567 {
594 NSSCKFWSession *fwSession; 568 NSSCKFWSession *fwSession;
595 569
596 #ifdef NSSDEBUG 570 #ifdef NSSDEBUG
597 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 571 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
598 return (NSSCKFWSession *)NULL; 572 return (NSSCKFWSession *)NULL;
599 } 573 }
600 #endif /* NSSDEBUG */ 574 #endif /* NSSDEBUG */
601 575
602 if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { 576 if (CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex)) {
603 return (NSSCKFWSession *)NULL; 577 return (NSSCKFWSession *)NULL;
604 } 578 }
605 579
606 fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup( 580 fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup(
607 fwInstance->sessionHandleHash, (const void *)hSession); 581 fwInstance->sessionHandleHash, (const void *)hSession);
608 582
609 /* Assert(hSession == nssCKFWSession_GetHandle(fwSession)) */ 583 /* Assert(hSession == nssCKFWSession_GetHandle(fwSession)) */
610 584
611 (void)nssCKFWMutex_Unlock(fwInstance->mutex); 585 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
612 586
613 return fwSession; 587 return fwSession;
614 } 588 }
615 589
616 /* 590 /*
617 * nssCKFWInstance_DestroySessionHandle 591 * nssCKFWInstance_DestroySessionHandle
618 * 592 *
619 */ 593 */
620 NSS_IMPLEMENT void 594 NSS_IMPLEMENT void
621 nssCKFWInstance_DestroySessionHandle 595 nssCKFWInstance_DestroySessionHandle(
622 ( 596 NSSCKFWInstance *fwInstance,
623 NSSCKFWInstance *fwInstance, 597 CK_SESSION_HANDLE hSession)
624 CK_SESSION_HANDLE hSession
625 )
626 { 598 {
627 NSSCKFWSession *fwSession; 599 NSSCKFWSession *fwSession;
628 600
629 #ifdef NSSDEBUG 601 #ifdef NSSDEBUG
630 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 602 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
631 return; 603 return;
632 } 604 }
633 #endif /* NSSDEBUG */ 605 #endif /* NSSDEBUG */
634 606
635 if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { 607 if (CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex)) {
608 return;
609 }
610
611 fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup(
612 fwInstance->sessionHandleHash, (const void *)hSession);
613 if (fwSession) {
614 nssCKFWHash_Remove(fwInstance->sessionHandleHash, (const void *)hSession );
615 nssCKFWSession_SetHandle(fwSession, (CK_SESSION_HANDLE)0);
616 }
617
618 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
619
636 return; 620 return;
637 }
638
639 fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup(
640 fwInstance->sessionHandleHash, (const void *)hSession);
641 if (fwSession) {
642 nssCKFWHash_Remove(fwInstance->sessionHandleHash, (const void *)hSession);
643 nssCKFWSession_SetHandle(fwSession, (CK_SESSION_HANDLE)0);
644 }
645
646 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
647
648 return;
649 } 621 }
650 622
651 /* 623 /*
652 * nssCKFWInstance_FindSessionHandle 624 * nssCKFWInstance_FindSessionHandle
653 * 625 *
654 */ 626 */
655 NSS_IMPLEMENT CK_SESSION_HANDLE 627 NSS_IMPLEMENT CK_SESSION_HANDLE
656 nssCKFWInstance_FindSessionHandle 628 nssCKFWInstance_FindSessionHandle(
657 ( 629 NSSCKFWInstance *fwInstance,
658 NSSCKFWInstance *fwInstance, 630 NSSCKFWSession *fwSession)
659 NSSCKFWSession *fwSession
660 )
661 { 631 {
662 #ifdef NSSDEBUG 632 #ifdef NSSDEBUG
663 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 633 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
664 return (CK_SESSION_HANDLE)0; 634 return (CK_SESSION_HANDLE)0;
665 } 635 }
666 636
667 if( CKR_OK != nssCKFWSession_verifyPointer(fwSession) ) { 637 if (CKR_OK != nssCKFWSession_verifyPointer(fwSession)) {
668 return (CK_SESSION_HANDLE)0; 638 return (CK_SESSION_HANDLE)0;
669 } 639 }
670 #endif /* NSSDEBUG */ 640 #endif /* NSSDEBUG */
671 641
672 return nssCKFWSession_GetHandle(fwSession); 642 return nssCKFWSession_GetHandle(fwSession);
673 /* look it up and assert? */ 643 /* look it up and assert? */
674 } 644 }
675 645
676 /* 646 /*
677 * nssCKFWInstance_CreateObjectHandle 647 * nssCKFWInstance_CreateObjectHandle
678 * 648 *
679 */ 649 */
680 NSS_IMPLEMENT CK_OBJECT_HANDLE 650 NSS_IMPLEMENT CK_OBJECT_HANDLE
681 nssCKFWInstance_CreateObjectHandle 651 nssCKFWInstance_CreateObjectHandle(
682 ( 652 NSSCKFWInstance *fwInstance,
683 NSSCKFWInstance *fwInstance, 653 NSSCKFWObject *fwObject,
684 NSSCKFWObject *fwObject, 654 CK_RV *pError)
685 CK_RV *pError
686 )
687 { 655 {
688 CK_OBJECT_HANDLE hObject; 656 CK_OBJECT_HANDLE hObject;
689 657
690 #ifdef NSSDEBUG 658 #ifdef NSSDEBUG
691 if (!pError) { 659 if (!pError) {
692 return (CK_OBJECT_HANDLE)0; 660 return (CK_OBJECT_HANDLE)0;
693 } 661 }
694 662
695 *pError = nssCKFWInstance_verifyPointer(fwInstance); 663 *pError = nssCKFWInstance_verifyPointer(fwInstance);
696 if( CKR_OK != *pError ) { 664 if (CKR_OK != *pError) {
697 return (CK_OBJECT_HANDLE)0; 665 return (CK_OBJECT_HANDLE)0;
698 } 666 }
699 #endif /* NSSDEBUG */ 667 #endif /* NSSDEBUG */
700 668
701 *pError = nssCKFWMutex_Lock(fwInstance->mutex); 669 *pError = nssCKFWMutex_Lock(fwInstance->mutex);
702 if( CKR_OK != *pError ) { 670 if (CKR_OK != *pError) {
703 return (CK_OBJECT_HANDLE)0; 671 return (CK_OBJECT_HANDLE)0;
704 } 672 }
705 673
706 hObject = ++(fwInstance->lastObjectHandle); 674 hObject = ++(fwInstance->lastObjectHandle);
707 675
708 *pError = nssCKFWObject_SetHandle(fwObject, hObject); 676 *pError = nssCKFWObject_SetHandle(fwObject, hObject);
709 if( CKR_OK != *pError ) { 677 if (CKR_OK != *pError) {
710 hObject = (CK_OBJECT_HANDLE)0; 678 hObject = (CK_OBJECT_HANDLE)0;
711 goto done; 679 goto done;
712 } 680 }
713 681
714 *pError = nssCKFWHash_Add(fwInstance->objectHandleHash, 682 *pError = nssCKFWHash_Add(fwInstance->objectHandleHash,
715 (const void *)hObject, (const void *)fwObject); 683 (const void *)hObject, (const void *)fwObject);
716 if( CKR_OK != *pError ) { 684 if (CKR_OK != *pError) {
717 hObject = (CK_OBJECT_HANDLE)0; 685 hObject = (CK_OBJECT_HANDLE)0;
718 goto done; 686 goto done;
719 } 687 }
720 688
721 done: 689 done:
722 (void)nssCKFWMutex_Unlock(fwInstance->mutex); 690 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
723 return hObject; 691 return hObject;
724 } 692 }
725 693
726 /* 694 /*
727 * nssCKFWInstance_ResolveObjectHandle 695 * nssCKFWInstance_ResolveObjectHandle
728 * 696 *
729 */ 697 */
730 NSS_IMPLEMENT NSSCKFWObject * 698 NSS_IMPLEMENT NSSCKFWObject *
731 nssCKFWInstance_ResolveObjectHandle 699 nssCKFWInstance_ResolveObjectHandle(
732 ( 700 NSSCKFWInstance *fwInstance,
733 NSSCKFWInstance *fwInstance, 701 CK_OBJECT_HANDLE hObject)
734 CK_OBJECT_HANDLE hObject
735 )
736 { 702 {
737 NSSCKFWObject *fwObject; 703 NSSCKFWObject *fwObject;
738 704
739 #ifdef NSSDEBUG 705 #ifdef NSSDEBUG
740 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 706 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
741 return (NSSCKFWObject *)NULL; 707 return (NSSCKFWObject *)NULL;
742 } 708 }
743 #endif /* NSSDEBUG */ 709 #endif /* NSSDEBUG */
744 710
745 if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { 711 if (CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex)) {
746 return (NSSCKFWObject *)NULL; 712 return (NSSCKFWObject *)NULL;
747 } 713 }
748 714
749 fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup( 715 fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
750 fwInstance->objectHandleHash, (const void *)hObject); 716 fwInstance->objectHandleHash, (const void *)hObject);
751 717
752 /* Assert(hObject == nssCKFWObject_GetHandle(fwObject)) */ 718 /* Assert(hObject == nssCKFWObject_GetHandle(fwObject)) */
753 719
754 (void)nssCKFWMutex_Unlock(fwInstance->mutex); 720 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
755 return fwObject; 721 return fwObject;
756 } 722 }
757 723
758 /* 724 /*
759 * nssCKFWInstance_ReassignObjectHandle 725 * nssCKFWInstance_ReassignObjectHandle
760 * 726 *
761 */ 727 */
762 NSS_IMPLEMENT CK_RV 728 NSS_IMPLEMENT CK_RV
763 nssCKFWInstance_ReassignObjectHandle 729 nssCKFWInstance_ReassignObjectHandle(
764 ( 730 NSSCKFWInstance *fwInstance,
765 NSSCKFWInstance *fwInstance, 731 CK_OBJECT_HANDLE hObject,
766 CK_OBJECT_HANDLE hObject, 732 NSSCKFWObject *fwObject)
767 NSSCKFWObject *fwObject
768 )
769 { 733 {
770 CK_RV error = CKR_OK; 734 CK_RV error = CKR_OK;
771 NSSCKFWObject *oldObject; 735 NSSCKFWObject *oldObject;
772 736
773 #ifdef NSSDEBUG 737 #ifdef NSSDEBUG
774 error = nssCKFWInstance_verifyPointer(fwInstance); 738 error = nssCKFWInstance_verifyPointer(fwInstance);
775 if( CKR_OK != error ) { 739 if (CKR_OK != error) {
776 return error; 740 return error;
777 } 741 }
778 #endif /* NSSDEBUG */ 742 #endif /* NSSDEBUG */
779 743
780 error = nssCKFWMutex_Lock(fwInstance->mutex); 744 error = nssCKFWMutex_Lock(fwInstance->mutex);
781 if( CKR_OK != error ) { 745 if (CKR_OK != error) {
746 return error;
747 }
748
749 oldObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
750 fwInstance->objectHandleHash, (const void *)hObject);
751 if (oldObject) {
752 /* Assert(hObject == nssCKFWObject_GetHandle(oldObject) */
753 (void)nssCKFWObject_SetHandle(oldObject, (CK_SESSION_HANDLE)0);
754 nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject);
755 }
756
757 error = nssCKFWObject_SetHandle(fwObject, hObject);
758 if (CKR_OK != error) {
759 goto done;
760 }
761 error = nssCKFWHash_Add(fwInstance->objectHandleHash,
762 (const void *)hObject, (const void *)fwObject);
763
764 done:
765 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
782 return error; 766 return error;
783 }
784
785 oldObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
786 fwInstance->objectHandleHash, (const void *)hObject);
787 if(oldObject) {
788 /* Assert(hObject == nssCKFWObject_GetHandle(oldObject) */
789 (void)nssCKFWObject_SetHandle(oldObject, (CK_SESSION_HANDLE)0);
790 nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject);
791 }
792
793 error = nssCKFWObject_SetHandle(fwObject, hObject);
794 if( CKR_OK != error ) {
795 goto done;
796 }
797 error = nssCKFWHash_Add(fwInstance->objectHandleHash,
798 (const void *)hObject, (const void *)fwObject);
799
800 done:
801 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
802 return error;
803 } 767 }
804 768
805 /* 769 /*
806 * nssCKFWInstance_DestroyObjectHandle 770 * nssCKFWInstance_DestroyObjectHandle
807 * 771 *
808 */ 772 */
809 NSS_IMPLEMENT void 773 NSS_IMPLEMENT void
810 nssCKFWInstance_DestroyObjectHandle 774 nssCKFWInstance_DestroyObjectHandle(
811 ( 775 NSSCKFWInstance *fwInstance,
812 NSSCKFWInstance *fwInstance, 776 CK_OBJECT_HANDLE hObject)
813 CK_OBJECT_HANDLE hObject
814 )
815 { 777 {
816 NSSCKFWObject *fwObject; 778 NSSCKFWObject *fwObject;
817 779
818 #ifdef NSSDEBUG 780 #ifdef NSSDEBUG
819 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 781 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
820 return; 782 return;
821 } 783 }
822 #endif /* NSSDEBUG */ 784 #endif /* NSSDEBUG */
823 785
824 if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { 786 if (CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex)) {
787 return;
788 }
789
790 fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
791 fwInstance->objectHandleHash, (const void *)hObject);
792 if (fwObject) {
793 /* Assert(hObject = nssCKFWObject_GetHandle(fwObject)) */
794 nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject);
795 (void)nssCKFWObject_SetHandle(fwObject, (CK_SESSION_HANDLE)0);
796 }
797
798 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
825 return; 799 return;
826 }
827
828 fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
829 fwInstance->objectHandleHash, (const void *)hObject);
830 if (fwObject) {
831 /* Assert(hObject = nssCKFWObject_GetHandle(fwObject)) */
832 nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject);
833 (void)nssCKFWObject_SetHandle(fwObject, (CK_SESSION_HANDLE)0);
834 }
835
836 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
837 return;
838 } 800 }
839 801
840 /* 802 /*
841 * nssCKFWInstance_FindObjectHandle 803 * nssCKFWInstance_FindObjectHandle
842 * 804 *
843 */ 805 */
844 NSS_IMPLEMENT CK_OBJECT_HANDLE 806 NSS_IMPLEMENT CK_OBJECT_HANDLE
845 nssCKFWInstance_FindObjectHandle 807 nssCKFWInstance_FindObjectHandle(
846 ( 808 NSSCKFWInstance *fwInstance,
847 NSSCKFWInstance *fwInstance, 809 NSSCKFWObject *fwObject)
848 NSSCKFWObject *fwObject
849 )
850 { 810 {
851 #ifdef NSSDEBUG 811 #ifdef NSSDEBUG
852 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 812 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
853 return (CK_OBJECT_HANDLE)0; 813 return (CK_OBJECT_HANDLE)0;
854 } 814 }
855 815
856 if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) { 816 if (CKR_OK != nssCKFWObject_verifyPointer(fwObject)) {
857 return (CK_OBJECT_HANDLE)0; 817 return (CK_OBJECT_HANDLE)0;
858 } 818 }
859 #endif /* NSSDEBUG */ 819 #endif /* NSSDEBUG */
860 820
861 return nssCKFWObject_GetHandle(fwObject); 821 return nssCKFWObject_GetHandle(fwObject);
862 } 822 }
863 823
864 /* 824 /*
865 * nssCKFWInstance_GetNSlots 825 * nssCKFWInstance_GetNSlots
866 * 826 *
867 */ 827 */
868 NSS_IMPLEMENT CK_ULONG 828 NSS_IMPLEMENT CK_ULONG
869 nssCKFWInstance_GetNSlots 829 nssCKFWInstance_GetNSlots(
870 ( 830 NSSCKFWInstance *fwInstance,
871 NSSCKFWInstance *fwInstance, 831 CK_RV *pError)
872 CK_RV *pError
873 )
874 { 832 {
875 #ifdef NSSDEBUG 833 #ifdef NSSDEBUG
876 if (!pError) { 834 if (!pError) {
877 return (CK_ULONG)0; 835 return (CK_ULONG)0;
878 } 836 }
879 837
880 *pError = nssCKFWInstance_verifyPointer(fwInstance); 838 *pError = nssCKFWInstance_verifyPointer(fwInstance);
881 if( CKR_OK != *pError ) { 839 if (CKR_OK != *pError) {
882 return (CK_ULONG)0; 840 return (CK_ULONG)0;
883 } 841 }
884 #endif /* NSSDEBUG */ 842 #endif /* NSSDEBUG */
885 843
886 *pError = CKR_OK; 844 *pError = CKR_OK;
887 return fwInstance->nSlots; 845 return fwInstance->nSlots;
888 } 846 }
889 847
890 /* 848 /*
891 * nssCKFWInstance_GetCryptokiVersion 849 * nssCKFWInstance_GetCryptokiVersion
892 * 850 *
893 */ 851 */
894 NSS_IMPLEMENT CK_VERSION 852 NSS_IMPLEMENT CK_VERSION
895 nssCKFWInstance_GetCryptokiVersion 853 nssCKFWInstance_GetCryptokiVersion(
896 ( 854 NSSCKFWInstance *fwInstance)
897 NSSCKFWInstance *fwInstance
898 )
899 { 855 {
900 CK_VERSION rv; 856 CK_VERSION rv;
901 857
902 #ifdef NSSDEBUG 858 #ifdef NSSDEBUG
903 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 859 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
904 rv.major = rv.minor = 0; 860 rv.major = rv.minor = 0;
905 return rv; 861 return rv;
906 } 862 }
907 #endif /* NSSDEBUG */ 863 #endif /* NSSDEBUG */
908 864
909 if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { 865 if (CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex)) {
910 rv.major = rv.minor = 0; 866 rv.major = rv.minor = 0;
867 return rv;
868 }
869
870 if ((0 != fwInstance->cryptokiVersion.major) ||
871 (0 != fwInstance->cryptokiVersion.minor)) {
872 rv = fwInstance->cryptokiVersion;
873 goto done;
874 }
875
876 if (fwInstance->mdInstance->GetCryptokiVersion) {
877 fwInstance->cryptokiVersion = fwInstance->mdInstance->GetCryptokiVersion (
878 fwInstance->mdInstance, fwInstance);
879 } else {
880 fwInstance->cryptokiVersion.major = 2;
881 fwInstance->cryptokiVersion.minor = 1;
882 }
883
884 rv = fwInstance->cryptokiVersion;
885
886 done:
887 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
911 return rv; 888 return rv;
912 }
913
914 if( (0 != fwInstance->cryptokiVersion.major) ||
915 (0 != fwInstance->cryptokiVersion.minor) ) {
916 rv = fwInstance->cryptokiVersion;
917 goto done;
918 }
919
920 if (fwInstance->mdInstance->GetCryptokiVersion) {
921 fwInstance->cryptokiVersion = fwInstance->mdInstance->GetCryptokiVersion(
922 fwInstance->mdInstance, fwInstance);
923 } else {
924 fwInstance->cryptokiVersion.major = 2;
925 fwInstance->cryptokiVersion.minor = 1;
926 }
927
928 rv = fwInstance->cryptokiVersion;
929
930 done:
931 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
932 return rv;
933 } 889 }
934 890
935 /* 891 /*
936 * nssCKFWInstance_GetManufacturerID 892 * nssCKFWInstance_GetManufacturerID
937 * 893 *
938 */ 894 */
939 NSS_IMPLEMENT CK_RV 895 NSS_IMPLEMENT CK_RV
940 nssCKFWInstance_GetManufacturerID 896 nssCKFWInstance_GetManufacturerID(
941 ( 897 NSSCKFWInstance *fwInstance,
942 NSSCKFWInstance *fwInstance, 898 CK_CHAR manufacturerID[32])
943 CK_CHAR manufacturerID[32]
944 )
945 { 899 {
946 CK_RV error = CKR_OK; 900 CK_RV error = CKR_OK;
947 901
948 #ifdef NSSDEBUG 902 #ifdef NSSDEBUG
949 if( (CK_CHAR_PTR)NULL == manufacturerID ) { 903 if ((CK_CHAR_PTR)NULL == manufacturerID) {
950 return CKR_ARGUMENTS_BAD; 904 return CKR_ARGUMENTS_BAD;
951 } 905 }
952 906
953 error = nssCKFWInstance_verifyPointer(fwInstance); 907 error = nssCKFWInstance_verifyPointer(fwInstance);
954 if( CKR_OK != error ) { 908 if (CKR_OK != error) {
955 return error; 909 return error;
956 } 910 }
957 #endif /* NSSDEBUG */ 911 #endif /* NSSDEBUG */
958 912
959 error = nssCKFWMutex_Lock(fwInstance->mutex); 913 error = nssCKFWMutex_Lock(fwInstance->mutex);
960 if( CKR_OK != error ) { 914 if (CKR_OK != error) {
915 return error;
916 }
917
918 if (!fwInstance->manufacturerID) {
919 if (fwInstance->mdInstance->GetManufacturerID) {
920 fwInstance->manufacturerID = fwInstance->mdInstance->GetManufacturer ID(
921 fwInstance->mdInstance, fwInstance, &error);
922 if ((!fwInstance->manufacturerID) && (CKR_OK != error)) {
923 goto done;
924 }
925 } else {
926 fwInstance->manufacturerID = (NSSUTF8 *)"";
927 }
928 }
929
930 (void)nssUTF8_CopyIntoFixedBuffer(fwInstance->manufacturerID, (char *)manufa cturerID, 32, ' ');
931 error = CKR_OK;
932
933 done:
934 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
961 return error; 935 return error;
962 }
963
964 if (!fwInstance->manufacturerID) {
965 if (fwInstance->mdInstance->GetManufacturerID) {
966 fwInstance->manufacturerID = fwInstance->mdInstance->GetManufacturerID(
967 fwInstance->mdInstance, fwInstance, &error);
968 if ((!fwInstance->manufacturerID) && (CKR_OK != error)) {
969 goto done;
970 }
971 } else {
972 fwInstance->manufacturerID = (NSSUTF8 *) "";
973 }
974 }
975
976 (void)nssUTF8_CopyIntoFixedBuffer(fwInstance->manufacturerID, (char *)manufact urerID, 32, ' ');
977 error = CKR_OK;
978
979 done:
980 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
981 return error;
982 } 936 }
983 937
984 /* 938 /*
985 * nssCKFWInstance_GetFlags 939 * nssCKFWInstance_GetFlags
986 * 940 *
987 */ 941 */
988 NSS_IMPLEMENT CK_ULONG 942 NSS_IMPLEMENT CK_ULONG
989 nssCKFWInstance_GetFlags 943 nssCKFWInstance_GetFlags(
990 ( 944 NSSCKFWInstance *fwInstance)
991 NSSCKFWInstance *fwInstance
992 )
993 { 945 {
994 #ifdef NSSDEBUG 946 #ifdef NSSDEBUG
995 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 947 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
996 return (CK_ULONG)0; 948 return (CK_ULONG)0;
997 } 949 }
998 #endif /* NSSDEBUG */ 950 #endif /* NSSDEBUG */
999 951
1000 /* No "instance flags" are yet defined by Cryptoki. */ 952 /* No "instance flags" are yet defined by Cryptoki. */
1001 return (CK_ULONG)0; 953 return (CK_ULONG)0;
1002 } 954 }
1003 955
1004 /* 956 /*
1005 * nssCKFWInstance_GetLibraryDescription 957 * nssCKFWInstance_GetLibraryDescription
1006 * 958 *
1007 */ 959 */
1008 NSS_IMPLEMENT CK_RV 960 NSS_IMPLEMENT CK_RV
1009 nssCKFWInstance_GetLibraryDescription 961 nssCKFWInstance_GetLibraryDescription(
1010 ( 962 NSSCKFWInstance *fwInstance,
1011 NSSCKFWInstance *fwInstance, 963 CK_CHAR libraryDescription[32])
1012 CK_CHAR libraryDescription[32]
1013 )
1014 { 964 {
1015 CK_RV error = CKR_OK; 965 CK_RV error = CKR_OK;
1016 966
1017 #ifdef NSSDEBUG 967 #ifdef NSSDEBUG
1018 if( (CK_CHAR_PTR)NULL == libraryDescription ) { 968 if ((CK_CHAR_PTR)NULL == libraryDescription) {
1019 return CKR_ARGUMENTS_BAD; 969 return CKR_ARGUMENTS_BAD;
1020 } 970 }
1021 971
1022 error = nssCKFWInstance_verifyPointer(fwInstance); 972 error = nssCKFWInstance_verifyPointer(fwInstance);
1023 if( CKR_OK != error ) { 973 if (CKR_OK != error) {
1024 return error; 974 return error;
1025 } 975 }
1026 #endif /* NSSDEBUG */ 976 #endif /* NSSDEBUG */
1027 977
1028 error = nssCKFWMutex_Lock(fwInstance->mutex); 978 error = nssCKFWMutex_Lock(fwInstance->mutex);
1029 if( CKR_OK != error ) { 979 if (CKR_OK != error) {
980 return error;
981 }
982
983 if (!fwInstance->libraryDescription) {
984 if (fwInstance->mdInstance->GetLibraryDescription) {
985 fwInstance->libraryDescription = fwInstance->mdInstance->GetLibraryD escription(
986 fwInstance->mdInstance, fwInstance, &error);
987 if ((!fwInstance->libraryDescription) && (CKR_OK != error)) {
988 goto done;
989 }
990 } else {
991 fwInstance->libraryDescription = (NSSUTF8 *)"";
992 }
993 }
994
995 (void)nssUTF8_CopyIntoFixedBuffer(fwInstance->libraryDescription, (char *)li braryDescription, 32, ' ');
996 error = CKR_OK;
997
998 done:
999 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
1030 return error; 1000 return error;
1031 }
1032
1033 if (!fwInstance->libraryDescription) {
1034 if (fwInstance->mdInstance->GetLibraryDescription) {
1035 fwInstance->libraryDescription = fwInstance->mdInstance->GetLibraryDescrip tion(
1036 fwInstance->mdInstance, fwInstance, &error);
1037 if ((!fwInstance->libraryDescription) && (CKR_OK != error)) {
1038 goto done;
1039 }
1040 } else {
1041 fwInstance->libraryDescription = (NSSUTF8 *) "";
1042 }
1043 }
1044
1045 (void)nssUTF8_CopyIntoFixedBuffer(fwInstance->libraryDescription, (char *)libr aryDescription, 32, ' ');
1046 error = CKR_OK;
1047
1048 done:
1049 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
1050 return error;
1051 } 1001 }
1052 1002
1053 /* 1003 /*
1054 * nssCKFWInstance_GetLibraryVersion 1004 * nssCKFWInstance_GetLibraryVersion
1055 * 1005 *
1056 */ 1006 */
1057 NSS_IMPLEMENT CK_VERSION 1007 NSS_IMPLEMENT CK_VERSION
1058 nssCKFWInstance_GetLibraryVersion 1008 nssCKFWInstance_GetLibraryVersion(
1059 ( 1009 NSSCKFWInstance *fwInstance)
1060 NSSCKFWInstance *fwInstance
1061 )
1062 { 1010 {
1063 CK_VERSION rv; 1011 CK_VERSION rv;
1064 1012
1065 #ifdef NSSDEBUG 1013 #ifdef NSSDEBUG
1066 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 1014 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
1067 rv.major = rv.minor = 0; 1015 rv.major = rv.minor = 0;
1068 return rv; 1016 return rv;
1069 } 1017 }
1070 #endif /* NSSDEBUG */ 1018 #endif /* NSSDEBUG */
1071 1019
1072 if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) { 1020 if (CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex)) {
1073 rv.major = rv.minor = 0; 1021 rv.major = rv.minor = 0;
1022 return rv;
1023 }
1024
1025 if ((0 != fwInstance->libraryVersion.major) ||
1026 (0 != fwInstance->libraryVersion.minor)) {
1027 rv = fwInstance->libraryVersion;
1028 goto done;
1029 }
1030
1031 if (fwInstance->mdInstance->GetLibraryVersion) {
1032 fwInstance->libraryVersion = fwInstance->mdInstance->GetLibraryVersion(
1033 fwInstance->mdInstance, fwInstance);
1034 } else {
1035 fwInstance->libraryVersion.major = 0;
1036 fwInstance->libraryVersion.minor = 3;
1037 }
1038
1039 rv = fwInstance->libraryVersion;
1040 done:
1041 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
1074 return rv; 1042 return rv;
1075 }
1076
1077 if( (0 != fwInstance->libraryVersion.major) ||
1078 (0 != fwInstance->libraryVersion.minor) ) {
1079 rv = fwInstance->libraryVersion;
1080 goto done;
1081 }
1082
1083 if (fwInstance->mdInstance->GetLibraryVersion) {
1084 fwInstance->libraryVersion = fwInstance->mdInstance->GetLibraryVersion(
1085 fwInstance->mdInstance, fwInstance);
1086 } else {
1087 fwInstance->libraryVersion.major = 0;
1088 fwInstance->libraryVersion.minor = 3;
1089 }
1090
1091 rv = fwInstance->libraryVersion;
1092 done:
1093 (void)nssCKFWMutex_Unlock(fwInstance->mutex);
1094 return rv;
1095 } 1043 }
1096 1044
1097 /* 1045 /*
1098 * nssCKFWInstance_GetModuleHandlesSessionObjects 1046 * nssCKFWInstance_GetModuleHandlesSessionObjects
1099 * 1047 *
1100 */ 1048 */
1101 NSS_IMPLEMENT CK_BBOOL 1049 NSS_IMPLEMENT CK_BBOOL
1102 nssCKFWInstance_GetModuleHandlesSessionObjects 1050 nssCKFWInstance_GetModuleHandlesSessionObjects(
1103 ( 1051 NSSCKFWInstance *fwInstance)
1104 NSSCKFWInstance *fwInstance
1105 )
1106 { 1052 {
1107 #ifdef NSSDEBUG 1053 #ifdef NSSDEBUG
1108 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 1054 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
1109 return CK_FALSE; 1055 return CK_FALSE;
1110 } 1056 }
1111 #endif /* NSSDEBUG */ 1057 #endif /* NSSDEBUG */
1112 1058
1113 return fwInstance->moduleHandlesSessionObjects; 1059 return fwInstance->moduleHandlesSessionObjects;
1114 } 1060 }
1115 1061
1116 /* 1062 /*
1117 * nssCKFWInstance_GetSlots 1063 * nssCKFWInstance_GetSlots
1118 * 1064 *
1119 */ 1065 */
1120 NSS_IMPLEMENT NSSCKFWSlot ** 1066 NSS_IMPLEMENT NSSCKFWSlot **
1121 nssCKFWInstance_GetSlots 1067 nssCKFWInstance_GetSlots(
1122 ( 1068 NSSCKFWInstance *fwInstance,
1123 NSSCKFWInstance *fwInstance, 1069 CK_RV *pError)
1124 CK_RV *pError
1125 )
1126 { 1070 {
1127 #ifdef NSSDEBUG 1071 #ifdef NSSDEBUG
1128 if (!pError) { 1072 if (!pError) {
1129 return (NSSCKFWSlot **)NULL; 1073 return (NSSCKFWSlot **)NULL;
1130 } 1074 }
1131 1075
1132 *pError = nssCKFWInstance_verifyPointer(fwInstance); 1076 *pError = nssCKFWInstance_verifyPointer(fwInstance);
1133 if( CKR_OK != *pError ) { 1077 if (CKR_OK != *pError) {
1134 return (NSSCKFWSlot **)NULL; 1078 return (NSSCKFWSlot **)NULL;
1135 } 1079 }
1136 #endif /* NSSDEBUG */ 1080 #endif /* NSSDEBUG */
1137 1081
1138 return fwInstance->fwSlotList; 1082 return fwInstance->fwSlotList;
1139 } 1083 }
1140 1084
1141 /* 1085 /*
1142 * nssCKFWInstance_WaitForSlotEvent 1086 * nssCKFWInstance_WaitForSlotEvent
1143 * 1087 *
1144 */ 1088 */
1145 NSS_IMPLEMENT NSSCKFWSlot * 1089 NSS_IMPLEMENT NSSCKFWSlot *
1146 nssCKFWInstance_WaitForSlotEvent 1090 nssCKFWInstance_WaitForSlotEvent(
1147 ( 1091 NSSCKFWInstance *fwInstance,
1148 NSSCKFWInstance *fwInstance, 1092 CK_BBOOL block,
1149 CK_BBOOL block, 1093 CK_RV *pError)
1150 CK_RV *pError
1151 )
1152 { 1094 {
1153 NSSCKFWSlot *fwSlot = (NSSCKFWSlot *)NULL; 1095 NSSCKFWSlot *fwSlot = (NSSCKFWSlot *)NULL;
1154 NSSCKMDSlot *mdSlot; 1096 NSSCKMDSlot *mdSlot;
1155 CK_ULONG i, n; 1097 CK_ULONG i, n;
1156 1098
1157 #ifdef NSSDEBUG 1099 #ifdef NSSDEBUG
1158 if (!pError) { 1100 if (!pError) {
1159 return (NSSCKFWSlot *)NULL; 1101 return (NSSCKFWSlot *)NULL;
1160 } 1102 }
1161 1103
1162 *pError = nssCKFWInstance_verifyPointer(fwInstance); 1104 *pError = nssCKFWInstance_verifyPointer(fwInstance);
1163 if( CKR_OK != *pError ) { 1105 if (CKR_OK != *pError) {
1164 return (NSSCKFWSlot *)NULL; 1106 return (NSSCKFWSlot *)NULL;
1165 } 1107 }
1166 1108
1167 switch( block ) { 1109 switch (block) {
1168 case CK_TRUE: 1110 case CK_TRUE:
1169 case CK_FALSE: 1111 case CK_FALSE:
1170 break; 1112 break;
1171 default: 1113 default:
1172 *pError = CKR_ARGUMENTS_BAD; 1114 *pError = CKR_ARGUMENTS_BAD;
1173 return (NSSCKFWSlot *)NULL; 1115 return (NSSCKFWSlot *)NULL;
1174 } 1116 }
1175 #endif /* NSSDEBUG */ 1117 #endif /* NSSDEBUG */
1176 1118
1177 if (!fwInstance->mdInstance->WaitForSlotEvent) { 1119 if (!fwInstance->mdInstance->WaitForSlotEvent) {
1178 *pError = CKR_NO_EVENT; 1120 *pError = CKR_NO_EVENT;
1179 return (NSSCKFWSlot *)NULL; 1121 return (NSSCKFWSlot *)NULL;
1180 } 1122 }
1181 1123
1182 mdSlot = fwInstance->mdInstance->WaitForSlotEvent( 1124 mdSlot = fwInstance->mdInstance->WaitForSlotEvent(
1183 fwInstance->mdInstance, 1125 fwInstance->mdInstance,
1184 fwInstance, 1126 fwInstance,
1185 block, 1127 block,
1186 pError 1128 pError);
1187 );
1188 1129
1189 if (!mdSlot) { 1130 if (!mdSlot) {
1190 return (NSSCKFWSlot *)NULL; 1131 return (NSSCKFWSlot *)NULL;
1191 } 1132 }
1192 1133
1193 n = nssCKFWInstance_GetNSlots(fwInstance, pError); 1134 n = nssCKFWInstance_GetNSlots(fwInstance, pError);
1194 if( ((CK_ULONG)0 == n) && (CKR_OK != *pError) ) { 1135 if (((CK_ULONG)0 == n) && (CKR_OK != *pError)) {
1195 return (NSSCKFWSlot *)NULL; 1136 return (NSSCKFWSlot *)NULL;
1196 } 1137 }
1197 1138
1198 for( i = 0; i < n; i++ ) { 1139 for (i = 0; i < n; i++) {
1199 if( fwInstance->mdSlotList[i] == mdSlot ) { 1140 if (fwInstance->mdSlotList[i] == mdSlot) {
1200 fwSlot = fwInstance->fwSlotList[i]; 1141 fwSlot = fwInstance->fwSlotList[i];
1201 break; 1142 break;
1143 }
1202 } 1144 }
1203 }
1204 1145
1205 if (!fwSlot) { 1146 if (!fwSlot) {
1206 /* Internal error */ 1147 /* Internal error */
1207 *pError = CKR_GENERAL_ERROR; 1148 *pError = CKR_GENERAL_ERROR;
1208 return (NSSCKFWSlot *)NULL; 1149 return (NSSCKFWSlot *)NULL;
1209 } 1150 }
1210 1151
1211 return fwSlot; 1152 return fwSlot;
1212 } 1153 }
1213 1154
1214 /* 1155 /*
1215 * NSSCKFWInstance_GetMDInstance 1156 * NSSCKFWInstance_GetMDInstance
1216 * 1157 *
1217 */ 1158 */
1218 NSS_IMPLEMENT NSSCKMDInstance * 1159 NSS_IMPLEMENT NSSCKMDInstance *
1219 NSSCKFWInstance_GetMDInstance 1160 NSSCKFWInstance_GetMDInstance(
1220 ( 1161 NSSCKFWInstance *fwInstance)
1221 NSSCKFWInstance *fwInstance
1222 )
1223 { 1162 {
1224 #ifdef DEBUG 1163 #ifdef DEBUG
1225 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 1164 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
1226 return (NSSCKMDInstance *)NULL; 1165 return (NSSCKMDInstance *)NULL;
1227 } 1166 }
1228 #endif /* DEBUG */ 1167 #endif /* DEBUG */
1229 1168
1230 return nssCKFWInstance_GetMDInstance(fwInstance); 1169 return nssCKFWInstance_GetMDInstance(fwInstance);
1231 } 1170 }
1232 1171
1233 /* 1172 /*
1234 * NSSCKFWInstance_GetArena 1173 * NSSCKFWInstance_GetArena
1235 * 1174 *
1236 */ 1175 */
1237 NSS_IMPLEMENT NSSArena * 1176 NSS_IMPLEMENT NSSArena *
1238 NSSCKFWInstance_GetArena 1177 NSSCKFWInstance_GetArena(
1239 ( 1178 NSSCKFWInstance *fwInstance,
1240 NSSCKFWInstance *fwInstance, 1179 CK_RV *pError)
1241 CK_RV *pError
1242 )
1243 { 1180 {
1244 #ifdef DEBUG 1181 #ifdef DEBUG
1245 if (!pError) { 1182 if (!pError) {
1246 return (NSSArena *)NULL; 1183 return (NSSArena *)NULL;
1247 } 1184 }
1248 1185
1249 *pError = nssCKFWInstance_verifyPointer(fwInstance); 1186 *pError = nssCKFWInstance_verifyPointer(fwInstance);
1250 if( CKR_OK != *pError ) { 1187 if (CKR_OK != *pError) {
1251 return (NSSArena *)NULL; 1188 return (NSSArena *)NULL;
1252 } 1189 }
1253 #endif /* DEBUG */ 1190 #endif /* DEBUG */
1254 1191
1255 return nssCKFWInstance_GetArena(fwInstance, pError); 1192 return nssCKFWInstance_GetArena(fwInstance, pError);
1256 } 1193 }
1257 1194
1258 /* 1195 /*
1259 * NSSCKFWInstance_MayCreatePthreads 1196 * NSSCKFWInstance_MayCreatePthreads
1260 * 1197 *
1261 */ 1198 */
1262 NSS_IMPLEMENT CK_BBOOL 1199 NSS_IMPLEMENT CK_BBOOL
1263 NSSCKFWInstance_MayCreatePthreads 1200 NSSCKFWInstance_MayCreatePthreads(
1264 ( 1201 NSSCKFWInstance *fwInstance)
1265 NSSCKFWInstance *fwInstance
1266 )
1267 { 1202 {
1268 #ifdef DEBUG 1203 #ifdef DEBUG
1269 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 1204 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
1270 return CK_FALSE; 1205 return CK_FALSE;
1271 } 1206 }
1272 #endif /* DEBUG */ 1207 #endif /* DEBUG */
1273 1208
1274 return nssCKFWInstance_MayCreatePthreads(fwInstance); 1209 return nssCKFWInstance_MayCreatePthreads(fwInstance);
1275 } 1210 }
1276 1211
1277 /* 1212 /*
1278 * NSSCKFWInstance_CreateMutex 1213 * NSSCKFWInstance_CreateMutex
1279 * 1214 *
1280 */ 1215 */
1281 NSS_IMPLEMENT NSSCKFWMutex * 1216 NSS_IMPLEMENT NSSCKFWMutex *
1282 NSSCKFWInstance_CreateMutex 1217 NSSCKFWInstance_CreateMutex(
1283 ( 1218 NSSCKFWInstance *fwInstance,
1284 NSSCKFWInstance *fwInstance, 1219 NSSArena *arena,
1285 NSSArena *arena, 1220 CK_RV *pError)
1286 CK_RV *pError
1287 )
1288 { 1221 {
1289 #ifdef DEBUG 1222 #ifdef DEBUG
1290 if (!pError) { 1223 if (!pError) {
1291 return (NSSCKFWMutex *)NULL; 1224 return (NSSCKFWMutex *)NULL;
1292 } 1225 }
1293 1226
1294 *pError = nssCKFWInstance_verifyPointer(fwInstance); 1227 *pError = nssCKFWInstance_verifyPointer(fwInstance);
1295 if( CKR_OK != *pError ) { 1228 if (CKR_OK != *pError) {
1296 return (NSSCKFWMutex *)NULL; 1229 return (NSSCKFWMutex *)NULL;
1297 } 1230 }
1298 #endif /* DEBUG */ 1231 #endif /* DEBUG */
1299 1232
1300 return nssCKFWInstance_CreateMutex(fwInstance, arena, pError); 1233 return nssCKFWInstance_CreateMutex(fwInstance, arena, pError);
1301 } 1234 }
1302 1235
1303 /* 1236 /*
1304 * NSSCKFWInstance_GetConfigurationData 1237 * NSSCKFWInstance_GetConfigurationData
1305 * 1238 *
1306 */ 1239 */
1307 NSS_IMPLEMENT NSSUTF8 * 1240 NSS_IMPLEMENT NSSUTF8 *
1308 NSSCKFWInstance_GetConfigurationData 1241 NSSCKFWInstance_GetConfigurationData(
1309 ( 1242 NSSCKFWInstance *fwInstance)
1310 NSSCKFWInstance *fwInstance
1311 )
1312 { 1243 {
1313 #ifdef DEBUG 1244 #ifdef DEBUG
1314 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 1245 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
1315 return (NSSUTF8 *)NULL; 1246 return (NSSUTF8 *)NULL;
1316 } 1247 }
1317 #endif /* DEBUG */ 1248 #endif /* DEBUG */
1318 1249
1319 return nssCKFWInstance_GetConfigurationData(fwInstance); 1250 return nssCKFWInstance_GetConfigurationData(fwInstance);
1320 } 1251 }
1321 1252
1322 /* 1253 /*
1323 * NSSCKFWInstance_GetInitArgs 1254 * NSSCKFWInstance_GetInitArgs
1324 * 1255 *
1325 */ 1256 */
1326 NSS_IMPLEMENT CK_C_INITIALIZE_ARGS_PTR 1257 NSS_IMPLEMENT CK_C_INITIALIZE_ARGS_PTR
1327 NSSCKFWInstance_GetInitArgs 1258 NSSCKFWInstance_GetInitArgs(
1328 ( 1259 NSSCKFWInstance *fwInstance)
1329 NSSCKFWInstance *fwInstance
1330 )
1331 { 1260 {
1332 #ifdef DEBUG 1261 #ifdef DEBUG
1333 if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) { 1262 if (CKR_OK != nssCKFWInstance_verifyPointer(fwInstance)) {
1334 return (CK_C_INITIALIZE_ARGS_PTR)NULL; 1263 return (CK_C_INITIALIZE_ARGS_PTR)NULL;
1335 } 1264 }
1336 #endif /* DEBUG */ 1265 #endif /* DEBUG */
1337 1266
1338 return nssCKFWInstance_GetInitArgs(fwInstance); 1267 return nssCKFWInstance_GetInitArgs(fwInstance);
1339 } 1268 }
1340
OLDNEW
« no previous file with comments | « nss/lib/ckfw/hash.c ('k') | nss/lib/ckfw/mechanism.c » ('j') | nss/lib/util/secoid.c » ('J')

Powered by Google App Engine
This is Rietveld 408576698