static void testDupCTL(void) { PCCTL_CONTEXT context, dupContext; BOOL res; context = CertDuplicateCTLContext(NULL); ok(context == NULL, "expected NULL\n"); context = CertCreateCTLContext(X509_ASN_ENCODING, signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent)); dupContext = CertDuplicateCTLContext(context); ok(dupContext != NULL, "expected a context\n"); ok(dupContext == context, "expected identical context addresses\n"); res = CertFreeCTLContext(dupContext); ok(res, "CertFreeCTLContext failed\n"); res = CertFreeCTLContext(context); ok(res, "CertFreeCTLContext failed\n"); res = CertFreeCTLContext(NULL); ok(res, "CertFreeCTLContext failed\n"); }
static BOOL CRYPT_MemAddCtl(PWINECRYPT_CERTSTORE store, void *ctl, void *toReplace, const void **ppStoreContext) { WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store; PCTL_CONTEXT context; TRACE("(%p, %p, %p, %p)\n", store, ctl, toReplace, ppStoreContext); context = ContextList_Add(ms->ctls, ctl, toReplace); if (context) { context->hCertStore = store; if (ppStoreContext) *ppStoreContext = CertDuplicateCTLContext(context); } return context != 0; }
BOOL WINAPI CertAddCTLContextToStore(HCERTSTORE hCertStore, PCCTL_CONTEXT pCtlContext, DWORD dwAddDisposition, PCCTL_CONTEXT* ppStoreContext) { PWINECRYPT_CERTSTORE store = hCertStore; BOOL ret = TRUE; PCCTL_CONTEXT toAdd = NULL, existing = NULL; TRACE("(%p, %p, %08x, %p)\n", hCertStore, pCtlContext, dwAddDisposition, ppStoreContext); if (dwAddDisposition != CERT_STORE_ADD_ALWAYS) { existing = CertFindCTLInStore(hCertStore, 0, 0, CTL_FIND_EXISTING, pCtlContext, NULL); } switch (dwAddDisposition) { case CERT_STORE_ADD_ALWAYS: toAdd = CertDuplicateCTLContext(pCtlContext); break; case CERT_STORE_ADD_NEW: if (existing) { TRACE("found matching CTL, not adding\n"); SetLastError(CRYPT_E_EXISTS); ret = FALSE; } else toAdd = CertDuplicateCTLContext(pCtlContext); break; case CERT_STORE_ADD_NEWER: if (existing) { LONG newer = CompareFileTime(&existing->pCtlInfo->ThisUpdate, &pCtlContext->pCtlInfo->ThisUpdate); if (newer < 0) toAdd = CertDuplicateCTLContext(pCtlContext); else { TRACE("existing CTL is newer, not adding\n"); SetLastError(CRYPT_E_EXISTS); ret = FALSE; } } else toAdd = CertDuplicateCTLContext(pCtlContext); break; case CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES: if (existing) { LONG newer = CompareFileTime(&existing->pCtlInfo->ThisUpdate, &pCtlContext->pCtlInfo->ThisUpdate); if (newer < 0) { toAdd = CertDuplicateCTLContext(pCtlContext); CtlContext_CopyProperties(existing, pCtlContext); } else { TRACE("existing CTL is newer, not adding\n"); SetLastError(CRYPT_E_EXISTS); ret = FALSE; } } else toAdd = CertDuplicateCTLContext(pCtlContext); break; case CERT_STORE_ADD_REPLACE_EXISTING: toAdd = CertDuplicateCTLContext(pCtlContext); break; case CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES: toAdd = CertDuplicateCTLContext(pCtlContext); if (existing) CtlContext_CopyProperties(toAdd, existing); break; case CERT_STORE_ADD_USE_EXISTING: if (existing) { CtlContext_CopyProperties(existing, pCtlContext); if (ppStoreContext) *ppStoreContext = CertDuplicateCTLContext(existing); } else toAdd = CertDuplicateCTLContext(pCtlContext); break; default: FIXME("Unimplemented add disposition %d\n", dwAddDisposition); ret = FALSE; } if (toAdd) { if (store) ret = store->ctls.addContext(store, (void *)toAdd, (void *)existing, (const void **)ppStoreContext); else if (ppStoreContext) *ppStoreContext = CertDuplicateCTLContext(toAdd); CertFreeCTLContext(toAdd); } CertFreeCTLContext(existing); TRACE("returning %d\n", ret); return ret; }