Paul Vriens : advapi/service: Check if we have enough access rights to create a service.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Jul 12 08:32:24 CDT 2007


Module: wine
Branch: master
Commit: c011369aab8087882ac1535448cc1c806c512761
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c011369aab8087882ac1535448cc1c806c512761

Author: Paul Vriens <paul.vriens.wine at gmail.com>
Date:   Wed Jul 11 21:22:21 2007 +0200

advapi/service: Check if we have enough access rights to create a service.

---

 dlls/advapi32/service.c       |    6 ++++++
 dlls/advapi32/tests/service.c |   17 ++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c
index 54bfc8e..d95796f 100644
--- a/dlls/advapi32/service.c
+++ b/dlls/advapi32/service.c
@@ -1315,6 +1315,12 @@ CreateServiceW( SC_HANDLE hSCManager, LPCWSTR lpServiceName,
         return NULL;
     }
 
+    if (!(hscm->dwAccess & SC_MANAGER_CREATE_SERVICE))
+    {
+        SetLastError(ERROR_ACCESS_DENIED);
+        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 be526bd..0003db5 100644
--- a/dlls/advapi32/tests/service.c
+++ b/dlls/advapi32/tests/service.c
@@ -137,6 +137,7 @@ 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";
+    static const CHAR empty               [] = "";
 
     /* All NULL */
     SetLastError(0xdeadbeef);
@@ -173,13 +174,19 @@ static void test_create_delete_svc(void)
     /* 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 */
-    }
+
+    /* They can even be empty at this stage of parameter checking */
+    SetLastError(0xdeadbeef);
+    svc_handle1 = CreateServiceA(scm_handle, empty, NULL, 0, 0, 0, 0, pathname, NULL, NULL, NULL, NULL, NULL);
+    ok(!svc_handle1, "Expected failure\n");
+    ok(GetLastError() == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, 0, 0, 0, empty, NULL, NULL, NULL, NULL, NULL);
+    ok(!svc_handle1, "Expected failure\n");
+    ok(GetLastError() == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
 
     CloseServiceHandle(scm_handle);
 }




More information about the wine-cvs mailing list