wtsapi32: Improve WTSEnumerateSessionsW() stub.

This commit is contained in:
Paul Gofman 2023-09-07 10:03:00 -06:00 committed by Alexandre Julliard
parent 7c94e4243c
commit 6c3399a9b3
2 changed files with 53 additions and 7 deletions

View file

@ -306,6 +306,38 @@ static void test_WTSQueryUserToken(void)
ok(GetLastError()==ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %ld\n", GetLastError());
}
static void test_WTSEnumerateSessions(void)
{
BOOL console_found = FALSE, services_found = FALSE;
WTS_SESSION_INFOW *info;
unsigned int i;
DWORD count;
BOOL bret;
bret = WTSEnumerateSessionsW(WTS_CURRENT_SERVER_HANDLE, 0, 1, &info, &count);
ok(bret, "got error %lu.\n", GetLastError());
todo_wine_if(count == 1) ok(count >= 2, "got %lu.\n", count);
for (i = 0; i < count; ++i)
{
trace("SessionId %lu, name %s, State %d.\n", info[i].SessionId, debugstr_w(info[i].pWinStationName), info[i].State);
if (!wcscmp(info[i].pWinStationName, L"Console"))
{
console_found = TRUE;
ok(info[i].State == WTSActive, "got State %d.\n", info[i].State);
}
else if (!wcscmp(info[i].pWinStationName, L"Services"))
{
services_found = TRUE;
ok(info[i].State == WTSDisconnected, "got State %d.\n", info[i].State);
}
}
ok(console_found, "Console session not found.\n");
todo_wine ok(services_found, "Services session not found.\n");
WTSFreeMemory(info);
}
START_TEST (wtsapi)
{
pWTSEnumerateProcessesExW = (void *)GetProcAddress(GetModuleHandleA("wtsapi32"), "WTSEnumerateProcessesExW");
@ -314,4 +346,5 @@ START_TEST (wtsapi)
test_WTSEnumerateProcessesW();
test_WTSQuerySessionInformation();
test_WTSQueryUserToken();
test_WTSEnumerateSessions();
}

View file

@ -309,16 +309,29 @@ BOOL WINAPI WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version,
/************************************************************
* WTSEnumerateEnumerateSessionsW (WTSAPI32.@)
*/
BOOL WINAPI WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version,
PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount)
BOOL WINAPI WTSEnumerateSessionsW(HANDLE server, DWORD reserved, DWORD version,
PWTS_SESSION_INFOW *session_info, DWORD *count)
{
FIXME("Stub %p 0x%08lx 0x%08lx %p %p\n", hServer, Reserved, Version,
ppSessionInfo, pCount);
static const WCHAR session_name[] = L"Console";
if (!ppSessionInfo || !pCount) return FALSE;
FIXME("%p 0x%08lx 0x%08lx %p %p semi-stub.\n", server, reserved, version, session_info, count);
*pCount = 0;
*ppSessionInfo = NULL;
if (!session_info || !count) return FALSE;
if (!(*session_info = heap_alloc(sizeof(**session_info) + sizeof(session_name))))
{
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
if (!ProcessIdToSessionId( GetCurrentProcessId(), &(*session_info)->SessionId))
{
WTSFreeMemory(*session_info);
return FALSE;
}
*count = 1;
(*session_info)->State = WTSActive;
(*session_info)->pWinStationName = (WCHAR *)((char *)*session_info + sizeof(**session_info));
memcpy((*session_info)->pWinStationName, session_name, sizeof(session_name));
return TRUE;
}