Commit af27e215 authored by Paul Vriens's avatar Paul Vriens Committed by Alexandre Julliard

advapi32/service: Some tests for DeleteService.

parent f8f6340a
...@@ -1558,6 +1558,12 @@ BOOL WINAPI DeleteService( SC_HANDLE hService ) ...@@ -1558,6 +1558,12 @@ BOOL WINAPI DeleteService( SC_HANDLE hService )
return FALSE; return FALSE;
} }
if (!(hsvc->dwAccess & DELETE))
{
SetLastError(ERROR_ACCESS_DENIED);
return FALSE;
}
/* Close the key to the service */ /* Close the key to the service */
RegCloseKey(hsvc->hkey); RegCloseKey(hsvc->hkey);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winerror.h" #include "winerror.h"
#include "winreg.h"
#include "winsvc.h" #include "winsvc.h"
#include "lmcons.h" #include "lmcons.h"
...@@ -323,9 +324,58 @@ static void test_create_delete_svc(void) ...@@ -323,9 +324,58 @@ static void test_create_delete_svc(void)
else else
skip("Could not retrieve a displayname (Spooler service doesn't exist)\n"); 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); 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) static void test_close(void)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment