Found when debugging the "inf2cat" tool from the Windows 10 DDK.
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- This is a set of four patches I wrote in the process of trying to make it possible for our tests to install and run PnP drivers. Some context on that follows:
Normally 64-bit Windows prevents unsigned drivers from being installed. This requirement can be overridden temporarily in boot options, but supposedly not for PnP drivers (though I haven't tested this).
It requires a lot of code, but it is actually possible to generate a catalog file, sign it with a self-signed certificate, add that certificate to the trusted publisher and root stores, and thereby install a test driver without prompting any dialog boxes. The basic process is described in more detail by Microsoft here:
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/introducti...
It's harder for us, of course, because we don't really have access to those tools; instead we have to reverse-engineer them and replicate them in C code. Fortunately I already have a working test that is able to at least call SetupCopyOEMInf() successfully; hopefully actual driver code won't present any additional difficulty...
dlls/wintrust/crypt.c | 20 +++++++++++--------- dlls/wintrust/tests/crypt.c | 3 +-- 2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/dlls/wintrust/crypt.c b/dlls/wintrust/crypt.c index b454c8b8853..4eef9d1bcbf 100644 --- a/dlls/wintrust/crypt.c +++ b/dlls/wintrust/crypt.c @@ -851,18 +851,18 @@ BOOL WINAPI CryptCATCatalogInfoFromContext(HCATINFO hcatinfo, CATALOG_INFO *info /*********************************************************************** * CryptCATOpen (WINTRUST.@) */ -HANDLE WINAPI CryptCATOpen(LPWSTR pwszFileName, DWORD fdwOpenFlags, HCRYPTPROV hProv, +HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv, DWORD dwPublicVersion, DWORD dwEncodingType) { HANDLE file, hmsg; BYTE *buffer = NULL; - DWORD size, flags = OPEN_EXISTING; + DWORD size, open_mode = OPEN_EXISTING; struct cryptcat *cc;
- TRACE("%s, %x, %lx, %x, %x\n", debugstr_w(pwszFileName), fdwOpenFlags, - hProv, dwPublicVersion, dwEncodingType); + TRACE("filename %s, flags %#x, provider %#lx, version %#x, type %#x\n", + debugstr_w(filename), flags, hProv, dwPublicVersion, dwEncodingType);
- if (!pwszFileName) + if (!filename) { SetLastError(ERROR_INVALID_PARAMETER); return INVALID_HANDLE_VALUE; @@ -870,10 +870,12 @@ HANDLE WINAPI CryptCATOpen(LPWSTR pwszFileName, DWORD fdwOpenFlags, HCRYPTPROV h
if (!dwEncodingType) dwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
- if (fdwOpenFlags & CRYPTCAT_OPEN_ALWAYS) flags |= OPEN_ALWAYS; - if (fdwOpenFlags & CRYPTCAT_OPEN_CREATENEW) flags |= CREATE_NEW; + if (flags & CRYPTCAT_OPEN_ALWAYS) + open_mode = OPEN_ALWAYS; + if (flags & CRYPTCAT_OPEN_CREATENEW) + open_mode = CREATE_NEW;
- file = CreateFileW(pwszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, flags, 0, NULL); + file = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, open_mode, 0, NULL); if (file == INVALID_HANDLE_VALUE) return INVALID_HANDLE_VALUE;
size = GetFileSize(file, NULL); @@ -951,7 +953,7 @@ HANDLE WINAPI CryptCATOpen(LPWSTR pwszFileName, DWORD fdwOpenFlags, HCRYPTPROV h p += size; } cc->inner = decode_inner_content(hmsg, dwEncodingType, &cc->inner_len); - if (!cc->inner || !CryptSIPRetrieveSubjectGuid(pwszFileName, NULL, &cc->subject)) + if (!cc->inner || !CryptSIPRetrieveSubjectGuid(filename, NULL, &cc->subject)) { CryptMsgClose(hmsg); HeapFree(GetProcessHeap(), 0, cc->attr); diff --git a/dlls/wintrust/tests/crypt.c b/dlls/wintrust/tests/crypt.c index dfa411548f9..e9928470332 100644 --- a/dlls/wintrust/tests/crypt.c +++ b/dlls/wintrust/tests/crypt.c @@ -434,8 +434,7 @@ static void test_CryptCATOpen(void) ret = pCryptCATClose(cat); todo_wine ok(ret, "flags %#x: failed to close file\n", flags); ret = DeleteFileW(filename); - todo_wine_if (flags & (CRYPTCAT_OPEN_ALWAYS | CRYPTCAT_OPEN_CREATENEW)) - ok(ret, "flags %#x: failed to delete file, error %u\n", flags, GetLastError()); + ok(ret, "flags %#x: failed to delete file, error %u\n", flags, GetLastError()); }
file = _wfopen(filename, L"w");