From 1d534244702f7c5ca64d707628fd397cbcbb0b8e Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Fri, 17 Aug 2007 11:59:28 -0700 Subject: [PATCH] crypt32: Don't store the crypto provider when it isn't needed. --- dlls/crypt32/collectionstore.c | 3 +-- dlls/crypt32/crypt32_private.h | 10 ++++------ dlls/crypt32/filestore.c | 9 ++++++--- dlls/crypt32/provstore.c | 11 ++++------- dlls/crypt32/regstore.c | 7 +++++-- dlls/crypt32/store.c | 33 +++++++++++++++++---------------- 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/dlls/crypt32/collectionstore.c b/dlls/crypt32/collectionstore.c index e4123375aa..9bf6d1daa7 100644 --- a/dlls/crypt32/collectionstore.c +++ b/dlls/crypt32/collectionstore.c @@ -357,8 +357,7 @@ PWINECRYPT_CERTSTORE CRYPT_CollectionOpenStore(HCRYPTPROV hCryptProv, if (store) { memset(store, 0, sizeof(WINE_COLLECTIONSTORE)); - CRYPT_InitStore(&store->hdr, hCryptProv, dwFlags, - StoreTypeCollection); + CRYPT_InitStore(&store->hdr, dwFlags, StoreTypeCollection); store->hdr.closeStore = CRYPT_CollectionCloseStore; store->hdr.certs.addContext = CRYPT_CollectionAddCert; store->hdr.certs.enumContext = CRYPT_CollectionEnumCert; diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h index d2a70a7315..ffd5a87515 100644 --- a/dlls/crypt32/crypt32_private.h +++ b/dlls/crypt32/crypt32_private.h @@ -222,7 +222,6 @@ typedef struct WINE_CRYPTCERTSTORE DWORD dwMagic; LONG ref; DWORD dwOpenFlags; - HCRYPTPROV cryptProv; CertStoreType type; PFN_CERT_STORE_PROV_CLOSE closeStore; CONTEXT_FUNCS certs; @@ -231,16 +230,15 @@ typedef struct WINE_CRYPTCERTSTORE PCONTEXT_PROPERTY_LIST properties; } WINECRYPT_CERTSTORE, *PWINECRYPT_CERTSTORE; -void CRYPT_InitStore(WINECRYPT_CERTSTORE *store, HCRYPTPROV hCryptProv, - DWORD dwFlags, CertStoreType type); +void CRYPT_InitStore(WINECRYPT_CERTSTORE *store, DWORD dwFlags, + CertStoreType type); void CRYPT_FreeStore(PWINECRYPT_CERTSTORE store); void CRYPT_EmptyStore(HCERTSTORE store); PWINECRYPT_CERTSTORE CRYPT_CollectionOpenStore(HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara); -PWINECRYPT_CERTSTORE CRYPT_ProvCreateStore(HCRYPTPROV hCryptProv, - DWORD dwFlags, PWINECRYPT_CERTSTORE memStore, - const CERT_STORE_PROV_INFO *pProvInfo); +PWINECRYPT_CERTSTORE CRYPT_ProvCreateStore(DWORD dwFlags, + PWINECRYPT_CERTSTORE memStore, const CERT_STORE_PROV_INFO *pProvInfo); PWINECRYPT_CERTSTORE CRYPT_ProvOpenStore(LPCSTR lpszStoreProvider, DWORD dwEncodingType, HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara); diff --git a/dlls/crypt32/filestore.c b/dlls/crypt32/filestore.c index 45beccac73..afe4327f8c 100644 --- a/dlls/crypt32/filestore.c +++ b/dlls/crypt32/filestore.c @@ -167,7 +167,7 @@ PWINECRYPT_CERTSTORE CRYPT_FileOpenStore(HCRYPTPROV hCryptProv, DWORD dwFlags, { PWINECRYPT_CERTSTORE memStore; - memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, hCryptProv, + memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); if (memStore) { @@ -189,8 +189,11 @@ PWINECRYPT_CERTSTORE CRYPT_FileOpenStore(HCRYPTPROV hCryptProv, DWORD dwFlags, sizeof(fileProvFuncs[0]); provInfo.rgpvStoreProvFunc = fileProvFuncs; provInfo.hStoreProv = info; - store = CRYPT_ProvCreateStore(hCryptProv, dwFlags, memStore, - &provInfo); + store = CRYPT_ProvCreateStore(dwFlags, memStore, &provInfo); + /* File store doesn't need crypto provider, so close it */ + if (hCryptProv && + !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG)) + CryptReleaseContext(hCryptProv, 0); } } } diff --git a/dlls/crypt32/provstore.c b/dlls/crypt32/provstore.c index d58612ad70..b1053ae146 100644 --- a/dlls/crypt32/provstore.c +++ b/dlls/crypt32/provstore.c @@ -193,16 +193,14 @@ static BOOL WINAPI CRYPT_ProvControl(HCERTSTORE hCertStore, DWORD dwFlags, return ret; } -PWINECRYPT_CERTSTORE CRYPT_ProvCreateStore(HCRYPTPROV hCryptProv, - DWORD dwFlags, PWINECRYPT_CERTSTORE memStore, - const CERT_STORE_PROV_INFO *pProvInfo) +PWINECRYPT_CERTSTORE CRYPT_ProvCreateStore(DWORD dwFlags, + PWINECRYPT_CERTSTORE memStore, const CERT_STORE_PROV_INFO *pProvInfo) { PWINE_PROVIDERSTORE ret = CryptMemAlloc(sizeof(WINE_PROVIDERSTORE)); if (ret) { - CRYPT_InitStore(&ret->hdr, hCryptProv, dwFlags, - StoreTypeProvider); + CRYPT_InitStore(&ret->hdr, dwFlags, StoreTypeProvider); ret->dwStoreProvFlags = pProvInfo->dwStoreProvFlags; if (ret->dwStoreProvFlags & CERT_STORE_PROV_EXTERNAL_FLAG) { @@ -289,8 +287,7 @@ PWINECRYPT_CERTSTORE CRYPT_ProvOpenStore(LPCSTR lpszStoreProvider, { if (provOpenFunc(lpszStoreProvider, dwEncodingType, hCryptProv, dwFlags, pvPara, memStore, &provInfo)) - ret = CRYPT_ProvCreateStore(hCryptProv, dwFlags, memStore, - &provInfo); + ret = CRYPT_ProvCreateStore(dwFlags, memStore, &provInfo); else CertCloseStore(memStore, 0); } diff --git a/dlls/crypt32/regstore.c b/dlls/crypt32/regstore.c index 7bfb4dfe11..e7de5fdaf1 100644 --- a/dlls/crypt32/regstore.c +++ b/dlls/crypt32/regstore.c @@ -530,8 +530,11 @@ PWINECRYPT_CERTSTORE CRYPT_RegOpenStore(HCRYPTPROV hCryptProv, DWORD dwFlags, sizeof(regProvFuncs[0]); provInfo.rgpvStoreProvFunc = regProvFuncs; provInfo.hStoreProv = regInfo; - store = CRYPT_ProvCreateStore(hCryptProv, dwFlags, memStore, - &provInfo); + store = CRYPT_ProvCreateStore(dwFlags, memStore, &provInfo); + /* Reg store doesn't need crypto provider, so close it */ + if (hCryptProv && + !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG)) + CryptReleaseContext(hCryptProv, 0); } } } diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c index 28c843395c..fd7ec8ac5f 100644 --- a/dlls/crypt32/store.c +++ b/dlls/crypt32/store.c @@ -100,18 +100,12 @@ typedef struct _WINE_MSGSTOREINFO HCRYPTMSG msg; } WINE_MSGSTOREINFO, *PWINE_MSGSTOREINFO; -void CRYPT_InitStore(WINECRYPT_CERTSTORE *store, HCRYPTPROV hCryptProv, - DWORD dwFlags, CertStoreType type) +void CRYPT_InitStore(WINECRYPT_CERTSTORE *store, DWORD dwFlags, + CertStoreType type) { store->ref = 1; store->dwMagic = WINE_CRYPTCERTSTORE_MAGIC; store->type = type; - if (!hCryptProv) - { - hCryptProv = CRYPT_GetDefaultProvider(); - dwFlags |= CERT_STORE_NO_CRYPT_RELEASE_FLAG; - } - store->cryptProv = hCryptProv; store->dwOpenFlags = dwFlags; store->properties = NULL; } @@ -253,7 +247,7 @@ static WINECRYPT_CERTSTORE *CRYPT_MemOpenStore(HCRYPTPROV hCryptProv, if (store) { memset(store, 0, sizeof(WINE_MEMSTORE)); - CRYPT_InitStore(&store->hdr, hCryptProv, dwFlags, StoreTypeMem); + CRYPT_InitStore(&store->hdr, dwFlags, StoreTypeMem); store->hdr.closeStore = CRYPT_MemCloseStore; store->hdr.certs.addContext = CRYPT_MemAddCert; store->hdr.certs.enumContext = CRYPT_MemEnumCert; @@ -266,6 +260,9 @@ static WINECRYPT_CERTSTORE *CRYPT_MemOpenStore(HCRYPTPROV hCryptProv, sizeof(CERT_CONTEXT)); store->crls = ContextList_Create(pCRLInterface, sizeof(CRL_CONTEXT)); + /* Mem store doesn't need crypto provider, so close it */ + if (hCryptProv && !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG)) + CryptReleaseContext(hCryptProv, 0); } } return (PWINECRYPT_CERTSTORE)store; @@ -446,7 +443,7 @@ static PWINECRYPT_CERTSTORE CRYPT_SysOpenStoreW(HCRYPTPROV hCryptProv, if (ret) { HCERTSTORE regStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_REGISTRY_W, - 0, hCryptProv, dwFlags, pvPara); + 0, 0, dwFlags, pvPara); if (regStore) { @@ -465,7 +462,7 @@ static PWINECRYPT_CERTSTORE CRYPT_SysOpenStoreW(HCRYPTPROV hCryptProv, dwFlags &= ~CERT_SYSTEM_STORE_CURRENT_USER; dwFlags |= CERT_SYSTEM_STORE_LOCAL_MACHINE; regStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_REGISTRY_W, 0, - hCryptProv, dwFlags, pvPara); + 0, dwFlags, pvPara); if (regStore) { CertAddStoreToCollection(store, regStore, @@ -474,6 +471,9 @@ static PWINECRYPT_CERTSTORE CRYPT_SysOpenStoreW(HCRYPTPROV hCryptProv, CertCloseStore(regStore, 0); } } + /* System store doesn't need crypto provider, so close it */ + if (hCryptProv && !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG)) + CryptReleaseContext(hCryptProv, 0); } } return (PWINECRYPT_CERTSTORE)store; @@ -544,7 +544,7 @@ static PWINECRYPT_CERTSTORE CRYPT_MsgOpenStore(HCRYPTPROV hCryptProv, TRACE("(%ld, %08x, %p)\n", hCryptProv, dwFlags, pvPara); - memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, hCryptProv, + memStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); if (memStore) { @@ -609,8 +609,11 @@ static PWINECRYPT_CERTSTORE CRYPT_MsgOpenStore(HCRYPTPROV hCryptProv, sizeof(msgProvFuncs[0]); provInfo.rgpvStoreProvFunc = msgProvFuncs; provInfo.hStoreProv = info; - store = CRYPT_ProvCreateStore(hCryptProv, dwFlags, memStore, + store = CRYPT_ProvCreateStore(dwFlags, memStore, &provInfo); + /* Msg store doesn't need crypto provider, so close it */ + if (hCryptProv && !(dwFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG)) + CryptReleaseContext(hCryptProv, 0); } else CertCloseStore(memStore, 0); @@ -657,7 +660,7 @@ static PWINECRYPT_CERTSTORE CRYPT_PKCSOpenStore(HCRYPTPROV hCryptProv, } } if (ret) - store = CRYPT_MsgOpenStore(hCryptProv, dwFlags, msg); + store = CRYPT_MsgOpenStore(0, dwFlags, msg); CryptMsgClose(msg); TRACE("returning %p\n", store); return store; @@ -1133,8 +1136,6 @@ BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags) { TRACE("%p's ref count is 0, freeing\n", hcs); hcs->dwMagic = 0; - if (!(hcs->dwOpenFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG)) - CryptReleaseContext(hcs->cryptProv, 0); hcs->closeStore(hcs, dwFlags); } else