Commit dc660a81 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

crypt32: Combine redundant code.

parent 96ce83d0
...@@ -164,6 +164,16 @@ void Context_Release(void *context, size_t contextSize, ...@@ -164,6 +164,16 @@ void Context_Release(void *context, size_t contextSize,
TRACE("%p's ref count is %ld\n", context, base->ref); 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 struct ContextList
{ {
PCWINE_CONTEXT_INTERFACE contextInterface; PCWINE_CONTEXT_INTERFACE contextInterface;
......
...@@ -125,6 +125,10 @@ void *Context_GetExtra(const void *context, size_t contextSize); ...@@ -125,6 +125,10 @@ void *Context_GetExtra(const void *context, size_t contextSize);
/* Gets the context linked to by context, which must be a link context. */ /* Gets the context linked to by context, which must be a link context. */
void *Context_GetLinkedContext(void *context, size_t contextSize); 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; struct _CONTEXT_PROPERTY_LIST;
typedef struct _CONTEXT_PROPERTY_LIST *PCONTEXT_PROPERTY_LIST; typedef struct _CONTEXT_PROPERTY_LIST *PCONTEXT_PROPERTY_LIST;
......
...@@ -220,8 +220,7 @@ static BOOL CRYPT_MemAddCert(PWINECRYPT_CERTSTORE store, void *cert, ...@@ -220,8 +220,7 @@ static BOOL CRYPT_MemAddCert(PWINECRYPT_CERTSTORE store, void *cert,
{ {
context->hCertStore = store; context->hCertStore = store;
if (ppStoreContext) if (ppStoreContext)
*ppStoreContext = *ppStoreContext = CertDuplicateCertificateContext(context);
CertDuplicateCertificateContext(context);
} }
return context ? TRUE : FALSE; return context ? TRUE : FALSE;
} }
...@@ -262,8 +261,7 @@ static BOOL CRYPT_MemAddCrl(PWINECRYPT_CERTSTORE store, void *crl, ...@@ -262,8 +261,7 @@ static BOOL CRYPT_MemAddCrl(PWINECRYPT_CERTSTORE store, void *crl,
{ {
context->hCertStore = store; context->hCertStore = store;
if (ppStoreContext) if (ppStoreContext)
*ppStoreContext = *ppStoreContext = CertDuplicateCRLContext(context);
CertDuplicateCRLContext(context);
} }
return context ? TRUE : FALSE; return context ? TRUE : FALSE;
} }
...@@ -597,7 +595,7 @@ static void *CRYPT_CollectionEnumCRL(PWINECRYPT_CERTSTORE store, void *pPrev) ...@@ -597,7 +595,7 @@ static void *CRYPT_CollectionEnumCRL(PWINECRYPT_CERTSTORE store, void *pPrev)
{ {
PWINE_STORE_LIST_ENTRY storeEntry = PWINE_STORE_LIST_ENTRY storeEntry =
*(PWINE_STORE_LIST_ENTRY *)Context_GetExtra(pPrev, *(PWINE_STORE_LIST_ENTRY *)Context_GetExtra(pPrev,
sizeof(CERT_CONTEXT)); sizeof(CRL_CONTEXT));
ret = CRYPT_CollectionAdvanceEnum(cs, storeEntry, ret = CRYPT_CollectionAdvanceEnum(cs, storeEntry,
offsetof(WINECRYPT_CERTSTORE, crls), pCRLInterface, pPrev, offsetof(WINECRYPT_CERTSTORE, crls), pCRLInterface, pPrev,
...@@ -1227,14 +1225,11 @@ static void WINAPI CRYPT_RegCloseStore(HCERTSTORE hCertStore, DWORD dwFlags) ...@@ -1227,14 +1225,11 @@ static void WINAPI CRYPT_RegCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
CryptMemFree(store); CryptMemFree(store);
} }
static BOOL WINAPI CRYPT_RegWriteCert(HCERTSTORE hCertStore, static BOOL WINAPI CRYPT_RegWriteContext(PWINE_REGSTOREINFO store,
PCCERT_CONTEXT cert, DWORD dwFlags) const void *context, DWORD dwFlags)
{ {
PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore;
BOOL ret; BOOL ret;
TRACE("(%p, %p, %ld)\n", hCertStore, cert, dwFlags);
if (dwFlags & CERT_STORE_PROV_WRITE_ADD_FLAG) if (dwFlags & CERT_STORE_PROV_WRITE_ADD_FLAG)
{ {
store->dirty = TRUE; store->dirty = TRUE;
...@@ -1245,14 +1240,12 @@ static BOOL WINAPI CRYPT_RegWriteCert(HCERTSTORE hCertStore, ...@@ -1245,14 +1240,12 @@ static BOOL WINAPI CRYPT_RegWriteCert(HCERTSTORE hCertStore,
return ret; return ret;
} }
static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore, static BOOL CRYPT_RegDeleteContext(PWINE_REGSTOREINFO store,
PCCERT_CONTEXT pCertContext, DWORD dwFlags) struct list *deleteList, const void *context,
PCWINE_CONTEXT_INTERFACE contextInterface)
{ {
PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore;
BOOL ret; BOOL ret;
TRACE("(%p, %p, %08lx)\n", store, pCertContext, dwFlags);
if (store->dwOpenFlags & CERT_STORE_READONLY_FLAG) if (store->dwOpenFlags & CERT_STORE_READONLY_FLAG)
{ {
SetLastError(ERROR_ACCESS_DENIED); SetLastError(ERROR_ACCESS_DENIED);
...@@ -1267,12 +1260,12 @@ static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore, ...@@ -1267,12 +1260,12 @@ static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore,
{ {
DWORD size = sizeof(toDelete->hash); DWORD size = sizeof(toDelete->hash);
ret = CertGetCertificateContextProperty(pCertContext, ret = contextInterface->getProp(context, CERT_HASH_PROP_ID,
CERT_HASH_PROP_ID, toDelete->hash, &size); toDelete->hash, &size);
if (ret) if (ret)
{ {
EnterCriticalSection(&store->cs); EnterCriticalSection(&store->cs);
list_add_tail(&store->certsToDelete, &toDelete->entry); list_add_tail(deleteList, &toDelete->entry);
LeaveCriticalSection(&store->cs); LeaveCriticalSection(&store->cs);
} }
else else
...@@ -1289,66 +1282,46 @@ static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore, ...@@ -1289,66 +1282,46 @@ static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore,
return ret; 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, static BOOL WINAPI CRYPT_RegWriteCRL(HCERTSTORE hCertStore,
PCCRL_CONTEXT crl, DWORD dwFlags) PCCRL_CONTEXT crl, DWORD dwFlags)
{ {
PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore; PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore;
BOOL ret;
TRACE("(%p, %p, %ld)\n", hCertStore, crl, dwFlags); TRACE("(%p, %p, %ld)\n", hCertStore, crl, dwFlags);
if (dwFlags & CERT_STORE_PROV_WRITE_ADD_FLAG) return CRYPT_RegWriteContext(store, crl, dwFlags);
{
store->dirty = TRUE;
ret = TRUE;
}
else
ret = FALSE;
return ret;
} }
static BOOL WINAPI CRYPT_RegDeleteCRL(HCERTSTORE hCertStore, static BOOL WINAPI CRYPT_RegDeleteCRL(HCERTSTORE hCertStore,
PCCRL_CONTEXT pCrlContext, DWORD dwFlags) PCCRL_CONTEXT pCrlContext, DWORD dwFlags)
{ {
PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore; PWINE_REGSTOREINFO store = (PWINE_REGSTOREINFO)hCertStore;
BOOL ret;
TRACE("(%p, %p, %08lx)\n", store, pCrlContext, dwFlags); TRACE("(%p, %p, %08lx)\n", store, pCrlContext, dwFlags);
if (store->dwOpenFlags & CERT_STORE_READONLY_FLAG) return CRYPT_RegDeleteContext(store, &store->crlsToDelete, pCrlContext,
{ pCRLInterface);
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;
} }
static BOOL WINAPI CRYPT_RegControl(HCERTSTORE hCertStore, DWORD dwFlags, static BOOL WINAPI CRYPT_RegControl(HCERTSTORE hCertStore, DWORD dwFlags,
...@@ -1859,14 +1832,8 @@ DWORD CertStore_GetAccessState(HCERTSTORE hCertStore) ...@@ -1859,14 +1832,8 @@ DWORD CertStore_GetAccessState(HCERTSTORE hCertStore)
return state; return state;
} }
static void CertContext_CopyProperties(PCCERT_CONTEXT to, PCCERT_CONTEXT from) #define CertContext_CopyProperties(to, from) \
{ Context_CopyProperties((to), (from), sizeof(CERT_CONTEXT))
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);
}
BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore, BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore,
PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition, PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition,
...@@ -1992,14 +1959,8 @@ BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext) ...@@ -1992,14 +1959,8 @@ BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
return ret; return ret;
} }
static void CrlContext_CopyProperties(PCCRL_CONTEXT to, PCCRL_CONTEXT from) #define CrlContext_CopyProperties(to, from) \
{ Context_CopyProperties((to), (from), sizeof(CRL_CONTEXT))
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);
}
BOOL WINAPI CertAddCRLContextToStore(HCERTSTORE hCertStore, BOOL WINAPI CertAddCRLContextToStore(HCERTSTORE hCertStore,
PCCRL_CONTEXT pCrlContext, DWORD dwAddDisposition, PCCRL_CONTEXT pCrlContext, DWORD dwAddDisposition,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment