15#define _A2W(quote) __A2W(quote)
16#define __A2W(quote) L##quote
18#define EFI_TEST_GUID_STRING "{8768B7AC-F82F-4120-B093-30DFA27DA3B5}"
19#define EFI_TEST_VARIABLE_NAME "RosUefiVarTest"
21#define EFI_DUMMY_NAMESPACE_GUID_STRING "{00000000-0000-0000-0000-000000000000}"
22#define EFI_DUMMY_VARIABLE_NAME ""
38static ULONG RandomSeed;
39static DWORD EfiVariableValue;
41static VOID test_GetFirmwareType(
BOOL bIsUEFI)
45 FN_GetFirmwareType* pfnGetFirmwareType;
52 skip(
"Module kernel32 not found\n");
56 if (pfnGetFirmwareType ==
NULL)
58 skip(
"GetFirmwareType (NT6.2+ API) not found\n");
63 bResult = pfnGetFirmwareType(&FirmwareType);
65 "GetFirmwareType failed with error: 0x%08lX\n",
72 ok(FirmwareType == FirmwareExpect,
73 "FirmwareType is %d, but %d is expected.\n",
74 FirmwareType, FirmwareExpect);
79 BOOL bResult, bResultTemp, bIsUEFI;
100 test_GetFirmwareType(bIsUEFI);
103 skip(
"Skipping tests that require UEFI environment.\n");
113 ok(dwLengthTemp ==
dwLength && dwErrorTemp == dwError,
114 "dwLength = %lu, LastError = %lu, expected bResult = %lu, LastError = %lu\n",
122 EfiVariableValue =
RtlRandom(&RandomSeed);
129 sizeof(EfiVariableValue));
132 "bResult = %d, LastError = %lu, expected bResult = 0, LastError = ERROR_PRIVILEGE_NOT_HELD\n",
140 sizeof(EfiVariableValue));
142 ok(bResultTemp == bResult && dwErrorTemp == dwError,
143 "bResult = %d, LastError = %lu, expected bResult = %d, LastError = %lu\n",
153 skip(
"OpenProcessToken failed with error: 0x%08lX, aborting.\n",
GetLastError());
162 skip(
"NtAdjustPrivilegesToken failed with status: 0x%08lX, aborting.\n",
Status);
171 sizeof(EfiVariableValue));
173 "SetFirmwareEnvironmentVariableW failed with error: 0x%08lX\n",
183 "GetFirmwareEnvironmentVariableW failed with error: 0x%08lX\n",
187 ok(
dwLength ==
sizeof(EfiVariableValue) && dwValue == EfiVariableValue,
188 "Retrieved variable different from what we set, "
189 "dwLength = %lu, dwValue = %lu, expected dwLength = %u, dwValue = %lu",
192 sizeof(EfiVariableValue),
198 EfiVariableValue =
RtlRandom(&RandomSeed);
202 sizeof(EfiVariableValue));
204 "SetFirmwareEnvironmentVariableA failed with error: 0x%08lX\n",
214 "GetFirmwareEnvironmentVariableA failed with error: 0x%08lX\n",
218 ok(
dwLength ==
sizeof(EfiVariableValue) && dwValue == EfiVariableValue,
219 "Retrieved variable different from what we set, "
220 "dwLength = %lu, dwValue = %lu, expected dwLength = %u, dwValue = %lu",
223 sizeof(EfiVariableValue),
234 "SetFirmwareEnvironmentVariableW failed with error: 0x%08lX\n",
242 ok(
dwLength == 0,
"SetFirmwareEnvironmentVariableW didn't delete the variable!\n");
249 sizeof(EfiVariableValue));
252 skip(
"SetFirmwareEnvironmentVariableW failed to restore variable with error: 0x%08lX\n",
261 "SetFirmwareEnvironmentVariableA failed with error: 0x%08lX\n",
269 ok(
dwLength == 0,
"SetFirmwareEnvironmentVariableA didn't delete the variable!\n");
enum _FIRMWARE_TYPE FIRMWARE_TYPE
#define EFI_DUMMY_NAMESPACE_GUID_STRING
enum _FIRMWARE_TYPE * PFIRMWARE_TYPE
#define EFI_TEST_VARIABLE_NAME
#define EFI_TEST_GUID_STRING
#define EFI_DUMMY_VARIABLE_NAME
#define ERROR_INVALID_FUNCTION
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
#define GetProcAddress(x, y)
#define GetCurrentProcess()
static DWORD DWORD * dwLength
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
BOOL WINAPI SetFirmwareEnvironmentVariableA(_In_ LPCSTR lpName, _In_ LPCSTR lpGuid, _In_reads_bytes_opt_(nSize) PVOID pValue, _In_ DWORD nSize)
BOOL WINAPI SetFirmwareEnvironmentVariableW(_In_ LPCWSTR lpName, _In_ LPCWSTR lpGuid, _In_reads_bytes_opt_(nSize) PVOID pValue, _In_ DWORD nSize)
DWORD WINAPI GetTickCount(VOID)
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
#define SE_SYSTEM_ENVIRONMENT_PRIVILEGE
NTSYSAPI ULONG NTAPI RtlRandom(_Inout_ PULONG Seed)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtAdjustPrivilegesToken(_In_ HANDLE TokenHandle, _In_ BOOLEAN DisableAllPrivileges, _In_opt_ PTOKEN_PRIVILEGES NewState, _In_ ULONG BufferLength, _Out_writes_bytes_to_opt_(BufferLength, *ReturnLength) PTOKEN_PRIVILEGES PreviousState, _When_(PreviousState!=NULL, _Out_) PULONG ReturnLength)
Removes a certain amount of privileges of a token based upon the request by the caller.
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
DWORD WINAPI GetLastError(void)
#define ERROR_PRIVILEGE_NOT_HELD
FORCEINLINE LUID NTAPI_INLINE RtlConvertUlongToLuid(_In_ ULONG Val)
#define TOKEN_ADJUST_PRIVILEGES
#define SE_PRIVILEGE_ENABLED