Remove some Unicode->ANSI cross-calls in crypt functions.
This commit is contained in:
parent
fbecb0c319
commit
bd6f176df9
|
@ -43,6 +43,7 @@
|
|||
#include "winnls.h"
|
||||
#include "winreg.h"
|
||||
#include "wine/debug.h"
|
||||
#include "wine/unicode.h"
|
||||
#include "winternl.h"
|
||||
#include "ntstatus.h"
|
||||
|
||||
|
@ -50,38 +51,56 @@ WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
|||
|
||||
HWND crypt_hWindow = 0;
|
||||
|
||||
#define CRYPT_ReturnLastError(err) {SetLastError(err); return FALSE;}
|
||||
#define CRYPT_ReturnLastError(err) do {SetLastError(err); return FALSE;} while(0)
|
||||
|
||||
#define CRYPT_Alloc(size) ((LPVOID)LocalAlloc(LMEM_ZEROINIT, size))
|
||||
#define CRYPT_Free(buffer) (LocalFree((HLOCAL)buffer))
|
||||
|
||||
static inline PSTR CRYPT_GetProvKeyName(PCSTR pProvName)
|
||||
static inline PWSTR CRYPT_GetProvKeyName(PCWSTR pProvName)
|
||||
{
|
||||
PCSTR KEYSTR = "Software\\Microsoft\\Cryptography\\Defaults\\Provider\\";
|
||||
PSTR keyname;
|
||||
static const WCHAR KEYSTR[] = {
|
||||
'S','o','f','t','w','a','r','e','\\',
|
||||
'M','i','c','r','o','s','o','f','t','\\',
|
||||
'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
||||
'D','e','f','a','u','l','t','s','\\',
|
||||
'P','r','o','v','i','d','e','r','\\',0
|
||||
};
|
||||
PWSTR keyname;
|
||||
|
||||
keyname = CRYPT_Alloc(strlen(KEYSTR) + strlen(pProvName) +1);
|
||||
keyname = CRYPT_Alloc((strlenW(KEYSTR) + strlenW(pProvName) +1)*sizeof(WCHAR));
|
||||
if (keyname)
|
||||
{
|
||||
strcpy(keyname, KEYSTR);
|
||||
strcpy(keyname + strlen(KEYSTR), pProvName);
|
||||
strcpyW(keyname, KEYSTR);
|
||||
strcpyW(keyname + strlenW(KEYSTR), pProvName);
|
||||
} else
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
return keyname;
|
||||
}
|
||||
|
||||
static inline PSTR CRYPT_GetTypeKeyName(DWORD dwType, BOOL user)
|
||||
static inline PWSTR CRYPT_GetTypeKeyName(DWORD dwType, BOOL user)
|
||||
{
|
||||
PCSTR MACHINESTR = "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types\\Type XXX";
|
||||
PCSTR USERSTR = "Software\\Microsoft\\Cryptography\\Provider Type XXX";
|
||||
PSTR keyname;
|
||||
PSTR ptr;
|
||||
static const WCHAR MACHINESTR[] = {
|
||||
'S','o','f','t','w','a','r','e','\\',
|
||||
'M','i','c','r','o','s','o','f','t','\\',
|
||||
'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
||||
'D','e','f','a','u','l','t','s','\\',
|
||||
'P','r','o','v','i','d','e','r',' ','T','y','p','e','s','\\',
|
||||
'T','y','p','e',' ','X','X','X',0
|
||||
};
|
||||
static const WCHAR USERSTR[] = {
|
||||
'S','o','f','t','w','a','r','e','\\',
|
||||
'M','i','c','r','o','s','o','f','t','\\',
|
||||
'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
||||
'P','r','o','v','i','d','e','r',' ','T','y','p','e',' ','X','X','X',0
|
||||
};
|
||||
PWSTR keyname;
|
||||
PWSTR ptr;
|
||||
|
||||
keyname = CRYPT_Alloc( (user ? strlen(USERSTR) : strlen(MACHINESTR)) +1);
|
||||
keyname = CRYPT_Alloc( ((user ? strlenW(USERSTR) : strlenW(MACHINESTR)) +1)*sizeof(WCHAR));
|
||||
if (keyname)
|
||||
{
|
||||
user ? strcpy(keyname, USERSTR) : strcpy(keyname, MACHINESTR);
|
||||
ptr = keyname + strlen(keyname);
|
||||
user ? strcpyW(keyname, USERSTR) : strcpyW(keyname, MACHINESTR);
|
||||
ptr = keyname + strlenW(keyname);
|
||||
*(--ptr) = (dwType % 10) + '0';
|
||||
*(--ptr) = ((dwType / 10) % 10) + '0';
|
||||
*(--ptr) = (dwType / 100) + '0';
|
||||
|
@ -175,7 +194,7 @@ static BOOL CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
|
|||
if ( !(provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)) ) goto error
|
||||
#define CRYPT_GetProvFuncOpt(name) \
|
||||
provider->pFuncs->p##name = (void*)GetProcAddress(provider->hModule, #name)
|
||||
static PCRYPTPROV CRYPT_LoadProvider(PSTR pImage)
|
||||
static PCRYPTPROV CRYPT_LoadProvider(PWSTR pImage)
|
||||
{
|
||||
PCRYPTPROV provider;
|
||||
DWORD errorcode = ERROR_NOT_ENOUGH_MEMORY;
|
||||
|
@ -183,10 +202,10 @@ static PCRYPTPROV CRYPT_LoadProvider(PSTR pImage)
|
|||
if ( !(provider = CRYPT_Alloc(sizeof(CRYPTPROV))) ) goto error;
|
||||
if ( !(provider->pFuncs = CRYPT_Alloc(sizeof(PROVFUNCS))) ) goto error;
|
||||
if ( !(provider->pVTable = CRYPT_Alloc(sizeof(VTableProvStruc))) ) goto error;
|
||||
if ( !(provider->hModule = LoadLibraryA(pImage)) )
|
||||
if ( !(provider->hModule = LoadLibraryW(pImage)) )
|
||||
{
|
||||
errorcode = (GetLastError() == ERROR_FILE_NOT_FOUND) ? NTE_PROV_DLL_NOT_FOUND : NTE_PROVIDER_DLL_FAIL;
|
||||
FIXME("Failed to load dll %s\n", debugstr_a(pImage));
|
||||
FIXME("Failed to load dll %s\n", debugstr_w(pImage));
|
||||
goto error;
|
||||
}
|
||||
provider->dwMagic = MAGIC_CRYPTPROV;
|
||||
|
@ -249,7 +268,7 @@ error:
|
|||
|
||||
|
||||
/******************************************************************************
|
||||
* CryptAcquireContextA (ADVAPI32.@)
|
||||
* CryptAcquireContextW (ADVAPI32.@)
|
||||
* Acquire a crypto provider context handle.
|
||||
*
|
||||
* PARAMS
|
||||
|
@ -261,17 +280,21 @@ error:
|
|||
*
|
||||
* RETURNS TRUE on success, FALSE on failure.
|
||||
*/
|
||||
BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
||||
LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
|
||||
BOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR pszContainer,
|
||||
LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
|
||||
{
|
||||
PCRYPTPROV pProv = NULL;
|
||||
HKEY key;
|
||||
PSTR imagepath = NULL, keyname = NULL, provname = NULL, temp = NULL;
|
||||
PWSTR imagepath = NULL, keyname = NULL, provname = NULL, temp = NULL;
|
||||
PSTR provnameA = NULL, pszContainerA = NULL;
|
||||
DWORD keytype, type, len;
|
||||
ULONG r;
|
||||
static const WCHAR nameW[] = {'N','a','m','e',0};
|
||||
static const WCHAR typeW[] = {'T','y','p','e',0};
|
||||
static const WCHAR imagepathW[] = {'I','m','a','g','e',' ','P','a','t','h',0};
|
||||
|
||||
TRACE("(%p, %s, %s, %ld, %08lx)\n", phProv, pszContainer,
|
||||
pszProvider, dwProvType, dwFlags);
|
||||
TRACE("(%p, %s, %s, %ld, %08lx)\n", phProv, debugstr_w(pszContainer),
|
||||
debugstr_w(pszProvider), dwProvType, dwFlags);
|
||||
|
||||
if (dwProvType < 1 || dwProvType > MAXPROVTYPES)
|
||||
{
|
||||
|
@ -295,7 +318,7 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
||||
return FALSE;
|
||||
}
|
||||
if (RegOpenKeyA(HKEY_CURRENT_USER, keyname, &key))
|
||||
if (RegOpenKeyW(HKEY_CURRENT_USER, keyname, &key))
|
||||
{
|
||||
CRYPT_Free(keyname);
|
||||
if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, FALSE)) ) {
|
||||
|
@ -304,8 +327,8 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
||||
goto error;
|
||||
}
|
||||
if (RegOpenKeyA(HKEY_LOCAL_MACHINE, keyname, &key)) {
|
||||
TRACE("Did not find registry entry of crypto provider for %s.\n", debugstr_a(keyname));
|
||||
if (RegOpenKeyW(HKEY_LOCAL_MACHINE, keyname, &key)) {
|
||||
TRACE("Did not find registry entry of crypto provider for %s.\n", debugstr_w(keyname));
|
||||
CRYPT_Free(keyname);
|
||||
RegCloseKey(key);
|
||||
SetLastError(NTE_PROV_TYPE_NOT_DEF);
|
||||
|
@ -313,7 +336,7 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
}
|
||||
}
|
||||
CRYPT_Free(keyname);
|
||||
r = RegQueryValueExA(key, "Name", NULL, &keytype, NULL, &len);
|
||||
r = RegQueryValueExW(key, nameW, NULL, &keytype, NULL, &len);
|
||||
if( r != ERROR_SUCCESS || !len || keytype != REG_SZ)
|
||||
{
|
||||
TRACE("error %ld reading size of 'Name' from registry\n", r );
|
||||
|
@ -327,7 +350,7 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
goto error;
|
||||
}
|
||||
r = RegQueryValueExA(key, "Name", NULL, NULL, (LPBYTE)provname, &len);
|
||||
r = RegQueryValueExW(key, nameW, NULL, NULL, (LPBYTE)provname, &len);
|
||||
if( r != ERROR_SUCCESS )
|
||||
{
|
||||
TRACE("error %ld reading 'Name' from registry\n", r );
|
||||
|
@ -337,16 +360,16 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
}
|
||||
RegCloseKey(key);
|
||||
} else {
|
||||
if ( !(provname = CRYPT_Alloc(strlen(pszProvider) +1)) )
|
||||
if ( !(provname = CRYPT_Alloc((strlenW(pszProvider) +1)*sizeof(WCHAR))) )
|
||||
{
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
goto error;
|
||||
}
|
||||
strcpy(provname, pszProvider);
|
||||
strcpyW(provname, pszProvider);
|
||||
}
|
||||
|
||||
keyname = CRYPT_GetProvKeyName(provname);
|
||||
r = RegOpenKeyA(HKEY_LOCAL_MACHINE, keyname, &key);
|
||||
r = RegOpenKeyW(HKEY_LOCAL_MACHINE, keyname, &key);
|
||||
CRYPT_Free(keyname);
|
||||
if (r != ERROR_SUCCESS)
|
||||
{
|
||||
|
@ -354,7 +377,7 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
goto error;
|
||||
}
|
||||
len = sizeof(DWORD);
|
||||
r = RegQueryValueExA(key, "Type", NULL, NULL, (BYTE*)&type, &len);
|
||||
r = RegQueryValueExW(key, typeW, NULL, NULL, (BYTE*)&type, &len);
|
||||
if (r != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError(NTE_PROV_TYPE_ENTRY_BAD);
|
||||
|
@ -367,7 +390,7 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
goto error;
|
||||
}
|
||||
|
||||
r = RegQueryValueExA(key, "Image Path", NULL, &keytype, NULL, &len);
|
||||
r = RegQueryValueExW(key, imagepathW, NULL, &keytype, NULL, &len);
|
||||
if ( r != ERROR_SUCCESS || keytype != REG_SZ)
|
||||
{
|
||||
TRACE("error %ld reading size of 'Image Path' from registry\n", r );
|
||||
|
@ -381,7 +404,7 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
goto error;
|
||||
}
|
||||
r = RegQueryValueExA(key, "Image Path", NULL, NULL, (LPBYTE)temp, &len);
|
||||
r = RegQueryValueExW(key, imagepathW, NULL, NULL, (LPBYTE)temp, &len);
|
||||
if( r != ERROR_SUCCESS )
|
||||
{
|
||||
TRACE("error %ld reading 'Image Path' from registry\n", r );
|
||||
|
@ -390,13 +413,13 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
goto error;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
len = ExpandEnvironmentStringsA(temp, NULL, 0);
|
||||
if ( !(imagepath = CRYPT_Alloc(len)) )
|
||||
len = ExpandEnvironmentStringsW(temp, NULL, 0);
|
||||
if ( !(imagepath = CRYPT_Alloc(len*sizeof(WCHAR))) )
|
||||
{
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
goto error;
|
||||
}
|
||||
if (!ExpandEnvironmentStringsA(temp, imagepath, len))
|
||||
if (!ExpandEnvironmentStringsW(temp, imagepath, len))
|
||||
{
|
||||
/* ExpandEnvironmentStrings will call SetLastError */
|
||||
goto error;
|
||||
|
@ -407,8 +430,18 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
goto error;
|
||||
}
|
||||
pProv->pVTable->dwProvType = dwProvType;
|
||||
pProv->pVTable->pszProvName = provname;
|
||||
if (pProv->pFuncs->pCPAcquireContext(&pProv->hPrivate, (CHAR*)pszContainer, dwFlags, pProv->pVTable))
|
||||
if(!CRYPT_UnicodeToANSI(provname, &provnameA, -1))
|
||||
{
|
||||
/* CRYPT_UnicodeToANSI calls SetLastError */
|
||||
goto error;
|
||||
}
|
||||
pProv->pVTable->pszProvName = provnameA;
|
||||
if(!CRYPT_UnicodeToANSI(pszContainer, &pszContainerA, -1))
|
||||
{
|
||||
/* CRYPT_UnicodeToANSI calls SetLastError */
|
||||
goto error;
|
||||
}
|
||||
if (pProv->pFuncs->pCPAcquireContext(&pProv->hPrivate, pszContainerA, dwFlags, pProv->pVTable))
|
||||
{
|
||||
/* MSDN: When this flag is set, the value returned in phProv is undefined,
|
||||
* and thus, the CryptReleaseContext function need not be called afterwards.
|
||||
|
@ -418,12 +451,15 @@ BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
|||
{
|
||||
pProv->dwMagic = 0;
|
||||
FreeLibrary(pProv->hModule);
|
||||
CRYPT_Free(provname);
|
||||
CRYPT_Free(provnameA);
|
||||
CRYPT_Free(pProv->pVTable);
|
||||
CRYPT_Free(pProv->pFuncs);
|
||||
CRYPT_Free(pProv);
|
||||
} else {
|
||||
*phProv = (HCRYPTPROV)pProv;
|
||||
}
|
||||
CRYPT_Free(pszContainerA);
|
||||
CRYPT_Free(provname);
|
||||
CRYPT_Free(temp);
|
||||
CRYPT_Free(imagepath);
|
||||
return TRUE;
|
||||
|
@ -441,6 +477,10 @@ error:
|
|||
CRYPT_Free(pProv->pFuncs);
|
||||
CRYPT_Free(pProv);
|
||||
}
|
||||
if (pszContainerA)
|
||||
CRYPT_Free(pszContainerA);
|
||||
if (provnameA)
|
||||
CRYPT_Free(provnameA);
|
||||
if (provname)
|
||||
CRYPT_Free(provname);
|
||||
if (temp)
|
||||
|
@ -451,28 +491,28 @@ error:
|
|||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CryptAcquireContextW (ADVAPI32.@)
|
||||
* CryptAcquireContextA (ADVAPI32.@)
|
||||
*
|
||||
* see CryptAcquireContextA
|
||||
* see CryptAcquireContextW
|
||||
*/
|
||||
BOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR pszContainer,
|
||||
LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
|
||||
BOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR pszContainer,
|
||||
LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
|
||||
{
|
||||
PSTR pProvider = NULL, pContainer = NULL;
|
||||
PWSTR pProvider = NULL, pContainer = NULL;
|
||||
BOOL ret = FALSE;
|
||||
|
||||
TRACE("(%p, %s, %s, %ld, %08lx)\n", phProv, debugstr_w(pszContainer),
|
||||
debugstr_w(pszProvider), dwProvType, dwFlags);
|
||||
TRACE("(%p, %s, %s, %ld, %08lx)\n", phProv, pszContainer,
|
||||
pszProvider, dwProvType, dwFlags);
|
||||
|
||||
if ( !CRYPT_UnicodeToANSI(pszContainer, &pContainer, -1) )
|
||||
if ( !CRYPT_ANSIToUnicode(pszContainer, &pContainer, -1) )
|
||||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
if ( !CRYPT_UnicodeToANSI(pszProvider, &pProvider, -1) )
|
||||
if ( !CRYPT_ANSIToUnicode(pszProvider, &pProvider, -1) )
|
||||
{
|
||||
CRYPT_Free(pContainer);
|
||||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
}
|
||||
|
||||
ret = CryptAcquireContextA(phProv, pContainer, pProvider, dwProvType, dwFlags);
|
||||
ret = CryptAcquireContextW(phProv, pContainer, pProvider, dwProvType, dwFlags);
|
||||
|
||||
if (pContainer)
|
||||
CRYPT_Free(pContainer);
|
||||
|
@ -955,7 +995,6 @@ BOOL WINAPI CryptEnumProvidersW (DWORD dwIndex, DWORD *pdwReserved,
|
|||
DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszProvName, DWORD *pcbProvName)
|
||||
{
|
||||
HKEY hKey;
|
||||
|
||||
static const WCHAR providerW[] = {
|
||||
'S','o','f','t','w','a','r','e','\\',
|
||||
'M','i','c','r','o','s','o','f','t','\\',
|
||||
|
@ -963,7 +1002,6 @@ BOOL WINAPI CryptEnumProvidersW (DWORD dwIndex, DWORD *pdwReserved,
|
|||
'D','e','f','a','u','l','t','s','\\',
|
||||
'P','r','o','v','i','d','e','r',0
|
||||
};
|
||||
|
||||
static const WCHAR typeW[] = {'T','y','p','e',0};
|
||||
|
||||
TRACE("(%ld, %p, %ld, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
||||
|
@ -987,11 +1025,10 @@ BOOL WINAPI CryptEnumProvidersW (DWORD dwIndex, DWORD *pdwReserved,
|
|||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
|
||||
RegEnumKeyExW(hKey, dwIndex, provNameW, pcbProvName, NULL, NULL, NULL, NULL);
|
||||
CRYPT_Free(provNameW);
|
||||
(*pcbProvName)++;
|
||||
*pcbProvName *= sizeof(WCHAR);
|
||||
|
||||
CRYPT_Free(provNameW);
|
||||
|
||||
|
||||
if (dwIndex >= numkeys)
|
||||
CRYPT_ReturnLastError(ERROR_NO_MORE_ITEMS);
|
||||
} else {
|
||||
|
@ -1027,21 +1064,24 @@ BOOL WINAPI CryptEnumProvidersA (DWORD dwIndex, DWORD *pdwReserved,
|
|||
TRACE("(%ld, %p, %08lx, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
||||
pdwProvType, pszProvName, pcbProvName);
|
||||
|
||||
strlen = *pcbProvName * sizeof(WCHAR);
|
||||
CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, NULL, &strlen);
|
||||
if ( pszProvName && !(str = CRYPT_Alloc(strlen)) )
|
||||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
ret = CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, str, &strlen);
|
||||
if (str)
|
||||
{
|
||||
CRYPT_UnicodeToANSI(str, &pszProvName, *pcbProvName);
|
||||
CRYPT_Free(str);
|
||||
}
|
||||
*pcbProvName = strlen / sizeof(WCHAR); /* FIXME: not correct */
|
||||
if (str)
|
||||
{
|
||||
CRYPT_Free(str);
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
CRYPT_ReturnLastError(ERROR_MORE_DATA);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CryptEnumProviderTypesA (ADVAPI32i.@)
|
||||
* CryptEnumProviderTypesW (ADVAPI32i.@)
|
||||
*
|
||||
* Retrieves the next type of CSP supported.
|
||||
*
|
||||
|
@ -1059,16 +1099,24 @@ BOOL WINAPI CryptEnumProvidersA (DWORD dwIndex, DWORD *pdwReserved,
|
|||
* Failure: FALSE
|
||||
*
|
||||
* NOTES
|
||||
* If pszTypeName is NULL, CryptEnumProviderTypesA sets the size of the name
|
||||
* If pszTypeName is NULL, CryptEnumProviderTypesW sets the size of the name
|
||||
* for memory allocation purposes.
|
||||
*/
|
||||
BOOL WINAPI CryptEnumProviderTypesA (DWORD dwIndex, DWORD *pdwReserved,
|
||||
DWORD dwFlags, DWORD *pdwProvType, LPSTR pszTypeName, DWORD *pcbTypeName)
|
||||
BOOL WINAPI CryptEnumProviderTypesW (DWORD dwIndex, DWORD *pdwReserved,
|
||||
DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszTypeName, DWORD *pcbTypeName)
|
||||
{
|
||||
HKEY hKey, hSubkey;
|
||||
DWORD keylen, numkeys, dwType;
|
||||
PSTR keyname, ch;
|
||||
PWSTR keyname, ch;
|
||||
DWORD result;
|
||||
static const WCHAR KEYSTR[] = {
|
||||
'S','o','f','t','w','a','r','e','\\',
|
||||
'M','i','c','r','o','s','o','f','t','\\',
|
||||
'C','r','y','p','t','o','g','r','a','p','h','y','\\',
|
||||
'D','e','f','a','u','l','t','s','\\',
|
||||
'P','r','o','v','i','d','e','r',' ','T','y','p','e','s',0
|
||||
};
|
||||
static const WCHAR typenameW[] = {'T','y','p','e','N','a','m','e',0};
|
||||
|
||||
TRACE("(%ld, %p, %08lx, %p, %p, %p)\n", dwIndex, pdwReserved,
|
||||
dwFlags, pdwProvType, pszTypeName, pcbTypeName);
|
||||
|
@ -1077,28 +1125,28 @@ BOOL WINAPI CryptEnumProviderTypesA (DWORD dwIndex, DWORD *pdwReserved,
|
|||
CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER);
|
||||
if (dwFlags) CRYPT_ReturnLastError(NTE_BAD_FLAGS);
|
||||
|
||||
if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types", &hKey))
|
||||
if (RegOpenKeyW(HKEY_LOCAL_MACHINE, KEYSTR, &hKey))
|
||||
return FALSE;
|
||||
|
||||
RegQueryInfoKeyA(hKey, NULL, NULL, NULL, &numkeys, &keylen, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, &keylen, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
if (dwIndex >= numkeys)
|
||||
CRYPT_ReturnLastError(ERROR_NO_MORE_ITEMS);
|
||||
keylen++;
|
||||
if ( !(keyname = CRYPT_Alloc(keylen)) )
|
||||
if ( !(keyname = CRYPT_Alloc(keylen*sizeof(WCHAR))) )
|
||||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
if ( RegEnumKeyA(hKey, dwIndex, keyname, keylen) ) {
|
||||
if ( RegEnumKeyW(hKey, dwIndex, keyname, keylen) ) {
|
||||
CRYPT_Free(keyname);
|
||||
return FALSE;
|
||||
}
|
||||
RegOpenKeyA(hKey, keyname, &hSubkey);
|
||||
ch = keyname + strlen(keyname);
|
||||
RegOpenKeyW(hKey, keyname, &hSubkey);
|
||||
ch = keyname + strlenW(keyname);
|
||||
/* Convert "Type 000" to 0, etc/ */
|
||||
*pdwProvType = *(--ch) - '0';
|
||||
*pdwProvType += (*(--ch) - '0') * 10;
|
||||
*pdwProvType += (*(--ch) - '0') * 100;
|
||||
CRYPT_Free(keyname);
|
||||
|
||||
result = RegQueryValueExA(hSubkey, "TypeName", NULL, &dwType, (LPBYTE)pszTypeName, pcbTypeName);
|
||||
result = RegQueryValueExW(hSubkey, typenameW, NULL, &dwType, (LPBYTE)pszTypeName, pcbTypeName);
|
||||
if (result)
|
||||
CRYPT_ReturnLastError(result);
|
||||
|
||||
|
@ -1108,29 +1156,33 @@ BOOL WINAPI CryptEnumProviderTypesA (DWORD dwIndex, DWORD *pdwReserved,
|
|||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CryptEnumProviderTypesW (ADVAPI32.@)
|
||||
* CryptEnumProviderTypesA (ADVAPI32.@)
|
||||
*
|
||||
* see CryptEnumProviderTypesA
|
||||
* see CryptEnumProviderTypesW
|
||||
*/
|
||||
BOOL WINAPI CryptEnumProviderTypesW (DWORD dwIndex, DWORD *pdwReserved,
|
||||
DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszTypeName, DWORD *pcbTypeName)
|
||||
BOOL WINAPI CryptEnumProviderTypesA (DWORD dwIndex, DWORD *pdwReserved,
|
||||
DWORD dwFlags, DWORD *pdwProvType, LPSTR pszTypeName, DWORD *pcbTypeName)
|
||||
{
|
||||
PSTR str = NULL;
|
||||
PWSTR str = NULL;
|
||||
DWORD strlen;
|
||||
BOOL ret;
|
||||
|
||||
TRACE("(%ld, %p, %08lx, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
|
||||
pdwProvType, pszTypeName, pcbTypeName);
|
||||
strlen = *pcbTypeName / sizeof(WCHAR);
|
||||
|
||||
CryptEnumProviderTypesW(dwIndex, pdwReserved, dwFlags, pdwProvType, NULL, &strlen);
|
||||
if ( pszTypeName && !(str = CRYPT_Alloc(strlen)) )
|
||||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
ret = CryptEnumProviderTypesA(dwIndex, pdwReserved, dwFlags, pdwProvType, str, &strlen);
|
||||
ret = CryptEnumProviderTypesW(dwIndex, pdwReserved, dwFlags, pdwProvType, str, &strlen);
|
||||
if (str)
|
||||
CRYPT_UnicodeToANSI(str, &pszTypeName, *pcbTypeName);
|
||||
*pcbTypeName = strlen / sizeof(WCHAR);
|
||||
if (str)
|
||||
{
|
||||
CRYPT_ANSIToUnicode(str, &pszTypeName, *pcbTypeName);
|
||||
CRYPT_Free(str);
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
CRYPT_ReturnLastError(ERROR_MORE_DATA);
|
||||
}
|
||||
*pcbTypeName = strlen * sizeof(WCHAR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1214,7 +1266,7 @@ BOOL WINAPI CryptGenKey (HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKE
|
|||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CryptGetDefaultProviderA (ADVAPI32.@)
|
||||
* CryptGetDefaultProviderW (ADVAPI32.@)
|
||||
*
|
||||
* Finds the default CSP of a certain provider type.
|
||||
*
|
||||
|
@ -1233,12 +1285,13 @@ BOOL WINAPI CryptGenKey (HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKE
|
|||
* If pszProvName is NULL, pcbProvName will hold the size of the buffer for
|
||||
* memory allocation purposes on return.
|
||||
*/
|
||||
BOOL WINAPI CryptGetDefaultProviderA (DWORD dwProvType, DWORD *pdwReserved,
|
||||
DWORD dwFlags, LPSTR pszProvName, DWORD *pcbProvName)
|
||||
BOOL WINAPI CryptGetDefaultProviderW (DWORD dwProvType, DWORD *pdwReserved,
|
||||
DWORD dwFlags, LPWSTR pszProvName, DWORD *pcbProvName)
|
||||
{
|
||||
HKEY hKey;
|
||||
PSTR keyname;
|
||||
PWSTR keyname;
|
||||
DWORD result;
|
||||
static const WCHAR nameW[] = {'N','a','m','e',0};
|
||||
|
||||
if (pdwReserved || !pcbProvName)
|
||||
CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER);
|
||||
|
@ -1248,14 +1301,14 @@ BOOL WINAPI CryptGetDefaultProviderA (DWORD dwProvType, DWORD *pdwReserved,
|
|||
CRYPT_ReturnLastError(NTE_BAD_PROV_TYPE);
|
||||
if ( !(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)) )
|
||||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
if (RegOpenKeyA((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE ,keyname, &hKey))
|
||||
if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE ,keyname, &hKey))
|
||||
{
|
||||
CRYPT_Free(keyname);
|
||||
CRYPT_ReturnLastError(NTE_PROV_TYPE_NOT_DEF);
|
||||
}
|
||||
CRYPT_Free(keyname);
|
||||
|
||||
result = RegQueryValueExA(hKey, "Name", NULL, NULL, (LPBYTE)pszProvName, pcbProvName);
|
||||
result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, pcbProvName);
|
||||
if (result)
|
||||
{
|
||||
if (result != ERROR_MORE_DATA)
|
||||
|
@ -1271,29 +1324,32 @@ BOOL WINAPI CryptGetDefaultProviderA (DWORD dwProvType, DWORD *pdwReserved,
|
|||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CryptGetDefaultProviderW (ADVAPI32.@)
|
||||
* CryptGetDefaultProviderA (ADVAPI32.@)
|
||||
*
|
||||
* see CryptGetDefaultProviderA
|
||||
* see CryptGetDefaultProviderW
|
||||
*/
|
||||
BOOL WINAPI CryptGetDefaultProviderW (DWORD dwProvType, DWORD *pdwReserved,
|
||||
DWORD dwFlags, LPWSTR pszProvName, DWORD *pcbProvName)
|
||||
BOOL WINAPI CryptGetDefaultProviderA (DWORD dwProvType, DWORD *pdwReserved,
|
||||
DWORD dwFlags, LPSTR pszProvName, DWORD *pcbProvName)
|
||||
{
|
||||
PSTR str = NULL;
|
||||
PWSTR str = NULL;
|
||||
DWORD strlen;
|
||||
BOOL ret = FALSE;
|
||||
|
||||
TRACE("(%ld, %p, %08lx, %p, %p)\n", dwProvType, pdwReserved, dwFlags, pszProvName, pcbProvName);
|
||||
|
||||
strlen = *pcbProvName / sizeof(WCHAR);
|
||||
CryptGetDefaultProviderW(dwProvType, pdwReserved, dwFlags, NULL, &strlen);
|
||||
if ( pszProvName && !(str = CRYPT_Alloc(strlen)) )
|
||||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
ret = CryptGetDefaultProviderA(dwProvType, pdwReserved, dwFlags, str, &strlen);
|
||||
ret = CryptGetDefaultProviderW(dwProvType, pdwReserved, dwFlags, str, &strlen);
|
||||
if (str)
|
||||
CRYPT_UnicodeToANSI(str, &pszProvName, *pcbProvName);
|
||||
*pcbProvName = strlen / sizeof(WCHAR);
|
||||
if (str)
|
||||
{
|
||||
CRYPT_ANSIToUnicode(str, &pszProvName, *pcbProvName);
|
||||
CRYPT_Free(str);
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
CRYPT_ReturnLastError(ERROR_MORE_DATA);
|
||||
}
|
||||
*pcbProvName = strlen * sizeof(WCHAR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1696,7 +1752,7 @@ BOOL WINAPI CryptSetProviderW (LPCWSTR pszProvName, DWORD dwProvType)
|
|||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CryptSetProviderExA (ADVAPI32.@)
|
||||
* CryptSetProviderExW (ADVAPI32.@)
|
||||
*
|
||||
* Specifies the default CSP.
|
||||
*
|
||||
|
@ -1710,12 +1766,13 @@ BOOL WINAPI CryptSetProviderW (LPCWSTR pszProvName, DWORD dwProvType)
|
|||
* Success: TRUE
|
||||
* Failure: FALSE
|
||||
*/
|
||||
BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
||||
BOOL WINAPI CryptSetProviderExW (LPCWSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
||||
{
|
||||
HKEY hProvKey, hTypeKey;
|
||||
PSTR keyname;
|
||||
PWSTR keyname;
|
||||
static const WCHAR nameW[] = {'N','a','m','e',0};
|
||||
|
||||
TRACE("(%s, %ld, %p, %08lx)\n", pszProvName, dwProvType, pdwReserved, dwFlags);
|
||||
TRACE("(%s, %ld, %p, %08lx)\n", debugstr_w(pszProvName), dwProvType, pdwReserved, dwFlags);
|
||||
|
||||
if (!pszProvName || pdwReserved)
|
||||
CRYPT_ReturnLastError(ERROR_INVALID_PARAMETER);
|
||||
|
@ -1727,7 +1784,7 @@ BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pd
|
|||
|
||||
if (!(keyname = CRYPT_GetTypeKeyName(dwProvType, dwFlags & CRYPT_USER_DEFAULT)))
|
||||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
if (RegOpenKeyA((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
||||
if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
||||
keyname, &hTypeKey))
|
||||
{
|
||||
CRYPT_Free(keyname);
|
||||
|
@ -1737,7 +1794,7 @@ BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pd
|
|||
|
||||
if (dwFlags & CRYPT_DELETE_DEFAULT)
|
||||
{
|
||||
RegDeleteValueA(hTypeKey, "Name");
|
||||
RegDeleteValueW(hTypeKey, nameW);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1746,7 +1803,7 @@ BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pd
|
|||
RegCloseKey(hTypeKey);
|
||||
CRYPT_ReturnLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
}
|
||||
if (RegOpenKeyA((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
||||
if (RegOpenKeyW((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
|
||||
keyname, &hProvKey))
|
||||
{
|
||||
CRYPT_Free(keyname);
|
||||
|
@ -1755,7 +1812,7 @@ BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pd
|
|||
}
|
||||
CRYPT_Free(keyname);
|
||||
|
||||
if (RegSetValueExA(hTypeKey, "Name", 0, REG_SZ, (LPBYTE)pszProvName, strlen(pszProvName) + 1))
|
||||
if (RegSetValueExW(hTypeKey, nameW, 0, REG_SZ, (LPBYTE)pszProvName, (strlenW(pszProvName) + 1)*sizeof(WCHAR)))
|
||||
{
|
||||
RegCloseKey(hTypeKey);
|
||||
RegCloseKey(hProvKey);
|
||||
|
@ -1770,20 +1827,20 @@ BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pd
|
|||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CryptSetProviderExW (ADVAPI32.@)
|
||||
* CryptSetProviderExA (ADVAPI32.@)
|
||||
*
|
||||
* See CryptSetProviderExA
|
||||
* See CryptSetProviderExW
|
||||
*/
|
||||
BOOL WINAPI CryptSetProviderExW (LPCWSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
||||
BOOL WINAPI CryptSetProviderExA (LPCSTR pszProvName, DWORD dwProvType, DWORD *pdwReserved, DWORD dwFlags)
|
||||
{
|
||||
BOOL ret = FALSE;
|
||||
PSTR str = NULL;
|
||||
PWSTR str = NULL;
|
||||
|
||||
TRACE("(%s, %ld, %p, %08lx)\n", debugstr_w(pszProvName), dwProvType, pdwReserved, dwFlags);
|
||||
TRACE("(%s, %ld, %p, %08lx)\n", pszProvName, dwProvType, pdwReserved, dwFlags);
|
||||
|
||||
if (CRYPT_UnicodeToANSI(pszProvName, &str, -1))
|
||||
if (CRYPT_ANSIToUnicode(pszProvName, &str, -1))
|
||||
{
|
||||
ret = CryptSetProviderExA(str, dwProvType, pdwReserved, dwFlags);
|
||||
ret = CryptSetProviderExW(str, dwProvType, pdwReserved, dwFlags);
|
||||
CRYPT_Free(str);
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -384,7 +384,7 @@ static void test_enum_providers(void)
|
|||
DWORD providerLen;
|
||||
DWORD type;
|
||||
DWORD count;
|
||||
BOOL result;
|
||||
DWORD result;
|
||||
DWORD notNull = 5;
|
||||
DWORD notZeroFlags = 5;
|
||||
|
||||
|
@ -395,7 +395,10 @@ static void test_enum_providers(void)
|
|||
}
|
||||
|
||||
if (!FindProvRegVals(dwIndex, &dwType, &pszProvName, &cbName, &provCount))
|
||||
return;
|
||||
{
|
||||
trace("could not find providers in registry, skipping the test\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* check pdwReserved flag for NULL */
|
||||
result = pCryptEnumProvidersA(dwIndex, ¬Null, 0, &type, NULL, &providerLen);
|
||||
|
@ -439,12 +442,13 @@ static void test_enum_providers(void)
|
|||
if (!(provider = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, providerLen))))
|
||||
return;
|
||||
|
||||
providerLen = 0xdeadbeef;
|
||||
result = pCryptEnumProvidersA(dwIndex, NULL, 0, &type, provider, &providerLen);
|
||||
ok(result && type==dwType, "expected %ld, got %ld\n",
|
||||
dwType, type);
|
||||
ok(result && !strcmp(pszProvName, provider), "expected %s, got %s\n", pszProvName, provider);
|
||||
ok(result && cbName==providerLen, "expected %ld, got %ld\n",
|
||||
cbName, providerLen);
|
||||
ok(result, "expected TRUE, got %ld\n", result);
|
||||
ok(type==dwType, "expected %ld, got %ld\n", dwType, type);
|
||||
if (pszProvName)
|
||||
ok(!strcmp(pszProvName, provider), "expected %s, got %s\n", pszProvName, provider);
|
||||
ok(cbName==providerLen, "expected %ld, got %ld\n", cbName, providerLen);
|
||||
|
||||
LocalFree(provider);
|
||||
}
|
||||
|
@ -656,7 +660,11 @@ static void test_get_default_provider(void)
|
|||
return;
|
||||
}
|
||||
|
||||
FindDfltProvRegVals(dwProvType, dwFlags, &pszProvName, &cbProvName);
|
||||
if(!FindDfltProvRegVals(dwProvType, dwFlags, &pszProvName, &cbProvName))
|
||||
{
|
||||
trace("could not find default provider in registry, skipping the test\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* check pdwReserved for NULL */
|
||||
result = pCryptGetDefaultProviderA(provType, ¬Null, flags, provName, &provNameSize);
|
||||
|
@ -701,9 +709,12 @@ static void test_get_default_provider(void)
|
|||
if (!(provName = LocalAlloc(LMEM_ZEROINIT, provNameSize)))
|
||||
return;
|
||||
|
||||
provNameSize = 0xdeadbeef;
|
||||
result = pCryptGetDefaultProviderA(provType, NULL, flags, provName, &provNameSize);
|
||||
ok(result && !strcmp(pszProvName, provName), "expected %s, got %s\n", pszProvName, provName);
|
||||
ok(result && provNameSize==cbProvName, "expected %ld, got %ld\n", cbProvName, provNameSize);
|
||||
ok(result, "expected TRUE, got %ld\n", result);
|
||||
if(pszProvName)
|
||||
ok(!strcmp(pszProvName, provName), "expected %s, got %s\n", pszProvName, provName);
|
||||
ok(provNameSize==cbProvName, "expected %ld, got %ld\n", cbProvName, provNameSize);
|
||||
|
||||
LocalFree(provName);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue