rsaenh: Use helper function to delete a key container's registry key.

This commit is contained in:
Juan Lang 2007-11-06 11:53:14 -08:00 committed by Alexandre Julliard
parent 88405a68e7
commit 9260fcf7ac
1 changed files with 33 additions and 19 deletions

View File

@ -964,6 +964,38 @@ static BOOL open_container_key(LPCSTR pszContainerName, DWORD dwFlags, HKEY *phK
ERROR_SUCCESS;
}
/******************************************************************************
* delete_container_key [Internal]
*
* Deletes a key container's persistent storage.
*
* PARAMS
* pszContainerName [I] Name of the container to be opened.
* dwFlags [I] Flags indicating which keyset to be opened.
*/
static BOOL delete_container_key(LPCSTR pszContainerName, DWORD dwFlags)
{
CHAR szRegKey[MAX_PATH];
if (snprintf(szRegKey, MAX_PATH, RSAENH_REGKEY, pszContainerName) >= MAX_PATH) {
SetLastError(NTE_BAD_KEYSET_PARAM);
return FALSE;
} else {
HKEY hRootKey;
if (dwFlags & CRYPT_MACHINE_KEYSET)
hRootKey = HKEY_LOCAL_MACHINE;
else
hRootKey = HKEY_CURRENT_USER;
if (!RegDeleteKeyA(hRootKey, szRegKey)) {
SetLastError(ERROR_SUCCESS);
return TRUE;
} else {
SetLastError(NTE_BAD_KEYSET);
return FALSE;
}
}
}
/******************************************************************************
* store_key_container_keys [Internal]
*
@ -1479,7 +1511,6 @@ BOOL WINAPI RSAENH_CPAcquireContext(HCRYPTPROV *phProv, LPSTR pszContainer,
DWORD dwFlags, PVTableProvStruc pVTable)
{
CHAR szKeyContainerName[MAX_PATH];
CHAR szRegKey[MAX_PATH];
TRACE("(phProv=%p, pszContainer=%s, dwFlags=%08x, pVTable=%p)\n", phProv,
debugstr_a(pszContainer), dwFlags, pVTable);
@ -1501,24 +1532,7 @@ BOOL WINAPI RSAENH_CPAcquireContext(HCRYPTPROV *phProv, LPSTR pszContainer,
break;
case CRYPT_DELETEKEYSET:
if (snprintf(szRegKey, MAX_PATH, RSAENH_REGKEY, szKeyContainerName) >= MAX_PATH) {
SetLastError(NTE_BAD_KEYSET_PARAM);
return FALSE;
} else {
HKEY hRootKey;
if (dwFlags & CRYPT_MACHINE_KEYSET)
hRootKey = HKEY_LOCAL_MACHINE;
else
hRootKey = HKEY_CURRENT_USER;
if (!RegDeleteKeyA(hRootKey, szRegKey)) {
SetLastError(ERROR_SUCCESS);
return TRUE;
} else {
SetLastError(NTE_BAD_KEYSET);
return FALSE;
}
}
break;
return delete_container_key(szKeyContainerName, dwFlags);
case CRYPT_NEWKEYSET:
*phProv = read_key_container(szKeyContainerName, dwFlags, pVTable);