wintrust: Fix compilation on systems that don't support nameless unions.

This commit is contained in:
Francois Gouget 2007-09-11 16:37:44 +02:00 committed by Alexandre Julliard
parent 4ce6a5fa3d
commit 2eeb4eaf1d
3 changed files with 61 additions and 58 deletions

View File

@ -16,6 +16,9 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#define NONAMELESSUNION
#include "windef.h"
#include "winbase.h"
#include "wintrust.h"
@ -37,7 +40,7 @@ HRESULT WINAPI SoftpubInitialize(CRYPT_PROVIDER_DATA *data)
return ret;
}
/* Assumes data->pWintrustData->pFile exists. Makes sure a file handle is
/* Assumes data->pWintrustData->u.pFile exists. Makes sure a file handle is
* open for the file.
*/
static BOOL SOFTPUB_OpenFile(CRYPT_PROVIDER_DATA *data)
@ -48,13 +51,13 @@ static BOOL SOFTPUB_OpenFile(CRYPT_PROVIDER_DATA *data)
* typically have hFile as NULL rather than INVALID_HANDLE_VALUE. Check
* for both.
*/
if (!data->pWintrustData->pFile->hFile ||
data->pWintrustData->pFile->hFile == INVALID_HANDLE_VALUE)
if (!data->pWintrustData->u.pFile->hFile ||
data->pWintrustData->u.pFile->hFile == INVALID_HANDLE_VALUE)
{
data->pWintrustData->pFile->hFile =
CreateFileW(data->pWintrustData->pFile->pcwszFilePath, GENERIC_READ,
data->pWintrustData->u.pFile->hFile =
CreateFileW(data->pWintrustData->u.pFile->pcwszFilePath, GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (data->pWintrustData->pFile->hFile != INVALID_HANDLE_VALUE)
if (data->pWintrustData->u.pFile->hFile != INVALID_HANDLE_VALUE)
data->fOpenedFile = TRUE;
else
ret = FALSE;
@ -63,40 +66,40 @@ static BOOL SOFTPUB_OpenFile(CRYPT_PROVIDER_DATA *data)
return ret;
}
/* Assumes data->pWintrustData->pFile exists. Sets data->pPDSip->gSubject to
/* Assumes data->pWintrustData->u.pFile exists. Sets data->pPDSip->gSubject to
* the file's subject GUID.
*/
static BOOL SOFTPUB_GetFileSubject(CRYPT_PROVIDER_DATA *data)
{
BOOL ret;
if (!data->pWintrustData->pFile->pgKnownSubject)
if (!data->pWintrustData->u.pFile->pgKnownSubject)
{
ret = CryptSIPRetrieveSubjectGuid(
data->pWintrustData->pFile->pcwszFilePath,
data->pWintrustData->pFile->hFile,
&data->pPDSip->gSubject);
data->pWintrustData->u.pFile->pcwszFilePath,
data->pWintrustData->u.pFile->hFile,
&data->u.pPDSip->gSubject);
}
else
{
memcpy(&data->pPDSip->gSubject,
data->pWintrustData->pFile->pgKnownSubject, sizeof(GUID));
memcpy(&data->u.pPDSip->gSubject,
data->pWintrustData->u.pFile->pgKnownSubject, sizeof(GUID));
ret = TRUE;
}
TRACE("returning %d\n", ret);
return ret;
}
/* Assumes data->pPDSip exists, and its gSubject member set.
* Allocates data->pPDSip->pSip and loads it, if possible.
/* Assumes data->u.pPDSip exists, and its gSubject member set.
* Allocates data->u.pPDSip->pSip and loads it, if possible.
*/
static BOOL SOFTPUB_GetSIP(CRYPT_PROVIDER_DATA *data)
{
BOOL ret;
data->pPDSip->pSip = data->psPfns->pfnAlloc(sizeof(SIP_DISPATCH_INFO));
if (data->pPDSip->pSip)
ret = CryptSIPLoad(&data->pPDSip->gSubject, 0, data->pPDSip->pSip);
data->u.pPDSip->pSip = data->psPfns->pfnAlloc(sizeof(SIP_DISPATCH_INFO));
if (data->u.pPDSip->pSip)
ret = CryptSIPLoad(&data->u.pPDSip->gSubject, 0, data->u.pPDSip->pSip);
else
{
SetLastError(ERROR_OUTOFMEMORY);
@ -106,8 +109,8 @@ static BOOL SOFTPUB_GetSIP(CRYPT_PROVIDER_DATA *data)
return ret;
}
/* Assumes data->pPDSip has been loaded, and data->pPDSip->pSip allocated.
* Calls data->pPDSip->pSip->pfGet to construct data->hMsg.
/* Assumes data->u.pPDSip has been loaded, and data->u.pPDSip->pSip allocated.
* Calls data->u.pPDSip->pSip->pfGet to construct data->hMsg.
*/
static BOOL SOFTPUB_GetMessageFromFile(CRYPT_PROVIDER_DATA *data)
{
@ -115,21 +118,21 @@ static BOOL SOFTPUB_GetMessageFromFile(CRYPT_PROVIDER_DATA *data)
LPBYTE buf = NULL;
DWORD size = 0;
data->pPDSip->psSipSubjectInfo =
data->u.pPDSip->psSipSubjectInfo =
data->psPfns->pfnAlloc(sizeof(SIP_SUBJECTINFO));
if (!data->pPDSip->psSipSubjectInfo)
if (!data->u.pPDSip->psSipSubjectInfo)
{
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
data->pPDSip->psSipSubjectInfo->cbSize = sizeof(SIP_SUBJECTINFO);
data->pPDSip->psSipSubjectInfo->pgSubjectType = &data->pPDSip->gSubject;
data->pPDSip->psSipSubjectInfo->hFile = data->pWintrustData->pFile->hFile;
data->pPDSip->psSipSubjectInfo->pwsFileName =
data->pWintrustData->pFile->pcwszFilePath;
data->pPDSip->psSipSubjectInfo->hProv = data->hProv;
ret = data->pPDSip->pSip->pfGet(data->pPDSip->psSipSubjectInfo,
data->u.pPDSip->psSipSubjectInfo->cbSize = sizeof(SIP_SUBJECTINFO);
data->u.pPDSip->psSipSubjectInfo->pgSubjectType = &data->u.pPDSip->gSubject;
data->u.pPDSip->psSipSubjectInfo->hFile = data->pWintrustData->u.pFile->hFile;
data->u.pPDSip->psSipSubjectInfo->pwsFileName =
data->pWintrustData->u.pFile->pcwszFilePath;
data->u.pPDSip->psSipSubjectInfo->hProv = data->hProv;
ret = data->u.pPDSip->pSip->pfGet(data->u.pPDSip->psSipSubjectInfo,
&data->dwEncoding, 0, &size, 0);
if (!ret)
{
@ -144,7 +147,7 @@ static BOOL SOFTPUB_GetMessageFromFile(CRYPT_PROVIDER_DATA *data)
return FALSE;
}
ret = data->pPDSip->pSip->pfGet(data->pPDSip->psSipSubjectInfo,
ret = data->u.pPDSip->pSip->pfGet(data->u.pPDSip->psSipSubjectInfo,
&data->dwEncoding, 0, &size, buf);
if (ret)
{
@ -217,8 +220,8 @@ static DWORD SOFTPUB_DecodeInnerContent(CRYPT_PROVIDER_DATA *data)
SPC_INDIRECT_DATA_CONTENT_STRUCT, buf, size, 0, NULL, &size);
if (!ret)
goto error;
data->pPDSip->psIndirectData = data->psPfns->pfnAlloc(size);
if (!data->pPDSip->psIndirectData)
data->u.pPDSip->psIndirectData = data->psPfns->pfnAlloc(size);
if (!data->u.pPDSip->psIndirectData)
{
SetLastError(ERROR_OUTOFMEMORY);
ret = FALSE;
@ -226,7 +229,7 @@ static DWORD SOFTPUB_DecodeInnerContent(CRYPT_PROVIDER_DATA *data)
}
ret = CryptDecodeObject(data->dwEncoding,
SPC_INDIRECT_DATA_CONTENT_STRUCT, buf, size, 0,
data->pPDSip->psIndirectData, &size);
data->u.pPDSip->psIndirectData, &size);
}
else
{
@ -256,7 +259,7 @@ HRESULT WINAPI SoftpubLoadMessage(CRYPT_PROVIDER_DATA *data)
ret = TRUE;
break;
case WTD_CHOICE_FILE:
if (!data->pWintrustData->pFile)
if (!data->pWintrustData->u.pFile)
{
SetLastError(ERROR_INVALID_PARAMETER);
ret = FALSE;

View File

@ -68,7 +68,7 @@ static void test_encodeSPCLink(void)
LocalFree(buf);
}
/* With an invalid char: */
link.pwszUrl = (LPWSTR)nihongoURL;
U(link).pwszUrl = (LPWSTR)nihongoURL;
size = 1;
SetLastError(0xdeadbeef);
ret = CryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
@ -79,7 +79,7 @@ static void test_encodeSPCLink(void)
* index of the first invalid character.
*/
ok(size == 0, "Expected size 0, got %d\n", size);
link.pwszUrl = url;
U(link).pwszUrl = url;
ret = CryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
@ -90,7 +90,7 @@ static void test_encodeSPCLink(void)
LocalFree(buf);
}
link.dwLinkChoice = SPC_FILE_LINK_CHOICE;
link.pwszFile = (LPWSTR)nihongoURL;
U(link).pwszFile = (LPWSTR)nihongoURL;
ret = CryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
@ -101,7 +101,7 @@ static void test_encodeSPCLink(void)
LocalFree(buf);
}
link.dwLinkChoice = SPC_MONIKER_LINK_CHOICE;
memset(&link.Moniker, 0, sizeof(link.Moniker));
memset(&U(link).Moniker, 0, sizeof(U(link).Moniker));
ret = CryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
@ -111,9 +111,9 @@ static void test_encodeSPCLink(void)
ok(!memcmp(buf, emptyMonikerSPCLink, size), "Unexpected value\n");
LocalFree(buf);
}
memset(&link.Moniker.ClassId, 0xea, sizeof(link.Moniker.ClassId));
link.Moniker.SerializedData.pbData = data;
link.Moniker.SerializedData.cbData = sizeof(data);
memset(&U(link).Moniker.ClassId, 0xea, sizeof(U(link).Moniker.ClassId));
U(link).Moniker.SerializedData.pbData = data;
U(link).Moniker.SerializedData.cbData = sizeof(data);
ret = CryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
@ -145,7 +145,7 @@ static void test_decodeSPCLink(void)
link = (SPC_LINK *)buf;
ok(link->dwLinkChoice == SPC_URL_LINK_CHOICE,
"Expected SPC_URL_LINK_CHOICE, got %d\n", link->dwLinkChoice);
ok(lstrlenW(link->pwszUrl) == 0, "Expected empty string\n");
ok(lstrlenW(U(*link).pwszUrl) == 0, "Expected empty string\n");
LocalFree(buf);
}
ret = CryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
@ -157,7 +157,7 @@ static void test_decodeSPCLink(void)
link = (SPC_LINK *)buf;
ok(link->dwLinkChoice == SPC_URL_LINK_CHOICE,
"Expected SPC_URL_LINK_CHOICE, got %d\n", link->dwLinkChoice);
ok(!lstrcmpW(link->pwszUrl, url), "Unexpected URL\n");
ok(!lstrcmpW(U(*link).pwszUrl, url), "Unexpected URL\n");
LocalFree(buf);
}
ret = CryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
@ -169,7 +169,7 @@ static void test_decodeSPCLink(void)
link = (SPC_LINK *)buf;
ok(link->dwLinkChoice == SPC_FILE_LINK_CHOICE,
"Expected SPC_FILE_LINK_CHOICE, got %d\n", link->dwLinkChoice);
ok(!lstrcmpW(link->pwszFile, nihongoURL), "Unexpected file\n");
ok(!lstrcmpW(U(*link).pwszFile, nihongoURL), "Unexpected file\n");
LocalFree(buf);
}
ret = CryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
@ -183,9 +183,9 @@ static void test_decodeSPCLink(void)
link = (SPC_LINK *)buf;
ok(link->dwLinkChoice == SPC_MONIKER_LINK_CHOICE,
"Expected SPC_MONIKER_LINK_CHOICE, got %d\n", link->dwLinkChoice);
ok(!memcmp(&link->Moniker.ClassId, &emptyMoniker.ClassId,
ok(!memcmp(&U(*link).Moniker.ClassId, &emptyMoniker.ClassId,
sizeof(emptyMoniker.ClassId)), "Unexpected value\n");
ok(link->Moniker.SerializedData.cbData == 0,
ok(U(*link).Moniker.SerializedData.cbData == 0,
"Expected no serialized data\n");
LocalFree(buf);
}
@ -201,11 +201,11 @@ static void test_decodeSPCLink(void)
ok(link->dwLinkChoice == SPC_MONIKER_LINK_CHOICE,
"Expected SPC_MONIKER_LINK_CHOICE, got %d\n", link->dwLinkChoice);
memset(&id, 0xea, sizeof(id));
ok(!memcmp(&link->Moniker.ClassId, &id, sizeof(id)),
ok(!memcmp(&U(*link).Moniker.ClassId, &id, sizeof(id)),
"Unexpected value\n");
ok(link->Moniker.SerializedData.cbData == sizeof(data),
"Unexpected data size %d\n", link->Moniker.SerializedData.cbData);
ok(!memcmp(link->Moniker.SerializedData.pbData, data, sizeof(data)),
ok(U(*link).Moniker.SerializedData.cbData == sizeof(data),
"Unexpected data size %d\n", U(*link).Moniker.SerializedData.cbData);
ok(!memcmp(U(*link).Moniker.SerializedData.pbData, data, sizeof(data)),
"Unexpected value\n");
LocalFree(buf);
}
@ -311,7 +311,7 @@ static void test_encodeSPCPEImage(void)
LocalFree(buf);
}
/* Finally, a non-empty file: */
link.pwszFile = (LPWSTR)nihongoURL;
U(link).pwszFile = (LPWSTR)nihongoURL;
ret = CryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
&imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
@ -374,7 +374,7 @@ static void test_decodeSPCPEImage(void)
ok(imageData->pFile->dwLinkChoice == SPC_FILE_LINK_CHOICE,
"Expected SPC_FILE_LINK_CHOICE, got %d\n",
imageData->pFile->dwLinkChoice);
ok(!lstrcmpW(imageData->pFile->pwszFile, emptyString),
ok(!lstrcmpW(U(*imageData->pFile).pwszFile, emptyString),
"Unexpected file\n");
}
LocalFree(buf);
@ -397,7 +397,7 @@ static void test_decodeSPCPEImage(void)
ok(imageData->pFile->dwLinkChoice == SPC_FILE_LINK_CHOICE,
"Expected SPC_FILE_LINK_CHOICE, got %d\n",
imageData->pFile->dwLinkChoice);
ok(!lstrcmpW(imageData->pFile->pwszFile, emptyString),
ok(!lstrcmpW(U(*imageData->pFile).pwszFile, emptyString),
"Unexpected file\n");
}
LocalFree(buf);
@ -420,7 +420,7 @@ static void test_decodeSPCPEImage(void)
ok(imageData->pFile->dwLinkChoice == SPC_FILE_LINK_CHOICE,
"Expected SPC_FILE_LINK_CHOICE, got %d\n",
imageData->pFile->dwLinkChoice);
ok(!lstrcmpW(imageData->pFile->pwszFile, nihongoURL),
ok(!lstrcmpW(U(*imageData->pFile).pwszFile, nihongoURL),
"Unexpected file\n");
}
LocalFree(buf);

View File

@ -263,7 +263,7 @@ static void testObjTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %08x\n",
data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
wintrust_data.pCert = &certInfo;
U(wintrust_data).pCert = &certInfo;
wintrust_data.dwUnionChoice = WTD_CHOICE_CERT;
ret = funcs->pfnObjectTrust(&data);
ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
@ -274,14 +274,14 @@ static void testObjTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
CertFreeCertificateContext(certInfo.psCertContext);
certInfo.psCertContext = NULL;
wintrust_data.dwUnionChoice = WTD_CHOICE_FILE;
wintrust_data.pFile = NULL;
U(wintrust_data).pFile = NULL;
ret = funcs->pfnObjectTrust(&data);
ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);
ok(data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] ==
ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %08x\n",
data.padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
wintrust_data.pFile = &fileInfo;
U(wintrust_data).pFile = &fileInfo;
/* Crashes
ret = funcs->pfnObjectTrust(&data);
*/
@ -289,7 +289,7 @@ static void testObjTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)
lstrcatW(notepadPath, notepad);
fileInfo.pcwszFilePath = notepadPath;
/* pfnObjectTrust now crashes unless both pPDSip and psPfns are set */
data.pPDSip = &provDataSIP;
U(data).pPDSip = &provDataSIP;
data.psPfns = (CRYPT_PROVIDER_FUNCTIONS *)funcs;
ret = funcs->pfnObjectTrust(&data);
ok(ret == S_FALSE, "Expected S_FALSE, got %08x\n", ret);