2014-02-19 21:30:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Stefan Leichter
|
|
|
|
*
|
|
|
|
* 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 <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winternl.h>
|
|
|
|
#include <wtsapi32.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
static void test_WTSEnumerateProcessesW(void)
|
|
|
|
{
|
|
|
|
BOOL found = FALSE, ret;
|
|
|
|
DWORD count, i;
|
|
|
|
PWTS_PROCESS_INFOW info;
|
|
|
|
WCHAR *pname, nameW[MAX_PATH];
|
|
|
|
|
|
|
|
GetModuleFileNameW(NULL, nameW, MAX_PATH);
|
|
|
|
for (pname = nameW + lstrlenW(nameW); pname > nameW; pname--)
|
|
|
|
{
|
|
|
|
if(*pname == '/' || *pname == '\\')
|
|
|
|
{
|
|
|
|
pname++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info = NULL;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 1, 1, &info, &count);
|
|
|
|
ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
|
|
|
|
ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
|
2018-04-11 12:05:47 +02:00
|
|
|
WTSFreeMemory(info);
|
2014-02-19 21:30:39 +01:00
|
|
|
|
|
|
|
info = NULL;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 0, &info, &count);
|
|
|
|
ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
|
|
|
|
ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
|
2018-04-11 12:05:47 +02:00
|
|
|
WTSFreeMemory(info);
|
2014-02-19 21:30:39 +01:00
|
|
|
|
|
|
|
info = NULL;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 2, &info, &count);
|
|
|
|
ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
|
|
|
|
ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
|
2018-04-11 12:05:47 +02:00
|
|
|
WTSFreeMemory(info);
|
2014-02-19 21:30:39 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 1, NULL, &count);
|
|
|
|
ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
|
|
|
|
ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
|
|
|
|
|
|
|
|
info = NULL;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 1, &info, NULL);
|
|
|
|
ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
|
|
|
|
ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
|
2018-04-11 12:05:47 +02:00
|
|
|
WTSFreeMemory(info);
|
2014-02-19 21:30:39 +01:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
info = NULL;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 1, &info, &count);
|
|
|
|
ok(ret || broken(!ret), /* fails on Win2K with error ERROR_APP_WRONG_OS */
|
|
|
|
"expected WTSEnumerateProcessesW to succeed; failed with %d\n", GetLastError());
|
|
|
|
for(i = 0; ret && i < count; i++)
|
|
|
|
{
|
|
|
|
found = found || !lstrcmpW(pname, info[i].pProcessName);
|
|
|
|
}
|
|
|
|
todo_wine
|
|
|
|
ok(found || broken(!ret), "process name %s not found\n", wine_dbgstr_w(pname));
|
2018-04-11 12:05:47 +02:00
|
|
|
WTSFreeMemory(info);
|
2014-02-19 21:30:39 +01:00
|
|
|
}
|
|
|
|
|
2018-04-11 12:05:48 +02:00
|
|
|
static void test_WTSQuerySessionInformationW(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
WCHAR *buf;
|
|
|
|
DWORD count;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
buf = NULL;
|
|
|
|
ret = WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSUserName, &buf, &count);
|
|
|
|
ok(ret, "got %u\n", GetLastError());
|
|
|
|
ok(buf != NULL, "buf not set\n");
|
|
|
|
ok(count == (lstrlenW(buf) + 1) * sizeof(WCHAR), "got %u\n", count);
|
|
|
|
WTSFreeMemory(buf);
|
|
|
|
}
|
|
|
|
|
2019-01-06 04:17:54 +01:00
|
|
|
static void test_WTSQueryUserToken(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WTSQueryUserToken(WTS_CURRENT_SESSION, NULL);
|
|
|
|
ok(!ret, "expected WTSQueryUserToken to fail\n");
|
|
|
|
ok(GetLastError()==ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2014-02-19 21:30:39 +01:00
|
|
|
START_TEST (wtsapi)
|
|
|
|
{
|
|
|
|
test_WTSEnumerateProcessesW();
|
2018-04-11 12:05:48 +02:00
|
|
|
test_WTSQuerySessionInformationW();
|
2019-01-06 04:17:54 +01:00
|
|
|
test_WTSQueryUserToken();
|
2014-02-19 21:30:39 +01:00
|
|
|
}
|