2012-10-07 12:31:13 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS API Tests
|
|
|
|
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Test for the NtQuerySystemEnvironmentValue.
|
|
|
|
* PROGRAMMER: Hermès BÉLUSCA - MAÏTO <hermes.belusca@sfr.fr>
|
|
|
|
*/
|
|
|
|
|
2013-09-22 19:07:35 +00:00
|
|
|
#include <apitest.h>
|
|
|
|
|
2012-10-07 12:31:13 +00:00
|
|
|
#define WIN32_NO_STATUS
|
2013-02-05 17:54:22 +00:00
|
|
|
#include <ndk/setypes.h>
|
|
|
|
#include <ndk/rtlfuncs.h>
|
|
|
|
#include <ndk/exfuncs.h>
|
2012-10-07 12:31:13 +00:00
|
|
|
|
|
|
|
// Arbitrary-defined constants
|
|
|
|
#define MIN_BUFFER_LENGTH 4L
|
|
|
|
#define MAX_BUFFER_LENGTH 2048L
|
|
|
|
|
|
|
|
#define COUNT_OF(x) (sizeof((x))/sizeof((x)[0]))
|
|
|
|
|
2012-10-07 12:46:44 +00:00
|
|
|
typedef struct _TEST_CASE
|
2012-10-07 12:31:13 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Result;
|
|
|
|
UNICODE_STRING VariableName;
|
|
|
|
BOOLEAN AdjustPrivileges;
|
|
|
|
ULONG ValueBufferLength;
|
|
|
|
ULONG MinimalExpectedReturnedLength;
|
|
|
|
ULONG MaximalExpectedReturnedLength;
|
2012-10-07 12:46:44 +00:00
|
|
|
} TEST_CASE, *PTEST_CASE;
|
|
|
|
|
|
|
|
static TEST_CASE TestCases[] =
|
2012-10-07 12:31:13 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// Non-existent variable name.
|
|
|
|
//
|
|
|
|
{STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"NonExistent"), FALSE, 0, 0, 0},
|
|
|
|
{STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"NonExistent"), FALSE, MIN_BUFFER_LENGTH, 0, 0},
|
|
|
|
{STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"NonExistent"), FALSE, MAX_BUFFER_LENGTH, 0, 0},
|
|
|
|
{STATUS_UNSUCCESSFUL , RTL_CONSTANT_STRING(L"NonExistent"), TRUE , 0, 0, 0},
|
|
|
|
{STATUS_UNSUCCESSFUL , RTL_CONSTANT_STRING(L"NonExistent"), TRUE , MIN_BUFFER_LENGTH, 0, 0},
|
|
|
|
{STATUS_UNSUCCESSFUL , RTL_CONSTANT_STRING(L"NonExistent"), TRUE , MAX_BUFFER_LENGTH, 0, 0},
|
|
|
|
|
|
|
|
//
|
|
|
|
// Existent variable name.
|
|
|
|
//
|
|
|
|
{STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"LastKnownGood"), FALSE, 0, 0, 0},
|
|
|
|
{STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"LastKnownGood"), FALSE, MIN_BUFFER_LENGTH, 0, 0},
|
|
|
|
{STATUS_PRIVILEGE_NOT_HELD, RTL_CONSTANT_STRING(L"LastKnownGood"), FALSE, MAX_BUFFER_LENGTH, 0, 0},
|
|
|
|
{STATUS_BUFFER_OVERFLOW , RTL_CONSTANT_STRING(L"LastKnownGood"), TRUE , 0 , MIN_BUFFER_LENGTH, MAX_BUFFER_LENGTH},
|
|
|
|
{STATUS_BUFFER_OVERFLOW , RTL_CONSTANT_STRING(L"LastKnownGood"), TRUE , MIN_BUFFER_LENGTH, MIN_BUFFER_LENGTH, MAX_BUFFER_LENGTH},
|
|
|
|
{STATUS_SUCCESS , RTL_CONSTANT_STRING(L"LastKnownGood"), TRUE , MAX_BUFFER_LENGTH, MIN_BUFFER_LENGTH, MAX_BUFFER_LENGTH},
|
|
|
|
};
|
|
|
|
|
2012-10-07 14:17:37 +00:00
|
|
|
static void Test_API(IN ULONG TestNumber,
|
|
|
|
IN PTEST_CASE TestCase)
|
2012-10-07 12:31:13 +00:00
|
|
|
{
|
2012-10-07 12:46:44 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
BOOLEAN WasEnabled = FALSE;
|
|
|
|
WCHAR ValueBuffer[MAX_BUFFER_LENGTH / sizeof(WCHAR)];
|
|
|
|
ULONG ReturnedLength = 0;
|
2012-10-07 12:31:13 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Adjust the privileges if asked for (we need to
|
|
|
|
// have already administrator privileges to do so).
|
|
|
|
//
|
2012-10-07 12:46:44 +00:00
|
|
|
if (TestCase->AdjustPrivileges)
|
2012-10-07 12:31:13 +00:00
|
|
|
{
|
|
|
|
Status = RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE,
|
|
|
|
TRUE,
|
|
|
|
FALSE,
|
|
|
|
&WasEnabled);
|
2012-10-07 14:17:37 +00:00
|
|
|
ok(NT_SUCCESS(Status), "RtlAdjustPrivilege(%lu) failed : 0x%08lx\n", TestNumber, Status);
|
2012-10-07 12:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the system environment value and set the privilege back.
|
|
|
|
//
|
2012-10-07 12:46:44 +00:00
|
|
|
Status = NtQuerySystemEnvironmentValue(&TestCase->VariableName,
|
2012-10-07 12:31:13 +00:00
|
|
|
ValueBuffer,
|
2012-10-07 12:46:44 +00:00
|
|
|
TestCase->ValueBufferLength,
|
|
|
|
&ReturnedLength);
|
2012-10-07 12:31:13 +00:00
|
|
|
|
2012-10-07 12:46:44 +00:00
|
|
|
if (TestCase->AdjustPrivileges)
|
2012-10-07 12:31:13 +00:00
|
|
|
{
|
|
|
|
RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE,
|
|
|
|
WasEnabled,
|
|
|
|
FALSE,
|
|
|
|
&WasEnabled);
|
|
|
|
}
|
|
|
|
|
2012-10-07 12:46:44 +00:00
|
|
|
//
|
|
|
|
// Now check the results.
|
|
|
|
//
|
|
|
|
ok(Status == TestCase->Result,
|
2012-10-07 14:17:37 +00:00
|
|
|
"NtQuerySystemEnvironmentValue(%lu) failed : returned 0x%08lx, expected 0x%08lx\n",
|
|
|
|
TestNumber,
|
2012-10-07 12:46:44 +00:00
|
|
|
Status,
|
|
|
|
TestCase->Result);
|
|
|
|
|
|
|
|
ok( ((TestCase->MinimalExpectedReturnedLength <= ReturnedLength) && (ReturnedLength <= TestCase->MaximalExpectedReturnedLength)),
|
2012-10-07 14:17:37 +00:00
|
|
|
"NtQuerySystemEnvironmentValue(%lu) failed : returned length %lu, expected between %lu and %lu\n",
|
|
|
|
TestNumber,
|
2012-10-07 12:46:44 +00:00
|
|
|
ReturnedLength,
|
|
|
|
TestCase->MinimalExpectedReturnedLength,
|
|
|
|
TestCase->MaximalExpectedReturnedLength);
|
2012-10-07 12:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(NtQuerySystemEnvironmentValue)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < COUNT_OF(TestCases) ; ++i)
|
|
|
|
{
|
2012-10-07 14:17:37 +00:00
|
|
|
Test_API(i, &TestCases[i]);
|
2012-10-07 12:31:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|