Commit 81e6f0c1 authored by Michael Jung's avatar Michael Jung Committed by Alexandre Julliard

Reference counting for CRYPTPROV objects.

Implemented CryptContextAddRef.
parent 932533ca
......@@ -183,6 +183,7 @@ PCRYPTPROV CRYPT_LoadProvider(PSTR pImage)
FIXME("Failed to load dll %s\n", debugstr_a(pImage));
goto error;
}
provider->refcount = 1;
errorcode = NTE_PROVIDER_DLL_FAIL;
CRYPT_GetProvFunc(CPAcquireContext);
......@@ -525,9 +526,18 @@ BOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR pszContainer,
*/
BOOL WINAPI CryptContextAddRef (HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFlags)
{
FIXME("(0x%lx, %p, %08lx): stub!\n", hProv, pdwReserved, dwFlags);
return FALSE;
/* InterlockIncrement?? */
PCRYPTPROV pProv = (PCRYPTPROV)hProv;
TRACE("(0x%lx, %p, %08lx)\n", hProv, pdwReserved, dwFlags);
if (!pProv)
{
SetLastError(NTE_BAD_UID);
return FALSE;
}
pProv->refcount++;
return TRUE;
}
/******************************************************************************
......@@ -546,7 +556,7 @@ BOOL WINAPI CryptContextAddRef (HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFl
BOOL WINAPI CryptReleaseContext (HCRYPTPROV hProv, DWORD dwFlags)
{
PCRYPTPROV pProv = (PCRYPTPROV)hProv;
BOOL ret;
BOOL ret = TRUE;
TRACE("(0x%lx, %08ld)\n", hProv, dwFlags);
......@@ -555,16 +565,20 @@ BOOL WINAPI CryptReleaseContext (HCRYPTPROV hProv, DWORD dwFlags)
SetLastError(NTE_BAD_UID);
return FALSE;
}
/* FIXME: Decrement the counter here first if possible */
ret = pProv->pFuncs->pCPReleaseContext(pProv->hPrivate, dwFlags);
FreeLibrary(pProv->hModule);
pProv->refcount--;
if (pProv->refcount <= 0)
{
ret = pProv->pFuncs->pCPReleaseContext(pProv->hPrivate, dwFlags);
FreeLibrary(pProv->hModule);
#if 0
CRYPT_Free(pProv->pVTable->pContextInfo);
CRYPT_Free(pProv->pVTable->pContextInfo);
#endif
CRYPT_Free(pProv->pVTable->pszProvName);
CRYPT_Free(pProv->pVTable);
CRYPT_Free(pProv->pFuncs);
CRYPT_Free(pProv);
CRYPT_Free(pProv->pVTable->pszProvName);
CRYPT_Free(pProv->pVTable);
CRYPT_Free(pProv->pFuncs);
CRYPT_Free(pProv);
}
return ret;
}
......
......@@ -58,6 +58,7 @@ typedef struct tagPROVFUNCS
typedef struct tagCRYPTPROV
{
UINT refcount;
HMODULE hModule;
PPROVFUNCS pFuncs;
HCRYPTPROV hPrivate; /*CSP's handle - Should not be given to application under any circumstances!*/
......
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