2011-09-27 13:06:33 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS api tests
|
|
|
|
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Test for CreateService
|
2013-10-12 16:05:54 +00:00
|
|
|
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
|
2011-09-27 13:06:33 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-22 17:52:42 +00:00
|
|
|
#include <apitest.h>
|
|
|
|
|
2013-02-05 17:54:22 +00:00
|
|
|
#include <winreg.h>
|
|
|
|
#include <winsvc.h>
|
2011-09-27 13:06:33 +00:00
|
|
|
#include <strsafe.h>
|
|
|
|
|
|
|
|
static int MakeService(SC_HANDLE hScm, const wchar_t *serviceName, SC_HANDLE *hService, DWORD *tag)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
HKEY hKey = NULL;
|
|
|
|
DWORD type = 0, tagData = 0, tagSize;
|
|
|
|
wchar_t keyName[256];
|
|
|
|
|
|
|
|
SetLastError(DNS_ERROR_RCODE_NXRRSET);
|
|
|
|
*hService = CreateServiceW(
|
|
|
|
hScm,
|
|
|
|
serviceName,
|
|
|
|
NULL,
|
|
|
|
DELETE,
|
|
|
|
SERVICE_KERNEL_DRIVER,
|
|
|
|
SERVICE_BOOT_START,
|
|
|
|
SERVICE_ERROR_IGNORE,
|
|
|
|
L"%systemroot%\\drivers\\win32k.sys",
|
|
|
|
L"advapi32_apitest_CreateService_Test_Group",
|
|
|
|
tag,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
ok(*hService != NULL, "Failed to create service, error=0x%08lx\n", GetLastError());
|
|
|
|
if (!*hService)
|
|
|
|
{
|
|
|
|
skip("No service; cannot proceed with CreateService test\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-06-27 14:55:22 +00:00
|
|
|
ok_err(ERROR_SUCCESS);
|
2011-09-27 13:06:33 +00:00
|
|
|
|
|
|
|
ok(*tag != 0, "tag is zero, expected nonzero\n");
|
|
|
|
|
|
|
|
StringCbPrintfW(keyName, sizeof keyName, L"System\\CurrentControlSet\\Services\\%ls", serviceName);
|
|
|
|
ret = RegOpenKeyW(HKEY_LOCAL_MACHINE, keyName, &hKey);
|
|
|
|
ok(ret == ERROR_SUCCESS, "RegOpenKeyW failed with 0x%08lx\n", ret);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
skip("No regkey; cannot proceed with CreateService test\n");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
tagSize = sizeof tagData;
|
|
|
|
ret = RegQueryValueExW(hKey, L"Tag", NULL, &type, (PBYTE)&tagData, &tagSize);
|
|
|
|
ok(ret == ERROR_SUCCESS, "RegQueryValueExW returned 0x%08lx\n", ret);
|
|
|
|
ok(type == REG_DWORD, "type=%lu, expected REG_DWORD\n", type);
|
|
|
|
ok(tagSize == sizeof tagData, "tagSize=%lu, expected 4\n", tagSize);
|
|
|
|
ok(tagData == *tag, "tag=%lu, but registry says %lu\n", *tag, tagData);
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-02 21:42:33 +00:00
|
|
|
static void DestroyService(SC_HANDLE hService)
|
|
|
|
{
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
if (!hService)
|
|
|
|
return;
|
|
|
|
SetLastError(DNS_ERROR_RCODE_NXRRSET);
|
|
|
|
ret = DeleteService(hService);
|
|
|
|
ok(ret == TRUE, "DeleteService returned %ld, expected 1\n", ret);
|
|
|
|
ok(GetLastError() == DNS_ERROR_RCODE_NXRRSET /* win7 */
|
|
|
|
|| GetLastError() == ERROR_SUCCESS /* win2k3 */, "DeleteService GetLastError()=0x%08lx\n", GetLastError());
|
|
|
|
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
}
|
|
|
|
|
2011-09-27 13:06:33 +00:00
|
|
|
static void Test_CreateService(void)
|
|
|
|
{
|
|
|
|
SC_HANDLE hScm = NULL;
|
|
|
|
SC_HANDLE hService1 = NULL, hService2 = NULL;
|
2011-10-02 21:42:33 +00:00
|
|
|
SC_HANDLE hService3 = NULL;
|
2011-09-27 13:06:33 +00:00
|
|
|
DWORD tag1 = 0, tag2 = 0;
|
2011-10-02 21:42:33 +00:00
|
|
|
DWORD tag3 = 785;
|
2011-09-27 13:06:33 +00:00
|
|
|
|
|
|
|
SetLastError(DNS_ERROR_RCODE_NXRRSET);
|
|
|
|
hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
|
|
|
|
ok(hScm != NULL, "Failed to open service manager, error=0x%08lx\n", GetLastError());
|
|
|
|
if (!hScm)
|
|
|
|
{
|
|
|
|
skip("No service control manager; cannot proceed with CreateService test\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-06-27 14:55:22 +00:00
|
|
|
ok_err(ERROR_SUCCESS);
|
2011-09-27 13:06:33 +00:00
|
|
|
|
|
|
|
if (MakeService(hScm, L"advapi32_apitest_CreateService_Test_Service1", &hService1, &tag1))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (MakeService(hScm, L"advapi32_apitest_CreateService_Test_Service2", &hService2, &tag2))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ok(tag1 != tag2, "tag1=%lu, tag2=%lu\n", tag1, tag2);
|
|
|
|
|
2011-10-02 21:42:33 +00:00
|
|
|
/* ask for a tag, but don't have a group */
|
|
|
|
hService3 = CreateServiceW(
|
|
|
|
hScm,
|
|
|
|
L"advapi32_apitest_CreateService_Test_Service2",
|
|
|
|
NULL,
|
|
|
|
DELETE,
|
|
|
|
SERVICE_KERNEL_DRIVER,
|
|
|
|
SERVICE_BOOT_START,
|
|
|
|
SERVICE_ERROR_IGNORE,
|
|
|
|
L"%systemroot%\\drivers\\win32k.sys",
|
|
|
|
NULL,
|
|
|
|
&tag3,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
ok(hService3 == NULL, "hService3=%p\n", hService3);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "error=%lu\n", GetLastError());
|
|
|
|
ok(tag3 == 785, "tag3=%lu\n", tag3);
|
|
|
|
DestroyService(hService3);
|
2011-09-27 13:06:33 +00:00
|
|
|
|
2011-10-02 21:42:33 +00:00
|
|
|
hService3 = CreateServiceW(
|
|
|
|
hScm,
|
|
|
|
L"advapi32_apitest_CreateService_Test_Service2",
|
|
|
|
NULL,
|
|
|
|
DELETE,
|
|
|
|
SERVICE_KERNEL_DRIVER,
|
|
|
|
SERVICE_BOOT_START,
|
|
|
|
SERVICE_ERROR_IGNORE,
|
|
|
|
L"%systemroot%\\drivers\\win32k.sys",
|
|
|
|
L"",
|
|
|
|
&tag3,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
ok(hService3 == NULL, "hService3=%p\n", hService3);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "error=%lu\n", GetLastError());
|
|
|
|
ok(tag3 == 785, "tag3=%lu\n", tag3);
|
|
|
|
DestroyService(hService3);
|
2011-09-27 13:06:33 +00:00
|
|
|
|
2011-10-02 21:42:33 +00:00
|
|
|
cleanup:
|
2011-09-27 13:06:33 +00:00
|
|
|
|
2011-10-02 21:42:33 +00:00
|
|
|
DestroyService(hService2);
|
|
|
|
DestroyService(hService1);
|
2011-09-27 13:06:33 +00:00
|
|
|
|
|
|
|
if (hScm)
|
|
|
|
CloseServiceHandle(hScm);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(CreateService)
|
|
|
|
{
|
|
|
|
Test_CreateService();
|
|
|
|
}
|