Module: wine Branch: refs/heads/master Commit: dc660a81edae8a6e435c42a6e0bbdf03e9e20dbf URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=dc660a81edae8a6e435c42a6...
Author: Juan Lang juan_lang@yahoo.com Date: Fri May 26 09:41:37 2006 -0700
crypt32: Combine redundant code.
---
dlls/crypt32/context.c | 10 +++ dlls/crypt32/crypt32_private.h | 4 + dlls/crypt32/store.c | 117 +++++++++++++--------------------------- 3 files changed, 53 insertions(+), 78 deletions(-)
diff --git a/dlls/crypt32/context.c b/dlls/crypt32/context.c index a88286b..558be9d 100644 --- a/dlls/crypt32/context.c +++ b/dlls/crypt32/context.c @@ -164,6 +164,16 @@ void Context_Release(void *context, size TRACE("%p's ref count is %ld\n", context, base->ref); }
+void Context_CopyProperties(const void *to, const void *from, + size_t contextSize) +{ + PCONTEXT_PROPERTY_LIST toProperties, fromProperties; + + toProperties = Context_GetProperties((void *)to, contextSize); + fromProperties = Context_GetProperties((void *)from, contextSize); + ContextPropertyList_Copy(toProperties, fromProperties); +} + struct ContextList { PCWINE_CONTEXT_INTERFACE contextInterface; diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h index 67306b3..f8365d6 100644 --- a/dlls/crypt32/crypt32_private.h +++ b/dlls/crypt32/crypt32_private.h @@ -125,6 +125,10 @@ void *Context_GetExtra(const void *conte /* Gets the context linked to by context, which must be a link context. */ void *Context_GetLinkedContext(void *context, size_t contextSize);
+/* Copies properties from fromContext to toContext. */ +void Context_CopyProperties(const void *to, const void *from, + size_t contextSize); + struct _CONTEXT_PROPERTY_LIST; typedef struct _CONTEXT_PROPERTY_LIST *PCONTEXT_PROPERTY_LIST;
diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c index 6d3a1be..2ea714e 100644 --- a/dlls/crypt32/store.c +++ b/dlls/crypt32/store.c @@ -220,8 +220,7 @@ static BOOL CRYPT_MemAddCert(PWINECRYPT_ { context->hCertStore = store; if (ppStoreContext) - *ppStoreContext = - CertDuplicateCertificateContext(context); + *ppStoreContext = CertDuplicateCertificateContext(context); } return context ? TRUE : FALSE; } @@ -262,8 +261,7 @@ static BOOL CRYPT_MemAddCrl(PWINECRYPT_C { context->hCertStore = store; if (ppStoreContext) - *ppStoreContext = - CertDuplicateCRLContext(context); + *ppStoreContext = CertDuplicateCRLContext(context); } return context ? TRUE : FALSE; } @@ -597,7 +595,7 @@ static void *CRYPT_CollectionEnumCRL(PWI { PWINE_STORE_LIST_ENTRY storeEntry = *(PWINE_STORE_LIST_ENTRY *)Context_GetExtra(pPrev, - sizeof(CERT_CONTEXT)); + sizeof(CRL_CONTEXT));
ret = CRYPT_CollectionAdvanceEnum(cs, storeEntry, offsetof(WINECRYPT_CERTSTORE, crls), pCRLInterface, pPrev, @@ -1227,14 +1225,11 @@ static void WINAPI CRYPT_RegCloseStore(H CryptMemFree(store); }
-static BOOL WINAPI CRYPT_RegWriteCert(HCERTSTORE hCertStore, - PCCERT_CONTEXT cert, DWORD dwFlags) +static BOOL WINAPI CRYPT_RegWriteContext(PWINE_REGSTOREINFO store, + const void *context, DWORD dwFlags) { - PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore; BOOL ret;
- TRACE("(%p, %p, %ld)\n", hCertStore, cert, dwFlags); - if (dwFlags & CERT_STORE_PROV_WRITE_ADD_FLAG) { store->dirty = TRUE; @@ -1245,14 +1240,12 @@ static BOOL WINAPI CRYPT_RegWriteCert(HC return ret; }
-static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore, - PCCERT_CONTEXT pCertContext, DWORD dwFlags) +static BOOL CRYPT_RegDeleteContext(PWINE_REGSTOREINFO store, + struct list *deleteList, const void *context, + PCWINE_CONTEXT_INTERFACE contextInterface) { - PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore; BOOL ret;
- TRACE("(%p, %p, %08lx)\n", store, pCertContext, dwFlags); - if (store->dwOpenFlags & CERT_STORE_READONLY_FLAG) { SetLastError(ERROR_ACCESS_DENIED); @@ -1267,12 +1260,12 @@ static BOOL WINAPI CRYPT_RegDeleteCert(H { DWORD size = sizeof(toDelete->hash);
- ret = CertGetCertificateContextProperty(pCertContext, - CERT_HASH_PROP_ID, toDelete->hash, &size); + ret = contextInterface->getProp(context, CERT_HASH_PROP_ID, + toDelete->hash, &size); if (ret) { EnterCriticalSection(&store->cs); - list_add_tail(&store->certsToDelete, &toDelete->entry); + list_add_tail(deleteList, &toDelete->entry); LeaveCriticalSection(&store->cs); } else @@ -1289,66 +1282,46 @@ static BOOL WINAPI CRYPT_RegDeleteCert(H return ret; }
+static BOOL WINAPI CRYPT_RegWriteCert(HCERTSTORE hCertStore, + PCCERT_CONTEXT cert, DWORD dwFlags) +{ + PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore; + + TRACE("(%p, %p, %ld)\n", hCertStore, cert, dwFlags); + + return CRYPT_RegWriteContext(store, cert, dwFlags); +} + +static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore, + PCCERT_CONTEXT pCertContext, DWORD dwFlags) +{ + PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore; + + TRACE("(%p, %p, %08lx)\n", store, pCertContext, dwFlags); + + return CRYPT_RegDeleteContext(store, &store->certsToDelete, pCertContext, + pCertInterface); +} + static BOOL WINAPI CRYPT_RegWriteCRL(HCERTSTORE hCertStore, PCCRL_CONTEXT crl, DWORD dwFlags) { PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore; - BOOL ret;
TRACE("(%p, %p, %ld)\n", hCertStore, crl, dwFlags);
- if (dwFlags & CERT_STORE_PROV_WRITE_ADD_FLAG) - { - store->dirty = TRUE; - ret = TRUE; - } - else - ret = FALSE; - return ret; + return CRYPT_RegWriteContext(store, crl, dwFlags); }
static BOOL WINAPI CRYPT_RegDeleteCRL(HCERTSTORE hCertStore, PCCRL_CONTEXT pCrlContext, DWORD dwFlags) { PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore; - BOOL ret;
TRACE("(%p, %p, %08lx)\n", store, pCrlContext, dwFlags);
- if (store->dwOpenFlags & CERT_STORE_READONLY_FLAG) - { - SetLastError(ERROR_ACCESS_DENIED); - ret = FALSE; - } - else - { - PWINE_HASH_TO_DELETE toDelete = - CryptMemAlloc(sizeof(WINE_HASH_TO_DELETE)); - - if (toDelete) - { - DWORD size = sizeof(toDelete->hash); - - ret = CertGetCRLContextProperty(pCrlContext, CERT_HASH_PROP_ID, - toDelete->hash, &size); - if (ret) - { - EnterCriticalSection(&store->cs); - list_add_tail(&store->crlsToDelete, &toDelete->entry); - LeaveCriticalSection(&store->cs); - } - else - { - CryptMemFree(toDelete); - ret = FALSE; - } - } - else - ret = FALSE; - if (ret) - store->dirty = TRUE; - } - return ret; + return CRYPT_RegDeleteContext(store, &store->crlsToDelete, pCrlContext, + pCRLInterface); }
static BOOL WINAPI CRYPT_RegControl(HCERTSTORE hCertStore, DWORD dwFlags, @@ -1859,14 +1832,8 @@ DWORD CertStore_GetAccessState(HCERTSTOR return state; }
-static void CertContext_CopyProperties(PCCERT_CONTEXT to, PCCERT_CONTEXT from) -{ - PCONTEXT_PROPERTY_LIST toProperties, fromProperties; - - toProperties = Context_GetProperties((void *)to, sizeof(CERT_CONTEXT)); - fromProperties = Context_GetProperties((void *)from, sizeof(CERT_CONTEXT)); - ContextPropertyList_Copy(toProperties, fromProperties); -} +#define CertContext_CopyProperties(to, from) \ + Context_CopyProperties((to), (from), sizeof(CERT_CONTEXT))
BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition, @@ -1992,14 +1959,8 @@ BOOL WINAPI CertDeleteCertificateFromSto return ret; }
-static void CrlContext_CopyProperties(PCCRL_CONTEXT to, PCCRL_CONTEXT from) -{ - PCONTEXT_PROPERTY_LIST toProperties, fromProperties; - - toProperties = Context_GetProperties((void *)to, sizeof(CRL_CONTEXT)); - fromProperties = Context_GetProperties((void *)from, sizeof(CRL_CONTEXT)); - ContextPropertyList_Copy(toProperties, fromProperties); -} +#define CrlContext_CopyProperties(to, from) \ + Context_CopyProperties((to), (from), sizeof(CRL_CONTEXT))
BOOL WINAPI CertAddCRLContextToStore(HCERTSTORE hCertStore, PCCRL_CONTEXT pCrlContext, DWORD dwAddDisposition,