Changeset 84329 in vbox for trunk/src/VBox/Runtime/common/crypto/store-inmem.cpp
- Timestamp:
- May 18, 2020 1:35:33 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/store-inmem.cpp
r82968 r84329 86 86 /** Array of certificates. */ 87 87 PRTCRSTOREINMEMCERT *papCerts; 88 89 /** Parent store. */ 90 RTCRSTORE hParentStore; 91 /** The parent store callback table. */ 92 PCRTCRSTOREPROVIDER pParentProvider; 93 /** The parent store provider callback argument. */ 94 void *pvParentProvider; 88 95 } RTCRSTOREINMEM; 89 96 /** Pointer to an in-memory crypto store. */ … … 220 227 RTMemFree(pThis->papCerts); 221 228 pThis->papCerts = NULL; 229 230 if (pThis->hParentStore != NIL_RTCRSTORE) 231 { 232 RTCrStoreRelease(pThis->hParentStore); 233 pThis->hParentStore = NIL_RTCRSTORE; 234 } 235 222 236 RTMemFree(pThis); 223 237 } … … 249 263 { 250 264 PRTCRSTOREINMEM pThis = (PRTCRSTOREINMEM)pvProvider; 251 AssertReturn(pSearch->auOpaque[0] == ~(uintptr_t)pvProvider, NULL); 252 253 uintptr_t i = pSearch->auOpaque[1]; 254 if (i < pThis->cCerts) 255 { 256 pSearch->auOpaque[1] = i + 1; 257 PRTCRCERTCTXINT pCertCtx = &pThis->papCerts[i]->Core; 258 ASMAtomicIncU32(&pCertCtx->cRefs); 259 return &pCertCtx->Public; 260 } 261 return NULL; 265 if (pSearch->auOpaque[0] == ~(uintptr_t)pvProvider) 266 { 267 uintptr_t i = pSearch->auOpaque[1]; 268 if (i < pThis->cCerts) 269 { 270 pSearch->auOpaque[1] = i + 1; 271 PRTCRCERTCTXINT pCertCtx = &pThis->papCerts[i]->Core; 272 ASMAtomicIncU32(&pCertCtx->cRefs); 273 return &pCertCtx->Public; 274 } 275 276 /* Do we have a parent store to search? */ 277 if (pThis->hParentStore == NIL_RTCRSTORE) 278 return NULL; /* no */ 279 if ( !pThis->pParentProvider->pfnCertFindAll 280 || !pThis->pParentProvider->pfnCertSearchNext) 281 return NULL; 282 283 RTCRSTORECERTSEARCH const SavedSearch = *pSearch; 284 int rc = pThis->pParentProvider->pfnCertFindAll(pThis->pvParentProvider, pSearch); 285 AssertRCReturnStmt(rc, *pSearch = SavedSearch, NULL); 286 287 /* Restore the store.cpp specifics: */ 288 AssertCompile(RT_ELEMENTS(SavedSearch.auOpaque) == 4); 289 pSearch->auOpaque[2] = SavedSearch.auOpaque[2]; 290 pSearch->auOpaque[3] = SavedSearch.auOpaque[3]; 291 } 292 293 AssertReturn(pThis->pParentProvider, NULL); 294 AssertReturn(pThis->pParentProvider->pfnCertSearchNext, NULL); 295 return pThis->pParentProvider->pfnCertSearchNext(pThis->pvParentProvider, pSearch); 262 296 } 263 297 … … 266 300 static DECLCALLBACK(void) rtCrStoreInMem_CertSearchDestroy(void *pvProvider, PRTCRSTORECERTSEARCH pSearch) 267 301 { 268 NOREF(pvProvider); 269 AssertReturnVoid(pSearch->auOpaque[0] == ~(uintptr_t)pvProvider); 270 pSearch->auOpaque[0] = 0; 271 pSearch->auOpaque[1] = 0; 272 pSearch->auOpaque[2] = 0; 273 pSearch->auOpaque[3] = 0; 302 PRTCRSTOREINMEM pThis = (PRTCRSTOREINMEM)pvProvider; 303 if (pSearch->auOpaque[0] == ~(uintptr_t)pvProvider) 304 { 305 pSearch->auOpaque[0] = 0; 306 pSearch->auOpaque[1] = 0; 307 pSearch->auOpaque[2] = 0; 308 pSearch->auOpaque[3] = 0; 309 } 310 else 311 { 312 AssertReturnVoid(pThis->pParentProvider); 313 AssertReturnVoid(pThis->pParentProvider->pfnCertSearchDestroy); 314 pThis->pParentProvider->pfnCertSearchDestroy(pThis->pvParentProvider, pSearch); 315 } 274 316 } 275 317 … … 347 389 * @returns IPRT status code. 348 390 * @param ppStore Where to return the store instance. 349 */ 350 static int rtCrStoreInMemCreateInternal(PRTCRSTOREINMEM *ppStore) 391 * @param hParentStore Optional parent store. Consums reference on 392 * success. 393 */ 394 static int rtCrStoreInMemCreateInternal(PRTCRSTOREINMEM *ppStore, RTCRSTORE hParentStore) 351 395 { 352 396 PRTCRSTOREINMEM pStore = (PRTCRSTOREINMEM)RTMemAlloc(sizeof(*pStore)); 353 397 if (pStore) 354 398 { 355 pStore->cCerts = 0; 356 pStore->cCertsAlloc = 0; 357 pStore->papCerts = NULL; 399 pStore->cCerts = 0; 400 pStore->cCertsAlloc = 0; 401 pStore->papCerts = NULL; 402 pStore->hParentStore = hParentStore; 403 pStore->pParentProvider = NULL; 404 pStore->pvParentProvider = NULL; 358 405 *ppStore = pStore; 359 return VINF_SUCCESS; 406 if (hParentStore == NIL_RTCRSTORE) 407 return VINF_SUCCESS; 408 if (~(uintptr_t)hParentStore != ~(uintptr_t)pStore) 409 { 410 pStore->pParentProvider = rtCrStoreGetProvider(hParentStore, &pStore->pvParentProvider); 411 if (pStore->pParentProvider) 412 return VINF_SUCCESS; 413 AssertFailed(); 414 } 415 RTMemFree(pStore); 360 416 } 361 417 *ppStore = NULL; /* shut up gcc-maybe-pita warning. */ … … 364 420 365 421 366 RTDECL(int) RTCrStoreCreateInMem(PRTCRSTORE phStore, uint32_t cSizeHint) 367 { 422 RTDECL(int) RTCrStoreCreateInMemEx(PRTCRSTORE phStore, uint32_t cSizeHint, RTCRSTORE hParentStore) 423 { 424 if (hParentStore != NIL_RTCRSTORE) 425 { 426 uint32_t cRefs = RTCrStoreRetain(hParentStore); 427 AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE); 428 } 429 368 430 PRTCRSTOREINMEM pStore; 369 int rc = rtCrStoreInMemCreateInternal(&pStore );431 int rc = rtCrStoreInMemCreateInternal(&pStore, hParentStore); 370 432 if (RT_SUCCESS(rc)) 371 433 { … … 380 442 RTMemFree(pStore); 381 443 } 444 445 RTCrStoreRelease(hParentStore); 382 446 return rc; 383 447 } 448 RT_EXPORT_SYMBOL(RTCrStoreCreateInMemEx); 449 450 451 RTDECL(int) RTCrStoreCreateInMem(PRTCRSTORE phStore, uint32_t cSizeHint) 452 { 453 return RTCrStoreCreateInMemEx(phStore, cSizeHint, NIL_RTCRSTORE); 454 } 384 455 RT_EXPORT_SYMBOL(RTCrStoreCreateInMem); 385 456
Note:
See TracChangeset
for help on using the changeset viewer.