Paul Vriens : advapi/service: First tests (and fixes) for
CreateService.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu Jul 12 08:32:24 CDT 2007
Module: wine
Branch: master
Commit: 5dab8935b928c43e1050dffa55bbb37d270bc132
URL: http://source.winehq.org/git/wine.git/?a=commit;h=5dab8935b928c43e1050dffa55bbb37d270bc132
Author: Paul Vriens <paul.vriens.wine at gmail.com>
Date: Wed Jul 11 21:10:36 2007 +0200
advapi/service: First tests (and fixes) for CreateService.
---
dlls/advapi32/service.c | 6 ++++
dlls/advapi32/tests/service.c | 54 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c
index 55e9716..54bfc8e 100644
--- a/dlls/advapi32/service.c
+++ b/dlls/advapi32/service.c
@@ -1309,6 +1309,12 @@ CreateServiceW( SC_HANDLE hSCManager, LPCWSTR lpServiceName,
return NULL;
}
+ if (!lpServiceName || !lpBinaryPathName)
+ {
+ SetLastError(ERROR_INVALID_ADDRESS);
+ return NULL;
+ }
+
r = RegCreateKeyExW(hscm->hkey, lpServiceName, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dp);
if (r!=ERROR_SUCCESS)
diff --git a/dlls/advapi32/tests/service.c b/dlls/advapi32/tests/service.c
index b3779f9..be526bd 100644
--- a/dlls/advapi32/tests/service.c
+++ b/dlls/advapi32/tests/service.c
@@ -132,6 +132,59 @@ static void test_open_svc(void)
CloseServiceHandle(scm_handle);
}
+static void test_create_delete_svc(void)
+{
+ SC_HANDLE scm_handle, svc_handle1;
+ static const CHAR servicename [] = "Winetest";
+ static const CHAR pathname [] = "we_dont_care.exe";
+
+ /* All NULL */
+ SetLastError(0xdeadbeef);
+ svc_handle1 = CreateServiceA(NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL);
+ ok(!svc_handle1, "Expected failure\n");
+ ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
+
+ scm_handle = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
+
+ /* Only a valid handle to the Service Control Manager */
+ SetLastError(0xdeadbeef);
+ svc_handle1 = CreateServiceA(scm_handle, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL);
+ ok(!svc_handle1, "Expected failure\n");
+ ok(GetLastError() == ERROR_INVALID_ADDRESS /* W2K, W2K3, XP, Vista */ ||
+ GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
+ "Expected ERROR_INVALID_ADDRESS or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
+
+ /* Now with a servicename */
+ SetLastError(0xdeadbeef);
+ svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL);
+ ok(!svc_handle1, "Expected failure\n");
+ ok(GetLastError() == ERROR_INVALID_ADDRESS /* W2K, W2K3, XP, Vista */ ||
+ GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
+ "Expected ERROR_INVALID_ADDRESS or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
+
+ /* Or just a binary name */
+ SetLastError(0xdeadbeef);
+ svc_handle1 = CreateServiceA(scm_handle, NULL, NULL, 0, 0, 0, 0, pathname, NULL, NULL, NULL, NULL, NULL);
+ ok(!svc_handle1, "Expected failure\n");
+ ok(GetLastError() == ERROR_INVALID_ADDRESS /* W2K, W2K3, XP, Vista */ ||
+ GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
+ "Expected ERROR_INVALID_ADDRESS or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
+
+ /* Both servicename and binary name (We only have connect rights) */
+ SetLastError(0xdeadbeef);
+ svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, 0, 0, 0, pathname, NULL, NULL, NULL, NULL, NULL);
+ todo_wine
+ {
+ ok(!svc_handle1, "Expected failure\n");
+ ok(GetLastError() == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
+ DeleteService(svc_handle1); /* Wine doesn't care (yet) about access rights, line can be removed when fixed */
+ CloseServiceHandle(svc_handle1); /* Wine doesn't care (yet) about access rights, line can be removed when fixed */
+ }
+
+ CloseServiceHandle(scm_handle);
+}
+
+
static void test_close(void)
{
SC_HANDLE handle;
@@ -290,6 +343,7 @@ START_TEST(service)
/* First some parameter checking */
test_open_scm();
test_open_svc();
+ test_create_delete_svc();
test_close();
/* Test the creation, querying and deletion of a service */
test_sequence();
More information about the wine-cvs
mailing list