Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | /* |
michael@0 | 6 | * sessobj.c |
michael@0 | 7 | * |
michael@0 | 8 | * This file contains an NSSCKMDObject implementation for session |
michael@0 | 9 | * objects. The framework uses this implementation to manage |
michael@0 | 10 | * session objects when a Module doesn't wish to be bothered. |
michael@0 | 11 | */ |
michael@0 | 12 | |
michael@0 | 13 | #ifndef CK_T |
michael@0 | 14 | #include "ck.h" |
michael@0 | 15 | #endif /* CK_T */ |
michael@0 | 16 | |
michael@0 | 17 | /* |
michael@0 | 18 | * nssCKMDSessionObject |
michael@0 | 19 | * |
michael@0 | 20 | * -- create -- |
michael@0 | 21 | * nssCKMDSessionObject_Create |
michael@0 | 22 | * |
michael@0 | 23 | * -- EPV calls -- |
michael@0 | 24 | * nss_ckmdSessionObject_Finalize |
michael@0 | 25 | * nss_ckmdSessionObject_IsTokenObject |
michael@0 | 26 | * nss_ckmdSessionObject_GetAttributeCount |
michael@0 | 27 | * nss_ckmdSessionObject_GetAttributeTypes |
michael@0 | 28 | * nss_ckmdSessionObject_GetAttributeSize |
michael@0 | 29 | * nss_ckmdSessionObject_GetAttribute |
michael@0 | 30 | * nss_ckmdSessionObject_SetAttribute |
michael@0 | 31 | * nss_ckmdSessionObject_GetObjectSize |
michael@0 | 32 | */ |
michael@0 | 33 | |
michael@0 | 34 | struct nssCKMDSessionObjectStr { |
michael@0 | 35 | CK_ULONG n; |
michael@0 | 36 | NSSArena *arena; |
michael@0 | 37 | NSSItem *attributes; |
michael@0 | 38 | CK_ATTRIBUTE_TYPE_PTR types; |
michael@0 | 39 | nssCKFWHash *hash; |
michael@0 | 40 | }; |
michael@0 | 41 | typedef struct nssCKMDSessionObjectStr nssCKMDSessionObject; |
michael@0 | 42 | |
michael@0 | 43 | #ifdef DEBUG |
michael@0 | 44 | /* |
michael@0 | 45 | * But first, the pointer-tracking stuff. |
michael@0 | 46 | * |
michael@0 | 47 | * NOTE: the pointer-tracking support in NSS/base currently relies |
michael@0 | 48 | * upon NSPR's CallOnce support. That, however, relies upon NSPR's |
michael@0 | 49 | * locking, which is tied into the runtime. We need a pointer-tracker |
michael@0 | 50 | * implementation that uses the locks supplied through C_Initialize. |
michael@0 | 51 | * That support, however, can be filled in later. So for now, I'll |
michael@0 | 52 | * just do this routines as no-ops. |
michael@0 | 53 | */ |
michael@0 | 54 | |
michael@0 | 55 | static CK_RV |
michael@0 | 56 | nss_ckmdSessionObject_add_pointer |
michael@0 | 57 | ( |
michael@0 | 58 | const NSSCKMDObject *mdObject |
michael@0 | 59 | ) |
michael@0 | 60 | { |
michael@0 | 61 | return CKR_OK; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | static CK_RV |
michael@0 | 65 | nss_ckmdSessionObject_remove_pointer |
michael@0 | 66 | ( |
michael@0 | 67 | const NSSCKMDObject *mdObject |
michael@0 | 68 | ) |
michael@0 | 69 | { |
michael@0 | 70 | return CKR_OK; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | #ifdef NSS_DEBUG |
michael@0 | 74 | static CK_RV |
michael@0 | 75 | nss_ckmdSessionObject_verifyPointer |
michael@0 | 76 | ( |
michael@0 | 77 | const NSSCKMDObject *mdObject |
michael@0 | 78 | ) |
michael@0 | 79 | { |
michael@0 | 80 | return CKR_OK; |
michael@0 | 81 | } |
michael@0 | 82 | #endif |
michael@0 | 83 | |
michael@0 | 84 | #endif /* DEBUG */ |
michael@0 | 85 | |
michael@0 | 86 | /* |
michael@0 | 87 | * We must forward-declare these routines |
michael@0 | 88 | */ |
michael@0 | 89 | static void |
michael@0 | 90 | nss_ckmdSessionObject_Finalize |
michael@0 | 91 | ( |
michael@0 | 92 | NSSCKMDObject *mdObject, |
michael@0 | 93 | NSSCKFWObject *fwObject, |
michael@0 | 94 | NSSCKMDSession *mdSession, |
michael@0 | 95 | NSSCKFWSession *fwSession, |
michael@0 | 96 | NSSCKMDToken *mdToken, |
michael@0 | 97 | NSSCKFWToken *fwToken, |
michael@0 | 98 | NSSCKMDInstance *mdInstance, |
michael@0 | 99 | NSSCKFWInstance *fwInstance |
michael@0 | 100 | ); |
michael@0 | 101 | |
michael@0 | 102 | static CK_RV |
michael@0 | 103 | nss_ckmdSessionObject_Destroy |
michael@0 | 104 | ( |
michael@0 | 105 | NSSCKMDObject *mdObject, |
michael@0 | 106 | NSSCKFWObject *fwObject, |
michael@0 | 107 | NSSCKMDSession *mdSession, |
michael@0 | 108 | NSSCKFWSession *fwSession, |
michael@0 | 109 | NSSCKMDToken *mdToken, |
michael@0 | 110 | NSSCKFWToken *fwToken, |
michael@0 | 111 | NSSCKMDInstance *mdInstance, |
michael@0 | 112 | NSSCKFWInstance *fwInstance |
michael@0 | 113 | ); |
michael@0 | 114 | |
michael@0 | 115 | static CK_BBOOL |
michael@0 | 116 | nss_ckmdSessionObject_IsTokenObject |
michael@0 | 117 | ( |
michael@0 | 118 | NSSCKMDObject *mdObject, |
michael@0 | 119 | NSSCKFWObject *fwObject, |
michael@0 | 120 | NSSCKMDSession *mdSession, |
michael@0 | 121 | NSSCKFWSession *fwSession, |
michael@0 | 122 | NSSCKMDToken *mdToken, |
michael@0 | 123 | NSSCKFWToken *fwToken, |
michael@0 | 124 | NSSCKMDInstance *mdInstance, |
michael@0 | 125 | NSSCKFWInstance *fwInstance |
michael@0 | 126 | ); |
michael@0 | 127 | |
michael@0 | 128 | static CK_ULONG |
michael@0 | 129 | nss_ckmdSessionObject_GetAttributeCount |
michael@0 | 130 | ( |
michael@0 | 131 | NSSCKMDObject *mdObject, |
michael@0 | 132 | NSSCKFWObject *fwObject, |
michael@0 | 133 | NSSCKMDSession *mdSession, |
michael@0 | 134 | NSSCKFWSession *fwSession, |
michael@0 | 135 | NSSCKMDToken *mdToken, |
michael@0 | 136 | NSSCKFWToken *fwToken, |
michael@0 | 137 | NSSCKMDInstance *mdInstance, |
michael@0 | 138 | NSSCKFWInstance *fwInstance, |
michael@0 | 139 | CK_RV *pError |
michael@0 | 140 | ); |
michael@0 | 141 | |
michael@0 | 142 | static CK_RV |
michael@0 | 143 | nss_ckmdSessionObject_GetAttributeTypes |
michael@0 | 144 | ( |
michael@0 | 145 | NSSCKMDObject *mdObject, |
michael@0 | 146 | NSSCKFWObject *fwObject, |
michael@0 | 147 | NSSCKMDSession *mdSession, |
michael@0 | 148 | NSSCKFWSession *fwSession, |
michael@0 | 149 | NSSCKMDToken *mdToken, |
michael@0 | 150 | NSSCKFWToken *fwToken, |
michael@0 | 151 | NSSCKMDInstance *mdInstance, |
michael@0 | 152 | NSSCKFWInstance *fwInstance, |
michael@0 | 153 | CK_ATTRIBUTE_TYPE_PTR typeArray, |
michael@0 | 154 | CK_ULONG ulCount |
michael@0 | 155 | ); |
michael@0 | 156 | |
michael@0 | 157 | static CK_ULONG |
michael@0 | 158 | nss_ckmdSessionObject_GetAttributeSize |
michael@0 | 159 | ( |
michael@0 | 160 | NSSCKMDObject *mdObject, |
michael@0 | 161 | NSSCKFWObject *fwObject, |
michael@0 | 162 | NSSCKMDSession *mdSession, |
michael@0 | 163 | NSSCKFWSession *fwSession, |
michael@0 | 164 | NSSCKMDToken *mdToken, |
michael@0 | 165 | NSSCKFWToken *fwToken, |
michael@0 | 166 | NSSCKMDInstance *mdInstance, |
michael@0 | 167 | NSSCKFWInstance *fwInstance, |
michael@0 | 168 | CK_ATTRIBUTE_TYPE attribute, |
michael@0 | 169 | CK_RV *pError |
michael@0 | 170 | ); |
michael@0 | 171 | |
michael@0 | 172 | static NSSCKFWItem |
michael@0 | 173 | nss_ckmdSessionObject_GetAttribute |
michael@0 | 174 | ( |
michael@0 | 175 | NSSCKMDObject *mdObject, |
michael@0 | 176 | NSSCKFWObject *fwObject, |
michael@0 | 177 | NSSCKMDSession *mdSession, |
michael@0 | 178 | NSSCKFWSession *fwSession, |
michael@0 | 179 | NSSCKMDToken *mdToken, |
michael@0 | 180 | NSSCKFWToken *fwToken, |
michael@0 | 181 | NSSCKMDInstance *mdInstance, |
michael@0 | 182 | NSSCKFWInstance *fwInstance, |
michael@0 | 183 | CK_ATTRIBUTE_TYPE attribute, |
michael@0 | 184 | CK_RV *pError |
michael@0 | 185 | ); |
michael@0 | 186 | |
michael@0 | 187 | static CK_RV |
michael@0 | 188 | nss_ckmdSessionObject_SetAttribute |
michael@0 | 189 | ( |
michael@0 | 190 | NSSCKMDObject *mdObject, |
michael@0 | 191 | NSSCKFWObject *fwObject, |
michael@0 | 192 | NSSCKMDSession *mdSession, |
michael@0 | 193 | NSSCKFWSession *fwSession, |
michael@0 | 194 | NSSCKMDToken *mdToken, |
michael@0 | 195 | NSSCKFWToken *fwToken, |
michael@0 | 196 | NSSCKMDInstance *mdInstance, |
michael@0 | 197 | NSSCKFWInstance *fwInstance, |
michael@0 | 198 | CK_ATTRIBUTE_TYPE attribute, |
michael@0 | 199 | NSSItem *value |
michael@0 | 200 | ); |
michael@0 | 201 | |
michael@0 | 202 | static CK_ULONG |
michael@0 | 203 | nss_ckmdSessionObject_GetObjectSize |
michael@0 | 204 | ( |
michael@0 | 205 | NSSCKMDObject *mdObject, |
michael@0 | 206 | NSSCKFWObject *fwObject, |
michael@0 | 207 | NSSCKMDSession *mdSession, |
michael@0 | 208 | NSSCKFWSession *fwSession, |
michael@0 | 209 | NSSCKMDToken *mdToken, |
michael@0 | 210 | NSSCKFWToken *fwToken, |
michael@0 | 211 | NSSCKMDInstance *mdInstance, |
michael@0 | 212 | NSSCKFWInstance *fwInstance, |
michael@0 | 213 | CK_RV *pError |
michael@0 | 214 | ); |
michael@0 | 215 | |
michael@0 | 216 | /* |
michael@0 | 217 | * nssCKMDSessionObject_Create |
michael@0 | 218 | * |
michael@0 | 219 | */ |
michael@0 | 220 | NSS_IMPLEMENT NSSCKMDObject * |
michael@0 | 221 | nssCKMDSessionObject_Create |
michael@0 | 222 | ( |
michael@0 | 223 | NSSCKFWToken *fwToken, |
michael@0 | 224 | NSSArena *arena, |
michael@0 | 225 | CK_ATTRIBUTE_PTR attributes, |
michael@0 | 226 | CK_ULONG ulCount, |
michael@0 | 227 | CK_RV *pError |
michael@0 | 228 | ) |
michael@0 | 229 | { |
michael@0 | 230 | NSSCKMDObject *mdObject = (NSSCKMDObject *)NULL; |
michael@0 | 231 | nssCKMDSessionObject *mdso = (nssCKMDSessionObject *)NULL; |
michael@0 | 232 | CK_ULONG i; |
michael@0 | 233 | nssCKFWHash *hash; |
michael@0 | 234 | |
michael@0 | 235 | *pError = CKR_OK; |
michael@0 | 236 | |
michael@0 | 237 | mdso = nss_ZNEW(arena, nssCKMDSessionObject); |
michael@0 | 238 | if (!mdso) { |
michael@0 | 239 | goto loser; |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | mdso->arena = arena; |
michael@0 | 243 | mdso->n = ulCount; |
michael@0 | 244 | mdso->attributes = nss_ZNEWARRAY(arena, NSSItem, ulCount); |
michael@0 | 245 | if (!mdso->attributes) { |
michael@0 | 246 | goto loser; |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | mdso->types = nss_ZNEWARRAY(arena, CK_ATTRIBUTE_TYPE, ulCount); |
michael@0 | 250 | if (!mdso->types) { |
michael@0 | 251 | goto loser; |
michael@0 | 252 | } |
michael@0 | 253 | for( i = 0; i < ulCount; i++ ) { |
michael@0 | 254 | mdso->types[i] = attributes[i].type; |
michael@0 | 255 | mdso->attributes[i].size = attributes[i].ulValueLen; |
michael@0 | 256 | mdso->attributes[i].data = nss_ZAlloc(arena, attributes[i].ulValueLen); |
michael@0 | 257 | if (!mdso->attributes[i].data) { |
michael@0 | 258 | goto loser; |
michael@0 | 259 | } |
michael@0 | 260 | (void)nsslibc_memcpy(mdso->attributes[i].data, attributes[i].pValue, |
michael@0 | 261 | attributes[i].ulValueLen); |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | mdObject = nss_ZNEW(arena, NSSCKMDObject); |
michael@0 | 265 | if (!mdObject) { |
michael@0 | 266 | goto loser; |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | mdObject->etc = (void *)mdso; |
michael@0 | 270 | mdObject->Finalize = nss_ckmdSessionObject_Finalize; |
michael@0 | 271 | mdObject->Destroy = nss_ckmdSessionObject_Destroy; |
michael@0 | 272 | mdObject->IsTokenObject = nss_ckmdSessionObject_IsTokenObject; |
michael@0 | 273 | mdObject->GetAttributeCount = nss_ckmdSessionObject_GetAttributeCount; |
michael@0 | 274 | mdObject->GetAttributeTypes = nss_ckmdSessionObject_GetAttributeTypes; |
michael@0 | 275 | mdObject->GetAttributeSize = nss_ckmdSessionObject_GetAttributeSize; |
michael@0 | 276 | mdObject->GetAttribute = nss_ckmdSessionObject_GetAttribute; |
michael@0 | 277 | mdObject->SetAttribute = nss_ckmdSessionObject_SetAttribute; |
michael@0 | 278 | mdObject->GetObjectSize = nss_ckmdSessionObject_GetObjectSize; |
michael@0 | 279 | |
michael@0 | 280 | hash = nssCKFWToken_GetSessionObjectHash(fwToken); |
michael@0 | 281 | if (!hash) { |
michael@0 | 282 | *pError = CKR_GENERAL_ERROR; |
michael@0 | 283 | goto loser; |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | mdso->hash = hash; |
michael@0 | 287 | |
michael@0 | 288 | *pError = nssCKFWHash_Add(hash, mdObject, mdObject); |
michael@0 | 289 | if( CKR_OK != *pError ) { |
michael@0 | 290 | goto loser; |
michael@0 | 291 | } |
michael@0 | 292 | |
michael@0 | 293 | #ifdef DEBUG |
michael@0 | 294 | if(( *pError = nss_ckmdSessionObject_add_pointer(mdObject)) != CKR_OK ) { |
michael@0 | 295 | goto loser; |
michael@0 | 296 | } |
michael@0 | 297 | #endif /* DEBUG */ |
michael@0 | 298 | |
michael@0 | 299 | return mdObject; |
michael@0 | 300 | |
michael@0 | 301 | loser: |
michael@0 | 302 | if (mdso) { |
michael@0 | 303 | if (mdso->attributes) { |
michael@0 | 304 | for( i = 0; i < ulCount; i++ ) { |
michael@0 | 305 | nss_ZFreeIf(mdso->attributes[i].data); |
michael@0 | 306 | } |
michael@0 | 307 | nss_ZFreeIf(mdso->attributes); |
michael@0 | 308 | } |
michael@0 | 309 | nss_ZFreeIf(mdso->types); |
michael@0 | 310 | nss_ZFreeIf(mdso); |
michael@0 | 311 | } |
michael@0 | 312 | |
michael@0 | 313 | nss_ZFreeIf(mdObject); |
michael@0 | 314 | if (*pError == CKR_OK) { |
michael@0 | 315 | *pError = CKR_HOST_MEMORY; |
michael@0 | 316 | } |
michael@0 | 317 | return (NSSCKMDObject *)NULL; |
michael@0 | 318 | } |
michael@0 | 319 | |
michael@0 | 320 | /* |
michael@0 | 321 | * nss_ckmdSessionObject_Finalize |
michael@0 | 322 | * |
michael@0 | 323 | */ |
michael@0 | 324 | static void |
michael@0 | 325 | nss_ckmdSessionObject_Finalize |
michael@0 | 326 | ( |
michael@0 | 327 | NSSCKMDObject *mdObject, |
michael@0 | 328 | NSSCKFWObject *fwObject, |
michael@0 | 329 | NSSCKMDSession *mdSession, |
michael@0 | 330 | NSSCKFWSession *fwSession, |
michael@0 | 331 | NSSCKMDToken *mdToken, |
michael@0 | 332 | NSSCKFWToken *fwToken, |
michael@0 | 333 | NSSCKMDInstance *mdInstance, |
michael@0 | 334 | NSSCKFWInstance *fwInstance |
michael@0 | 335 | ) |
michael@0 | 336 | { |
michael@0 | 337 | /* This shouldn't ever be called */ |
michael@0 | 338 | return; |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | /* |
michael@0 | 342 | * nss_ckmdSessionObject_Destroy |
michael@0 | 343 | * |
michael@0 | 344 | */ |
michael@0 | 345 | |
michael@0 | 346 | static CK_RV |
michael@0 | 347 | nss_ckmdSessionObject_Destroy |
michael@0 | 348 | ( |
michael@0 | 349 | NSSCKMDObject *mdObject, |
michael@0 | 350 | NSSCKFWObject *fwObject, |
michael@0 | 351 | NSSCKMDSession *mdSession, |
michael@0 | 352 | NSSCKFWSession *fwSession, |
michael@0 | 353 | NSSCKMDToken *mdToken, |
michael@0 | 354 | NSSCKFWToken *fwToken, |
michael@0 | 355 | NSSCKMDInstance *mdInstance, |
michael@0 | 356 | NSSCKFWInstance *fwInstance |
michael@0 | 357 | ) |
michael@0 | 358 | { |
michael@0 | 359 | #ifdef NSSDEBUG |
michael@0 | 360 | CK_RV error = CKR_OK; |
michael@0 | 361 | #endif /* NSSDEBUG */ |
michael@0 | 362 | nssCKMDSessionObject *mdso; |
michael@0 | 363 | CK_ULONG i; |
michael@0 | 364 | |
michael@0 | 365 | #ifdef NSSDEBUG |
michael@0 | 366 | error = nss_ckmdSessionObject_verifyPointer(mdObject); |
michael@0 | 367 | if( CKR_OK != error ) { |
michael@0 | 368 | return error; |
michael@0 | 369 | } |
michael@0 | 370 | #endif /* NSSDEBUG */ |
michael@0 | 371 | |
michael@0 | 372 | mdso = (nssCKMDSessionObject *)mdObject->etc; |
michael@0 | 373 | |
michael@0 | 374 | nssCKFWHash_Remove(mdso->hash, mdObject); |
michael@0 | 375 | |
michael@0 | 376 | for( i = 0; i < mdso->n; i++ ) { |
michael@0 | 377 | nss_ZFreeIf(mdso->attributes[i].data); |
michael@0 | 378 | } |
michael@0 | 379 | nss_ZFreeIf(mdso->attributes); |
michael@0 | 380 | nss_ZFreeIf(mdso->types); |
michael@0 | 381 | nss_ZFreeIf(mdso); |
michael@0 | 382 | nss_ZFreeIf(mdObject); |
michael@0 | 383 | |
michael@0 | 384 | #ifdef DEBUG |
michael@0 | 385 | (void)nss_ckmdSessionObject_remove_pointer(mdObject); |
michael@0 | 386 | #endif /* DEBUG */ |
michael@0 | 387 | |
michael@0 | 388 | return CKR_OK; |
michael@0 | 389 | } |
michael@0 | 390 | |
michael@0 | 391 | /* |
michael@0 | 392 | * nss_ckmdSessionObject_IsTokenObject |
michael@0 | 393 | * |
michael@0 | 394 | */ |
michael@0 | 395 | |
michael@0 | 396 | static CK_BBOOL |
michael@0 | 397 | nss_ckmdSessionObject_IsTokenObject |
michael@0 | 398 | ( |
michael@0 | 399 | NSSCKMDObject *mdObject, |
michael@0 | 400 | NSSCKFWObject *fwObject, |
michael@0 | 401 | NSSCKMDSession *mdSession, |
michael@0 | 402 | NSSCKFWSession *fwSession, |
michael@0 | 403 | NSSCKMDToken *mdToken, |
michael@0 | 404 | NSSCKFWToken *fwToken, |
michael@0 | 405 | NSSCKMDInstance *mdInstance, |
michael@0 | 406 | NSSCKFWInstance *fwInstance |
michael@0 | 407 | ) |
michael@0 | 408 | { |
michael@0 | 409 | #ifdef NSSDEBUG |
michael@0 | 410 | if( CKR_OK != nss_ckmdSessionObject_verifyPointer(mdObject) ) { |
michael@0 | 411 | return CK_FALSE; |
michael@0 | 412 | } |
michael@0 | 413 | #endif /* NSSDEBUG */ |
michael@0 | 414 | |
michael@0 | 415 | /* |
michael@0 | 416 | * This implementation is only ever used for session objects. |
michael@0 | 417 | */ |
michael@0 | 418 | return CK_FALSE; |
michael@0 | 419 | } |
michael@0 | 420 | |
michael@0 | 421 | /* |
michael@0 | 422 | * nss_ckmdSessionObject_GetAttributeCount |
michael@0 | 423 | * |
michael@0 | 424 | */ |
michael@0 | 425 | static CK_ULONG |
michael@0 | 426 | nss_ckmdSessionObject_GetAttributeCount |
michael@0 | 427 | ( |
michael@0 | 428 | NSSCKMDObject *mdObject, |
michael@0 | 429 | NSSCKFWObject *fwObject, |
michael@0 | 430 | NSSCKMDSession *mdSession, |
michael@0 | 431 | NSSCKFWSession *fwSession, |
michael@0 | 432 | NSSCKMDToken *mdToken, |
michael@0 | 433 | NSSCKFWToken *fwToken, |
michael@0 | 434 | NSSCKMDInstance *mdInstance, |
michael@0 | 435 | NSSCKFWInstance *fwInstance, |
michael@0 | 436 | CK_RV *pError |
michael@0 | 437 | ) |
michael@0 | 438 | { |
michael@0 | 439 | nssCKMDSessionObject *obj; |
michael@0 | 440 | |
michael@0 | 441 | #ifdef NSSDEBUG |
michael@0 | 442 | if (!pError) { |
michael@0 | 443 | return 0; |
michael@0 | 444 | } |
michael@0 | 445 | |
michael@0 | 446 | *pError = nss_ckmdSessionObject_verifyPointer(mdObject); |
michael@0 | 447 | if( CKR_OK != *pError ) { |
michael@0 | 448 | return 0; |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | /* We could even check all the other arguments, for sanity. */ |
michael@0 | 452 | #endif /* NSSDEBUG */ |
michael@0 | 453 | |
michael@0 | 454 | obj = (nssCKMDSessionObject *)mdObject->etc; |
michael@0 | 455 | |
michael@0 | 456 | return obj->n; |
michael@0 | 457 | } |
michael@0 | 458 | |
michael@0 | 459 | /* |
michael@0 | 460 | * nss_ckmdSessionObject_GetAttributeTypes |
michael@0 | 461 | * |
michael@0 | 462 | */ |
michael@0 | 463 | static CK_RV |
michael@0 | 464 | nss_ckmdSessionObject_GetAttributeTypes |
michael@0 | 465 | ( |
michael@0 | 466 | NSSCKMDObject *mdObject, |
michael@0 | 467 | NSSCKFWObject *fwObject, |
michael@0 | 468 | NSSCKMDSession *mdSession, |
michael@0 | 469 | NSSCKFWSession *fwSession, |
michael@0 | 470 | NSSCKMDToken *mdToken, |
michael@0 | 471 | NSSCKFWToken *fwToken, |
michael@0 | 472 | NSSCKMDInstance *mdInstance, |
michael@0 | 473 | NSSCKFWInstance *fwInstance, |
michael@0 | 474 | CK_ATTRIBUTE_TYPE_PTR typeArray, |
michael@0 | 475 | CK_ULONG ulCount |
michael@0 | 476 | ) |
michael@0 | 477 | { |
michael@0 | 478 | #ifdef NSSDEBUG |
michael@0 | 479 | CK_RV error = CKR_OK; |
michael@0 | 480 | #endif /* NSSDEBUG */ |
michael@0 | 481 | nssCKMDSessionObject *obj; |
michael@0 | 482 | |
michael@0 | 483 | #ifdef NSSDEBUG |
michael@0 | 484 | error = nss_ckmdSessionObject_verifyPointer(mdObject); |
michael@0 | 485 | if( CKR_OK != error ) { |
michael@0 | 486 | return error; |
michael@0 | 487 | } |
michael@0 | 488 | |
michael@0 | 489 | /* We could even check all the other arguments, for sanity. */ |
michael@0 | 490 | #endif /* NSSDEBUG */ |
michael@0 | 491 | |
michael@0 | 492 | obj = (nssCKMDSessionObject *)mdObject->etc; |
michael@0 | 493 | |
michael@0 | 494 | if( ulCount < obj->n ) { |
michael@0 | 495 | return CKR_BUFFER_TOO_SMALL; |
michael@0 | 496 | } |
michael@0 | 497 | |
michael@0 | 498 | (void)nsslibc_memcpy(typeArray, obj->types, |
michael@0 | 499 | sizeof(CK_ATTRIBUTE_TYPE) * obj->n); |
michael@0 | 500 | |
michael@0 | 501 | return CKR_OK; |
michael@0 | 502 | } |
michael@0 | 503 | |
michael@0 | 504 | /* |
michael@0 | 505 | * nss_ckmdSessionObject_GetAttributeSize |
michael@0 | 506 | * |
michael@0 | 507 | */ |
michael@0 | 508 | static CK_ULONG |
michael@0 | 509 | nss_ckmdSessionObject_GetAttributeSize |
michael@0 | 510 | ( |
michael@0 | 511 | NSSCKMDObject *mdObject, |
michael@0 | 512 | NSSCKFWObject *fwObject, |
michael@0 | 513 | NSSCKMDSession *mdSession, |
michael@0 | 514 | NSSCKFWSession *fwSession, |
michael@0 | 515 | NSSCKMDToken *mdToken, |
michael@0 | 516 | NSSCKFWToken *fwToken, |
michael@0 | 517 | NSSCKMDInstance *mdInstance, |
michael@0 | 518 | NSSCKFWInstance *fwInstance, |
michael@0 | 519 | CK_ATTRIBUTE_TYPE attribute, |
michael@0 | 520 | CK_RV *pError |
michael@0 | 521 | ) |
michael@0 | 522 | { |
michael@0 | 523 | nssCKMDSessionObject *obj; |
michael@0 | 524 | CK_ULONG i; |
michael@0 | 525 | |
michael@0 | 526 | #ifdef NSSDEBUG |
michael@0 | 527 | if (!pError) { |
michael@0 | 528 | return 0; |
michael@0 | 529 | } |
michael@0 | 530 | |
michael@0 | 531 | *pError = nss_ckmdSessionObject_verifyPointer(mdObject); |
michael@0 | 532 | if( CKR_OK != *pError ) { |
michael@0 | 533 | return 0; |
michael@0 | 534 | } |
michael@0 | 535 | |
michael@0 | 536 | /* We could even check all the other arguments, for sanity. */ |
michael@0 | 537 | #endif /* NSSDEBUG */ |
michael@0 | 538 | |
michael@0 | 539 | obj = (nssCKMDSessionObject *)mdObject->etc; |
michael@0 | 540 | |
michael@0 | 541 | for( i = 0; i < obj->n; i++ ) { |
michael@0 | 542 | if( attribute == obj->types[i] ) { |
michael@0 | 543 | return (CK_ULONG)(obj->attributes[i].size); |
michael@0 | 544 | } |
michael@0 | 545 | } |
michael@0 | 546 | |
michael@0 | 547 | *pError = CKR_ATTRIBUTE_TYPE_INVALID; |
michael@0 | 548 | return 0; |
michael@0 | 549 | } |
michael@0 | 550 | |
michael@0 | 551 | /* |
michael@0 | 552 | * nss_ckmdSessionObject_GetAttribute |
michael@0 | 553 | * |
michael@0 | 554 | */ |
michael@0 | 555 | static NSSCKFWItem |
michael@0 | 556 | nss_ckmdSessionObject_GetAttribute |
michael@0 | 557 | ( |
michael@0 | 558 | NSSCKMDObject *mdObject, |
michael@0 | 559 | NSSCKFWObject *fwObject, |
michael@0 | 560 | NSSCKMDSession *mdSession, |
michael@0 | 561 | NSSCKFWSession *fwSession, |
michael@0 | 562 | NSSCKMDToken *mdToken, |
michael@0 | 563 | NSSCKFWToken *fwToken, |
michael@0 | 564 | NSSCKMDInstance *mdInstance, |
michael@0 | 565 | NSSCKFWInstance *fwInstance, |
michael@0 | 566 | CK_ATTRIBUTE_TYPE attribute, |
michael@0 | 567 | CK_RV *pError |
michael@0 | 568 | ) |
michael@0 | 569 | { |
michael@0 | 570 | NSSCKFWItem item; |
michael@0 | 571 | nssCKMDSessionObject *obj; |
michael@0 | 572 | CK_ULONG i; |
michael@0 | 573 | |
michael@0 | 574 | item.needsFreeing = PR_FALSE; |
michael@0 | 575 | item.item = NULL; |
michael@0 | 576 | #ifdef NSSDEBUG |
michael@0 | 577 | if (!pError) { |
michael@0 | 578 | return item; |
michael@0 | 579 | } |
michael@0 | 580 | |
michael@0 | 581 | *pError = nss_ckmdSessionObject_verifyPointer(mdObject); |
michael@0 | 582 | if( CKR_OK != *pError ) { |
michael@0 | 583 | return item; |
michael@0 | 584 | } |
michael@0 | 585 | |
michael@0 | 586 | /* We could even check all the other arguments, for sanity. */ |
michael@0 | 587 | #endif /* NSSDEBUG */ |
michael@0 | 588 | |
michael@0 | 589 | obj = (nssCKMDSessionObject *)mdObject->etc; |
michael@0 | 590 | |
michael@0 | 591 | for( i = 0; i < obj->n; i++ ) { |
michael@0 | 592 | if( attribute == obj->types[i] ) { |
michael@0 | 593 | item.item = &obj->attributes[i]; |
michael@0 | 594 | return item; |
michael@0 | 595 | } |
michael@0 | 596 | } |
michael@0 | 597 | |
michael@0 | 598 | *pError = CKR_ATTRIBUTE_TYPE_INVALID; |
michael@0 | 599 | return item; |
michael@0 | 600 | } |
michael@0 | 601 | |
michael@0 | 602 | /* |
michael@0 | 603 | * nss_ckmdSessionObject_SetAttribute |
michael@0 | 604 | * |
michael@0 | 605 | */ |
michael@0 | 606 | |
michael@0 | 607 | /* |
michael@0 | 608 | * Okay, so this implementation sucks. It doesn't support removing |
michael@0 | 609 | * an attribute (if value == NULL), and could be more graceful about |
michael@0 | 610 | * memory. It should allow "blank" slots in the arrays, with some |
michael@0 | 611 | * invalid attribute type, and then it could support removal much |
michael@0 | 612 | * more easily. Do this later. |
michael@0 | 613 | */ |
michael@0 | 614 | static CK_RV |
michael@0 | 615 | nss_ckmdSessionObject_SetAttribute |
michael@0 | 616 | ( |
michael@0 | 617 | NSSCKMDObject *mdObject, |
michael@0 | 618 | NSSCKFWObject *fwObject, |
michael@0 | 619 | NSSCKMDSession *mdSession, |
michael@0 | 620 | NSSCKFWSession *fwSession, |
michael@0 | 621 | NSSCKMDToken *mdToken, |
michael@0 | 622 | NSSCKFWToken *fwToken, |
michael@0 | 623 | NSSCKMDInstance *mdInstance, |
michael@0 | 624 | NSSCKFWInstance *fwInstance, |
michael@0 | 625 | CK_ATTRIBUTE_TYPE attribute, |
michael@0 | 626 | NSSItem *value |
michael@0 | 627 | ) |
michael@0 | 628 | { |
michael@0 | 629 | nssCKMDSessionObject *obj; |
michael@0 | 630 | CK_ULONG i; |
michael@0 | 631 | NSSItem n; |
michael@0 | 632 | NSSItem *ra; |
michael@0 | 633 | CK_ATTRIBUTE_TYPE_PTR rt; |
michael@0 | 634 | #ifdef NSSDEBUG |
michael@0 | 635 | CK_RV error; |
michael@0 | 636 | #endif /* NSSDEBUG */ |
michael@0 | 637 | |
michael@0 | 638 | #ifdef NSSDEBUG |
michael@0 | 639 | error = nss_ckmdSessionObject_verifyPointer(mdObject); |
michael@0 | 640 | if( CKR_OK != error ) { |
michael@0 | 641 | return 0; |
michael@0 | 642 | } |
michael@0 | 643 | |
michael@0 | 644 | /* We could even check all the other arguments, for sanity. */ |
michael@0 | 645 | #endif /* NSSDEBUG */ |
michael@0 | 646 | |
michael@0 | 647 | obj = (nssCKMDSessionObject *)mdObject->etc; |
michael@0 | 648 | |
michael@0 | 649 | n.size = value->size; |
michael@0 | 650 | n.data = nss_ZAlloc(obj->arena, n.size); |
michael@0 | 651 | if (!n.data) { |
michael@0 | 652 | return CKR_HOST_MEMORY; |
michael@0 | 653 | } |
michael@0 | 654 | (void)nsslibc_memcpy(n.data, value->data, n.size); |
michael@0 | 655 | |
michael@0 | 656 | for( i = 0; i < obj->n; i++ ) { |
michael@0 | 657 | if( attribute == obj->types[i] ) { |
michael@0 | 658 | nss_ZFreeIf(obj->attributes[i].data); |
michael@0 | 659 | obj->attributes[i] = n; |
michael@0 | 660 | return CKR_OK; |
michael@0 | 661 | } |
michael@0 | 662 | } |
michael@0 | 663 | |
michael@0 | 664 | /* |
michael@0 | 665 | * It's new. |
michael@0 | 666 | */ |
michael@0 | 667 | |
michael@0 | 668 | ra = (NSSItem *)nss_ZRealloc(obj->attributes, sizeof(NSSItem) * (obj->n + 1)); |
michael@0 | 669 | if (!ra) { |
michael@0 | 670 | nss_ZFreeIf(n.data); |
michael@0 | 671 | return CKR_HOST_MEMORY; |
michael@0 | 672 | } |
michael@0 | 673 | obj->attributes = ra; |
michael@0 | 674 | |
michael@0 | 675 | rt = (CK_ATTRIBUTE_TYPE_PTR)nss_ZRealloc(obj->types, |
michael@0 | 676 | sizeof(CK_ATTRIBUTE_TYPE) * (obj->n + 1)); |
michael@0 | 677 | if (!rt) { |
michael@0 | 678 | nss_ZFreeIf(n.data); |
michael@0 | 679 | return CKR_HOST_MEMORY; |
michael@0 | 680 | } |
michael@0 | 681 | |
michael@0 | 682 | obj->types = rt; |
michael@0 | 683 | obj->attributes[obj->n] = n; |
michael@0 | 684 | obj->types[obj->n] = attribute; |
michael@0 | 685 | obj->n++; |
michael@0 | 686 | |
michael@0 | 687 | return CKR_OK; |
michael@0 | 688 | } |
michael@0 | 689 | |
michael@0 | 690 | /* |
michael@0 | 691 | * nss_ckmdSessionObject_GetObjectSize |
michael@0 | 692 | * |
michael@0 | 693 | */ |
michael@0 | 694 | static CK_ULONG |
michael@0 | 695 | nss_ckmdSessionObject_GetObjectSize |
michael@0 | 696 | ( |
michael@0 | 697 | NSSCKMDObject *mdObject, |
michael@0 | 698 | NSSCKFWObject *fwObject, |
michael@0 | 699 | NSSCKMDSession *mdSession, |
michael@0 | 700 | NSSCKFWSession *fwSession, |
michael@0 | 701 | NSSCKMDToken *mdToken, |
michael@0 | 702 | NSSCKFWToken *fwToken, |
michael@0 | 703 | NSSCKMDInstance *mdInstance, |
michael@0 | 704 | NSSCKFWInstance *fwInstance, |
michael@0 | 705 | CK_RV *pError |
michael@0 | 706 | ) |
michael@0 | 707 | { |
michael@0 | 708 | nssCKMDSessionObject *obj; |
michael@0 | 709 | CK_ULONG i; |
michael@0 | 710 | CK_ULONG rv = (CK_ULONG)0; |
michael@0 | 711 | |
michael@0 | 712 | #ifdef NSSDEBUG |
michael@0 | 713 | if (!pError) { |
michael@0 | 714 | return 0; |
michael@0 | 715 | } |
michael@0 | 716 | |
michael@0 | 717 | *pError = nss_ckmdSessionObject_verifyPointer(mdObject); |
michael@0 | 718 | if( CKR_OK != *pError ) { |
michael@0 | 719 | return 0; |
michael@0 | 720 | } |
michael@0 | 721 | |
michael@0 | 722 | /* We could even check all the other arguments, for sanity. */ |
michael@0 | 723 | #endif /* NSSDEBUG */ |
michael@0 | 724 | |
michael@0 | 725 | obj = (nssCKMDSessionObject *)mdObject->etc; |
michael@0 | 726 | |
michael@0 | 727 | for( i = 0; i < obj->n; i++ ) { |
michael@0 | 728 | rv += obj->attributes[i].size; |
michael@0 | 729 | } |
michael@0 | 730 | |
michael@0 | 731 | rv += sizeof(NSSItem) * obj->n; |
michael@0 | 732 | rv += sizeof(CK_ATTRIBUTE_TYPE) * obj->n; |
michael@0 | 733 | rv += sizeof(nssCKMDSessionObject); |
michael@0 | 734 | |
michael@0 | 735 | return rv; |
michael@0 | 736 | } |
michael@0 | 737 | |
michael@0 | 738 | /* |
michael@0 | 739 | * nssCKMDFindSessionObjects |
michael@0 | 740 | * |
michael@0 | 741 | * -- create -- |
michael@0 | 742 | * nssCKMDFindSessionObjects_Create |
michael@0 | 743 | * |
michael@0 | 744 | * -- EPV calls -- |
michael@0 | 745 | * nss_ckmdFindSessionObjects_Final |
michael@0 | 746 | * nss_ckmdFindSessionObjects_Next |
michael@0 | 747 | */ |
michael@0 | 748 | |
michael@0 | 749 | struct nodeStr { |
michael@0 | 750 | struct nodeStr *next; |
michael@0 | 751 | NSSCKMDObject *mdObject; |
michael@0 | 752 | }; |
michael@0 | 753 | |
michael@0 | 754 | struct nssCKMDFindSessionObjectsStr { |
michael@0 | 755 | NSSArena *arena; |
michael@0 | 756 | CK_RV error; |
michael@0 | 757 | CK_ATTRIBUTE_PTR pTemplate; |
michael@0 | 758 | CK_ULONG ulCount; |
michael@0 | 759 | struct nodeStr *list; |
michael@0 | 760 | nssCKFWHash *hash; |
michael@0 | 761 | |
michael@0 | 762 | }; |
michael@0 | 763 | typedef struct nssCKMDFindSessionObjectsStr nssCKMDFindSessionObjects; |
michael@0 | 764 | |
michael@0 | 765 | #ifdef DEBUG |
michael@0 | 766 | /* |
michael@0 | 767 | * But first, the pointer-tracking stuff. |
michael@0 | 768 | * |
michael@0 | 769 | * NOTE: the pointer-tracking support in NSS/base currently relies |
michael@0 | 770 | * upon NSPR's CallOnce support. That, however, relies upon NSPR's |
michael@0 | 771 | * locking, which is tied into the runtime. We need a pointer-tracker |
michael@0 | 772 | * implementation that uses the locks supplied through C_Initialize. |
michael@0 | 773 | * That support, however, can be filled in later. So for now, I'll |
michael@0 | 774 | * just do this routines as no-ops. |
michael@0 | 775 | */ |
michael@0 | 776 | |
michael@0 | 777 | static CK_RV |
michael@0 | 778 | nss_ckmdFindSessionObjects_add_pointer |
michael@0 | 779 | ( |
michael@0 | 780 | const NSSCKMDFindObjects *mdFindObjects |
michael@0 | 781 | ) |
michael@0 | 782 | { |
michael@0 | 783 | return CKR_OK; |
michael@0 | 784 | } |
michael@0 | 785 | |
michael@0 | 786 | static CK_RV |
michael@0 | 787 | nss_ckmdFindSessionObjects_remove_pointer |
michael@0 | 788 | ( |
michael@0 | 789 | const NSSCKMDFindObjects *mdFindObjects |
michael@0 | 790 | ) |
michael@0 | 791 | { |
michael@0 | 792 | return CKR_OK; |
michael@0 | 793 | } |
michael@0 | 794 | |
michael@0 | 795 | #ifdef NSS_DEBUG |
michael@0 | 796 | static CK_RV |
michael@0 | 797 | nss_ckmdFindSessionObjects_verifyPointer |
michael@0 | 798 | ( |
michael@0 | 799 | const NSSCKMDFindObjects *mdFindObjects |
michael@0 | 800 | ) |
michael@0 | 801 | { |
michael@0 | 802 | return CKR_OK; |
michael@0 | 803 | } |
michael@0 | 804 | #endif |
michael@0 | 805 | |
michael@0 | 806 | #endif /* DEBUG */ |
michael@0 | 807 | |
michael@0 | 808 | /* |
michael@0 | 809 | * We must forward-declare these routines. |
michael@0 | 810 | */ |
michael@0 | 811 | static void |
michael@0 | 812 | nss_ckmdFindSessionObjects_Final |
michael@0 | 813 | ( |
michael@0 | 814 | NSSCKMDFindObjects *mdFindObjects, |
michael@0 | 815 | NSSCKFWFindObjects *fwFindObjects, |
michael@0 | 816 | NSSCKMDSession *mdSession, |
michael@0 | 817 | NSSCKFWSession *fwSession, |
michael@0 | 818 | NSSCKMDToken *mdToken, |
michael@0 | 819 | NSSCKFWToken *fwToken, |
michael@0 | 820 | NSSCKMDInstance *mdInstance, |
michael@0 | 821 | NSSCKFWInstance *fwInstance |
michael@0 | 822 | ); |
michael@0 | 823 | |
michael@0 | 824 | static NSSCKMDObject * |
michael@0 | 825 | nss_ckmdFindSessionObjects_Next |
michael@0 | 826 | ( |
michael@0 | 827 | NSSCKMDFindObjects *mdFindObjects, |
michael@0 | 828 | NSSCKFWFindObjects *fwFindObjects, |
michael@0 | 829 | NSSCKMDSession *mdSession, |
michael@0 | 830 | NSSCKFWSession *fwSession, |
michael@0 | 831 | NSSCKMDToken *mdToken, |
michael@0 | 832 | NSSCKFWToken *fwToken, |
michael@0 | 833 | NSSCKMDInstance *mdInstance, |
michael@0 | 834 | NSSCKFWInstance *fwInstance, |
michael@0 | 835 | NSSArena *arena, |
michael@0 | 836 | CK_RV *pError |
michael@0 | 837 | ); |
michael@0 | 838 | |
michael@0 | 839 | static CK_BBOOL |
michael@0 | 840 | items_match |
michael@0 | 841 | ( |
michael@0 | 842 | NSSItem *a, |
michael@0 | 843 | CK_VOID_PTR pValue, |
michael@0 | 844 | CK_ULONG ulValueLen |
michael@0 | 845 | ) |
michael@0 | 846 | { |
michael@0 | 847 | if( a->size != ulValueLen ) { |
michael@0 | 848 | return CK_FALSE; |
michael@0 | 849 | } |
michael@0 | 850 | |
michael@0 | 851 | if( PR_TRUE == nsslibc_memequal(a->data, pValue, ulValueLen, (PRStatus *)NULL) ) { |
michael@0 | 852 | return CK_TRUE; |
michael@0 | 853 | } else { |
michael@0 | 854 | return CK_FALSE; |
michael@0 | 855 | } |
michael@0 | 856 | } |
michael@0 | 857 | |
michael@0 | 858 | /* |
michael@0 | 859 | * Our hashtable iterator |
michael@0 | 860 | */ |
michael@0 | 861 | static void |
michael@0 | 862 | findfcn |
michael@0 | 863 | ( |
michael@0 | 864 | const void *key, |
michael@0 | 865 | void *value, |
michael@0 | 866 | void *closure |
michael@0 | 867 | ) |
michael@0 | 868 | { |
michael@0 | 869 | NSSCKMDObject *mdObject = (NSSCKMDObject *)value; |
michael@0 | 870 | nssCKMDSessionObject *mdso = (nssCKMDSessionObject *)mdObject->etc; |
michael@0 | 871 | nssCKMDFindSessionObjects *mdfso = (nssCKMDFindSessionObjects *)closure; |
michael@0 | 872 | CK_ULONG i, j; |
michael@0 | 873 | struct nodeStr *node; |
michael@0 | 874 | |
michael@0 | 875 | if( CKR_OK != mdfso->error ) { |
michael@0 | 876 | return; |
michael@0 | 877 | } |
michael@0 | 878 | |
michael@0 | 879 | for( i = 0; i < mdfso->ulCount; i++ ) { |
michael@0 | 880 | CK_ATTRIBUTE_PTR p = &mdfso->pTemplate[i]; |
michael@0 | 881 | |
michael@0 | 882 | for( j = 0; j < mdso->n; j++ ) { |
michael@0 | 883 | if( mdso->types[j] == p->type ) { |
michael@0 | 884 | if( !items_match(&mdso->attributes[j], p->pValue, p->ulValueLen) ) { |
michael@0 | 885 | return; |
michael@0 | 886 | } else { |
michael@0 | 887 | break; |
michael@0 | 888 | } |
michael@0 | 889 | } |
michael@0 | 890 | } |
michael@0 | 891 | |
michael@0 | 892 | if( j == mdso->n ) { |
michael@0 | 893 | /* Attribute not found */ |
michael@0 | 894 | return; |
michael@0 | 895 | } |
michael@0 | 896 | } |
michael@0 | 897 | |
michael@0 | 898 | /* Matches */ |
michael@0 | 899 | node = nss_ZNEW(mdfso->arena, struct nodeStr); |
michael@0 | 900 | if( (struct nodeStr *)NULL == node ) { |
michael@0 | 901 | mdfso->error = CKR_HOST_MEMORY; |
michael@0 | 902 | return; |
michael@0 | 903 | } |
michael@0 | 904 | |
michael@0 | 905 | node->mdObject = mdObject; |
michael@0 | 906 | node->next = mdfso->list; |
michael@0 | 907 | mdfso->list = node; |
michael@0 | 908 | |
michael@0 | 909 | return; |
michael@0 | 910 | } |
michael@0 | 911 | |
michael@0 | 912 | /* |
michael@0 | 913 | * nssCKMDFindSessionObjects_Create |
michael@0 | 914 | * |
michael@0 | 915 | */ |
michael@0 | 916 | NSS_IMPLEMENT NSSCKMDFindObjects * |
michael@0 | 917 | nssCKMDFindSessionObjects_Create |
michael@0 | 918 | ( |
michael@0 | 919 | NSSCKFWToken *fwToken, |
michael@0 | 920 | CK_ATTRIBUTE_PTR pTemplate, |
michael@0 | 921 | CK_ULONG ulCount, |
michael@0 | 922 | CK_RV *pError |
michael@0 | 923 | ) |
michael@0 | 924 | { |
michael@0 | 925 | NSSArena *arena; |
michael@0 | 926 | nssCKMDFindSessionObjects *mdfso; |
michael@0 | 927 | nssCKFWHash *hash; |
michael@0 | 928 | NSSCKMDFindObjects *rv; |
michael@0 | 929 | |
michael@0 | 930 | #ifdef NSSDEBUG |
michael@0 | 931 | if (!pError) { |
michael@0 | 932 | return (NSSCKMDFindObjects *)NULL; |
michael@0 | 933 | } |
michael@0 | 934 | |
michael@0 | 935 | *pError = nssCKFWToken_verifyPointer(fwToken); |
michael@0 | 936 | if( CKR_OK != *pError ) { |
michael@0 | 937 | return (NSSCKMDFindObjects *)NULL; |
michael@0 | 938 | } |
michael@0 | 939 | |
michael@0 | 940 | if( (CK_ATTRIBUTE_PTR)NULL == pTemplate ) { |
michael@0 | 941 | *pError = CKR_ARGUMENTS_BAD; |
michael@0 | 942 | return (NSSCKMDFindObjects *)NULL; |
michael@0 | 943 | } |
michael@0 | 944 | #endif /* NSSDEBUG */ |
michael@0 | 945 | |
michael@0 | 946 | *pError = CKR_OK; |
michael@0 | 947 | |
michael@0 | 948 | hash = nssCKFWToken_GetSessionObjectHash(fwToken); |
michael@0 | 949 | if (!hash) { |
michael@0 | 950 | *pError= CKR_GENERAL_ERROR; |
michael@0 | 951 | return (NSSCKMDFindObjects *)NULL; |
michael@0 | 952 | } |
michael@0 | 953 | |
michael@0 | 954 | arena = NSSArena_Create(); |
michael@0 | 955 | if (!arena) { |
michael@0 | 956 | *pError = CKR_HOST_MEMORY; |
michael@0 | 957 | return (NSSCKMDFindObjects *)NULL; |
michael@0 | 958 | } |
michael@0 | 959 | |
michael@0 | 960 | mdfso = nss_ZNEW(arena, nssCKMDFindSessionObjects); |
michael@0 | 961 | if (!mdfso) { |
michael@0 | 962 | goto loser; |
michael@0 | 963 | } |
michael@0 | 964 | |
michael@0 | 965 | rv = nss_ZNEW(arena, NSSCKMDFindObjects); |
michael@0 | 966 | if(rv == NULL) { |
michael@0 | 967 | goto loser; |
michael@0 | 968 | } |
michael@0 | 969 | |
michael@0 | 970 | mdfso->error = CKR_OK; |
michael@0 | 971 | mdfso->pTemplate = pTemplate; |
michael@0 | 972 | mdfso->ulCount = ulCount; |
michael@0 | 973 | mdfso->hash = hash; |
michael@0 | 974 | |
michael@0 | 975 | nssCKFWHash_Iterate(hash, findfcn, mdfso); |
michael@0 | 976 | |
michael@0 | 977 | if( CKR_OK != mdfso->error ) { |
michael@0 | 978 | goto loser; |
michael@0 | 979 | } |
michael@0 | 980 | |
michael@0 | 981 | rv->etc = (void *)mdfso; |
michael@0 | 982 | rv->Final = nss_ckmdFindSessionObjects_Final; |
michael@0 | 983 | rv->Next = nss_ckmdFindSessionObjects_Next; |
michael@0 | 984 | |
michael@0 | 985 | #ifdef DEBUG |
michael@0 | 986 | if( (*pError = nss_ckmdFindSessionObjects_add_pointer(rv)) != CKR_OK ) { |
michael@0 | 987 | goto loser; |
michael@0 | 988 | } |
michael@0 | 989 | #endif /* DEBUG */ |
michael@0 | 990 | mdfso->arena = arena; |
michael@0 | 991 | |
michael@0 | 992 | return rv; |
michael@0 | 993 | |
michael@0 | 994 | loser: |
michael@0 | 995 | if (arena) { |
michael@0 | 996 | NSSArena_Destroy(arena); |
michael@0 | 997 | } |
michael@0 | 998 | if (*pError == CKR_OK) { |
michael@0 | 999 | *pError = CKR_HOST_MEMORY; |
michael@0 | 1000 | } |
michael@0 | 1001 | return NULL; |
michael@0 | 1002 | } |
michael@0 | 1003 | |
michael@0 | 1004 | static void |
michael@0 | 1005 | nss_ckmdFindSessionObjects_Final |
michael@0 | 1006 | ( |
michael@0 | 1007 | NSSCKMDFindObjects *mdFindObjects, |
michael@0 | 1008 | NSSCKFWFindObjects *fwFindObjects, |
michael@0 | 1009 | NSSCKMDSession *mdSession, |
michael@0 | 1010 | NSSCKFWSession *fwSession, |
michael@0 | 1011 | NSSCKMDToken *mdToken, |
michael@0 | 1012 | NSSCKFWToken *fwToken, |
michael@0 | 1013 | NSSCKMDInstance *mdInstance, |
michael@0 | 1014 | NSSCKFWInstance *fwInstance |
michael@0 | 1015 | ) |
michael@0 | 1016 | { |
michael@0 | 1017 | nssCKMDFindSessionObjects *mdfso; |
michael@0 | 1018 | |
michael@0 | 1019 | #ifdef NSSDEBUG |
michael@0 | 1020 | if( CKR_OK != nss_ckmdFindSessionObjects_verifyPointer(mdFindObjects) ) { |
michael@0 | 1021 | return; |
michael@0 | 1022 | } |
michael@0 | 1023 | #endif /* NSSDEBUG */ |
michael@0 | 1024 | |
michael@0 | 1025 | mdfso = (nssCKMDFindSessionObjects *)mdFindObjects->etc; |
michael@0 | 1026 | if (mdfso->arena) NSSArena_Destroy(mdfso->arena); |
michael@0 | 1027 | |
michael@0 | 1028 | #ifdef DEBUG |
michael@0 | 1029 | (void)nss_ckmdFindSessionObjects_remove_pointer(mdFindObjects); |
michael@0 | 1030 | #endif /* DEBUG */ |
michael@0 | 1031 | |
michael@0 | 1032 | return; |
michael@0 | 1033 | } |
michael@0 | 1034 | |
michael@0 | 1035 | static NSSCKMDObject * |
michael@0 | 1036 | nss_ckmdFindSessionObjects_Next |
michael@0 | 1037 | ( |
michael@0 | 1038 | NSSCKMDFindObjects *mdFindObjects, |
michael@0 | 1039 | NSSCKFWFindObjects *fwFindObjects, |
michael@0 | 1040 | NSSCKMDSession *mdSession, |
michael@0 | 1041 | NSSCKFWSession *fwSession, |
michael@0 | 1042 | NSSCKMDToken *mdToken, |
michael@0 | 1043 | NSSCKFWToken *fwToken, |
michael@0 | 1044 | NSSCKMDInstance *mdInstance, |
michael@0 | 1045 | NSSCKFWInstance *fwInstance, |
michael@0 | 1046 | NSSArena *arena, |
michael@0 | 1047 | CK_RV *pError |
michael@0 | 1048 | ) |
michael@0 | 1049 | { |
michael@0 | 1050 | nssCKMDFindSessionObjects *mdfso; |
michael@0 | 1051 | NSSCKMDObject *rv = (NSSCKMDObject *)NULL; |
michael@0 | 1052 | |
michael@0 | 1053 | #ifdef NSSDEBUG |
michael@0 | 1054 | if( CKR_OK != nss_ckmdFindSessionObjects_verifyPointer(mdFindObjects) ) { |
michael@0 | 1055 | return (NSSCKMDObject *)NULL; |
michael@0 | 1056 | } |
michael@0 | 1057 | #endif /* NSSDEBUG */ |
michael@0 | 1058 | |
michael@0 | 1059 | mdfso = (nssCKMDFindSessionObjects *)mdFindObjects->etc; |
michael@0 | 1060 | |
michael@0 | 1061 | while (!rv) { |
michael@0 | 1062 | if( (struct nodeStr *)NULL == mdfso->list ) { |
michael@0 | 1063 | *pError = CKR_OK; |
michael@0 | 1064 | return (NSSCKMDObject *)NULL; |
michael@0 | 1065 | } |
michael@0 | 1066 | |
michael@0 | 1067 | if( nssCKFWHash_Exists(mdfso->hash, mdfso->list->mdObject) ) { |
michael@0 | 1068 | rv = mdfso->list->mdObject; |
michael@0 | 1069 | } |
michael@0 | 1070 | |
michael@0 | 1071 | mdfso->list = mdfso->list->next; |
michael@0 | 1072 | } |
michael@0 | 1073 | |
michael@0 | 1074 | return rv; |
michael@0 | 1075 | } |