Paul Vriens : advapi32/service: Some tests for DeleteService.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Jul 19 07:59:42 CDT 2007


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

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

advapi32/service: Some tests for DeleteService.

---

 dlls/advapi32/service.c       |    6 ++++
 dlls/advapi32/tests/service.c |   52 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c
index 76f8290..15fd4b2 100644
--- a/dlls/advapi32/service.c
+++ b/dlls/advapi32/service.c
@@ -1558,6 +1558,12 @@ BOOL WINAPI DeleteService( SC_HANDLE hService )
         return FALSE;
     }
 
+    if (!(hsvc->dwAccess & DELETE))
+    {
+        SetLastError(ERROR_ACCESS_DENIED);
+        return FALSE;
+    }
+
     /* Close the key to the service */
     RegCloseKey(hsvc->hkey);
 
diff --git a/dlls/advapi32/tests/service.c b/dlls/advapi32/tests/service.c
index 0547686..0bdb0bf 100644
--- a/dlls/advapi32/tests/service.c
+++ b/dlls/advapi32/tests/service.c
@@ -23,6 +23,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winerror.h"
+#include "winreg.h"
 #include "winsvc.h"
 #include "lmcons.h"
 
@@ -323,9 +324,58 @@ static void test_create_delete_svc(void)
     else
         skip("Could not retrieve a displayname (Spooler service doesn't exist)\n");
 
+    /* Windows doesn't care about the access rights for creation (which makes
+     * sense as there is no service yet) as long as there are sufficient
+     * rights to the manager.
+     */
+    SetLastError(0xdeadbeef);
+    svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
+                                 SERVICE_DISABLED, 0, pathname, NULL, NULL, NULL, NULL, NULL);
+    ok(svc_handle1 != NULL, "Could not create the service : %d\n", GetLastError());
+    ok(GetLastError() == ERROR_SUCCESS    /* W2K3, Vista */ ||
+       GetLastError() == 0xdeadbeef       /* NT4, XP */ ||
+       GetLastError() == ERROR_IO_PENDING /* W2K */,
+       "Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
+
+    /* DeleteService however must have proper rights */
+    SetLastError(0xdeadbeef);
+    ret = DeleteService(svc_handle1);
+    ok(!ret, "Expected failure\n");
+    ok(GetLastError() == ERROR_ACCESS_DENIED,
+       "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
+
+    /* Open the service with minimal rights for deletion.
+     * (Verified with 'SERVICE_ALL_ACCESS &~ DELETE')
+     */
+    CloseServiceHandle(svc_handle1);
+    svc_handle1 = OpenServiceA(scm_handle, servicename, DELETE);
+
+    /* Now that we have the proper rights, we should be able to delete */
+    SetLastError(0xdeadbeef);
+    ret = DeleteService(svc_handle1);
+    ok(ret, "Expected success\n");
+    ok(GetLastError() == ERROR_SUCCESS    /* W2K3 */ ||
+       GetLastError() == 0xdeadbeef       /* NT4, XP, Vista */ ||
+       GetLastError() == ERROR_IO_PENDING /* W2K */,
+       "Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
+
+    CloseServiceHandle(svc_handle1);
+
     CloseServiceHandle(scm_handle);
-}
 
+    /* Wait a while. One of the following tests also does a CreateService for the
+     * same servicename and this would result in an ERROR_SERVICE_MARKED_FOR_DELETE
+     * error if we do this to quick. Vista seems more picky then the others.
+     */
+    Sleep(1000);
+
+    /* And a final NULL check */
+    SetLastError(0xdeadbeef);
+    ret = DeleteService(NULL);
+    ok(!ret, "Expected failure\n");
+    ok(GetLastError() == ERROR_INVALID_HANDLE,
+        "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
+}
 
 static void test_close(void)
 {




More information about the wine-cvs mailing list