Milestone 5: deliver embedded RDP sessions and lifecycle hardening

This commit is contained in:
Keith Smith
2026-03-03 18:59:26 -07:00
parent 230a401386
commit 36006bd4aa
2941 changed files with 724359 additions and 77 deletions

View File

@@ -0,0 +1,25 @@
set(MODULE_NAME "TestSysInfo")
set(MODULE_PREFIX "TEST_SYSINFO")
disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR})
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_TESTS TestGetNativeSystemInfo.c TestCPUFeatures.c TestGetComputerName.c TestSystemTime.c
TestLocalTime.c
)
create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS})
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
target_link_libraries(${MODULE_NAME} winpr)
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")

View File

@@ -0,0 +1,65 @@
#include <winpr/crt.h>
#include <winpr/sysinfo.h>
#include <winpr/platform.h>
#define TEST_FEATURE(feature) \
printf("\t" #feature ": %s\n", IsProcessorFeaturePresent(feature) ? "yes" : "no")
#define TEST_FEATURE_EX(feature) \
printf("\t" #feature ": %s\n", IsProcessorFeaturePresentEx(feature) ? "yes" : "no")
int TestCPUFeatures(int argc, char* argv[])
{
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
printf("Base CPU Flags:\n");
#ifdef _M_IX86_AMD64
TEST_FEATURE(PF_MMX_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_XMMI_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_3DNOW_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_SSE3_INSTRUCTIONS_AVAILABLE);
printf("\n");
printf("Extended CPU Flags (not found in windows API):\n");
TEST_FEATURE_EX(PF_EX_3DNOW_PREFETCH);
TEST_FEATURE_EX(PF_EX_SSSE3);
TEST_FEATURE_EX(PF_EX_SSE41);
TEST_FEATURE_EX(PF_EX_SSE42);
TEST_FEATURE_EX(PF_EX_AVX);
TEST_FEATURE_EX(PF_EX_FMA);
TEST_FEATURE_EX(PF_EX_AVX_AES);
TEST_FEATURE_EX(PF_EX_AVX_PCLMULQDQ);
#elif defined(_M_ARM) || defined(_M_ARM64)
TEST_FEATURE(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_ARM_THUMB);
TEST_FEATURE(PF_ARM_VFP_32_REGISTERS_AVAILABLE);
TEST_FEATURE(PF_ARM_DIVIDE_INSTRUCTION_AVAILABLE);
TEST_FEATURE(PF_ARM_VFP3);
TEST_FEATURE(PF_ARM_THUMB);
TEST_FEATURE(PF_ARM_JAZELLE);
TEST_FEATURE(PF_ARM_DSP);
TEST_FEATURE(PF_ARM_THUMB2);
TEST_FEATURE(PF_ARM_T2EE);
TEST_FEATURE(PF_ARM_INTEL_WMMX);
printf("Extended CPU Flags (not found in windows API):\n");
TEST_FEATURE_EX(PF_EX_ARM_VFP1);
TEST_FEATURE_EX(PF_EX_ARM_VFP3D16);
TEST_FEATURE_EX(PF_EX_ARM_VFP4);
TEST_FEATURE_EX(PF_EX_ARM_IDIVA);
TEST_FEATURE_EX(PF_EX_ARM_IDIVT);
#elif defined(_M_E2K)
TEST_FEATURE(PF_MMX_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_3DNOW_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_SSE3_INSTRUCTIONS_AVAILABLE);
printf("\n");
printf("Extended CPU Flags (not found in windows API):\n");
TEST_FEATURE_EX(PF_EX_SSSE3);
TEST_FEATURE_EX(PF_EX_SSE41);
TEST_FEATURE_EX(PF_EX_SSE42);
TEST_FEATURE_EX(PF_EX_AVX);
TEST_FEATURE_EX(PF_EX_FMA);
#endif
printf("\n");
return 0;
}

View File

@@ -0,0 +1,372 @@
#include <stdio.h>
#include <string.h>
#include <winpr/wtypes.h>
#include <winpr/sysinfo.h>
#include <winpr/error.h>
static BOOL Test_GetComputerName(void)
{
/**
* BOOL WINAPI GetComputerName(LPTSTR lpBuffer, LPDWORD lpnSize);
*
* GetComputerName retrieves the NetBIOS name of the local computer.
*
* lpBuffer [out]
* A pointer to a buffer that receives the computer name or the cluster virtual server name.
* The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1 characters.
*
* lpnSize [in, out]
* On input, specifies the size of the buffer, in TCHARs.
* On output, the number of TCHARs copied to the destination buffer, not including the
* terminating null character. If the buffer is too small, the function fails and GetLastError
* returns ERROR_BUFFER_OVERFLOW. The lpnSize parameter specifies the size of the buffer
* required, including the terminating null character
*
*/
CHAR netbiosName1[MAX_COMPUTERNAME_LENGTH + 1] = WINPR_C_ARRAY_INIT;
CHAR netbiosName2[MAX_COMPUTERNAME_LENGTH + 1] = WINPR_C_ARRAY_INIT;
const size_t netbiosBufferSize = ARRAYSIZE(netbiosName1);
DWORD dwSize = 0;
DWORD dwNameLength = 0;
DWORD dwError = 0;
memset(netbiosName1, 0xAA, netbiosBufferSize);
memset(netbiosName2, 0xBB, netbiosBufferSize);
/* test with null buffer and zero size (required if buffer is null) */
dwSize = 0;
if (GetComputerNameA(nullptr, &dwSize) == TRUE)
{
(void)fprintf(stderr, "%s: (1) GetComputerNameA unexpectedly succeeded with null buffer\n",
__func__);
return FALSE;
}
if ((dwError = GetLastError()) != ERROR_BUFFER_OVERFLOW)
{
(void)fprintf(stderr,
"%s: (2) GetLastError returned 0x%08" PRIX32
" (expected ERROR_BUFFER_OVERFLOW)\n",
__func__, dwError);
return FALSE;
}
/* test with valid buffer and zero size */
dwSize = 0;
if (GetComputerNameA(netbiosName1, &dwSize) == TRUE)
{
(void)fprintf(stderr,
"%s: (3) GetComputerNameA unexpectedly succeeded with zero size parameter\n",
__func__);
return FALSE;
}
if ((dwError = GetLastError()) != ERROR_BUFFER_OVERFLOW)
{
(void)fprintf(stderr,
"%s: (4) GetLastError returned 0x%08" PRIX32
" (expected ERROR_BUFFER_OVERFLOW)\n",
__func__, dwError);
return FALSE;
}
/* check if returned size is valid: must be the size of the buffer required, including the
* terminating null character in this case */
if (dwSize < 2 || dwSize > netbiosBufferSize)
{
(void)fprintf(stderr,
"%s: (5) GetComputerNameA returned wrong size %" PRIu32
" (expected something in the range from 2 to %" PRIuz ")\n",
__func__, dwSize, netbiosBufferSize);
return FALSE;
}
dwNameLength = dwSize - 1;
/* test with returned size */
if (GetComputerNameA(netbiosName1, &dwSize) == FALSE)
{
(void)fprintf(stderr, "%s: (6) GetComputerNameA failed with error: 0x%08" PRIX32 "\n",
__func__, GetLastError());
return FALSE;
}
/* check if returned size is valid */
if (dwSize != dwNameLength)
{
(void)fprintf(stderr,
"%s: (7) GetComputerNameA returned wrong size %" PRIu32 " (expected %" PRIu32
")\n",
__func__, dwSize, dwNameLength);
return FALSE;
}
/* check if string is correctly terminated */
if (netbiosName1[dwSize] != 0)
{
(void)fprintf(stderr, "%s: (8) string termination error\n", __func__);
return FALSE;
}
/* test with real buffer size */
dwSize = netbiosBufferSize;
if (GetComputerNameA(netbiosName2, &dwSize) == FALSE)
{
(void)fprintf(stderr, "%s: (9) GetComputerNameA failed with error: 0x%08" PRIX32 "\n",
__func__, GetLastError());
return FALSE;
}
/* check if returned size is valid */
if (dwSize != dwNameLength)
{
(void)fprintf(stderr,
"%s: (10) GetComputerNameA returned wrong size %" PRIu32 " (expected %" PRIu32
")\n",
__func__, dwSize, dwNameLength);
return FALSE;
}
/* check if string is correctly terminated */
if (netbiosName2[dwSize] != 0)
{
(void)fprintf(stderr, "%s: (11) string termination error\n", __func__);
return FALSE;
}
/* compare the results */
if (strcmp(netbiosName1, netbiosName2) != 0)
{
(void)fprintf(stderr, "%s: (12) string compare mismatch\n", __func__);
return FALSE;
}
/* test with off by one buffer size */
dwSize = dwNameLength;
if (GetComputerNameA(netbiosName1, &dwSize) == TRUE)
{
(void)fprintf(stderr,
"%s: (13) GetComputerNameA unexpectedly succeeded with limited buffer size\n",
__func__);
return FALSE;
}
/* check if returned size is valid */
if (dwSize != dwNameLength + 1)
{
(void)fprintf(stderr,
"%s: (14) GetComputerNameA returned wrong size %" PRIu32 " (expected %" PRIu32
")\n",
__func__, dwSize, dwNameLength + 1);
return FALSE;
}
return TRUE;
}
static BOOL Test_GetComputerNameEx_Format(COMPUTER_NAME_FORMAT format)
{
/**
* BOOL WINAPI GetComputerNameEx(COMPUTER_NAME_FORMAT NameType, LPTSTR lpBuffer, LPDWORD
* lpnSize);
*
* Retrieves a NetBIOS or DNS name associated with the local computer.
*
* NameType [in]
* ComputerNameNetBIOS
* ComputerNameDnsHostname
* ComputerNameDnsDomain
* ComputerNameDnsFullyQualified
* ComputerNamePhysicalNetBIOS
* ComputerNamePhysicalDnsHostname
* ComputerNamePhysicalDnsDomain
* ComputerNamePhysicalDnsFullyQualified
*
* lpBuffer [out]
* A pointer to a buffer that receives the computer name or the cluster virtual server name.
* The length of the name may be greater than MAX_COMPUTERNAME_LENGTH characters because DNS
* allows longer names. To ensure that this buffer is large enough, set this parameter to
* nullptr and use the required buffer size returned in the lpnSize parameter.
*
* lpnSize [in, out]
* On input, specifies the size of the buffer, in TCHARs.
* On output, receives the number of TCHARs copied to the destination buffer, not including the
* terminating null character. If the buffer is too small, the function fails and GetLastError
* returns ERROR_MORE_DATA. This parameter receives the size of the buffer required, including
* the terminating null character. If lpBuffer is nullptr, this parameter must be zero.
*
*/
CHAR computerName1[255 + 1];
CHAR computerName2[255 + 1];
const DWORD nameBufferSize = sizeof(computerName1) / sizeof(CHAR);
DWORD dwSize = 0;
DWORD dwMinSize = 0;
DWORD dwNameLength = 0;
DWORD dwError = 0;
memset(computerName1, 0xAA, nameBufferSize);
memset(computerName2, 0xBB, nameBufferSize);
if (format == ComputerNameDnsDomain || format == ComputerNamePhysicalDnsDomain)
{
/* domain names may be empty, terminating null only */
dwMinSize = 1;
}
else
{
/* computer names must be at least 1 character */
dwMinSize = 2;
}
/* test with null buffer and zero size (required if buffer is null) */
dwSize = 0;
if (GetComputerNameExA(format, nullptr, &dwSize) == TRUE)
{
(void)fprintf(stderr,
"%s: (1/%d) GetComputerNameExA unexpectedly succeeded with null buffer\n",
__func__, format);
return FALSE;
}
if ((dwError = GetLastError()) != ERROR_MORE_DATA)
{
(void)fprintf(
stderr, "%s: (2/%d) GetLastError returned 0x%08" PRIX32 " (expected ERROR_MORE_DATA)\n",
__func__, format, dwError);
return FALSE;
}
/* test with valid buffer and zero size */
dwSize = 0;
if (GetComputerNameExA(format, computerName1, &dwSize) == TRUE)
{
(void)fprintf(
stderr,
"%s: (3/%d) GetComputerNameExA unexpectedly succeeded with zero size parameter\n",
__func__, format);
return FALSE;
}
if ((dwError = GetLastError()) != ERROR_MORE_DATA)
{
(void)fprintf(
stderr, "%s: (4/%d) GetLastError returned 0x%08" PRIX32 " (expected ERROR_MORE_DATA)\n",
__func__, format, dwError);
return FALSE;
}
/* check if returned size is valid: must be the size of the buffer required, including the
* terminating null character in this case */
if (dwSize < dwMinSize || dwSize > nameBufferSize)
{
(void)fprintf(stderr,
"%s: (5/%d) GetComputerNameExA returned wrong size %" PRIu32
" (expected something in the range from %" PRIu32 " to %" PRIu32 ")\n",
__func__, format, dwSize, dwMinSize, nameBufferSize);
return FALSE;
}
dwNameLength = dwSize - 1;
/* test with returned size */
if (GetComputerNameExA(format, computerName1, &dwSize) == FALSE)
{
(void)fprintf(stderr, "%s: (6/%d) GetComputerNameExA failed with error: 0x%08" PRIX32 "\n",
__func__, format, GetLastError());
return FALSE;
}
/* check if returned size is valid */
if (dwSize != dwNameLength)
{
(void)fprintf(stderr,
"%s: (7/%d) GetComputerNameExA returned wrong size %" PRIu32
" (expected %" PRIu32 ")\n",
__func__, format, dwSize, dwNameLength);
return FALSE;
}
/* check if string is correctly terminated */
if (computerName1[dwSize] != 0)
{
(void)fprintf(stderr, "%s: (8/%d) string termination error\n", __func__, format);
return FALSE;
}
/* test with real buffer size */
dwSize = nameBufferSize;
if (GetComputerNameExA(format, computerName2, &dwSize) == FALSE)
{
(void)fprintf(stderr, "%s: (9/%d) GetComputerNameExA failed with error: 0x%08" PRIX32 "\n",
__func__, format, GetLastError());
return FALSE;
}
/* check if returned size is valid */
if (dwSize != dwNameLength)
{
(void)fprintf(stderr,
"%s: (10/%d) GetComputerNameExA returned wrong size %" PRIu32
" (expected %" PRIu32 ")\n",
__func__, format, dwSize, dwNameLength);
return FALSE;
}
/* check if string is correctly terminated */
if (computerName2[dwSize] != 0)
{
(void)fprintf(stderr, "%s: (11/%d) string termination error\n", __func__, format);
return FALSE;
}
/* compare the results */
if (strcmp(computerName1, computerName2) != 0)
{
(void)fprintf(stderr, "%s: (12/%d) string compare mismatch\n", __func__, format);
return FALSE;
}
/* test with off by one buffer size */
dwSize = dwNameLength;
if (GetComputerNameExA(format, computerName1, &dwSize) == TRUE)
{
(void)fprintf(
stderr,
"%s: (13/%d) GetComputerNameExA unexpectedly succeeded with limited buffer size\n",
__func__, format);
return FALSE;
}
/* check if returned size is valid */
if (dwSize != dwNameLength + 1)
{
(void)fprintf(stderr,
"%s: (14/%d) GetComputerNameExA returned wrong size %" PRIu32
" (expected %" PRIu32 ")\n",
__func__, format, dwSize, dwNameLength + 1);
return FALSE;
}
return TRUE;
}
int TestGetComputerName(int argc, char* argv[])
{
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
if (!Test_GetComputerName())
return -1;
if (!Test_GetComputerNameEx_Format(ComputerNameNetBIOS))
return -1;
if (!Test_GetComputerNameEx_Format(ComputerNameDnsHostname))
return -1;
if (!Test_GetComputerNameEx_Format(ComputerNameDnsDomain))
return -1;
if (!Test_GetComputerNameEx_Format(ComputerNameDnsFullyQualified))
return -1;
if (!Test_GetComputerNameEx_Format(ComputerNamePhysicalNetBIOS))
return -1;
if (!Test_GetComputerNameEx_Format(ComputerNamePhysicalDnsHostname))
return -1;
if (!Test_GetComputerNameEx_Format(ComputerNamePhysicalDnsDomain))
return -1;
if (!Test_GetComputerNameEx_Format(ComputerNamePhysicalDnsFullyQualified))
return -1;
return 0;
}

View File

@@ -0,0 +1,33 @@
#include <winpr/crt.h>
#include <winpr/sysinfo.h>
int TestGetNativeSystemInfo(int argc, char* argv[])
{
SYSTEM_INFO sysinfo = WINPR_C_ARRAY_INIT;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
GetNativeSystemInfo(&sysinfo);
const UINT16 wProcessorArchitecture =
sysinfo.DUMMYUNIONNAME.DUMMYSTRUCTNAME.wProcessorArchitecture;
const UINT16 wReserved = sysinfo.DUMMYUNIONNAME.DUMMYSTRUCTNAME.wReserved;
printf("SystemInfo:\n");
printf("\twProcessorArchitecture: %" PRIu16 "\n", wProcessorArchitecture);
printf("\twReserved: %" PRIu16 "\n", wReserved);
printf("\tdwPageSize: 0x%08" PRIX32 "\n", sysinfo.dwPageSize);
printf("\tlpMinimumApplicationAddress: %p\n", sysinfo.lpMinimumApplicationAddress);
printf("\tlpMaximumApplicationAddress: %p\n", sysinfo.lpMaximumApplicationAddress);
printf("\tdwActiveProcessorMask: %p\n", (void*)sysinfo.dwActiveProcessorMask);
printf("\tdwNumberOfProcessors: %" PRIu32 "\n", sysinfo.dwNumberOfProcessors);
printf("\tdwProcessorType: %" PRIu32 "\n", sysinfo.dwProcessorType);
printf("\tdwAllocationGranularity: %" PRIu32 "\n", sysinfo.dwAllocationGranularity);
printf("\twProcessorLevel: %" PRIu16 "\n", sysinfo.wProcessorLevel);
printf("\twProcessorRevision: %" PRIu16 "\n", sysinfo.wProcessorRevision);
printf("\n");
return 0;
}

View File

@@ -0,0 +1,21 @@
#include <winpr/crt.h>
#include <winpr/sysinfo.h>
int TestLocalTime(int argc, char* argv[])
{
SYSTEMTIME lTime;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
GetLocalTime(&lTime);
printf("GetLocalTime: wYear: %" PRIu16 " wMonth: %" PRIu16 " wDayOfWeek: %" PRIu16
" wDay: %" PRIu16 " wHour: %" PRIu16 " wMinute: %" PRIu16 " wSecond: %" PRIu16
" wMilliseconds: %" PRIu16 "\n",
lTime.wYear, lTime.wMonth, lTime.wDayOfWeek, lTime.wDay, lTime.wHour, lTime.wMinute,
lTime.wSecond, lTime.wMilliseconds);
return 0;
}

View File

@@ -0,0 +1,21 @@
#include <winpr/crt.h>
#include <winpr/sysinfo.h>
int TestSystemTime(int argc, char* argv[])
{
SYSTEMTIME sTime;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
GetSystemTime(&sTime);
printf("GetSystemTime: wYear: %" PRIu16 " wMonth: %" PRIu16 " wDayOfWeek: %" PRIu16
" wDay: %" PRIu16 " wHour: %" PRIu16 " wMinute: %" PRIu16 " wSecond: %" PRIu16
" wMilliseconds: %" PRIu16 "\n",
sTime.wYear, sTime.wMonth, sTime.wDayOfWeek, sTime.wDay, sTime.wHour, sTime.wMinute,
sTime.wSecond, sTime.wMilliseconds);
return 0;
}