ntdll: - `NtQuerySystemInformation` `SystemBootEnvironmentInformation` - `NtQuerySystemEnvironmentValueEx`
kernel32: - `GetFirmwareType` - `GetFirmwareEnvironmentVariableExA` - `GetFirmwareEnvironmentVariableExW` - `GetFirmwareEnvironmentVariableA` - `GetFirmwareEnvironmentVariableW`.
The code is needed to check SecureBoot status, security systems and for example to check the licenses of software that can use efi variables. The behavior matches the behavior of Windows 11. And the output is no different on wine and Windows 11.
Example:
```C #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> #include <winnt.h> #include <winternl.h> #include <winbase.h> #include <securitybaseapi.h>
/* x86_64-w64-mingw32-gcc -O2 firmware.c -o firmware.exe -Wl,--subsystem,console */ #define SystemBootEnvironmentInformation 90
#define GUID_FORMAT "%08X-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX" #define GUID_ARG(guid) \ (unsigned int)(guid).Data1, (guid).Data2, (guid).Data3, (guid).Data4[0], \ (guid).Data4[1], (guid).Data4[2], (guid).Data4[3], (guid).Data4[4], \ (guid).Data4[5], (guid).Data4[6], (guid).Data4[7]
typedef struct _SYSTEM_BOOT_ENVIRONMENT_INFORMATION { GUID BootIdentifier; FIRMWARE_TYPE FirmwareType; union { ULONGLONG BootFlags; struct { ULONGLONG DbgMenuOsSelection : 1; ULONGLONG DbgHiberBoot : 1; ULONGLONG DbgSoftBoot : 1; ULONGLONG DbgMeasuredLaunch : 1; ULONGLONG DbgMeasuredLaunchCapable : 1; ULONGLONG DbgSystemHiveReplace : 1; ULONGLONG DbgMeasuredLaunchSmmProtections : 1; ULONGLONG DbgMeasuredLaunchSmmLevel : 7; }; }; } SYSTEM_BOOT_ENVIRONMENT_INFORMATION, *PSYSTEM_BOOT_ENVIRONMENT_INFORMATION;
typedef NTSTATUS(NTAPI *LPFNZwInitUnicodeString)(IN OUT PUNICODE_STRING DestinationString, IN PCWSTR SourceString);
typedef NTSTATUS(NTAPI *LPFNZwQuerySystemInformation)( IN SYSTEM_INFORMATION_CLASS SystemInformationClass, IN OUT PVOID SystemInformation, IN ULONG SystemInformationLength, OUT PULONG ReturnLength);
typedef NTSTATUS(NTAPI *LPFNZwQuerySystemEnvironmentValueEx)( IN PUNICODE_STRING VariableName, IN LPGUID VendorGuid, IN PVOID Value, IN OUT PULONG ReturnLength, OUT PULONG Attributes);
BOOL EnableTokenPrivilege(HANDLE hToken, const char *pszPrivilegesName, BOOL bEnabled) { LUID luid; TOKEN_PRIVILEGES tp;
if (!LookupPrivilegeValue(NULL, pszPrivilegesName, &luid)) { return FALSE; }
tp.PrivilegeCount = 1; tp.Privileges[0].Luid = luid; tp.Privileges[0].Attributes = bEnabled ? SE_PRIVILEGE_ENABLED : 0;
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) { return FALSE; }
return TRUE; }
int main(int argc, char **argv) { DWORD ret; ULONG ret_size; HANDLE hToken; HANDLE hProcess; HINSTANCE hNTdll; NTSTATUS status; DWORD attributes; BOOLEAN secureboot = 0; FIRMWARE_TYPE type = FirmwareTypeUnknown; char asus_license[2048] = {0}; UNICODE_STRING asus_name; UNICODE_STRING dummy_name; UNICODE_STRING secureboot_name;
GUID asus_guid = { 0x02076249, 0xa52b, 0x420e, {0xbd, 0x53, 0xae, 0xd0, 0x44, 0x34, 0x93, 0x79}}; GUID secureboot_guid = { 0x8be4df61, 0x93ca, 0x11d2, {0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c}}; GUID dummy_guid = {0};
SYSTEM_BOOT_ENVIRONMENT_INFORMATION boot_info = {0};
LPFNZwInitUnicodeString ZwInitUnicodeString; LPFNZwQuerySystemInformation ZwQuerySystemInformation; LPFNZwQuerySystemEnvironmentValueEx ZwQuerySystemEnvironmentValueEx;
hNTdll = LoadLibraryW(L"Ntdll.dll");
if (!hNTdll) { printf("Can't load ntdll liabrary!\n"); return -1; }
ZwInitUnicodeString = (LPFNZwInitUnicodeString)GetProcAddress(hNTdll, "RtlInitUnicodeString"); if (!ZwInitUnicodeString) { printf("Can't get GetProcAddress RtlInitUnicodeString error: %d!\n", GetLastError()); return -1; }
ZwInitUnicodeString(&asus_name, L"AsusOnboardToolLicense"); ZwInitUnicodeString(&dummy_name, L"DummyName"); ZwInitUnicodeString(&secureboot_name, L"SecureBoot");
ZwQuerySystemInformation = (LPFNZwQuerySystemInformation)GetProcAddress(hNTdll, "ZwQuerySystemInformation"); if (!ZwQuerySystemInformation) { printf("Can't get GetProcAddress ZwQuerySystemInformation error: %d!\n", GetLastError()); return -1; }
ZwQuerySystemEnvironmentValueEx = (LPFNZwQuerySystemEnvironmentValueEx)GetProcAddress( hNTdll, "ZwQuerySystemEnvironmentValueEx"); if (!ZwQuerySystemEnvironmentValueEx) { printf("Can't get GetProcAddress ZwQuerySystemEnvironmentValueEx error: %d!\n", GetLastError()); return -1; }
hProcess = GetCurrentProcess(); if (!hProcess) { printf("GetCurrentProcessToken error: %d!\n", GetLastError()); return -1; }
if (!OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { printf("OpenProcessToken error: %d!\n", GetLastError()); return -1; }
if (!EnableTokenPrivilege(hToken, SE_SYSTEM_ENVIRONMENT_NAME, TRUE)) { printf("EnableTokenPrivilege error: %d!\n", GetLastError()); return -1; }
if (GetFirmwareType(&type)) printf("GetFirmwareType: %s\n\n", type == FirmwareTypeUefi ? "UEFI" : "BIOS");
ret = GetFirmwareEnvironmentVariableA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", &secureboot, sizeof(BOOLEAN)); if (!ret) printf("GetFirmwareEnvironmentVariableA error: 0x%08lx.\n\n", GetLastError());
printf("GetFirmwareEnvironmentVariableA\nBytes: %d\nSecureBoot: %s\n\n", ret, secureboot ? "enabled" : "disabled");
ret = GetFirmwareEnvironmentVariableA("DummyName", "{00000000-0000-0000-0000-000000000000}", &secureboot, sizeof(BOOLEAN)); if (!ret) printf("GetFirmwareEnvironmentVariableA Dummy GUID error: 0x%08lx.\n\n", GetLastError());
secureboot = 0; ret = GetFirmwareEnvironmentVariableW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", &secureboot, sizeof(BOOLEAN)); if (!ret) printf("GetFirmwareEnvironmentVariableW error: 0x%08lx.\n\n", GetLastError());
printf("GetFirmwareEnvironmentVariableW\nBytes: %d\nSecureBoot: %s\n\n", ret, secureboot ? "enabled" : "disabled");
attributes = 0; secureboot = 0; ret = GetFirmwareEnvironmentVariableExA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", &secureboot, sizeof(BOOLEAN), &attributes); if (!ret) printf("GetFirmwareEnvironmentVariableExA error: 0x%08lx.\n\n", GetLastError());
printf("GetFirmwareEnvironmentVariableExA\nBytes: %d\nAttributes: 0x%08x\nSecureBoot: %s\n\n", ret, attributes, secureboot ? "enabled" : "disabled");
attributes = 0; ret = GetFirmwareEnvironmentVariableExW(L"AsusOnboardToolLicense", L"{02076249-a52b-420e-bd53-aed044349379}", asus_license, sizeof(asus_license), &attributes); if (!ret) printf("GetFirmwareEnvironmentVariableExW error: 0x%08lx.\n\n", GetLastError());
printf("GetFirmwareEnvironmentVariableExW\nBytes: %d\nAttributes: 0x%08x\nAsus License: \n%s\n\n", ret, attributes, asus_license);
ret_size = sizeof(secureboot); attributes = 0; secureboot = 0; status = ZwQuerySystemEnvironmentValueEx(&secureboot_name, &secureboot_guid, &secureboot, &ret_size, &attributes);
if (!status) printf("NtQuerySystemEnvironmentValueEx error: 0x%08lx.\n\n", status);
printf("NtQuerySystemEnvironmentValueEx\nBytes: %d\nAttributes: 0x%08x\nSecureBoot: %s\n\n", ret_size, attributes, secureboot ? "enabled" : "disabled");
ret_size = sizeof(secureboot); attributes = 0; secureboot = 0; status = ZwQuerySystemEnvironmentValueEx(&dummy_name, &dummy_guid, &secureboot, &ret_size, &attributes);
printf("NtQuerySystemEnvironmentValueEx Dummy GUID error: 0x%08lx.\n\n", status);
ret_size = sizeof(asus_license); attributes = 0; for (size_t i = 0; i < ret_size; i++) { asus_license[i] = '\0'; } status = ZwQuerySystemEnvironmentValueEx(&asus_name, &asus_guid, asus_license, &ret_size, &attributes); if (status) printf("NtQuerySystemEnvironmentValueEx error: 0x%08lx.\n\n", status);
printf("NtQuerySystemEnvironmentValueEx\nBytes: %d\nAttributes: 0x%08x\nAsus License: \n%s\n\n", ret_size, attributes, asus_license);
status = ZwQuerySystemInformation( (SYSTEM_INFORMATION_CLASS)SystemBootEnvironmentInformation, &boot_info, sizeof(boot_info), &ret_size); if (status) printf("NtQuerySystemInformation error: 0x%08lx.\n\n", status);
printf("SystemBootEnvironmentInformation:\nBootIdentifier: {" GUID_FORMAT "}", GUID_ARG(boot_info.BootIdentifier)); printf("\nFirmwareType: %s\nBootFlags: 0x%llX\n\n", (boot_info.FirmwareType == FirmwareTypeUefi ? "UEFI" : "BIOS"), boot_info.BootFlags);
FreeLibrary(hNTdll);
return 0; } ```
Output: ``` GetFirmwareType: UEFI
GetFirmwareEnvironmentVariableA Bytes: 1 SecureBoot: enabled
GetFirmwareEnvironmentVariableW Bytes: 1 SecureBoot: enabled
GetFirmwareEnvironmentVariableExA Bytes: 1 Attributes: 0x00000006 SecureBoot: enabled
GetFirmwareEnvironmentVariableExW Bytes: 1570 Attributes: 0x00000006 Asus License: BASE64_BIG_LICENSE_TEXT== [LicenseID]:FED7A1 [Model]:Dummy-BaseBoard-Id [Tools]:WAsusDmiS,LogoFlashS,ASUSFwConfigS,AsusEventLogS,AsusNvLockS [Customer]:DummyLic [Expire]:2022-11-24
NtQuerySystemEnvironmentValueEx Bytes: 1 Attributes: 0x00000006 SecureBoot: enabled
NtQuerySystemEnvironmentValueEx Bytes: 1570 Attributes: 0x00000006 Asus License: BASE64_BIG_LICENSE_TEXT== [LicenseID]:FED7A1 [Model]:Dummy-BaseBoard-Id [Tools]:WAsusDmiS,LogoFlashS,ASUSFwConfigS,AsusEventLogS,AsusNvLockS [Customer]:DummyLic [Expire]:2022-11-24
SystemBootEnvironmentInformation: BootIdentifier: {8522FFCA-6A31-11EF-952A-966164983DCB} FirmwareType: UEFI BootFlags: 0x0 ```
-- v27: kernel32: Implement GetFirmwareEnvironmentVariableExA, GetFirmwareEnvironmentVariableExW, GetFirmwareEnvironmentVariableA, GetFirmwareEnvironmentVariableW. ntdll: Implement NtQuerySystemEnvironmentValueEx.
From: Grigory Vasilyev h0tc0d3@gmail.com
--- dlls/ntdll/tests/info.c | 32 ++++++++++++++ dlls/ntdll/unix/system.c | 96 ++++++++++++++++++++++++++++++++++++++++ dlls/wow64/system.c | 3 ++ include/winternl.h | 22 +++++++++ 4 files changed, 153 insertions(+)
diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c index ba19b248e43..62c17649808 100644 --- a/dlls/ntdll/tests/info.c +++ b/dlls/ntdll/tests/info.c @@ -322,6 +322,37 @@ static void test_query_basic(void) } }
+static void test_query_boot(void) +{ + NTSTATUS status; + ULONG ret_size; + SYSTEM_BOOT_ENVIRONMENT_INFORMATION bi = {0}; + + /* + * NtQuerySystemInformation - SystemBootEnvironmentInformation + */ + status = pNtQuerySystemInformation(SystemBootEnvironmentInformation, &bi, sizeof(bi), &ret_size); + if (status == STATUS_NOT_IMPLEMENTED) + { + skip("NtQuerySystemInformation - SystemBootEnvironmentInformation not implemented.\n"); + return; + } + ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS.\n"); + + ok(ret_size == sizeof(bi), "Expected ret_size == sizeof(SYSTEM_BOOT_ENVIRONMENT_INFORMATION).\n"); + + ok(bi.FirmwareType == FirmwareTypeBios || bi.FirmwareType == FirmwareTypeUefi, + "Expected FirmwareTypeBios or FirmwareTypeUefi, got %02x\n", bi.FirmwareType); + + ok(bi.BootIdentifier.Data1 != 0, "A non-zero BootIdentifier value is expected.\n"); + + status = pNtQuerySystemInformation(SystemBootEnvironmentInformation, NULL, sizeof(bi), NULL); + ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION.\n"); + + status = pNtQuerySystemInformation(SystemBootEnvironmentInformation, NULL, 0, NULL); + ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH.\n"); +} + static void test_query_cpu(void) { NTSTATUS status; @@ -4080,6 +4111,7 @@ START_TEST(info)
/* NtQuerySystemInformation */ test_query_basic(); + test_query_boot(); test_query_cpu(); test_query_performance(); test_query_timeofday(); diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index b015cfff923..b280b552ec7 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -30,6 +30,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <errno.h> @@ -2927,6 +2928,101 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class, break; }
+ case SystemBootEnvironmentInformation: /* 90 */ + { + static SYSTEM_BOOT_ENVIRONMENT_INFORMATION boot_info = {0}; + struct stat stat_info = {0}; + ssize_t ssz; +#if defined(__linux__) || defined(__gnu_linux__) + int fd; + char buffer[32]; +#endif + len = sizeof(boot_info); + if (size == len) + { +#if defined(__linux__) || defined(__gnu_linux__) + if (boot_info.FirmwareType == FirmwareTypeUnknown) + { + if (!stat("/sys/firmware/efi", &stat_info)) + boot_info.FirmwareType = FirmwareTypeUefi; + else + boot_info.FirmwareType = FirmwareTypeBios; + } +#elif defined(__APPLE__) + /* + * Since 2006, Mac computers use Extensible Firmware Interface (EFI). + * Reference: https://support.apple.com/guide/security/uefi-firmware-security-in-an-intel-... + */ + boot_info.FirmwareType = FirmwareTypeUefi; +#else + boot_info.FirmwareType = FirmwareTypeBios; +#endif + if (boot_info.BootIdentifier.Data1 == 0) + { +#if defined(__linux__) || defined(__gnu_linux__) + if (!stat("/etc/machine-id", &stat_info) && stat_info.st_size >= 32) + { + fd = open("/etc/machine-id", O_RDONLY); + if (fd == -1) + goto try_read_hostid; + ssz = read(fd, &buffer, 32); + if (ssz < 0) + { + close(fd); + goto try_read_hostid; + } + close(fd); + if (sscanf(buffer, + "%08X%04hX%04hX%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX", + (unsigned int *)&boot_info.BootIdentifier.Data1, &boot_info.BootIdentifier.Data2, + &boot_info.BootIdentifier.Data3, &boot_info.BootIdentifier.Data4[0], + &boot_info.BootIdentifier.Data4[1], &boot_info.BootIdentifier.Data4[2], + &boot_info.BootIdentifier.Data4[3], &boot_info.BootIdentifier.Data4[4], + &boot_info.BootIdentifier.Data4[5], &boot_info.BootIdentifier.Data4[6], + &boot_info.BootIdentifier.Data4[7]) != 11) + goto try_read_hostid; + } + else + { + try_read_hostid: +#endif +#ifdef __APPLE__ + if (!stat("/Users", &stat_info) || !stat("/System", &stat_info)) +#else + if (!stat("/home", &stat_info) || !stat("/usr", &stat_info)) +#endif + { + boot_info.BootIdentifier.Data1 = gethostid() & 0xFFFFFFFF; + boot_info.BootIdentifier.Data2 = stat_info.st_dev & 0xFFFF; + boot_info.BootIdentifier.Data3 = stat_info.st_ino & 0xFFFF; + boot_info.BootIdentifier.Data4[0] = 'W' ^ (boot_info.BootIdentifier.Data1 & 0xFF); + boot_info.BootIdentifier.Data4[1] = 'I' ^ ((boot_info.BootIdentifier.Data1 >> 4) & 0xFF); + boot_info.BootIdentifier.Data4[2] = 'N' ^ ((boot_info.BootIdentifier.Data1 >> 8) & 0xFF); + boot_info.BootIdentifier.Data4[3] = 'E' ^ ((boot_info.BootIdentifier.Data1 >> 12) & 0xFF); + boot_info.BootIdentifier.Data4[4] = 'B' ^ ((boot_info.BootIdentifier.Data1 >> 16) & 0xFF); + boot_info.BootIdentifier.Data4[5] = 'O' ^ ((boot_info.BootIdentifier.Data1 >> 20) & 0xFF); + boot_info.BootIdentifier.Data4[6] = 'O' ^ ((boot_info.BootIdentifier.Data1 >> 24) & 0xFF); + boot_info.BootIdentifier.Data4[7] = 'T' ^ ((boot_info.BootIdentifier.Data1 >> 28) & 0xFF); + } +#if defined(__linux__) || defined(__gnu_linux__) + } +#endif + boot_info.BootIdentifier.Data3 &= 0x0fff; + boot_info.BootIdentifier.Data3 |= (4 << 12); + /* Set the topmost bits of Data4 (clock_seq_hi_and_reserved) as + * specified in RFC 4122, section 4.4. + */ + boot_info.BootIdentifier.Data4[0] &= 0x3f; + boot_info.BootIdentifier.Data4[0] |= 0x80; + } + if (!info) ret = STATUS_ACCESS_VIOLATION; + else memcpy(info, &boot_info, len); + } + else ret = STATUS_INFO_LENGTH_MISMATCH; + if (ret_size) *ret_size = len; + break; + } + case SystemCpuInformation: /* 1 */ if (size >= (len = sizeof(cpu_info))) memcpy(info, &cpu_info, len); else ret = STATUS_INFO_LENGTH_MISMATCH; diff --git a/dlls/wow64/system.c b/dlls/wow64/system.c index 5f3056a4179..402b53e1eda 100644 --- a/dlls/wow64/system.c +++ b/dlls/wow64/system.c @@ -356,6 +356,9 @@ NTSTATUS WINAPI wow64_NtQuerySystemInformation( UINT *args ) if (retlen) *retlen = sizeof(SYSTEM_BASIC_INFORMATION32); return status;
+ case SystemBootEnvironmentInformation: /* SYSTEM_BOOT_ENVIRONMENT_INFORMATION */ + return NtQuerySystemInformation(class, ptr, len, retlen); + case SystemProcessInformation: /* SYSTEM_PROCESS_INFORMATION */ case SystemExtendedProcessInformation: /* SYSTEM_PROCESS_INFORMATION */ { diff --git a/include/winternl.h b/include/winternl.h index 828fbc6e915..510bba09042 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -2724,6 +2724,28 @@ typedef struct _SYSTEM_BASIC_INFORMATION { #endif } SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;
+/* System Information Class 0x90 */ +typedef struct _SYSTEM_BOOT_ENVIRONMENT_INFORMATION +{ + GUID BootIdentifier; + FIRMWARE_TYPE FirmwareType; + union + { + ULONGLONG BootFlags; + struct + { + ULONGLONG DbgMenuOsSelection : 1; + ULONGLONG DbgHiberBoot : 1; + ULONGLONG DbgSoftBoot : 1; + ULONGLONG DbgMeasuredLaunch : 1; + ULONGLONG DbgMeasuredLaunchCapable : 1; + ULONGLONG DbgSystemHiveReplace : 1; + ULONGLONG DbgMeasuredLaunchSmmProtections : 1; + ULONGLONG DbgMeasuredLaunchSmmLevel : 7; + }; + }; +} SYSTEM_BOOT_ENVIRONMENT_INFORMATION, *PSYSTEM_BOOT_ENVIRONMENT_INFORMATION; + /* System Information Class 0x01 */
typedef struct _SYSTEM_CPU_INFORMATION {
From: Grigory Vasilyev h0tc0d3@gmail.com
--- dlls/kernel32/process.c | 12 ++++++- dlls/kernel32/tests/Makefile.in | 1 + dlls/kernel32/tests/firmware.c | 55 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 dlls/kernel32/tests/firmware.c
diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c index 2a4ddc68f02..88a0ce2bc33 100644 --- a/dlls/kernel32/process.c +++ b/dlls/kernel32/process.c @@ -763,10 +763,20 @@ BOOL WINAPI SetFirmwareEnvironmentVariableW(const WCHAR *name, const WCHAR *guid */ BOOL WINAPI GetFirmwareType(FIRMWARE_TYPE *type) { + SYSTEM_BOOT_ENVIRONMENT_INFORMATION boot_info = {0}; + if (!type) + { + SetLastError(ERROR_INVALID_PARAMETER); return FALSE; + } + + if(!set_ntstatus(NtQuerySystemInformation(SystemBootEnvironmentInformation, + &boot_info, sizeof(boot_info), NULL))) + return FALSE; + + *type = boot_info.FirmwareType;
- *type = FirmwareTypeUnknown; return TRUE; }
diff --git a/dlls/kernel32/tests/Makefile.in b/dlls/kernel32/tests/Makefile.in index e9516603ce9..17d08b7cdf6 100644 --- a/dlls/kernel32/tests/Makefile.in +++ b/dlls/kernel32/tests/Makefile.in @@ -16,6 +16,7 @@ SOURCES = \ environ.c \ fiber.c \ file.c \ + firmware.c \ format_msg.c \ generated.c \ heap.c \ diff --git a/dlls/kernel32/tests/firmware.c b/dlls/kernel32/tests/firmware.c new file mode 100644 index 00000000000..5552d70e7e1 --- /dev/null +++ b/dlls/kernel32/tests/firmware.c @@ -0,0 +1,55 @@ +/* Unit test suite for *Information* Registry API functions + * + * Copyright 2024 Grigory Vasilyev + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "wine/test.h" +#include "windef.h" +#include "winbase.h" +#include "winerror.h" +#include "winuser.h" +#include "winternl.h" + +static void test_get_firmware_type(void) +{ + FIRMWARE_TYPE ft; + BOOL status; + + status = GetFirmwareType(&ft); + if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) + { + skip("GetFirmwareType not implemented.\n"); + return; + } + + ok(status == TRUE, "Expected TRUE.\n"); + + ok(ft == FirmwareTypeBios || ft == FirmwareTypeUefi, + "Expected FirmwareTypeBios or FirmwareTypeUefi, got %08x\n", ft); + + status = GetFirmwareType(NULL); + ok(status == FALSE && GetLastError() == ERROR_INVALID_PARAMETER, + "Expected FALSE and GetLastError() == ERROR_INVALID_PARAMETER\n"); +} + +START_TEST(firmware) +{ + test_get_firmware_type(); +}
From: Grigory Vasilyev h0tc0d3@gmail.com
--- dlls/ntdll/tests/info.c | 52 +++++++++++++++++- dlls/ntdll/unix/system.c | 112 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c index 62c17649808..b1f5fd2fe1c 100644 --- a/dlls/ntdll/tests/info.c +++ b/dlls/ntdll/tests/info.c @@ -34,6 +34,7 @@ static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG); static NTSTATUS (WINAPI * pNtSetSystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG); static NTSTATUS (WINAPI * pRtlGetNativeSystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG); +static NTSTATUS (WINAPI * pNtQuerySystemEnvironmentValueEx)(PUNICODE_STRING, LPGUID, PVOID, PULONG, PULONG); static NTSTATUS (WINAPI * pNtQuerySystemInformationEx)(SYSTEM_INFORMATION_CLASS, void*, ULONG, void*, ULONG, ULONG*); static NTSTATUS (WINAPI * pNtPowerInformation)(POWER_INFORMATION_LEVEL, PVOID, ULONG, PVOID, ULONG); static NTSTATUS (WINAPI * pNtQueryInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG, PULONG); @@ -91,6 +92,7 @@ static void InitFunctionPtrs(void)
NTDLL_GET_PROC(NtQuerySystemInformation); NTDLL_GET_PROC(NtQuerySystemInformationEx); + NTDLL_GET_PROC(NtQuerySystemEnvironmentValueEx); NTDLL_GET_PROC(NtSetSystemInformation); NTDLL_GET_PROC(RtlGetNativeSystemInformation); NTDLL_GET_PROC(NtPowerInformation); @@ -322,10 +324,14 @@ static void test_query_basic(void) } }
-static void test_query_boot(void) +static void test_query_boot_and_system_env(void) { NTSTATUS status; ULONG ret_size; + BOOLEAN secureboot; + DWORD attributes; + UNICODE_STRING secureboot_name; + GUID secureboot_guid = {0x8be4df61, 0x93ca, 0x11d2, {0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c}}; SYSTEM_BOOT_ENVIRONMENT_INFORMATION bi = {0};
/* @@ -351,6 +357,48 @@ static void test_query_boot(void)
status = pNtQuerySystemInformation(SystemBootEnvironmentInformation, NULL, 0, NULL); ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH.\n"); + + /* + * NtQuerySystemEnvironmentValueEx + */ + RtlInitUnicodeString(&secureboot_name, L"SecureBoot"); + ret_size = sizeof(secureboot); + + status = pNtQuerySystemEnvironmentValueEx(&secureboot_name, &secureboot_guid, &secureboot, &ret_size, &attributes); + if(bi.FirmwareType != FirmwareTypeUefi) + ok(status == STATUS_NOT_IMPLEMENTED, "Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots.\n"); + + if (status == STATUS_NOT_IMPLEMENTED) + { + skip("NtQuerySystemEnvironmentValueEx not implemented.\n"); + return; + } + + ok(status == STATUS_SUCCESS || status == STATUS_VARIABLE_NOT_FOUND, "Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND.\n"); + + status = pNtQuerySystemEnvironmentValueEx(NULL, NULL, &secureboot, &ret_size, &attributes); + ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER.\n"); + + status = pNtQuerySystemEnvironmentValueEx(NULL, &secureboot_guid, &secureboot, &ret_size, &attributes); + ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER.\n"); + + status = pNtQuerySystemEnvironmentValueEx(&secureboot_name, NULL, &secureboot, &ret_size, &attributes); + ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER.\n"); + + status = pNtQuerySystemEnvironmentValueEx(&secureboot_name, &secureboot_guid, NULL, NULL, NULL); + ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER.\n"); + + status = pNtQuerySystemEnvironmentValueEx(&secureboot_name, &secureboot_guid, &secureboot, NULL, NULL); + ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER.\n"); + + status = pNtQuerySystemEnvironmentValueEx(&secureboot_name, &secureboot_guid, &secureboot, NULL, &attributes); + ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS.\n"); + + status = pNtQuerySystemEnvironmentValueEx(&secureboot_name, &secureboot_guid, NULL, &ret_size, NULL); + ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS.\n"); + + status = pNtQuerySystemEnvironmentValueEx(&secureboot_name, &secureboot_guid, NULL, &ret_size, &attributes); + ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS.\n"); }
static void test_query_cpu(void) @@ -4111,7 +4159,7 @@ START_TEST(info)
/* NtQuerySystemInformation */ test_query_basic(); - test_query_boot(); + test_query_boot_and_system_env(); test_query_cpu(); test_query_performance(); test_query_timeofday(); diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index b280b552ec7..f5c3d1d20e2 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -3912,9 +3912,121 @@ NTSTATUS WINAPI NtQuerySystemEnvironmentValue( UNICODE_STRING *name, WCHAR *buff NTSTATUS WINAPI NtQuerySystemEnvironmentValueEx( UNICODE_STRING *name, GUID *vendor, void *buffer, ULONG *retlen, ULONG *attrib ) { +#if defined(__linux__) || defined(__gnu_linux__) + int fd, rc; + size_t bytes, pos = 0; + ssize_t ssz; + char buff[4]; + char *cname; + char filename[PATH_MAX + 1]; + NTSTATUS status; + struct stat stat_info = {0}; + static SYSTEM_BOOT_ENVIRONMENT_INFORMATION boot_info = {0}; + + if(boot_info.FirmwareType == FirmwareTypeUnknown) + { + status = NtQuerySystemInformation(SystemBootEnvironmentInformation, + &boot_info, sizeof(boot_info), NULL); + if(status != STATUS_SUCCESS) return status; + } + + if(boot_info.FirmwareType != FirmwareTypeUefi) + { + /* + * This behavior matches the behavior of Windows for non-UEFI boots, + * and older versions of Windows. + */ + return STATUS_NOT_IMPLEMENTED; + } + + if(!name || !vendor || (name && vendor && !retlen && !attrib)) + { + return STATUS_INVALID_PARAMETER; + } + + cname = (char *) malloc(wcslen(name->Buffer) * 3 + 1); + if(!cname) + return STATUS_MEMORY_NOT_ALLOCATED; + + rc = ntdll_wcstoumbs(name->Buffer, wcslen(name->Buffer) + 1, cname, wcslen(name->Buffer) * 3 + 1, TRUE); + if(rc <= 0) { + free(cname); + return STATUS_SOME_NOT_MAPPED; + } + + snprintf(filename, sizeof(filename), + "/sys/firmware/efi/efivars/%s-%08lx-%04hx-%04hx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", + cname, (unsigned long)vendor->Data1, vendor->Data2, vendor->Data3, + vendor->Data4[0], vendor->Data4[1], vendor->Data4[2], vendor->Data4[3], + vendor->Data4[4], vendor->Data4[5], vendor->Data4[6], vendor->Data4[7]); + + fd = open(filename, O_RDONLY); + if (fd == -1) + { + free(cname); + return STATUS_VARIABLE_NOT_FOUND; + } + + rc = fstat(fd, &stat_info); + if (rc < 0 || stat_info.st_size == 0) + goto done; + + if(attrib) ssz = read(fd, attrib, 4); + else ssz = read(fd, buff, 4); // lseek not work in efifs. + if (ssz < 0) goto done; + + if(buffer && retlen) + { + if (stat_info.st_size - 4 < *retlen) + bytes = stat_info.st_size - 4; + else + bytes = *retlen; + while (pos < bytes) + { + ssz = read(fd, (char *) buffer + pos, bytes - pos); + if (ssz < 0) goto done; + pos += ssz; + } + *retlen = ssz & 0xFFFFFFFF; + } + else if(retlen) *retlen = (stat_info.st_size - 4) & 0xFFFFFFFF; + + close(fd); + return STATUS_SUCCESS; + +done: + free(cname); + if (fd >= 0) + close(fd); + return STATUS_UNSUCCESSFUL; +#elif defined(__APPLE__) + if(!name || !vendor || (name && vendor && !retlen && !attrib)) + { + return STATUS_INVALID_PARAMETER; + } + + /* + * Since 2006, Mac computers use Extensible Firmware Interface (EFI). + * Apple requires a developer account and mandatory code signing, + * and the entire system boot process is verified, we can return SecureBoot enabled. + * Reference: https://support.apple.com/guide/security/uefi-firmware-security-in-an-intel-... + */ + if(vendor->Data1 == 0x8be4df61 && vendor->Data2 == 0x93ca && vendor->Data3 == 0x11d2 && wcscmp(name->Buffer, L"SecureBoot") + && vendor->Data4[0] == 0xaa && vendor->Data4[1] == 0x0d && vendor->Data4[2] == 0x00 && vendor->Data4[3] == 0xe0 + && vendor->Data4[4] == 0x98 && vendor->Data4[5] == 0x03 && vendor->Data4[6] == 0x2b && vendor->Data4[7] == 0x8c) + { + if(attrib) *attrib = 0x06; + if(retlen) *retlen = sizeof(BOOLEAN) & 0xFFFFFFFF; + if(buffer) *((BOOLEAN *)buffer) = 1; + return STATUS_SUCCESS; + } + + return STATUS_VARIABLE_NOT_FOUND; +#else FIXME( "(%s, %s, %p, %p, %p), stub\n", debugstr_us(name), debugstr_guid(vendor), buffer, retlen, attrib ); return STATUS_NOT_IMPLEMENTED; +#endif }
From: Grigory Vasilyev h0tc0d3@gmail.com
--- dlls/kernel32/kernel32.spec | 2 + dlls/kernel32/process.c | 116 ++++++++++++- dlls/kernel32/tests/firmware.c | 295 +++++++++++++++++++++++++++++++++ include/winbase.h | 4 + 4 files changed, 411 insertions(+), 6 deletions(-)
diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index 7ed8048f5d0..5d3556a2078 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -695,7 +695,9 @@ @ stdcall -import GetFileType(long) @ stdcall -import GetFinalPathNameByHandleA(long ptr long long) @ stdcall -import GetFinalPathNameByHandleW(long ptr long long) +@ stdcall GetFirmwareEnvironmentVariableExA(str str ptr long ptr) @ stdcall GetFirmwareEnvironmentVariableA(str str ptr long) +@ stdcall GetFirmwareEnvironmentVariableExW(wstr wstr ptr long ptr) @ stdcall GetFirmwareEnvironmentVariableW(wstr wstr ptr long) @ stdcall GetFirmwareType(ptr) @ stdcall -import GetFullPathNameA(str long ptr ptr) diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c index 88a0ce2bc33..bf7f2898d27 100644 --- a/dlls/kernel32/process.c +++ b/dlls/kernel32/process.c @@ -718,14 +718,119 @@ WORD WINAPI GetMaximumProcessorGroupCount(void) return groups; }
+/*********************************************************************** + * GetFirmwareEnvironmentVariableExA (KERNEL32.@) + */ +DWORD WINAPI GetFirmwareEnvironmentVariableExA(LPCSTR name, LPCSTR guid, PVOID buffer, DWORD size, PDWORD attributes) +{ + int nsize; + GUID vendor = {0}; + LPWSTR wname; + LPWSTR wguid; + NTSTATUS status; + UNICODE_STRING uname; + UNICODE_STRING uguid; + DWORD ret_size = size; + + if(!name || !guid || !attributes) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + nsize = MultiByteToWideChar(CP_ACP, 0, guid, -1, NULL, 0); + + if (!(wguid = HeapAlloc(GetProcessHeap(), 0, nsize * sizeof(wguid)))) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + + MultiByteToWideChar(CP_ACP, 0, guid, -1, wguid, nsize); + + RtlInitUnicodeString(&uguid, wguid); + + if (!set_ntstatus(RtlGUIDFromString(&uguid, &vendor))) + return 0; + + nsize = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0); + + if (!(wname = HeapAlloc(GetProcessHeap(), 0, nsize * sizeof(wname)))) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + + MultiByteToWideChar(CP_ACP, 0, name, -1, wname, nsize); + + RtlInitUnicodeString(&uname, wname); + + status = NtQuerySystemEnvironmentValueEx(&uname, &vendor, buffer, + &ret_size, attributes); + if (status) + { + if(status == STATUS_VARIABLE_NOT_FOUND) + SetLastError(ERROR_ENVVAR_NOT_FOUND); + else if(status == STATUS_NOT_IMPLEMENTED) + SetLastError(ERROR_INVALID_FUNCTION); + else + SetLastError(RtlNtStatusToDosError(status)); + ret_size = 0; + } + + HeapFree(GetProcessHeap(), 0, wname); + HeapFree(GetProcessHeap(), 0, wguid); + + return ret_size; +} + /*********************************************************************** * GetFirmwareEnvironmentVariableA (KERNEL32.@) */ DWORD WINAPI GetFirmwareEnvironmentVariableA(LPCSTR name, LPCSTR guid, PVOID buffer, DWORD size) { - FIXME("stub: %s %s %p %lu\n", debugstr_a(name), debugstr_a(guid), buffer, size); - SetLastError(ERROR_INVALID_FUNCTION); - return 0; + DWORD attributes; + return GetFirmwareEnvironmentVariableExA(name, guid, buffer, size, &attributes); +} + +/*********************************************************************** + * GetFirmwareEnvironmentVariableExW (KERNEL32.@) + */ +DWORD WINAPI GetFirmwareEnvironmentVariableExW(LPCWSTR name, LPCWSTR guid, PVOID buffer, DWORD size, PDWORD attributes) +{ + GUID vendor = {0}; + NTSTATUS status; + UNICODE_STRING uname; + UNICODE_STRING uguid; + DWORD ret_size = size; + + if(!name || !guid || !attributes) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + RtlInitUnicodeString(&uguid, guid); + + if (!set_ntstatus(RtlGUIDFromString(&uguid, &vendor))) + return 0; + + RtlInitUnicodeString(&uname, name); + + status = NtQuerySystemEnvironmentValueEx(&uname, &vendor, buffer, + &ret_size, attributes); + if (status) + { + if(status == STATUS_VARIABLE_NOT_FOUND) + SetLastError(ERROR_ENVVAR_NOT_FOUND); + else if(status == STATUS_NOT_IMPLEMENTED) + SetLastError(ERROR_INVALID_FUNCTION); + else + SetLastError(RtlNtStatusToDosError(status)); + ret_size = 0; + } + + return ret_size; }
/*********************************************************************** @@ -733,9 +838,8 @@ DWORD WINAPI GetFirmwareEnvironmentVariableA(LPCSTR name, LPCSTR guid, PVOID buf */ DWORD WINAPI GetFirmwareEnvironmentVariableW(LPCWSTR name, LPCWSTR guid, PVOID buffer, DWORD size) { - FIXME("stub: %s %s %p %lu\n", debugstr_w(name), debugstr_w(guid), buffer, size); - SetLastError(ERROR_INVALID_FUNCTION); - return 0; + DWORD attributes; + return GetFirmwareEnvironmentVariableExW(name, guid, buffer, size, &attributes); }
/*********************************************************************** diff --git a/dlls/kernel32/tests/firmware.c b/dlls/kernel32/tests/firmware.c index 5552d70e7e1..c8ac8b7491c 100644 --- a/dlls/kernel32/tests/firmware.c +++ b/dlls/kernel32/tests/firmware.c @@ -49,7 +49,302 @@ static void test_get_firmware_type(void) "Expected FALSE and GetLastError() == ERROR_INVALID_PARAMETER\n"); }
+static BOOL EnableTokenPrivilege(HANDLE hToken, const char *pszPrivilegesName, BOOL bEnabled) +{ + LUID luid; + TOKEN_PRIVILEGES tp; + + if (!LookupPrivilegeValueA(NULL, pszPrivilegesName, &luid)) + { + return FALSE; + } + + tp.PrivilegeCount = 1; + tp.Privileges[0].Luid = luid; + tp.Privileges[0].Attributes = bEnabled ? SE_PRIVILEGE_ENABLED : 0; + + if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) + { + return FALSE; + } + + return TRUE; +} + +static void test_get_firmware_environment(void) +{ + int status; + BOOLEAN secureboot; + DWORD attributes; + HANDLE hToken; + HANDLE hProcess; + BOOL privileged = FALSE; + + hProcess = GetCurrentProcess(); + if(hProcess && OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken) + && EnableTokenPrivilege(hToken, SE_SYSTEM_ENVIRONMENT_NAME, TRUE)) + privileged = TRUE; + + /* + * GetFirmwareEnvironmentVariableA + */ + status = GetFirmwareEnvironmentVariableA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, sizeof(BOOLEAN)); + + if(!privileged && !status && GetLastError() == ERROR_PRIVILEGE_NOT_HELD) + { + skip("GetFirmwareEnvironmentVariable* demand privileges SE_SYSTEM_ENVIRONMENT_NAME.\n"); + return; + } + + if (!status && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) + { + skip("GetFirmwareEnvironmentVariableA call NtQuerySystemEnvironmentValueEx" + "and NtQuerySystemEnvironmentValueEx not implemented.\n"); + goto get_firmware_environment_variable_w; + } + + if (!status && GetLastError() == ERROR_INVALID_FUNCTION) + { + skip("GetFirmwareEnvironmentVariableA call NtQuerySystemEnvironmentValueEx" + " and NtQuerySystemEnvironmentValueEx returned ERROR_INVALID_FUNCTION.\n" + "This behavior matches the behavior of Windows for non-UEFI boots and older versions of Windows.\n"); + goto get_firmware_environment_variable_w; + } + + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableA(NULL, NULL, &secureboot, sizeof(secureboot)); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableA(NULL, "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, sizeof(secureboot)); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableA("SecureBoot", NULL, &secureboot, sizeof(secureboot)); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", NULL, 0); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, 0); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + NULL, sizeof(secureboot)); + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableA("DummyName", "{00000000-0000-0000-0000-000000000000}", + &secureboot, sizeof(secureboot)); + ok(GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + /* + * GetFirmwareEnvironmentVariableW + */ + get_firmware_environment_variable_w: + status = GetFirmwareEnvironmentVariableW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, sizeof(BOOLEAN)); + + if (!status && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) + { + skip("GetFirmwareEnvironmentVariableW call NtQuerySystemEnvironmentValueEx" + "and NtQuerySystemEnvironmentValueEx not implemented.\n"); + goto get_firmware_environment_variable_ex_a; + } + + if (!status && GetLastError() == ERROR_INVALID_FUNCTION) + { + skip("GetFirmwareEnvironmentVariableW call NtQuerySystemEnvironmentValueEx" + " and NtQuerySystemEnvironmentValueEx returned ERROR_INVALID_FUNCTION.\n" + "This behavior matches the behavior of Windows for non-UEFI boots and older versions of Windows.\n"); + goto get_firmware_environment_variable_ex_a; + } + + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0, got error %ld\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableW(NULL, NULL, &secureboot, sizeof(secureboot)); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableW(NULL, L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, sizeof(secureboot)); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableW(L"SecureBoot", NULL, &secureboot, sizeof(secureboot)); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + NULL, 0); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, 0); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + NULL, sizeof(secureboot)); + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableW(L"DummyName", L"{00000000-0000-0000-0000-000000000000}", + &secureboot, sizeof(secureboot)); + ok(GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + /* + * GetFirmwareEnvironmentVariableExA + */ + get_firmware_environment_variable_ex_a: + status = GetFirmwareEnvironmentVariableExA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, sizeof(BOOLEAN), &attributes); + + if (!status && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) + { + skip("GetFirmwareEnvironmentVariableExA call NtQuerySystemEnvironmentValueEx" + "and NtQuerySystemEnvironmentValueEx not implemented.\n"); + goto get_firmware_environment_variable_ex_w; + } + + if (!status && GetLastError() == ERROR_INVALID_FUNCTION) + { + skip("GetFirmwareEnvironmentVariableExA call NtQuerySystemEnvironmentValueEx" + " and NtQuerySystemEnvironmentValueEx returned ERROR_INVALID_FUNCTION.\n" + "This behavior matches the behavior of Windows for non-UEFI boots and older versions of Windows.\n"); + goto get_firmware_environment_variable_ex_w; + } + + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0, got error %ld\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExA(NULL, NULL, &secureboot, sizeof(secureboot), &attributes); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExA(NULL, "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, sizeof(secureboot), &attributes); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExA("SecureBoot", NULL, &secureboot, + sizeof(secureboot), &attributes); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + NULL, 0, NULL); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, 0, NULL); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, 0, &attributes); + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + NULL, sizeof(secureboot), NULL); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExA("SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + NULL, sizeof(secureboot), &attributes); + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExA("DummyName", "{00000000-0000-0000-0000-000000000000}", + &secureboot, sizeof(secureboot), &attributes); + ok(GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + /* + * GetFirmwareEnvironmentVariableExW + */ + get_firmware_environment_variable_ex_w: + status = GetFirmwareEnvironmentVariableExW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, sizeof(BOOLEAN), &attributes); + + if (!status && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) + { + skip("GetFirmwareEnvironmentVariableExW call NtQuerySystemEnvironmentValueEx" + "and NtQuerySystemEnvironmentValueEx not implemented.\n"); + return; + } + + if (!status && GetLastError() == ERROR_INVALID_FUNCTION) + { + skip("GetFirmwareEnvironmentVariableExW call NtQuerySystemEnvironmentValueEx" + " and NtQuerySystemEnvironmentValueEx returned ERROR_INVALID_FUNCTION.\n" + "This behavior matches the behavior of Windows for non-UEFI boots and older versions of Windows.\n"); + return; + } + + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0, got error %ld\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExW(NULL, NULL, &secureboot, sizeof(secureboot), &attributes); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExW(NULL, L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, sizeof(secureboot), &attributes); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExW(L"SecureBoot", NULL, &secureboot, sizeof(secureboot), &attributes); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + NULL, 0, NULL); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, 0, NULL); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + &secureboot, 0, &attributes); + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + NULL, sizeof(secureboot), NULL); + ok(GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExW(L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", + NULL, sizeof(secureboot), &attributes); + ok(status > 0 || GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); + + status = GetFirmwareEnvironmentVariableExW(L"DummyName", L"{00000000-0000-0000-0000-000000000000}", + &secureboot, sizeof(secureboot), &attributes); + ok(GetLastError() == ERROR_ENVVAR_NOT_FOUND, + "Expected ERROR_ENVVAR_NOT_FOUND, got error %ld.\n", GetLastError()); +} + START_TEST(firmware) { test_get_firmware_type(); + test_get_firmware_environment(); } diff --git a/include/winbase.h b/include/winbase.h index fe143cc7a61..2517417b170 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -2216,6 +2216,10 @@ WINBASEAPI DWORD WINAPI GetFileSize(HANDLE,LPDWORD); WINBASEAPI BOOL WINAPI GetFileSizeEx(HANDLE,PLARGE_INTEGER); WINBASEAPI BOOL WINAPI GetFileTime(HANDLE,LPFILETIME,LPFILETIME,LPFILETIME); WINBASEAPI DWORD WINAPI GetFileType(HANDLE); +WINBASEAPI DWORD WINAPI GetFirmwareEnvironmentVariableA(LPCSTR,LPCSTR,PVOID,DWORD); +WINBASEAPI DWORD WINAPI GetFirmwareEnvironmentVariableExA(LPCSTR,LPCSTR,PVOID,DWORD,PDWORD); +WINBASEAPI DWORD WINAPI GetFirmwareEnvironmentVariableW(LPCWSTR,LPCWSTR,PVOID,DWORD); +WINBASEAPI DWORD WINAPI GetFirmwareEnvironmentVariableExW(LPCWSTR,LPCWSTR,PVOID,DWORD,PDWORD); WINBASEAPI BOOL WINAPI GetFirmwareType(PFIRMWARE_TYPE); #define GetFreeSpace(w) (__MSABI_LONG(0x100000)) WINBASEAPI DWORD WINAPI GetFullPathNameA(LPCSTR,DWORD,LPSTR,LPSTR*);
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=148319
Your paranoid android.
=== w1064_adm (64 bit report) ===
kernel32: firmware.c:115: Test failed: Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:132: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:137: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:142: Test failed: Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:147: Test failed: Expected ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:172: Test failed: Expected status > 0, got error 1314 firmware.c:190: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:195: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:200: Test failed: Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:205: Test failed: Expected ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:230: Test failed: Expected status > 0, got error 1314 firmware.c:249: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:254: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:259: Test failed: Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:264: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:269: Test failed: Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:274: Test failed: Expected ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:299: Test failed: Expected status > 0, got error 1314 firmware.c:317: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:322: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:327: Test failed: Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:332: Test failed: Expected ERROR_INVALID_PARAMETER, got error 1314. firmware.c:337: Test failed: Expected status > 0 or GetLastError() == ERROR_ENVVAR_NOT_FOUND, got error 1314. firmware.c:342: Test failed: Expected ERROR_ENVVAR_NOT_FOUND, got error 1314.
=== w10pro64_en_AE_u8 (32 bit report) ===
kernel32: heap.c:3314: Test failed: HeapValidate failed heap.c:3323: Test failed: HeapValidate failed
=== w10pro64_ja (64 bit report) ===
kernel32: process.c:2740: Test failed: expected 0 active processes, got 1
=== w10pro64_zh_CN (64 bit report) ===
kernel32: process.c:2739: Test failed: expected 0 assigned processes, got 1 process.c:2739: Test failed: expected 0 process IDs, got 1
=== w7u_2qxl (32 bit report) ===
ntdll: info.c:348: Test failed: Expected ret_size == sizeof(SYSTEM_BOOT_ENVIRONMENT_INFORMATION).
=== w7u_adm (32 bit report) ===
ntdll: info.c:348: Test failed: Expected ret_size == sizeof(SYSTEM_BOOT_ENVIRONMENT_INFORMATION).
=== w7u_el (32 bit report) ===
ntdll: info.c:348: Test failed: Expected ret_size == sizeof(SYSTEM_BOOT_ENVIRONMENT_INFORMATION).
=== w1064_tsign (32 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w10pro64 (32 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w10pro64_en_AE_u8 (32 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w11pro64 (32 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w7pro64 (64 bit report) ===
ntdll: info.c:348: Test failed: Expected ret_size == sizeof(SYSTEM_BOOT_ENVIRONMENT_INFORMATION).
=== w1064_2qxl (64 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w1064_adm (64 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w1064_tsign (64 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w10pro64 (64 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w10pro64_ar (64 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w10pro64_ja (64 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w10pro64_zh_CN (64 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== w11pro64_amd (64 bit report) ===
ntdll: info.c:369: Test failed: Expected STATUS_NOT_IMPLEMENTED on non-UEFI boots. info.c:377: Test failed: Expected STATUS_SUCCESS or STATUS_VARIABLE_NOT_FOUND. info.c:380: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:383: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:386: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:389: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:392: Test failed: Expected STATUS_INVALID_PARAMETER. info.c:395: Test failed: Expected STATUS_SUCCESS. info.c:398: Test failed: Expected STATUS_SUCCESS. info.c:401: Test failed: Expected STATUS_SUCCESS.
=== debian11 (32 bit zh:CN report) ===
kernel32: comm.c:1586: Test failed: Unexpected time 1002, expected around 500
=== debian11b (64 bit WoW report) ===
dinput: joystick8.c:5762: Test failed: input 1: WaitForSingleObject returned 0x102 joystick8.c:5763: Test failed: input 1: got 0 WM_INPUT messages joystick8.c:5766: Test failed: input 1: got dwType 0 joystick8.c:5767: Test failed: input 1: got header.dwSize 0 joystick8.c:5769: Test failed: input 1: got hDevice 0000000000000000 joystick8.c:5771: Test failed: input 1: got dwSizeHid 0 joystick8.c:5772: Test failed: input 1: got dwCount 0
user32: input.c:4305: Test succeeded inside todo block: button_down_hwnd_todo 1: got MSG_TEST_WIN hwnd 0000000000B000DE, msg WM_LBUTTONDOWN, wparam 0x1, lparam 0x320032
Alfred Agrell (@Alcaro) commented about dlls/kernel32/process.c:
RtlInitUnicodeString(&uname, wname);
- if (!set_ntstatus(NtQuerySystemEnvironmentValueEx(&uname, &vendor, buffer,
&ret_size, attributes)))
- status = NtQuerySystemEnvironmentValueEx(&uname, &vendor, buffer,
&ret_size, attributes);
- if (status)
- {
if(status == STATUS_VARIABLE_NOT_FOUND)
what. set_ntstatus already maps those two correctly.
And if it didn't, the correct solution would be to teach it, not skip it.
Alfred Agrell (@Alcaro) commented about dlls/kernel32/process.c:
- RtlInitUnicodeString(&uguid, wguid);
- if (!set_ntstatus(RtlGUIDFromString(&uguid, &vendor)))
return 0;
- nsize = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
- if (!(wname = HeapAlloc(GetProcessHeap(), 0, nsize * sizeof(wname))))
- {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
- }
- MultiByteToWideChar(CP_ACP, 0, name, -1, wname, nsize);
- RtlInitUnicodeString(&uname, wname);
This could be slightly simplified by calling GetFirmwareEnvironmentVariableExW here instead of NtQuerySystemEnvironmentValueEx.
Alfred Agrell (@Alcaro) commented about dlls/ntdll/unix/system.c:
&boot_info.BootIdentifier.Data4[3], &boot_info.BootIdentifier.Data4[4],
&boot_info.BootIdentifier.Data4[5], &boot_info.BootIdentifier.Data4[6],
&boot_info.BootIdentifier.Data4[7]) != 11)
goto try_read_hostid;
}
else
{
try_read_hostid:
+#endif +#ifdef __APPLE__
if (!stat("/Users", &stat_info) || !stat("/System", &stat_info))
+#else
if (!stat("/home", &stat_info) || !stat("/usr", &stat_info))
+#endif
{
boot_info.BootIdentifier.Data1 = gethostid() & 0xFFFFFFFF;
That's some complicated stuff.
No comment on whether it's worth it. I'll leave that question to someone else.
Alfred Agrell (@Alcaro) commented about dlls/ntdll/unix/system.c:
- if (fd >= 0)
close(fd);
- return STATUS_UNSUCCESSFUL;
+#elif defined(__APPLE__)
- if(!name || !vendor || (name && vendor && !retlen && !attrib))
- {
return STATUS_INVALID_PARAMETER;
- }
- /*
* Since 2006, Mac computers use Extensible Firmware Interface (EFI).
* Apple requires a developer account and mandatory code signing,
* and the entire system boot process is verified, we can return SecureBoot enabled.
* Reference: https://support.apple.com/guide/security/uefi-firmware-security-in-an-intel-based-mac-seced055bcf6/web
*/
- if(vendor->Data1 == 0x8be4df61 && vendor->Data2 == 0x93ca && vendor->Data3 == 0x11d2 && wcscmp(name->Buffer, L"SecureBoot")
I'd memcmp the guid instead. And you forgot the ! on the wcscmp. And do L strings do the right thing in Unix side code?
Is this piece even tested?
On Mon Sep 9 15:50:23 2024 +0000, Alfred Agrell wrote:
what. set_ntstatus already maps those two correctly. And if it didn't, the correct solution would be to teach it, not skip it.
This tested Windows 11 behavior for these functions, set_ntstatus does not work correctly. I would leave it like this.
On Mon Sep 9 15:50:23 2024 +0000, Alfred Agrell wrote:
This could be slightly simplified by calling GetFirmwareEnvironmentVariableExW here instead of NtQuerySystemEnvironmentValueEx.
I would leave it like this.
On Mon Sep 9 15:50:23 2024 +0000, Alfred Agrell wrote:
That's some complicated stuff. No comment on whether it's worth it. I'll leave that question to someone else.
@Alcaro it works as expected and sets a BootIdentifier that does not change across reboots. This behavior is similar to Windows. But there are fewer possible variations. If you find data sources that do not change and are unique to the system, I can improve the variability.
On Mon Sep 9 15:50:23 2024 +0000, Alfred Agrell wrote:
I'd memcmp the guid instead. And you forgot the ! on the wcscmp. And do L strings do the right thing in Unix side code? Is this piece even tested?
@Alcaro Compiles, but not tested. I don't have a mac.
On Mon Sep 9 15:58:18 2024 +0000, Grigory Vasilyev wrote:
I would leave it like this.
Fwiw Nikolay suggested the same a while back https://gitlab.winehq.org/wine/wine/-/merge_requests/6423#note_81129