2 * PROJECT: ReactOS Service Control Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/services/rpcserver.c
5 * PURPOSE: RPC server interface for the advapi32 calls
6 * COPYRIGHT: Copyright 2005-2006 Eric Kohl
7 * Copyright 2006-2007 Hervé Poussineau <hpoussin@reactos.org>
8 * Copyright 2007 Ged Murphy <gedmurphy@reactos.org>
11 /* INCLUDES ****************************************************************/
19 /* GLOBALS *****************************************************************/
21 #define MANAGER_TAG 0x72674D68 /* 'hMgr' */
22 #define SERVICE_TAG 0x63765368 /* 'hSvc' */
24 typedef struct _SCMGR_HANDLE
32 typedef struct _MANAGER_HANDLE
36 /* FIXME: Insert more data here */
38 WCHAR DatabaseName
[1];
39 } MANAGER_HANDLE
, *PMANAGER_HANDLE
;
42 typedef struct _SERVICE_HANDLE
47 PSERVICE ServiceEntry
;
49 /* FIXME: Insert more data here */
51 } SERVICE_HANDLE
, *PSERVICE_HANDLE
;
54 #define SC_MANAGER_READ \
55 (STANDARD_RIGHTS_READ | \
56 SC_MANAGER_QUERY_LOCK_STATUS | \
57 SC_MANAGER_ENUMERATE_SERVICE)
59 #define SC_MANAGER_WRITE \
60 (STANDARD_RIGHTS_WRITE | \
61 SC_MANAGER_MODIFY_BOOT_CONFIG | \
62 SC_MANAGER_CREATE_SERVICE)
64 #define SC_MANAGER_EXECUTE \
65 (STANDARD_RIGHTS_EXECUTE | \
67 SC_MANAGER_ENUMERATE_SERVICE | \
68 SC_MANAGER_CONNECT | \
69 SC_MANAGER_CREATE_SERVICE)
72 #define SERVICE_READ \
73 (STANDARD_RIGHTS_READ | \
74 SERVICE_INTERROGATE | \
75 SERVICE_ENUMERATE_DEPENDENTS | \
76 SERVICE_QUERY_STATUS | \
79 #define SERVICE_WRITE \
80 (STANDARD_RIGHTS_WRITE | \
81 SERVICE_CHANGE_CONFIG)
83 #define SERVICE_EXECUTE \
84 (STANDARD_RIGHTS_EXECUTE | \
85 SERVICE_USER_DEFINED_CONTROL | \
86 SERVICE_PAUSE_CONTINUE | \
91 /* VARIABLES ***************************************************************/
93 static GENERIC_MAPPING
94 ScmManagerMapping
= {SC_MANAGER_READ
,
97 SC_MANAGER_ALL_ACCESS
};
99 static GENERIC_MAPPING
100 ScmServiceMapping
= {SERVICE_READ
,
103 SC_MANAGER_ALL_ACCESS
};
106 /* FUNCTIONS ***************************************************************/
109 ScmStartRpcServer(VOID
)
113 DPRINT("ScmStartRpcServer() called\n");
115 Status
= RpcServerUseProtseqEpW(L
"ncacn_np",
119 if (Status
!= RPC_S_OK
)
121 DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status
);
125 Status
= RpcServerRegisterIf(svcctl_v2_0_s_ifspec
,
128 if (Status
!= RPC_S_OK
)
130 DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status
);
134 Status
= RpcServerListen(1, 20, TRUE
);
135 if (Status
!= RPC_S_OK
)
137 DPRINT1("RpcServerListen() failed (Status %lx)\n", Status
);
141 DPRINT("ScmStartRpcServer() done\n");
146 ScmCreateManagerHandle(LPWSTR lpDatabaseName
,
151 if (lpDatabaseName
== NULL
)
152 lpDatabaseName
= SERVICES_ACTIVE_DATABASEW
;
154 if (_wcsicmp(lpDatabaseName
,SERVICES_FAILED_DATABASEW
)==0)
156 DPRINT1("Database %S, does not exist\n",lpDatabaseName
);
157 return ERROR_DATABASE_DOES_NOT_EXIST
;
159 else if (_wcsicmp(lpDatabaseName
, SERVICES_ACTIVE_DATABASEW
) != 0)
161 DPRINT1("Invalid Database name %S.\n",lpDatabaseName
);
162 return ERROR_INVALID_NAME
;
165 Ptr
= (MANAGER_HANDLE
*) HeapAlloc(GetProcessHeap(),
167 sizeof(MANAGER_HANDLE
) + (wcslen(lpDatabaseName
) + 1) * sizeof(WCHAR
));
169 return ERROR_NOT_ENOUGH_MEMORY
;
171 Ptr
->Handle
.Tag
= MANAGER_TAG
;
172 Ptr
->Handle
.RefCount
= 1;
174 /* FIXME: initialize more data here */
176 wcscpy(Ptr
->DatabaseName
, lpDatabaseName
);
178 *Handle
= (SC_HANDLE
)Ptr
;
180 return ERROR_SUCCESS
;
185 ScmCreateServiceHandle(PSERVICE lpServiceEntry
,
190 Ptr
= (SERVICE_HANDLE
*) HeapAlloc(GetProcessHeap(),
192 sizeof(SERVICE_HANDLE
));
194 return ERROR_NOT_ENOUGH_MEMORY
;
196 Ptr
->Handle
.Tag
= SERVICE_TAG
;
197 Ptr
->Handle
.RefCount
= 1;
199 /* FIXME: initialize more data here */
200 Ptr
->ServiceEntry
= lpServiceEntry
;
202 *Handle
= (SC_HANDLE
)Ptr
;
204 return ERROR_SUCCESS
;
209 ScmCheckAccess(SC_HANDLE Handle
,
210 DWORD dwDesiredAccess
)
212 PMANAGER_HANDLE hMgr
;
214 hMgr
= (PMANAGER_HANDLE
)Handle
;
215 if (hMgr
->Handle
.Tag
== MANAGER_TAG
)
217 RtlMapGenericMask(&dwDesiredAccess
,
220 hMgr
->Handle
.DesiredAccess
= dwDesiredAccess
;
222 return ERROR_SUCCESS
;
224 else if (hMgr
->Handle
.Tag
== SERVICE_TAG
)
226 RtlMapGenericMask(&dwDesiredAccess
,
229 hMgr
->Handle
.DesiredAccess
= dwDesiredAccess
;
231 return ERROR_SUCCESS
;
234 return ERROR_INVALID_HANDLE
;
239 ScmAssignNewTag(PSERVICE lpService
)
242 DPRINT("Assigning new tag to service %S\n", lpService
->lpServiceName
);
243 lpService
->dwTag
= 0;
244 return ERROR_SUCCESS
;
248 /* Internal recursive function */
249 /* Need to search for every dependency on every service */
251 Int_EnumDependentServicesW(HKEY hServicesKey
,
253 DWORD dwServiceState
,
254 PSERVICE
*lpServices
,
255 LPDWORD pcbBytesNeeded
,
256 LPDWORD lpServicesReturned
)
258 DWORD dwError
= ERROR_SUCCESS
;
259 WCHAR szNameBuf
[MAX_PATH
];
260 WCHAR szValueBuf
[MAX_PATH
];
261 WCHAR
*lpszNameBuf
= szNameBuf
;
262 WCHAR
*lpszValueBuf
= szValueBuf
;
266 PSERVICE lpCurrentService
;
267 HKEY hServiceEnumKey
;
268 DWORD dwCurrentServiceState
= SERVICE_ACTIVE
;
269 DWORD dwDependServiceStrPtr
= 0;
270 DWORD dwRequiredSize
= 0;
272 /* Get the number of service keys */
273 dwError
= RegQueryInfoKeyW(hServicesKey
,
285 if (dwError
!= ERROR_SUCCESS
)
287 DPRINT1("ERROR! Unable to get number of services keys.\n");
291 /* Iterate the service keys to see if another service depends on the this service */
292 for (dwIteration
= 0; dwIteration
< dwNumSubKeys
; dwIteration
++)
295 dwError
= RegEnumKeyExW(hServicesKey
,
303 if (dwError
!= ERROR_SUCCESS
)
306 /* Open the Service key */
307 dwError
= RegOpenKeyExW(hServicesKey
,
312 if (dwError
!= ERROR_SUCCESS
)
317 /* Check for the DependOnService Value */
318 dwError
= RegQueryValueExW(hServiceEnumKey
,
322 (LPBYTE
)lpszValueBuf
,
325 /* FIXME: Handle load order. */
327 /* If the service found has a DependOnService value */
328 if (dwError
== ERROR_SUCCESS
)
330 dwDependServiceStrPtr
= 0;
332 /* Can be more than one Dependencies in the DependOnService string */
333 while (wcslen(lpszValueBuf
+ dwDependServiceStrPtr
) > 0)
335 if (_wcsicmp(lpszValueBuf
+ dwDependServiceStrPtr
, lpService
->lpServiceName
) == 0)
337 /* Get the current enumed service pointer */
338 lpCurrentService
= ScmGetServiceEntryByName(lpszNameBuf
);
340 /* Check for valid Service */
341 if (!lpCurrentService
)
343 /* This should never happen! */
344 DPRINT1("This should not happen at this point, report to Developer\n");
345 return ERROR_NOT_FOUND
;
348 /* Determine state the service is in */
349 if (lpCurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
350 dwCurrentServiceState
= SERVICE_INACTIVE
;
352 /* If the ServiceState matches that requested or searching for SERVICE_STATE_ALL */
353 if ((dwCurrentServiceState
== dwServiceState
) ||
354 (dwServiceState
== SERVICE_STATE_ALL
))
356 /* Calculate the required size */
357 dwRequiredSize
+= sizeof(SERVICE_STATUS
);
358 dwRequiredSize
+= ((wcslen(lpCurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
));
359 dwRequiredSize
+= ((wcslen(lpCurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
361 /* Add the size for service name and display name pointers */
362 dwRequiredSize
+= (2 * sizeof(PVOID
));
364 /* increase the BytesNeeded size */
365 *pcbBytesNeeded
= *pcbBytesNeeded
+ dwRequiredSize
;
367 /* Don't fill callers buffer yet, as MSDN read that the last service with dependency
370 /* Recursive call to check for its dependencies */
371 Int_EnumDependentServicesW(hServicesKey
,
378 /* If the lpServices is valid set the service pointer */
380 lpServices
[*lpServicesReturned
] = lpCurrentService
;
382 *lpServicesReturned
= *lpServicesReturned
+ 1;
386 dwDependServiceStrPtr
+= (wcslen(lpszValueBuf
+ dwDependServiceStrPtr
) + 1);
389 else if (*pcbBytesNeeded
)
391 dwError
= ERROR_SUCCESS
;
394 RegCloseKey(hServiceEnumKey
);
402 DWORD
RCloseServiceHandle(
403 LPSC_RPC_HANDLE hSCObject
)
405 PMANAGER_HANDLE hManager
;
406 PSERVICE_HANDLE hService
;
410 DWORD pcbBytesNeeded
= 0;
411 DWORD dwServicesReturned
= 0;
413 DPRINT("RCloseServiceHandle() called\n");
415 DPRINT("hSCObject = %p\n", *hSCObject
);
418 return ERROR_INVALID_HANDLE
;
420 hManager
= (PMANAGER_HANDLE
)*hSCObject
;
421 hService
= (PSERVICE_HANDLE
)*hSCObject
;
422 if (hManager
->Handle
.Tag
== MANAGER_TAG
)
424 DPRINT("Found manager handle\n");
426 hManager
->Handle
.RefCount
--;
427 if (hManager
->Handle
.RefCount
== 0)
429 /* FIXME: add handle cleanup code */
431 HeapFree(GetProcessHeap(), 0, hManager
);
435 DPRINT("RCloseServiceHandle() done\n");
436 return ERROR_SUCCESS
;
438 else if (hService
->Handle
.Tag
== SERVICE_TAG
)
440 DPRINT("Found service handle\n");
442 /* Get the pointer to the service record */
443 lpService
= hService
->ServiceEntry
;
445 ASSERT(hService
->Handle
.RefCount
> 0);
447 hService
->Handle
.RefCount
--;
448 if (hService
->Handle
.RefCount
== 0)
450 /* FIXME: add handle cleanup code */
452 /* Free the handle */
453 HeapFree(GetProcessHeap(), 0, hService
);
457 ASSERT(lpService
->dwRefCount
> 0);
459 lpService
->dwRefCount
--;
460 DPRINT("CloseServiceHandle - lpService->dwRefCount %u\n",
461 lpService
->dwRefCount
);
463 if (lpService
->dwRefCount
== 0)
465 /* If this service has been marked for deletion */
466 if (lpService
->bDeleted
)
468 /* Open the Services Reg key */
469 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
470 L
"System\\CurrentControlSet\\Services",
472 KEY_SET_VALUE
| KEY_READ
,
474 if (dwError
!= ERROR_SUCCESS
)
476 DPRINT1("Failed to open services key\n");
480 /* Call the internal function with NULL, just to get bytes we need */
481 Int_EnumDependentServicesW(hServicesKey
,
486 &dwServicesReturned
);
488 /* if pcbBytesNeeded returned a value then there are services running that are dependent on this service*/
491 DPRINT1("Deletion failed due to running dependencies.\n");
492 RegCloseKey(hServicesKey
);
493 return ERROR_SUCCESS
;
496 /* There are no references and no runnning dependencies,
497 it is now safe to delete the service */
499 /* Delete the Service Key */
500 dwError
= RegDeleteKeyW(hServicesKey
,
501 lpService
->lpServiceName
);
503 RegCloseKey(hServicesKey
);
505 if (dwError
!= ERROR_SUCCESS
)
507 DPRINT1("Failed to Delete the Service Registry key\n");
511 /* Delete the Service */
512 ScmDeleteServiceRecord(lpService
);
516 DPRINT("RCloseServiceHandle() done\n");
517 return ERROR_SUCCESS
;
520 DPRINT1("Invalid handle tag (Tag %lx)\n", hManager
->Handle
.Tag
);
522 return ERROR_INVALID_HANDLE
;
527 DWORD
RControlService(
528 SC_RPC_HANDLE hService
,
530 LPSERVICE_STATUS lpServiceStatus
)
532 PSERVICE_HANDLE hSvc
;
534 ACCESS_MASK DesiredAccess
;
535 DWORD dwError
= ERROR_SUCCESS
;
536 DWORD pcbBytesNeeded
= 0;
537 DWORD dwServicesReturned
= 0;
538 HKEY hServicesKey
= NULL
;
540 DPRINT("RControlService() called\n");
543 return ERROR_SHUTDOWN_IN_PROGRESS
;
545 /* Check the service handle */
546 hSvc
= (PSERVICE_HANDLE
)hService
;
547 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
549 DPRINT1("Invalid handle tag!\n");
550 return ERROR_INVALID_HANDLE
;
553 /* Check the service entry point */
554 lpService
= hSvc
->ServiceEntry
;
555 if (lpService
== NULL
)
557 DPRINT1("lpService == NULL!\n");
558 return ERROR_INVALID_HANDLE
;
561 /* Check access rights */
564 case SERVICE_CONTROL_STOP
:
565 DesiredAccess
= SERVICE_STOP
;
568 case SERVICE_CONTROL_PAUSE
:
569 case SERVICE_CONTROL_CONTINUE
:
570 DesiredAccess
= SERVICE_PAUSE_CONTINUE
;
573 case SERVICE_INTERROGATE
:
574 DesiredAccess
= SERVICE_INTERROGATE
;
578 if (dwControl
>= 128 && dwControl
<= 255)
579 DesiredAccess
= SERVICE_USER_DEFINED_CONTROL
;
581 DesiredAccess
= SERVICE_QUERY_CONFIG
|
582 SERVICE_CHANGE_CONFIG
|
583 SERVICE_QUERY_STATUS
|
585 SERVICE_PAUSE_CONTINUE
;
589 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
591 return ERROR_ACCESS_DENIED
;
593 if (dwControl
== SERVICE_CONTROL_STOP
)
595 /* Check if the service has dependencies running as windows
596 doesn't stop a service that does */
598 /* Open the Services Reg key */
599 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
600 L
"System\\CurrentControlSet\\Services",
604 if (dwError
!= ERROR_SUCCESS
)
606 DPRINT1("Failed to open services key\n");
610 /* Call the internal function with NULL, just to get bytes we need */
611 Int_EnumDependentServicesW(hServicesKey
,
616 &dwServicesReturned
);
618 RegCloseKey(hServicesKey
);
620 /* If pcbBytesNeeded is not zero then there are services running that
621 are dependent on this service */
622 if (pcbBytesNeeded
!= 0)
624 DPRINT("Service has running dependencies. Failed to stop service.\n");
625 return ERROR_DEPENDENT_SERVICES_RUNNING
;
629 if (lpService
->Status
.dwServiceType
& SERVICE_DRIVER
)
631 /* Send control code to the driver */
632 dwError
= ScmControlDriver(lpService
,
638 /* Send control code to the service */
639 dwError
= ScmControlService(lpService
,
644 if ((dwError
== ERROR_SUCCESS
) && (pcbBytesNeeded
))
645 dwError
= ERROR_DEPENDENT_SERVICES_RUNNING
;
647 /* Return service status information */
648 RtlCopyMemory(lpServiceStatus
,
650 sizeof(SERVICE_STATUS
));
657 DWORD
RDeleteService(
658 SC_RPC_HANDLE hService
)
660 PSERVICE_HANDLE hSvc
;
664 DPRINT("RDeleteService() called\n");
667 return ERROR_SHUTDOWN_IN_PROGRESS
;
669 hSvc
= (PSERVICE_HANDLE
)hService
;
670 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
671 return ERROR_INVALID_HANDLE
;
673 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
675 return ERROR_ACCESS_DENIED
;
677 lpService
= hSvc
->ServiceEntry
;
678 if (lpService
== NULL
)
680 DPRINT1("lpService == NULL!\n");
681 return ERROR_INVALID_HANDLE
;
684 /* FIXME: Acquire service database lock exclusively */
686 if (lpService
->bDeleted
)
688 DPRINT1("The service has already been marked for delete!\n");
689 return ERROR_SERVICE_MARKED_FOR_DELETE
;
692 /* Mark service for delete */
693 lpService
->bDeleted
= TRUE
;
695 dwError
= ScmMarkServiceForDelete(lpService
);
697 /* FIXME: Release service database lock */
699 DPRINT("RDeleteService() done\n");
706 DWORD
RLockServiceDatabase(
707 SC_RPC_HANDLE hSCManager
,
708 LPSC_RPC_LOCK lpLock
)
710 PMANAGER_HANDLE hMgr
;
712 DPRINT("RLockServiceDatabase() called\n");
716 hMgr
= (PMANAGER_HANDLE
)hSCManager
;
717 if (!hMgr
|| hMgr
->Handle
.Tag
!= MANAGER_TAG
)
718 return ERROR_INVALID_HANDLE
;
720 if (!RtlAreAllAccessesGranted(hMgr
->Handle
.DesiredAccess
,
722 return ERROR_ACCESS_DENIED
;
724 // return ScmLockDatabase(0, hMgr->0xC, hLock);
726 /* FIXME: Lock the database */
727 *lpLock
= (SC_RPC_LOCK
)0x12345678; /* Dummy! */
729 return ERROR_SUCCESS
;
734 DWORD
RQueryServiceObjectSecurity(
735 SC_RPC_HANDLE hService
,
736 SECURITY_INFORMATION dwSecurityInformation
,
737 LPBYTE lpSecurityDescriptor
,
739 LPBOUNDED_DWORD_256K pcbBytesNeeded
)
741 PSERVICE_HANDLE hSvc
;
743 ULONG DesiredAccess
= 0;
749 SECURITY_DESCRIPTOR ObjectDescriptor
;
751 DPRINT("RQueryServiceObjectSecurity() called\n");
753 hSvc
= (PSERVICE_HANDLE
)hService
;
754 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
756 DPRINT1("Invalid handle tag!\n");
757 return ERROR_INVALID_HANDLE
;
760 if (dwSecurityInformation
& (DACL_SECURITY_INFORMATION
||
761 GROUP_SECURITY_INFORMATION
||
762 OWNER_SECURITY_INFORMATION
))
763 DesiredAccess
|= READ_CONTROL
;
765 if (dwSecurityInformation
& SACL_SECURITY_INFORMATION
)
766 DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
768 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
771 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
772 return ERROR_ACCESS_DENIED
;
775 lpService
= hSvc
->ServiceEntry
;
776 if (lpService
== NULL
)
778 DPRINT1("lpService == NULL!\n");
779 return ERROR_INVALID_HANDLE
;
782 /* FIXME: Lock the service list */
785 Status
= RtlCreateSecurityDescriptor(&ObjectDescriptor
, SECURITY_DESCRIPTOR_REVISION
);
787 Status
= RtlQuerySecurityObject(&ObjectDescriptor
/* lpService->lpSecurityDescriptor */,
788 dwSecurityInformation
,
789 (PSECURITY_DESCRIPTOR
)lpSecurityDescriptor
,
793 /* FIXME: Unlock the service list */
795 if (NT_SUCCESS(Status
))
797 *pcbBytesNeeded
= dwBytesNeeded
;
798 dwError
= STATUS_SUCCESS
;
800 else if (Status
== STATUS_BUFFER_TOO_SMALL
)
802 *pcbBytesNeeded
= dwBytesNeeded
;
803 dwError
= ERROR_INSUFFICIENT_BUFFER
;
805 else if (Status
== STATUS_BAD_DESCRIPTOR_FORMAT
)
807 dwError
= ERROR_GEN_FAILURE
;
811 dwError
= RtlNtStatusToDosError(Status
);
819 DWORD
RSetServiceObjectSecurity(
820 SC_RPC_HANDLE hService
,
821 DWORD dwSecurityInformation
,
822 LPBYTE lpSecurityDescriptor
,
823 DWORD dwSecuityDescriptorSize
)
825 PSERVICE_HANDLE hSvc
;
827 ULONG DesiredAccess
= 0;
828 /* HANDLE hToken = NULL; */
830 /* NTSTATUS Status; */
833 DPRINT1("RSetServiceObjectSecurity() called\n");
835 hSvc
= (PSERVICE_HANDLE
)hService
;
836 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
838 DPRINT1("Invalid handle tag!\n");
839 return ERROR_INVALID_HANDLE
;
842 if (dwSecurityInformation
== 0 ||
843 dwSecurityInformation
& ~(OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
844 | DACL_SECURITY_INFORMATION
| SACL_SECURITY_INFORMATION
))
845 return ERROR_INVALID_PARAMETER
;
847 if (!RtlValidSecurityDescriptor((PSECURITY_DESCRIPTOR
)lpSecurityDescriptor
))
848 return ERROR_INVALID_PARAMETER
;
850 if (dwSecurityInformation
& SACL_SECURITY_INFORMATION
)
851 DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
853 if (dwSecurityInformation
& DACL_SECURITY_INFORMATION
)
854 DesiredAccess
|= WRITE_DAC
;
856 if (dwSecurityInformation
& (OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
))
857 DesiredAccess
|= WRITE_OWNER
;
859 if ((dwSecurityInformation
& OWNER_SECURITY_INFORMATION
) &&
860 (((PISECURITY_DESCRIPTOR
)lpSecurityDescriptor
)->Owner
== NULL
))
861 return ERROR_INVALID_PARAMETER
;
863 if ((dwSecurityInformation
& GROUP_SECURITY_INFORMATION
) &&
864 (((PISECURITY_DESCRIPTOR
)lpSecurityDescriptor
)->Group
== NULL
))
865 return ERROR_INVALID_PARAMETER
;
867 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
870 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
871 return ERROR_ACCESS_DENIED
;
874 lpService
= hSvc
->ServiceEntry
;
875 if (lpService
== NULL
)
877 DPRINT1("lpService == NULL!\n");
878 return ERROR_INVALID_HANDLE
;
881 if (lpService
->bDeleted
)
882 return ERROR_SERVICE_MARKED_FOR_DELETE
;
885 RpcImpersonateClient(NULL
);
887 Status
= NtOpenThreadToken(NtCurrentThread(),
891 if (!NT_SUCCESS(Status
))
892 return RtlNtStatusToDosError(Status
);
896 /* FIXME: Lock service database */
898 Status
= RtlSetSecurityObject(dwSecurityInformation
,
899 (PSECURITY_DESCRIPTOR
)lpSecurityDescriptor
,
900 &lpService
->lpSecurityDescriptor
,
903 if (!NT_SUCCESS(Status
))
905 dwError
= RtlNtStatusToDosError(Status
);
910 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
911 READ_CONTROL
| KEY_CREATE_SUB_KEY
| KEY_SET_VALUE
,
913 if (dwError
!= ERROR_SUCCESS
)
917 dwError
= ERROR_SUCCESS
;
918 // dwError = ScmWriteSecurityDescriptor(hServiceKey,
919 // lpService->lpSecurityDescriptor);
921 RegFlushKey(hServiceKey
);
922 RegCloseKey(hServiceKey
);
931 /* FIXME: Unlock service database */
933 DPRINT("RSetServiceObjectSecurity() done (Error %lu)\n", dwError
);
940 DWORD
RQueryServiceStatus(
941 SC_RPC_HANDLE hService
,
942 LPSERVICE_STATUS lpServiceStatus
)
944 PSERVICE_HANDLE hSvc
;
947 DPRINT("RQueryServiceStatus() called\n");
950 return ERROR_SHUTDOWN_IN_PROGRESS
;
952 hSvc
= (PSERVICE_HANDLE
)hService
;
953 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
955 DPRINT1("Invalid handle tag!\n");
956 return ERROR_INVALID_HANDLE
;
959 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
960 SERVICE_QUERY_STATUS
))
962 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
963 return ERROR_ACCESS_DENIED
;
966 lpService
= hSvc
->ServiceEntry
;
967 if (lpService
== NULL
)
969 DPRINT1("lpService == NULL!\n");
970 return ERROR_INVALID_HANDLE
;
973 /* Return service status information */
974 RtlCopyMemory(lpServiceStatus
,
976 sizeof(SERVICE_STATUS
));
978 return ERROR_SUCCESS
;
983 ScmIsValidServiceState(DWORD dwCurrentState
)
985 switch (dwCurrentState
)
987 case SERVICE_STOPPED
:
988 case SERVICE_START_PENDING
:
989 case SERVICE_STOP_PENDING
:
990 case SERVICE_RUNNING
:
991 case SERVICE_CONTINUE_PENDING
:
992 case SERVICE_PAUSE_PENDING
:
1003 DWORD
RSetServiceStatus(
1004 RPC_SERVICE_STATUS_HANDLE hServiceStatus
,
1005 LPSERVICE_STATUS lpServiceStatus
)
1009 DPRINT("RSetServiceStatus() called\n");
1010 DPRINT("hServiceStatus = %p\n", hServiceStatus
);
1011 DPRINT("dwServiceType = %lu\n", lpServiceStatus
->dwServiceType
);
1012 DPRINT("dwCurrentState = %lu\n", lpServiceStatus
->dwCurrentState
);
1013 DPRINT("dwControlsAccepted = %lu\n", lpServiceStatus
->dwControlsAccepted
);
1014 DPRINT("dwWin32ExitCode = %lu\n", lpServiceStatus
->dwWin32ExitCode
);
1015 DPRINT("dwServiceSpecificExitCode = %lu\n", lpServiceStatus
->dwServiceSpecificExitCode
);
1016 DPRINT("dwCheckPoint = %lu\n", lpServiceStatus
->dwCheckPoint
);
1017 DPRINT("dwWaitHint = %lu\n", lpServiceStatus
->dwWaitHint
);
1019 if (hServiceStatus
== 0)
1021 DPRINT1("hServiceStatus == NULL!\n");
1022 return ERROR_INVALID_HANDLE
;
1025 lpService
= ScmGetServiceEntryByClientHandle((HANDLE
)hServiceStatus
);
1026 if (lpService
== NULL
)
1028 DPRINT1("lpService == NULL!\n");
1029 return ERROR_INVALID_HANDLE
;
1032 /* Check current state */
1033 if (!ScmIsValidServiceState(lpServiceStatus
->dwCurrentState
))
1035 DPRINT1("Invalid service state!\n");
1036 return ERROR_INVALID_DATA
;
1039 /* Check service type */
1040 if (!(lpServiceStatus
->dwServiceType
& SERVICE_WIN32
) &&
1041 (lpServiceStatus
->dwServiceType
& SERVICE_DRIVER
))
1043 DPRINT1("Invalid service type!\n");
1044 return ERROR_INVALID_DATA
;
1047 /* Check accepted controls */
1048 if (lpServiceStatus
->dwControlsAccepted
& ~0xFF)
1050 DPRINT1("Invalid controls accepted!\n");
1051 return ERROR_INVALID_DATA
;
1055 RtlCopyMemory(&lpService
->Status
,
1057 sizeof(SERVICE_STATUS
));
1059 DPRINT("Set %S to %lu\n", lpService
->lpDisplayName
, lpService
->Status
.dwCurrentState
);
1060 DPRINT("RSetServiceStatus() done\n");
1062 return ERROR_SUCCESS
;
1067 DWORD
RUnlockServiceDatabase(
1071 return ERROR_SUCCESS
;
1076 DWORD
RNotifyBootConfigStatus(
1077 SVCCTL_HANDLEW lpMachineName
,
1078 DWORD BootAcceptable
)
1081 return ERROR_CALL_NOT_IMPLEMENTED
;
1086 DWORD
RI_ScSetServiceBitsW(
1087 RPC_SERVICE_STATUS_HANDLE hServiceStatus
,
1088 DWORD dwServiceBits
,
1090 int bUpdateImmediately
,
1094 return ERROR_CALL_NOT_IMPLEMENTED
;
1099 DWORD
RChangeServiceConfigW(
1100 SC_RPC_HANDLE hService
,
1101 DWORD dwServiceType
,
1103 DWORD dwErrorControl
,
1104 LPWSTR lpBinaryPathName
,
1105 LPWSTR lpLoadOrderGroup
,
1107 LPBYTE lpDependencies
,
1109 LPWSTR lpServiceStartName
,
1112 LPWSTR lpDisplayName
)
1114 DWORD dwError
= ERROR_SUCCESS
;
1115 PSERVICE_HANDLE hSvc
;
1116 PSERVICE lpService
= NULL
;
1117 HKEY hServiceKey
= NULL
;
1118 LPWSTR lpDisplayNameW
= NULL
;
1120 DPRINT("RChangeServiceConfigW() called\n");
1121 DPRINT("dwServiceType = %lu\n", dwServiceType
);
1122 DPRINT("dwStartType = %lu\n", dwStartType
);
1123 DPRINT("dwErrorControl = %lu\n", dwErrorControl
);
1124 DPRINT("lpBinaryPathName = %S\n", lpBinaryPathName
);
1125 DPRINT("lpLoadOrderGroup = %S\n", lpLoadOrderGroup
);
1126 DPRINT("lpDisplayName = %S\n", lpDisplayName
);
1129 return ERROR_SHUTDOWN_IN_PROGRESS
;
1131 hSvc
= (PSERVICE_HANDLE
)hService
;
1132 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
1134 DPRINT1("Invalid handle tag!\n");
1135 return ERROR_INVALID_HANDLE
;
1138 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
1139 SERVICE_CHANGE_CONFIG
))
1141 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
1142 return ERROR_ACCESS_DENIED
;
1145 lpService
= hSvc
->ServiceEntry
;
1146 if (lpService
== NULL
)
1148 DPRINT1("lpService == NULL!\n");
1149 return ERROR_INVALID_HANDLE
;
1152 /* FIXME: Lock database exclusively */
1154 if (lpService
->bDeleted
)
1156 /* FIXME: Unlock database */
1157 DPRINT1("The service has already been marked for delete!\n");
1158 return ERROR_SERVICE_MARKED_FOR_DELETE
;
1161 /* Open the service key */
1162 dwError
= ScmOpenServiceKey(lpService
->szServiceName
,
1165 if (dwError
!= ERROR_SUCCESS
)
1168 /* Write service data to the registry */
1169 /* Set the display name */
1170 if (lpDisplayName
!= NULL
&& *lpDisplayName
!= 0)
1172 RegSetValueExW(hServiceKey
,
1176 (LPBYTE
)lpDisplayName
,
1177 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
1179 /* Update the display name */
1180 lpDisplayNameW
= (LPWSTR
)HeapAlloc(GetProcessHeap(),
1182 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
1183 if (lpDisplayNameW
== NULL
)
1185 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
1189 if (lpService
->lpDisplayName
!= lpService
->lpServiceName
)
1190 HeapFree(GetProcessHeap(), 0, lpService
->lpDisplayName
);
1192 lpService
->lpDisplayName
= lpDisplayNameW
;
1195 if (dwServiceType
!= SERVICE_NO_CHANGE
)
1197 /* Set the service type */
1198 dwError
= RegSetValueExW(hServiceKey
,
1202 (LPBYTE
)&dwServiceType
,
1204 if (dwError
!= ERROR_SUCCESS
)
1207 lpService
->Status
.dwServiceType
= dwServiceType
;
1210 if (dwStartType
!= SERVICE_NO_CHANGE
)
1212 /* Set the start value */
1213 dwError
= RegSetValueExW(hServiceKey
,
1217 (LPBYTE
)&dwStartType
,
1219 if (dwError
!= ERROR_SUCCESS
)
1222 lpService
->dwStartType
= dwStartType
;
1225 if (dwErrorControl
!= SERVICE_NO_CHANGE
)
1227 /* Set the error control value */
1228 dwError
= RegSetValueExW(hServiceKey
,
1232 (LPBYTE
)&dwErrorControl
,
1234 if (dwError
!= ERROR_SUCCESS
)
1237 lpService
->dwErrorControl
= dwErrorControl
;
1241 /* FIXME: set the new ImagePath value */
1243 /* Set the image path */
1244 if (dwServiceType
& SERVICE_WIN32
)
1246 if (lpBinaryPathName
!= NULL
&& *lpBinaryPathName
!= 0)
1248 dwError
= RegSetValueExW(hServiceKey
,
1252 (LPBYTE
)lpBinaryPathName
,
1253 (wcslen(lpBinaryPathName
) + 1) * sizeof(WCHAR
));
1254 if (dwError
!= ERROR_SUCCESS
)
1258 else if (dwServiceType
& SERVICE_DRIVER
)
1260 if (lpImagePath
!= NULL
&& *lpImagePath
!= 0)
1262 dwError
= RegSetValueExW(hServiceKey
,
1266 (LPBYTE
)lpImagePath
,
1267 (wcslen(lpImagePath
) + 1) *sizeof(WCHAR
));
1268 if (dwError
!= ERROR_SUCCESS
)
1274 /* Set the group name */
1275 if (lpLoadOrderGroup
!= NULL
&& *lpLoadOrderGroup
!= 0)
1277 dwError
= RegSetValueExW(hServiceKey
,
1281 (LPBYTE
)lpLoadOrderGroup
,
1282 (wcslen(lpLoadOrderGroup
) + 1) * sizeof(WCHAR
));
1283 if (dwError
!= ERROR_SUCCESS
)
1285 /* FIXME: Update lpService->lpServiceGroup */
1288 if (lpdwTagId
!= NULL
)
1290 dwError
= ScmAssignNewTag(lpService
);
1291 if (dwError
!= ERROR_SUCCESS
)
1294 dwError
= RegSetValueExW(hServiceKey
,
1298 (LPBYTE
)&lpService
->dwTag
,
1300 if (dwError
!= ERROR_SUCCESS
)
1303 *lpdwTagId
= lpService
->dwTag
;
1306 /* Write dependencies */
1307 if (lpDependencies
!= NULL
&& *lpDependencies
!= 0)
1309 dwError
= ScmWriteDependencies(hServiceKey
,
1310 (LPWSTR
)lpDependencies
,
1312 if (dwError
!= ERROR_SUCCESS
)
1316 if (lpPassword
!= NULL
)
1318 /* FIXME: Write password */
1321 /* FIXME: Unlock database */
1324 if (hServiceKey
!= NULL
)
1325 RegCloseKey(hServiceKey
);
1327 DPRINT("RChangeServiceConfigW() done (Error %lu)\n", dwError
);
1333 /* Create a path suitable for the bootloader out of the full path */
1335 ScmConvertToBootPathName(wchar_t *CanonName
, wchar_t **RelativeName
)
1337 DWORD ServiceNameLen
, BufferSize
, ExpandedLen
;
1340 UNICODE_STRING NtPathName
, SystemRoot
, LinkTarget
;
1341 OBJECT_ATTRIBUTES ObjectAttributes
;
1343 HANDLE SymbolicLinkHandle
;
1345 DPRINT("ScmConvertToBootPathName %S\n", CanonName
);
1347 ServiceNameLen
= wcslen(CanonName
);
1349 /* First check, if it's already good */
1350 if (ServiceNameLen
> 12 &&
1351 !_wcsnicmp(L
"\\SystemRoot\\", CanonName
, 12))
1353 *RelativeName
= LocalAlloc(LMEM_ZEROINIT
, ServiceNameLen
* sizeof(WCHAR
) + sizeof(WCHAR
));
1354 if (*RelativeName
== NULL
)
1356 DPRINT1("Error allocating memory for boot driver name!\n");
1357 return ERROR_NOT_ENOUGH_MEMORY
;
1361 wcscpy(*RelativeName
, CanonName
);
1363 DPRINT1("Bootdriver name %S\n", *RelativeName
);
1364 return ERROR_SUCCESS
;
1367 /* If it has %SystemRoot% prefix, substitute it to \System*/
1368 if (ServiceNameLen
> 13 &&
1369 !_wcsnicmp(L
"%SystemRoot%\\", CanonName
, 13))
1371 /* There is no +sizeof(wchar_t) because the name is less by 1 wchar */
1372 *RelativeName
= LocalAlloc(LMEM_ZEROINIT
, ServiceNameLen
* sizeof(WCHAR
));
1374 if (*RelativeName
== NULL
)
1376 DPRINT1("Error allocating memory for boot driver name!\n");
1377 return ERROR_NOT_ENOUGH_MEMORY
;
1381 wcscpy(*RelativeName
, L
"\\SystemRoot\\");
1382 wcscat(*RelativeName
, CanonName
+ 13);
1384 DPRINT1("Bootdriver name %S\n", *RelativeName
);
1385 return ERROR_SUCCESS
;
1388 /* Get buffer size needed for expanding env strings */
1389 BufferSize
= ExpandEnvironmentStringsW(L
"%SystemRoot%\\", &Dest
, 1);
1391 if (BufferSize
<= 1)
1393 DPRINT1("Error during a call to ExpandEnvironmentStringsW()\n");
1394 return ERROR_INVALID_ENVIRONMENT
;
1397 /* Allocate memory, since the size is known now */
1398 Expanded
= LocalAlloc(LMEM_ZEROINIT
, BufferSize
* sizeof(WCHAR
) + sizeof(WCHAR
));
1401 DPRINT1("Error allocating memory for boot driver name!\n");
1402 return ERROR_NOT_ENOUGH_MEMORY
;
1406 if (ExpandEnvironmentStringsW(L
"%SystemRoot%\\", Expanded
, BufferSize
) >
1409 DPRINT1("Error during a call to ExpandEnvironmentStringsW()\n");
1410 LocalFree(Expanded
);
1411 return ERROR_NOT_ENOUGH_MEMORY
;
1414 /* Convert to NY-style path */
1415 if (!RtlDosPathNameToNtPathName_U(Expanded
, &NtPathName
, NULL
, NULL
))
1417 DPRINT1("Error during a call to RtlDosPathNameToNtPathName_U()\n");
1418 return ERROR_INVALID_ENVIRONMENT
;
1421 DPRINT("Converted to NT-style %wZ\n", &NtPathName
);
1423 /* No need to keep the dos-path anymore */
1424 LocalFree(Expanded
);
1426 /* Copy it to the allocated place */
1427 Expanded
= LocalAlloc(LMEM_ZEROINIT
, NtPathName
.Length
+ sizeof(WCHAR
));
1430 DPRINT1("Error allocating memory for boot driver name!\n");
1431 return ERROR_NOT_ENOUGH_MEMORY
;
1434 ExpandedLen
= NtPathName
.Length
/ sizeof(WCHAR
);
1435 wcsncpy(Expanded
, NtPathName
.Buffer
, ExpandedLen
);
1436 Expanded
[ExpandedLen
] = 0;
1438 if (ServiceNameLen
> ExpandedLen
&&
1439 !_wcsnicmp(Expanded
, CanonName
, ExpandedLen
))
1441 /* Only \SystemRoot\ is missing */
1442 *RelativeName
= LocalAlloc(LMEM_ZEROINIT
,
1443 (ServiceNameLen
- ExpandedLen
) * sizeof(WCHAR
) + 13*sizeof(WCHAR
));
1444 if (*RelativeName
== NULL
)
1446 DPRINT1("Error allocating memory for boot driver name!\n");
1447 LocalFree(Expanded
);
1448 return ERROR_NOT_ENOUGH_MEMORY
;
1451 wcscpy(*RelativeName
, L
"\\SystemRoot\\");
1452 wcscat(*RelativeName
, CanonName
+ ExpandedLen
);
1454 RtlFreeUnicodeString(&NtPathName
);
1455 return ERROR_SUCCESS
;
1458 /* The most complex case starts here */
1459 RtlInitUnicodeString(&SystemRoot
, L
"\\SystemRoot");
1460 InitializeObjectAttributes(&ObjectAttributes
,
1462 OBJ_CASE_INSENSITIVE
,
1466 /* Open this symlink */
1467 Status
= NtOpenSymbolicLinkObject(&SymbolicLinkHandle
, SYMBOLIC_LINK_QUERY
, &ObjectAttributes
);
1469 if (NT_SUCCESS(Status
))
1471 LinkTarget
.Length
= 0;
1472 LinkTarget
.MaximumLength
= 0;
1474 DPRINT("Opened symbolic link object\n");
1476 Status
= NtQuerySymbolicLinkObject(SymbolicLinkHandle
, &LinkTarget
, &BufferSize
);
1477 if (NT_SUCCESS(Status
) || Status
== STATUS_BUFFER_TOO_SMALL
)
1479 /* Check if required buffer size is sane */
1480 if (BufferSize
> 0xFFFD)
1482 DPRINT1("Too large buffer required\n");
1485 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
1486 LocalFree(Expanded
);
1487 return ERROR_NOT_ENOUGH_MEMORY
;
1490 /* Alloc the string */
1491 LinkTarget
.Buffer
= LocalAlloc(LMEM_ZEROINIT
, BufferSize
+ sizeof(WCHAR
));
1492 if (!LinkTarget
.Buffer
)
1494 DPRINT1("Unable to alloc buffer\n");
1495 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
1496 LocalFree(Expanded
);
1497 return ERROR_NOT_ENOUGH_MEMORY
;
1500 /* Do a real query now */
1501 LinkTarget
.Length
= BufferSize
;
1502 LinkTarget
.MaximumLength
= LinkTarget
.Length
+ sizeof(WCHAR
);
1504 Status
= NtQuerySymbolicLinkObject(SymbolicLinkHandle
, &LinkTarget
, &BufferSize
);
1505 if (NT_SUCCESS(Status
))
1507 DPRINT("LinkTarget: %wZ\n", &LinkTarget
);
1509 ExpandedLen
= LinkTarget
.Length
/ sizeof(WCHAR
);
1510 if ((ServiceNameLen
> ExpandedLen
) &&
1511 !_wcsnicmp(LinkTarget
.Buffer
, CanonName
, ExpandedLen
))
1513 *RelativeName
= LocalAlloc(LMEM_ZEROINIT
,
1514 (ServiceNameLen
- ExpandedLen
) * sizeof(WCHAR
) + 13*sizeof(WCHAR
));
1516 if (*RelativeName
== NULL
)
1518 DPRINT1("Unable to alloc buffer\n");
1519 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
1520 LocalFree(Expanded
);
1521 RtlFreeUnicodeString(&NtPathName
);
1522 return ERROR_NOT_ENOUGH_MEMORY
;
1525 /* Copy it over, substituting the first part
1527 wcscpy(*RelativeName
, L
"\\SystemRoot\\");
1528 wcscat(*RelativeName
, CanonName
+ExpandedLen
+1);
1531 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
1532 LocalFree(Expanded
);
1533 RtlFreeUnicodeString(&NtPathName
);
1535 /* Return success */
1536 return ERROR_SUCCESS
;
1540 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
1541 LocalFree(Expanded
);
1542 RtlFreeUnicodeString(&NtPathName
);
1543 return ERROR_INVALID_PARAMETER
;
1548 DPRINT1("Error, Status = %08X\n", Status
);
1549 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
1550 LocalFree(Expanded
);
1551 RtlFreeUnicodeString(&NtPathName
);
1552 return ERROR_INVALID_PARAMETER
;
1557 DPRINT1("Error, Status = %08X\n", Status
);
1558 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
1559 LocalFree(Expanded
);
1560 RtlFreeUnicodeString(&NtPathName
);
1561 return ERROR_INVALID_PARAMETER
;
1566 DPRINT1("Error, Status = %08X\n", Status
);
1567 LocalFree(Expanded
);
1568 return ERROR_INVALID_PARAMETER
;
1572 *RelativeName
= NULL
;
1573 return ERROR_INVALID_PARAMETER
;
1577 ScmCanonDriverImagePath(DWORD dwStartType
,
1578 const wchar_t *lpServiceName
,
1579 wchar_t **lpCanonName
)
1581 DWORD ServiceNameLen
, Result
;
1582 UNICODE_STRING NtServiceName
;
1583 WCHAR
*RelativeName
;
1584 const WCHAR
*SourceName
= lpServiceName
;
1586 /* Calculate the length of the service's name */
1587 ServiceNameLen
= wcslen(lpServiceName
);
1589 /* 12 is wcslen(L"\\SystemRoot\\") */
1590 if (ServiceNameLen
> 12 &&
1591 !_wcsnicmp(L
"\\SystemRoot\\", lpServiceName
, 12))
1593 /* SystemRoot prefix is already included */
1595 *lpCanonName
= LocalAlloc(LMEM_ZEROINIT
, ServiceNameLen
* sizeof(WCHAR
) + sizeof(WCHAR
));
1597 if (*lpCanonName
== NULL
)
1599 DPRINT1("Error allocating memory for canonized service name!\n");
1600 return ERROR_NOT_ENOUGH_MEMORY
;
1603 /* If it's a boot-time driver, it must be systemroot relative */
1604 if (dwStartType
== SERVICE_BOOT_START
)
1608 wcscpy(*lpCanonName
, SourceName
);
1610 DPRINT("Canonicalized name %S\n", *lpCanonName
);
1614 /* Check if it has %SystemRoot% (len=13) */
1615 if (ServiceNameLen
> 13 &&
1616 !_wcsnicmp(L
"%%SystemRoot%%\\", lpServiceName
, 13))
1618 /* Substitute %SystemRoot% with \\SystemRoot\\ */
1619 *lpCanonName
= LocalAlloc(LMEM_ZEROINIT
, ServiceNameLen
* sizeof(WCHAR
) + sizeof(WCHAR
));
1621 if (*lpCanonName
== NULL
)
1623 DPRINT1("Error allocating memory for canonized service name!\n");
1624 return ERROR_NOT_ENOUGH_MEMORY
;
1627 /* If it's a boot-time driver, it must be systemroot relative */
1628 if (dwStartType
== SERVICE_BOOT_START
)
1629 wcscpy(*lpCanonName
, L
"\\SystemRoot\\");
1631 wcscat(*lpCanonName
, lpServiceName
+ 13);
1633 DPRINT("Canonicalized name %S\n", *lpCanonName
);
1637 /* Check if it's a relative path name */
1638 if (lpServiceName
[0] != L
'\\' && lpServiceName
[1] != L
':')
1640 *lpCanonName
= LocalAlloc(LMEM_ZEROINIT
, ServiceNameLen
* sizeof(WCHAR
) + sizeof(WCHAR
));
1642 if (*lpCanonName
== NULL
)
1644 DPRINT1("Error allocating memory for canonized service name!\n");
1645 return ERROR_NOT_ENOUGH_MEMORY
;
1648 /* Just copy it over without changing */
1649 wcscpy(*lpCanonName
, lpServiceName
);
1654 /* It seems to be a DOS path, convert it */
1655 if (!RtlDosPathNameToNtPathName_U(lpServiceName
, &NtServiceName
, NULL
, NULL
))
1657 DPRINT1("RtlDosPathNameToNtPathName_U() failed!\n");
1658 return ERROR_INVALID_PARAMETER
;
1661 *lpCanonName
= LocalAlloc(LMEM_ZEROINIT
, NtServiceName
.Length
+ sizeof(WCHAR
));
1663 if (*lpCanonName
== NULL
)
1665 DPRINT1("Error allocating memory for canonized service name!\n");
1666 RtlFreeUnicodeString(&NtServiceName
);
1667 return ERROR_NOT_ENOUGH_MEMORY
;
1670 /* Copy the string */
1671 wcsncpy(*lpCanonName
, NtServiceName
.Buffer
, NtServiceName
.Length
/ sizeof(WCHAR
));
1673 /* The unicode string is not needed anymore */
1674 RtlFreeUnicodeString(&NtServiceName
);
1676 if (dwStartType
!= SERVICE_BOOT_START
)
1678 DPRINT("Canonicalized name %S\n", *lpCanonName
);
1682 /* The service is boot-started, so must be relative */
1683 Result
= ScmConvertToBootPathName(*lpCanonName
, &RelativeName
);
1686 /* There is a problem, free name and return */
1687 LocalFree(*lpCanonName
);
1688 DPRINT1("Error converting named!\n");
1692 ASSERT(RelativeName
);
1694 /* Copy that string */
1695 wcscpy(*lpCanonName
, RelativeName
+ 12);
1697 /* Free the allocated buffer */
1698 LocalFree(RelativeName
);
1700 DPRINT("Canonicalized name %S\n", *lpCanonName
);
1708 DWORD
RCreateServiceW(
1709 SC_RPC_HANDLE hSCManager
,
1710 LPCWSTR lpServiceName
,
1711 LPCWSTR lpDisplayName
,
1712 DWORD dwDesiredAccess
,
1713 DWORD dwServiceType
,
1715 DWORD dwErrorControl
,
1716 LPCWSTR lpBinaryPathName
,
1717 LPCWSTR lpLoadOrderGroup
,
1719 LPBYTE lpDependencies
,
1721 LPCWSTR lpServiceStartName
,
1724 LPSC_RPC_HANDLE lpServiceHandle
)
1726 PMANAGER_HANDLE hManager
;
1727 DWORD dwError
= ERROR_SUCCESS
;
1728 PSERVICE lpService
= NULL
;
1729 SC_HANDLE hServiceHandle
= NULL
;
1730 LPWSTR lpImagePath
= NULL
;
1731 HKEY hServiceKey
= NULL
;
1733 DPRINT("RCreateServiceW() called\n");
1734 DPRINT("lpServiceName = %S\n", lpServiceName
);
1735 DPRINT("lpDisplayName = %S\n", lpDisplayName
);
1736 DPRINT("dwDesiredAccess = %lx\n", dwDesiredAccess
);
1737 DPRINT("dwServiceType = %lu\n", dwServiceType
);
1738 DPRINT("dwStartType = %lu\n", dwStartType
);
1739 DPRINT("dwErrorControl = %lu\n", dwErrorControl
);
1740 DPRINT("lpBinaryPathName = %S\n", lpBinaryPathName
);
1741 DPRINT("lpLoadOrderGroup = %S\n", lpLoadOrderGroup
);
1744 return ERROR_SHUTDOWN_IN_PROGRESS
;
1746 hManager
= (PMANAGER_HANDLE
)hSCManager
;
1747 if (!hManager
|| hManager
->Handle
.Tag
!= MANAGER_TAG
)
1749 DPRINT1("Invalid manager handle!\n");
1750 return ERROR_INVALID_HANDLE
;
1753 /* Check access rights */
1754 if (!RtlAreAllAccessesGranted(hManager
->Handle
.DesiredAccess
,
1755 SC_MANAGER_CREATE_SERVICE
))
1757 DPRINT1("Insufficient access rights! 0x%lx\n",
1758 hManager
->Handle
.DesiredAccess
);
1759 return ERROR_ACCESS_DENIED
;
1762 if (wcslen(lpServiceName
) == 0)
1764 return ERROR_INVALID_NAME
;
1767 if (wcslen(lpBinaryPathName
) == 0)
1769 return ERROR_INVALID_PARAMETER
;
1772 if ((dwServiceType
== (SERVICE_WIN32_OWN_PROCESS
| SERVICE_INTERACTIVE_PROCESS
)) &&
1773 (lpServiceStartName
))
1775 return ERROR_INVALID_PARAMETER
;
1778 if ((dwServiceType
> SERVICE_WIN32_SHARE_PROCESS
) &&
1779 (dwServiceType
!= (SERVICE_WIN32_OWN_PROCESS
| SERVICE_INTERACTIVE_PROCESS
)) &&
1780 (dwServiceType
!= (SERVICE_WIN32_SHARE_PROCESS
| SERVICE_INTERACTIVE_PROCESS
)))
1782 return ERROR_INVALID_PARAMETER
;
1785 if (dwStartType
> SERVICE_DISABLED
)
1787 return ERROR_INVALID_PARAMETER
;
1790 lpService
= ScmGetServiceEntryByName(lpServiceName
);
1793 /* check if it is marked for deletion */
1794 if (lpService
->bDeleted
)
1795 return ERROR_SERVICE_MARKED_FOR_DELETE
;
1796 /* Return Error exist */
1797 return ERROR_SERVICE_EXISTS
;
1800 if (lpDisplayName
!= NULL
&&
1801 ScmGetServiceEntryByDisplayName(lpDisplayName
) != NULL
)
1802 return ERROR_DUPLICATE_SERVICE_NAME
;
1804 if (dwServiceType
& SERVICE_DRIVER
)
1806 dwError
= ScmCanonDriverImagePath(dwStartType
,
1809 if (dwError
!= ERROR_SUCCESS
)
1814 if (dwStartType
== SERVICE_BOOT_START
||
1815 dwStartType
== SERVICE_SYSTEM_START
)
1817 return ERROR_INVALID_PARAMETER
;
1821 /* Allocate a new service entry */
1822 dwError
= ScmCreateNewServiceRecord(lpServiceName
,
1824 if (dwError
!= ERROR_SUCCESS
)
1827 /* Fill the new service entry */
1828 lpService
->Status
.dwServiceType
= dwServiceType
;
1829 lpService
->dwStartType
= dwStartType
;
1830 lpService
->dwErrorControl
= dwErrorControl
;
1832 /* Fill the display name */
1833 if (lpDisplayName
!= NULL
&&
1834 *lpDisplayName
!= 0 &&
1835 _wcsicmp(lpService
->lpDisplayName
, lpDisplayName
) != 0)
1837 lpService
->lpDisplayName
= (WCHAR
*) HeapAlloc(GetProcessHeap(), 0,
1838 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
1839 if (lpService
->lpDisplayName
== NULL
)
1841 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
1844 wcscpy(lpService
->lpDisplayName
, lpDisplayName
);
1847 /* Assign the service to a group */
1848 if (lpLoadOrderGroup
!= NULL
&& *lpLoadOrderGroup
!= 0)
1850 dwError
= ScmSetServiceGroup(lpService
,
1852 if (dwError
!= ERROR_SUCCESS
)
1856 /* Assign a new tag */
1857 if (lpdwTagId
!= NULL
)
1859 dwError
= ScmAssignNewTag(lpService
);
1860 if (dwError
!= ERROR_SUCCESS
)
1864 /* Write service data to the registry */
1865 /* Create the service key */
1866 dwError
= ScmCreateServiceKey(lpServiceName
,
1869 if (dwError
!= ERROR_SUCCESS
)
1872 /* Set the display name */
1873 if (lpDisplayName
!= NULL
&& *lpDisplayName
!= 0)
1875 RegSetValueExW(hServiceKey
,
1879 (LPBYTE
)lpDisplayName
,
1880 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
1883 /* Set the service type */
1884 dwError
= RegSetValueExW(hServiceKey
,
1888 (LPBYTE
)&dwServiceType
,
1890 if (dwError
!= ERROR_SUCCESS
)
1893 /* Set the start value */
1894 dwError
= RegSetValueExW(hServiceKey
,
1898 (LPBYTE
)&dwStartType
,
1900 if (dwError
!= ERROR_SUCCESS
)
1903 /* Set the error control value */
1904 dwError
= RegSetValueExW(hServiceKey
,
1908 (LPBYTE
)&dwErrorControl
,
1910 if (dwError
!= ERROR_SUCCESS
)
1913 /* Set the image path */
1914 if (dwServiceType
& SERVICE_WIN32
)
1916 dwError
= RegSetValueExW(hServiceKey
,
1920 (LPBYTE
)lpBinaryPathName
,
1921 (wcslen(lpBinaryPathName
) + 1) * sizeof(WCHAR
));
1922 if (dwError
!= ERROR_SUCCESS
)
1925 else if (dwServiceType
& SERVICE_DRIVER
)
1927 dwError
= RegSetValueExW(hServiceKey
,
1931 (LPBYTE
)lpImagePath
,
1932 (wcslen(lpImagePath
) + 1) * sizeof(WCHAR
));
1933 if (dwError
!= ERROR_SUCCESS
)
1937 /* Set the group name */
1938 if (lpLoadOrderGroup
!= NULL
&& *lpLoadOrderGroup
!= 0)
1940 dwError
= RegSetValueExW(hServiceKey
,
1944 (LPBYTE
)lpLoadOrderGroup
,
1945 (wcslen(lpLoadOrderGroup
) + 1) * sizeof(WCHAR
));
1946 if (dwError
!= ERROR_SUCCESS
)
1950 if (lpdwTagId
!= NULL
)
1952 dwError
= RegSetValueExW(hServiceKey
,
1956 (LPBYTE
)&lpService
->dwTag
,
1958 if (dwError
!= ERROR_SUCCESS
)
1962 /* Write dependencies */
1963 if (lpDependencies
!= NULL
&& *lpDependencies
!= 0)
1965 dwError
= ScmWriteDependencies(hServiceKey
,
1966 (LPWSTR
)lpDependencies
,
1968 if (dwError
!= ERROR_SUCCESS
)
1972 /* FIXME: Handle lpServiceStartName propertly! */
1973 /* If a non driver and NULL for lpServiceStartName, write ObjectName as LocalSystem */
1974 if ((dwServiceType
& SERVICE_WIN32
) && (!lpServiceStartName
))
1976 dwError
= RegSetValueExW(hServiceKey
,
1980 (LPBYTE
)L
"LocalSystem",
1982 if (dwError
!= ERROR_SUCCESS
)
1986 if (lpPassword
!= NULL
)
1988 /* FIXME: Write password */
1991 dwError
= ScmCreateServiceHandle(lpService
,
1993 if (dwError
!= ERROR_SUCCESS
)
1996 dwError
= ScmCheckAccess(hServiceHandle
,
1998 if (dwError
!= ERROR_SUCCESS
)
2001 lpService
->dwRefCount
= 1;
2002 DPRINT("CreateService - lpService->dwRefCount %u\n", lpService
->dwRefCount
);
2005 if (hServiceKey
!= NULL
)
2006 RegCloseKey(hServiceKey
);
2008 if (dwError
== ERROR_SUCCESS
)
2010 DPRINT("hService %p\n", hServiceHandle
);
2011 *lpServiceHandle
= (SC_RPC_HANDLE
)hServiceHandle
;
2013 if (lpdwTagId
!= NULL
)
2014 *lpdwTagId
= lpService
->dwTag
;
2018 /* Release the display name buffer */
2019 if (lpService
->lpServiceName
!= NULL
)
2020 HeapFree(GetProcessHeap(), 0, lpService
->lpDisplayName
);
2024 /* Remove the service handle */
2025 HeapFree(GetProcessHeap(), 0, hServiceHandle
);
2028 if (lpService
!= NULL
)
2030 /* FIXME: remove the service entry */
2034 if (lpImagePath
!= NULL
)
2035 HeapFree(GetProcessHeap(), 0, lpImagePath
);
2037 DPRINT("RCreateServiceW() done (Error %lu)\n", dwError
);
2044 DWORD
REnumDependentServicesW(
2045 SC_RPC_HANDLE hService
,
2046 DWORD dwServiceState
,
2049 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
2050 LPBOUNDED_DWORD_256K lpServicesReturned
)
2052 DWORD dwError
= ERROR_SUCCESS
;
2053 DWORD dwServicesReturned
= 0;
2054 DWORD dwServiceCount
;
2055 HKEY hServicesKey
= NULL
;
2056 LPSC_RPC_HANDLE hSCObject
;
2057 PSERVICE_HANDLE hSvc
;
2058 PSERVICE lpService
= NULL
;
2059 PSERVICE
*lpServicesArray
= NULL
;
2060 LPENUM_SERVICE_STATUSW lpServicesPtr
= NULL
;
2063 *pcbBytesNeeded
= 0;
2064 *lpServicesReturned
= 0;
2066 DPRINT("REnumDependentServicesW() called\n");
2068 hSCObject
= &hService
;
2069 hSvc
= (PSERVICE_HANDLE
) *hSCObject
;
2070 lpService
= hSvc
->ServiceEntry
;
2072 /* Check access rights */
2073 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
2074 SC_MANAGER_ENUMERATE_SERVICE
))
2076 DPRINT1("Insufficient access rights! 0x%lx\n",
2077 hSvc
->Handle
.DesiredAccess
);
2078 return ERROR_ACCESS_DENIED
;
2081 /* Open the Services Reg key */
2082 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
2083 L
"System\\CurrentControlSet\\Services",
2087 if (dwError
!= ERROR_SUCCESS
)
2090 /* First determine the bytes needed and get the number of dependent services */
2091 dwError
= Int_EnumDependentServicesW(hServicesKey
,
2096 &dwServicesReturned
);
2097 if (dwError
!= ERROR_SUCCESS
)
2100 /* If buffer size is less than the bytes needed or pointer is null */
2101 if ((!lpServices
) || (cbBufSize
< *pcbBytesNeeded
))
2103 dwError
= ERROR_MORE_DATA
;
2107 /* Allocate memory for array of service pointers */
2108 lpServicesArray
= HeapAlloc(GetProcessHeap(),
2110 (dwServicesReturned
+ 1) * sizeof(PSERVICE
));
2111 if (!lpServicesArray
)
2113 DPRINT1("Could not allocate a buffer!!\n");
2114 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
2118 dwServicesReturned
= 0;
2119 *pcbBytesNeeded
= 0;
2121 dwError
= Int_EnumDependentServicesW(hServicesKey
,
2126 &dwServicesReturned
);
2127 if (dwError
!= ERROR_SUCCESS
)
2132 lpServicesPtr
= (LPENUM_SERVICE_STATUSW
) lpServices
;
2133 lpStr
= (LPWSTR
)(lpServices
+ (dwServicesReturned
* sizeof(ENUM_SERVICE_STATUSW
)));
2135 /* Copy EnumDepenedentService to Buffer */
2136 for (dwServiceCount
= 0; dwServiceCount
< dwServicesReturned
; dwServiceCount
++)
2138 lpService
= lpServicesArray
[dwServiceCount
];
2140 /* Copy status info */
2141 memcpy(&lpServicesPtr
->ServiceStatus
,
2143 sizeof(SERVICE_STATUS
));
2145 /* Copy display name */
2146 wcscpy(lpStr
, lpService
->lpDisplayName
);
2147 lpServicesPtr
->lpDisplayName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServices
);
2148 lpStr
+= (wcslen(lpService
->lpDisplayName
) + 1);
2150 /* Copy service name */
2151 wcscpy(lpStr
, lpService
->lpServiceName
);
2152 lpServicesPtr
->lpServiceName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServices
);
2153 lpStr
+= (wcslen(lpService
->lpServiceName
) + 1);
2158 *lpServicesReturned
= dwServicesReturned
;
2161 if (lpServicesArray
!= NULL
)
2162 HeapFree(GetProcessHeap(), 0, lpServicesArray
);
2164 RegCloseKey(hServicesKey
);
2166 DPRINT("REnumDependentServicesW() done (Error %lu)\n", dwError
);
2173 DWORD
REnumServicesStatusW(
2174 SC_RPC_HANDLE hSCManager
,
2175 DWORD dwServiceType
,
2176 DWORD dwServiceState
,
2179 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
2180 LPBOUNDED_DWORD_256K lpServicesReturned
,
2181 LPBOUNDED_DWORD_256K lpResumeHandle
)
2183 PMANAGER_HANDLE hManager
;
2185 DWORD dwError
= ERROR_SUCCESS
;
2186 PLIST_ENTRY ServiceEntry
;
2187 PSERVICE CurrentService
;
2189 DWORD dwRequiredSize
;
2190 DWORD dwServiceCount
;
2192 DWORD dwLastResumeCount
= 0;
2193 LPENUM_SERVICE_STATUSW lpStatusPtr
;
2196 DPRINT("REnumServicesStatusW() called\n");
2199 return ERROR_SHUTDOWN_IN_PROGRESS
;
2201 hManager
= (PMANAGER_HANDLE
)hSCManager
;
2202 if (!hManager
|| hManager
->Handle
.Tag
!= MANAGER_TAG
)
2204 DPRINT1("Invalid manager handle!\n");
2205 return ERROR_INVALID_HANDLE
;
2208 *pcbBytesNeeded
= 0;
2209 *lpServicesReturned
= 0;
2211 if ((dwServiceType
!=SERVICE_DRIVER
) && (dwServiceType
!=SERVICE_WIN32
))
2213 DPRINT("Not a valid Service Type!\n");
2214 return ERROR_INVALID_PARAMETER
;
2217 if ((dwServiceState
<SERVICE_ACTIVE
) || (dwServiceState
>SERVICE_STATE_ALL
))
2219 DPRINT("Not a valid Service State!\n");
2220 return ERROR_INVALID_PARAMETER
;
2223 /* Check access rights */
2224 if (!RtlAreAllAccessesGranted(hManager
->Handle
.DesiredAccess
,
2225 SC_MANAGER_ENUMERATE_SERVICE
))
2227 DPRINT1("Insufficient access rights! 0x%lx\n",
2228 hManager
->Handle
.DesiredAccess
);
2229 return ERROR_ACCESS_DENIED
;
2233 dwLastResumeCount
= *lpResumeHandle
;
2235 /* FIXME: Lock the service list shared */
2237 lpService
= ScmGetServiceEntryByResumeCount(dwLastResumeCount
);
2238 if (lpService
== NULL
)
2240 dwError
= ERROR_SUCCESS
;
2247 for (ServiceEntry
= &lpService
->ServiceListEntry
;
2248 ServiceEntry
!= &ServiceListHead
;
2249 ServiceEntry
= ServiceEntry
->Flink
)
2251 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
2255 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
2258 dwState
= SERVICE_ACTIVE
;
2259 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
2260 dwState
= SERVICE_INACTIVE
;
2262 if ((dwState
& dwServiceState
) == 0)
2265 dwSize
= sizeof(ENUM_SERVICE_STATUSW
) +
2266 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
2267 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
2269 if (dwRequiredSize
+ dwSize
> dwBufSize
)
2271 DPRINT("Service name: %S no fit\n", CurrentService
->lpServiceName
);
2275 DPRINT("Service name: %S fit\n", CurrentService
->lpServiceName
);
2276 dwRequiredSize
+= dwSize
;
2278 dwLastResumeCount
= CurrentService
->dwResumeCount
;
2281 DPRINT("dwRequiredSize: %lu\n", dwRequiredSize
);
2282 DPRINT("dwServiceCount: %lu\n", dwServiceCount
);
2285 ServiceEntry
!= &ServiceListHead
;
2286 ServiceEntry
= ServiceEntry
->Flink
)
2288 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
2292 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
2295 dwState
= SERVICE_ACTIVE
;
2296 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
2297 dwState
= SERVICE_INACTIVE
;
2299 if ((dwState
& dwServiceState
) == 0)
2302 dwRequiredSize
+= (sizeof(ENUM_SERVICE_STATUSW
) +
2303 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
2304 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
)));
2306 dwError
= ERROR_MORE_DATA
;
2309 DPRINT("*pcbBytesNeeded: %lu\n", dwRequiredSize
);
2312 *lpResumeHandle
= dwLastResumeCount
;
2314 *lpServicesReturned
= dwServiceCount
;
2315 *pcbBytesNeeded
= dwRequiredSize
;
2317 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpBuffer
;
2318 lpStringPtr
= (LPWSTR
)((ULONG_PTR
)lpBuffer
+
2319 dwServiceCount
* sizeof(ENUM_SERVICE_STATUSW
));
2322 for (ServiceEntry
= &lpService
->ServiceListEntry
;
2323 ServiceEntry
!= &ServiceListHead
;
2324 ServiceEntry
= ServiceEntry
->Flink
)
2326 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
2330 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
2333 dwState
= SERVICE_ACTIVE
;
2334 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
2335 dwState
= SERVICE_INACTIVE
;
2337 if ((dwState
& dwServiceState
) == 0)
2340 dwSize
= sizeof(ENUM_SERVICE_STATUSW
) +
2341 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
2342 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
2344 if (dwRequiredSize
+ dwSize
> dwBufSize
)
2347 /* Copy the service name */
2348 wcscpy(lpStringPtr
, CurrentService
->lpServiceName
);
2349 lpStatusPtr
->lpServiceName
= (LPWSTR
)((ULONG_PTR
)lpStringPtr
- (ULONG_PTR
)lpBuffer
);
2350 lpStringPtr
+= (wcslen(CurrentService
->lpServiceName
) + 1);
2352 /* Copy the display name */
2353 wcscpy(lpStringPtr
, CurrentService
->lpDisplayName
);
2354 lpStatusPtr
->lpDisplayName
= (LPWSTR
)((ULONG_PTR
)lpStringPtr
- (ULONG_PTR
)lpBuffer
);
2355 lpStringPtr
+= (wcslen(CurrentService
->lpDisplayName
) + 1);
2357 /* Copy the status information */
2358 memcpy(&lpStatusPtr
->ServiceStatus
,
2359 &CurrentService
->Status
,
2360 sizeof(SERVICE_STATUS
));
2363 dwRequiredSize
+= dwSize
;
2368 *pcbBytesNeeded
= 0;
2369 if (lpResumeHandle
) *lpResumeHandle
= 0;
2373 /* FIXME: Unlock the service list */
2375 DPRINT("REnumServicesStatusW() done (Error %lu)\n", dwError
);
2382 DWORD
ROpenSCManagerW(
2383 LPWSTR lpMachineName
,
2384 LPWSTR lpDatabaseName
,
2385 DWORD dwDesiredAccess
,
2386 LPSC_RPC_HANDLE lpScHandle
)
2391 DPRINT("ROpenSCManagerW() called\n");
2392 DPRINT("lpMachineName = %p\n", lpMachineName
);
2393 DPRINT("lpMachineName: %S\n", lpMachineName
);
2394 DPRINT("lpDataBaseName = %p\n", lpDatabaseName
);
2395 DPRINT("lpDataBaseName: %S\n", lpDatabaseName
);
2396 DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess
);
2399 return ERROR_SHUTDOWN_IN_PROGRESS
;
2402 return ERROR_INVALID_PARAMETER
;
2404 dwError
= ScmCreateManagerHandle(lpDatabaseName
,
2406 if (dwError
!= ERROR_SUCCESS
)
2408 DPRINT1("ScmCreateManagerHandle() failed (Error %lu)\n", dwError
);
2412 /* Check the desired access */
2413 dwError
= ScmCheckAccess(hHandle
,
2414 dwDesiredAccess
| SC_MANAGER_CONNECT
);
2415 if (dwError
!= ERROR_SUCCESS
)
2417 DPRINT1("ScmCheckAccess() failed (Error %lu)\n", dwError
);
2418 HeapFree(GetProcessHeap(), 0, hHandle
);
2422 *lpScHandle
= (SC_RPC_HANDLE
)hHandle
;
2423 DPRINT("*hScm = %p\n", *lpScHandle
);
2425 DPRINT("ROpenSCManagerW() done\n");
2427 return ERROR_SUCCESS
;
2432 DWORD
ROpenServiceW(
2433 SC_RPC_HANDLE hSCManager
,
2434 LPWSTR lpServiceName
,
2435 DWORD dwDesiredAccess
,
2436 LPSC_RPC_HANDLE lpServiceHandle
)
2439 PMANAGER_HANDLE hManager
;
2443 DPRINT("ROpenServiceW() called\n");
2444 DPRINT("hSCManager = %p\n", hSCManager
);
2445 DPRINT("lpServiceName = %p\n", lpServiceName
);
2446 DPRINT("lpServiceName: %S\n", lpServiceName
);
2447 DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess
);
2450 return ERROR_SHUTDOWN_IN_PROGRESS
;
2452 hManager
= (PMANAGER_HANDLE
)hSCManager
;
2453 if (!hManager
|| hManager
->Handle
.Tag
!= MANAGER_TAG
)
2455 DPRINT1("Invalid manager handle!\n");
2456 return ERROR_INVALID_HANDLE
;
2459 if (!lpServiceHandle
)
2460 return ERROR_INVALID_PARAMETER
;
2463 return ERROR_INVALID_ADDRESS
;
2465 /* FIXME: Lock the service list */
2467 /* Get service database entry */
2468 lpService
= ScmGetServiceEntryByName(lpServiceName
);
2469 if (lpService
== NULL
)
2471 DPRINT("Could not find a service!\n");
2472 return ERROR_SERVICE_DOES_NOT_EXIST
;
2475 /* Create a service handle */
2476 dwError
= ScmCreateServiceHandle(lpService
,
2478 if (dwError
!= ERROR_SUCCESS
)
2480 DPRINT1("ScmCreateServiceHandle() failed (Error %lu)\n", dwError
);
2484 /* Check the desired access */
2485 dwError
= ScmCheckAccess(hHandle
,
2487 if (dwError
!= ERROR_SUCCESS
)
2489 DPRINT1("ScmCheckAccess() failed (Error %lu)\n", dwError
);
2490 HeapFree(GetProcessHeap(), 0, hHandle
);
2494 lpService
->dwRefCount
++;
2495 DPRINT("OpenService - lpService->dwRefCount %u\n",lpService
->dwRefCount
);
2497 *lpServiceHandle
= (SC_RPC_HANDLE
)hHandle
;
2498 DPRINT("*hService = %p\n", *lpServiceHandle
);
2500 DPRINT("ROpenServiceW() done\n");
2502 return ERROR_SUCCESS
;
2507 DWORD
RQueryServiceConfigW(
2508 SC_RPC_HANDLE hService
,
2509 LPBYTE lpBuf
, //LPQUERY_SERVICE_CONFIGW lpServiceConfig,
2511 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
2513 LPQUERY_SERVICE_CONFIGW lpServiceConfig
= (LPQUERY_SERVICE_CONFIGW
)lpBuf
;
2514 DWORD dwError
= ERROR_SUCCESS
;
2515 PSERVICE_HANDLE hSvc
;
2516 PSERVICE lpService
= NULL
;
2517 HKEY hServiceKey
= NULL
;
2518 LPWSTR lpImagePath
= NULL
;
2519 LPWSTR lpServiceStartName
= NULL
;
2520 DWORD dwRequiredSize
;
2521 LPQUERY_SERVICE_CONFIGW lpConfig
= NULL
;
2522 WCHAR lpEmptyString
[] = {0,0};
2525 DPRINT("RQueryServiceConfigW() called\n");
2528 return ERROR_SHUTDOWN_IN_PROGRESS
;
2530 hSvc
= (PSERVICE_HANDLE
)hService
;
2531 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
2533 DPRINT1("Invalid handle tag!\n");
2534 return ERROR_INVALID_HANDLE
;
2537 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
2538 SERVICE_QUERY_CONFIG
))
2540 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
2541 return ERROR_ACCESS_DENIED
;
2544 lpService
= hSvc
->ServiceEntry
;
2545 if (lpService
== NULL
)
2547 DPRINT1("lpService == NULL!\n");
2548 return ERROR_INVALID_HANDLE
;
2551 /* FIXME: Lock the service database shared */
2553 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
2556 if (dwError
!= ERROR_SUCCESS
)
2559 dwError
= ScmReadString(hServiceKey
,
2562 if (dwError
!= ERROR_SUCCESS
)
2565 ScmReadString(hServiceKey
,
2567 &lpServiceStartName
);
2569 dwRequiredSize
= sizeof(QUERY_SERVICE_CONFIGW
);
2571 if (lpImagePath
!= NULL
)
2572 dwRequiredSize
+= ((wcslen(lpImagePath
) + 1) * sizeof(WCHAR
));
2574 dwRequiredSize
+= 2 * sizeof(WCHAR
);
2576 if (lpService
->lpGroup
!= NULL
)
2577 dwRequiredSize
+= ((wcslen(lpService
->lpGroup
->lpGroupName
) + 1) * sizeof(WCHAR
));
2579 dwRequiredSize
+= 2 * sizeof(WCHAR
);
2581 /* FIXME: Add Dependencies length*/
2583 if (lpServiceStartName
!= NULL
)
2584 dwRequiredSize
+= ((wcslen(lpServiceStartName
) + 1) * sizeof(WCHAR
));
2586 dwRequiredSize
+= 2 * sizeof(WCHAR
);
2588 if (lpService
->lpDisplayName
!= NULL
)
2589 dwRequiredSize
+= ((wcslen(lpService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
2591 dwRequiredSize
+= 2 * sizeof(WCHAR
);
2593 if (lpServiceConfig
== NULL
|| cbBufSize
< dwRequiredSize
)
2595 dwError
= ERROR_INSUFFICIENT_BUFFER
;
2599 lpConfig
= (LPQUERY_SERVICE_CONFIGW
)lpServiceConfig
;
2600 lpConfig
->dwServiceType
= lpService
->Status
.dwServiceType
;
2601 lpConfig
->dwStartType
= lpService
->dwStartType
;
2602 lpConfig
->dwErrorControl
= lpService
->dwErrorControl
;
2603 lpConfig
->dwTagId
= lpService
->dwTag
;
2605 lpStr
= (LPWSTR
)(lpConfig
+ 1);
2607 if (lpImagePath
!= NULL
)
2609 wcscpy(lpStr
, lpImagePath
);
2613 wcscpy(lpStr
, lpEmptyString
);
2616 lpConfig
->lpBinaryPathName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
2617 lpStr
+= (wcslen(lpStr
) + 1);
2619 if (lpService
->lpGroup
!= NULL
)
2621 wcscpy(lpStr
, lpService
->lpGroup
->lpGroupName
);
2625 wcscpy(lpStr
, lpEmptyString
);
2628 lpConfig
->lpLoadOrderGroup
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
2629 lpStr
+= (wcslen(lpStr
) + 1);
2631 /* FIXME: Append Dependencies */
2632 wcscpy(lpStr
, lpEmptyString
);
2634 lpStr
+= (wcslen(lpStr
) + 1);
2635 lpConfig
->lpDependencies
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
2637 if (lpServiceStartName
!= NULL
)
2639 wcscpy(lpStr
, lpServiceStartName
);
2643 wcscpy(lpStr
, lpEmptyString
);
2646 lpConfig
->lpServiceStartName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
2647 lpStr
+= (wcslen(lpStr
) + 1);
2649 if (lpService
->lpDisplayName
!= NULL
)
2651 wcscpy(lpStr
, lpService
->lpDisplayName
);
2655 wcscpy(lpStr
, lpEmptyString
);
2658 lpConfig
->lpDisplayName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
2661 if (pcbBytesNeeded
!= NULL
)
2662 *pcbBytesNeeded
= dwRequiredSize
;
2665 if (lpImagePath
!= NULL
)
2666 HeapFree(GetProcessHeap(), 0, lpImagePath
);
2668 if (lpServiceStartName
!= NULL
)
2669 HeapFree(GetProcessHeap(), 0, lpServiceStartName
);
2671 if (hServiceKey
!= NULL
)
2672 RegCloseKey(hServiceKey
);
2674 /* FIXME: Unlock the service database */
2676 DPRINT("RQueryServiceConfigW() done\n");
2683 DWORD
RQueryServiceLockStatusW(
2684 SC_RPC_HANDLE hSCManager
,
2685 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
2687 LPBOUNDED_DWORD_4K pcbBytesNeeded
)
2690 return ERROR_CALL_NOT_IMPLEMENTED
;
2695 DWORD
RStartServiceW(
2696 SC_RPC_HANDLE hService
,
2698 LPSTRING_PTRSW argv
)
2700 DWORD dwError
= ERROR_SUCCESS
;
2701 PSERVICE_HANDLE hSvc
;
2702 PSERVICE lpService
= NULL
;
2704 DPRINT("RStartServiceW() called\n");
2707 return ERROR_SHUTDOWN_IN_PROGRESS
;
2709 hSvc
= (PSERVICE_HANDLE
)hService
;
2710 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
2712 DPRINT1("Invalid handle tag!\n");
2713 return ERROR_INVALID_HANDLE
;
2716 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
2719 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
2720 return ERROR_ACCESS_DENIED
;
2723 lpService
= hSvc
->ServiceEntry
;
2724 if (lpService
== NULL
)
2726 DPRINT1("lpService == NULL!\n");
2727 return ERROR_INVALID_HANDLE
;
2730 if (lpService
->dwStartType
== SERVICE_DISABLED
)
2731 return ERROR_SERVICE_DISABLED
;
2733 if (lpService
->bDeleted
)
2734 return ERROR_SERVICE_MARKED_FOR_DELETE
;
2741 /* Start the service */
2742 dwError
= ScmStartService(lpService
, argc
, (LPWSTR
*)argv
);
2749 DWORD
RGetServiceDisplayNameW(
2750 SC_RPC_HANDLE hSCManager
,
2751 LPCWSTR lpServiceName
,
2752 LPWSTR lpDisplayName
,
2755 // PMANAGER_HANDLE hManager;
2760 DPRINT("RGetServiceDisplayNameW() called\n");
2761 DPRINT("hSCManager = %p\n", hSCManager
);
2762 DPRINT("lpServiceName: %S\n", lpServiceName
);
2763 DPRINT("lpDisplayName: %p\n", lpDisplayName
);
2764 DPRINT("*lpcchBuffer: %lu\n", *lpcchBuffer
);
2766 // hManager = (PMANAGER_HANDLE)hSCManager;
2767 // if (hManager->Handle.Tag != MANAGER_TAG)
2769 // DPRINT1("Invalid manager handle!\n");
2770 // return ERROR_INVALID_HANDLE;
2773 /* Get service database entry */
2774 lpService
= ScmGetServiceEntryByName(lpServiceName
);
2775 if (lpService
== NULL
)
2777 DPRINT1("Could not find a service!\n");
2779 /* If the service could not be found and lpcchBuffer is less than 2, windows
2780 puts null in lpDisplayName and puts 2 in lpcchBuffer */
2781 if (*lpcchBuffer
< 2)
2784 if (lpDisplayName
!= NULL
)
2786 *lpDisplayName
= '\0';
2790 return ERROR_SERVICE_DOES_NOT_EXIST
;
2793 if (!lpService
->lpDisplayName
)
2795 dwLength
= wcslen(lpService
->lpServiceName
);
2797 if (lpDisplayName
!= NULL
&&
2798 *lpcchBuffer
> dwLength
)
2800 wcscpy(lpDisplayName
, lpService
->lpServiceName
);
2805 dwLength
= wcslen(lpService
->lpDisplayName
);
2807 if (lpDisplayName
!= NULL
&&
2808 *lpcchBuffer
> dwLength
)
2810 wcscpy(lpDisplayName
, lpService
->lpDisplayName
);
2814 dwError
= (*lpcchBuffer
> dwLength
) ? ERROR_SUCCESS
: ERROR_INSUFFICIENT_BUFFER
;
2816 *lpcchBuffer
= dwLength
;
2823 DWORD
RGetServiceKeyNameW(
2824 SC_RPC_HANDLE hSCManager
,
2825 LPCWSTR lpDisplayName
,
2826 LPWSTR lpServiceName
,
2829 // PMANAGER_HANDLE hManager;
2834 DPRINT("RGetServiceKeyNameW() called\n");
2835 DPRINT("hSCManager = %p\n", hSCManager
);
2836 DPRINT("lpDisplayName: %S\n", lpDisplayName
);
2837 DPRINT("lpServiceName: %p\n", lpServiceName
);
2838 DPRINT("*lpcchBuffer: %lu\n", *lpcchBuffer
);
2840 // hManager = (PMANAGER_HANDLE)hSCManager;
2841 // if (hManager->Handle.Tag != MANAGER_TAG)
2843 // DPRINT1("Invalid manager handle!\n");
2844 // return ERROR_INVALID_HANDLE;
2847 /* Get service database entry */
2848 lpService
= ScmGetServiceEntryByDisplayName(lpDisplayName
);
2849 if (lpService
== NULL
)
2851 DPRINT1("Could not find a service!\n");
2853 /* If the service could not be found and lpcchBuffer is less than 2, windows
2854 puts null in lpDisplayName and puts 2 in lpcchBuffer */
2855 if (*lpcchBuffer
< 2)
2858 if (lpServiceName
!= NULL
)
2860 *lpServiceName
= '\0';
2864 return ERROR_SERVICE_DOES_NOT_EXIST
;
2867 dwLength
= wcslen(lpService
->lpServiceName
);
2869 if (lpServiceName
!= NULL
&&
2870 *lpcchBuffer
> dwLength
)
2872 wcscpy(lpServiceName
, lpService
->lpServiceName
);
2873 *lpcchBuffer
= dwLength
;
2874 return ERROR_SUCCESS
;
2877 dwError
= (*lpcchBuffer
> dwLength
) ? ERROR_SUCCESS
: ERROR_INSUFFICIENT_BUFFER
;
2879 *lpcchBuffer
= dwLength
;
2886 DWORD
RI_ScSetServiceBitsA(
2887 RPC_SERVICE_STATUS_HANDLE hServiceStatus
,
2888 DWORD dwServiceBits
,
2890 int bUpdateImmediately
,
2894 return ERROR_CALL_NOT_IMPLEMENTED
;
2899 DWORD
RChangeServiceConfigA(
2900 SC_RPC_HANDLE hService
,
2901 DWORD dwServiceType
,
2903 DWORD dwErrorControl
,
2904 LPSTR lpBinaryPathName
,
2905 LPSTR lpLoadOrderGroup
,
2907 LPSTR lpDependencies
,
2909 LPSTR lpServiceStartName
,
2912 LPSTR lpDisplayName
)
2914 DWORD dwError
= ERROR_SUCCESS
;
2915 PSERVICE_HANDLE hSvc
;
2916 PSERVICE lpService
= NULL
;
2917 HKEY hServiceKey
= NULL
;
2918 LPWSTR lpDisplayNameW
= NULL
;
2919 // LPWSTR lpBinaryPathNameW = NULL;
2920 LPWSTR lpLoadOrderGroupW
= NULL
;
2921 LPWSTR lpDependenciesW
= NULL
;
2922 // LPWSTR lpPasswordW = NULL;
2924 DPRINT("RChangeServiceConfigA() called\n");
2925 DPRINT("dwServiceType = %lu\n", dwServiceType
);
2926 DPRINT("dwStartType = %lu\n", dwStartType
);
2927 DPRINT("dwErrorControl = %lu\n", dwErrorControl
);
2928 DPRINT("lpBinaryPathName = %s\n", lpBinaryPathName
);
2929 DPRINT("lpLoadOrderGroup = %s\n", lpLoadOrderGroup
);
2930 DPRINT("lpDisplayName = %s\n", lpDisplayName
);
2933 return ERROR_SHUTDOWN_IN_PROGRESS
;
2935 hSvc
= (PSERVICE_HANDLE
)hService
;
2936 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
2938 DPRINT1("Invalid handle tag!\n");
2939 return ERROR_INVALID_HANDLE
;
2942 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
2943 SERVICE_CHANGE_CONFIG
))
2945 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
2946 return ERROR_ACCESS_DENIED
;
2949 lpService
= hSvc
->ServiceEntry
;
2950 if (lpService
== NULL
)
2952 DPRINT1("lpService == NULL!\n");
2953 return ERROR_INVALID_HANDLE
;
2956 /* FIXME: Lock database exclusively */
2958 if (lpService
->bDeleted
)
2960 /* FIXME: Unlock database */
2961 DPRINT1("The service has already been marked for delete!\n");
2962 return ERROR_SERVICE_MARKED_FOR_DELETE
;
2965 /* Open the service key */
2966 dwError
= ScmOpenServiceKey(lpService
->szServiceName
,
2969 if (dwError
!= ERROR_SUCCESS
)
2972 /* Write service data to the registry */
2974 if (lpDisplayName
!= NULL
&& *lpDisplayName
!= 0)
2976 /* Set the display name */
2977 lpDisplayNameW
= HeapAlloc(GetProcessHeap(),
2979 (strlen(lpDisplayName
) + 1) * sizeof(WCHAR
));
2980 if (lpDisplayNameW
== NULL
)
2982 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
2986 MultiByteToWideChar(CP_ACP
,
2991 strlen(lpDisplayName
) + 1);
2993 RegSetValueExW(hServiceKey
,
2997 (LPBYTE
)lpDisplayNameW
,
2998 (wcslen(lpDisplayNameW
) + 1) * sizeof(WCHAR
));
3000 /* Update lpService->lpDisplayName */
3001 if (lpService
->lpDisplayName
)
3002 HeapFree(GetProcessHeap(), 0, lpService
->lpDisplayName
);
3004 lpService
->lpDisplayName
= lpDisplayNameW
;
3007 if (dwServiceType
!= SERVICE_NO_CHANGE
)
3009 /* Set the service type */
3010 dwError
= RegSetValueExW(hServiceKey
,
3014 (LPBYTE
)&dwServiceType
,
3016 if (dwError
!= ERROR_SUCCESS
)
3019 lpService
->Status
.dwServiceType
= dwServiceType
;
3022 if (dwStartType
!= SERVICE_NO_CHANGE
)
3024 /* Set the start value */
3025 dwError
= RegSetValueExW(hServiceKey
,
3029 (LPBYTE
)&dwStartType
,
3031 if (dwError
!= ERROR_SUCCESS
)
3034 lpService
->dwStartType
= dwStartType
;
3037 if (dwErrorControl
!= SERVICE_NO_CHANGE
)
3039 /* Set the error control value */
3040 dwError
= RegSetValueExW(hServiceKey
,
3044 (LPBYTE
)&dwErrorControl
,
3046 if (dwError
!= ERROR_SUCCESS
)
3049 lpService
->dwErrorControl
= dwErrorControl
;
3053 /* FIXME: set the new ImagePath value */
3055 /* Set the image path */
3056 if (dwServiceType
& SERVICE_WIN32
)
3058 if (lpBinaryPathName
!= NULL
&& *lpBinaryPathName
!= 0)
3060 lpBinaryPathNameW
=HeapAlloc(GetProcessHeap(),0, (strlen(lpBinaryPathName
)+1) * sizeof(WCHAR
));
3061 MultiByteToWideChar(CP_ACP
, 0, lpBinaryPathName
, -1, lpBinaryPathNameW
, wcslen(lpBinaryPathNameW
)+1);
3062 dwError
= RegSetValueExW(hServiceKey
,
3066 (LPBYTE
)lpBinaryPathNameW
,
3067 (wcslen(lpBinaryPathNameW
) + 1) * sizeof(WCHAR
));
3068 if (dwError
!= ERROR_SUCCESS
)
3072 else if (dwServiceType
& SERVICE_DRIVER
)
3074 if (lpImagePath
!= NULL
&& *lpImagePath
!= 0)
3076 dwError
= RegSetValueExW(hServiceKey
,
3080 (LPBYTE
)lpImagePath
,
3081 (wcslen(lpImagePath
) + 1) *sizeof(WCHAR
));
3082 if (dwError
!= ERROR_SUCCESS
)
3088 /* Set the group name */
3089 if (lpLoadOrderGroup
!= NULL
&& *lpLoadOrderGroup
!= 0)
3091 lpLoadOrderGroupW
= HeapAlloc(GetProcessHeap(),
3093 (strlen(lpLoadOrderGroup
)+1) * sizeof(WCHAR
));
3094 if (lpLoadOrderGroupW
== NULL
)
3096 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
3100 MultiByteToWideChar(CP_ACP
,
3105 wcslen(lpLoadOrderGroupW
) + 1);
3107 dwError
= RegSetValueExW(hServiceKey
,
3111 (LPBYTE
)lpLoadOrderGroupW
,
3112 (wcslen(lpLoadOrderGroupW
) + 1) * sizeof(WCHAR
));
3113 if (dwError
!= ERROR_SUCCESS
)
3116 /* FIXME: Update lpService->lpServiceGroup */
3118 HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW
);
3121 if (lpdwTagId
!= NULL
)
3123 dwError
= ScmAssignNewTag(lpService
);
3124 if (dwError
!= ERROR_SUCCESS
)
3127 dwError
= RegSetValueExW(hServiceKey
,
3131 (LPBYTE
)&lpService
->dwTag
,
3133 if (dwError
!= ERROR_SUCCESS
)
3136 *lpdwTagId
= lpService
->dwTag
;
3139 /* Write dependencies */
3140 if (lpDependencies
!= NULL
&& *lpDependencies
!= 0)
3142 lpDependenciesW
= HeapAlloc(GetProcessHeap(),
3144 (strlen(lpDependencies
)+1) * sizeof(WCHAR
));
3145 if (lpDependenciesW
== NULL
)
3147 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
3151 MultiByteToWideChar(CP_ACP
,
3156 wcslen(lpDependenciesW
)+1);
3158 dwError
= ScmWriteDependencies(hServiceKey
,
3159 (LPWSTR
)lpDependenciesW
,
3162 HeapFree(GetProcessHeap(), 0, lpDependenciesW
);
3165 if (lpPassword
!= NULL
)
3167 /* FIXME: Write password */
3170 /* FIXME: Unlock database */
3173 if (hServiceKey
!= NULL
)
3174 RegCloseKey(hServiceKey
);
3176 DPRINT("RChangeServiceConfigA() done (Error %lu)\n", dwError
);
3183 DWORD
RCreateServiceA(
3184 SC_RPC_HANDLE hSCManager
,
3185 LPSTR lpServiceName
,
3186 LPSTR lpDisplayName
,
3187 DWORD dwDesiredAccess
,
3188 DWORD dwServiceType
,
3190 DWORD dwErrorControl
,
3191 LPSTR lpBinaryPathName
,
3192 LPSTR lpLoadOrderGroup
,
3194 LPBYTE lpDependencies
,
3196 LPSTR lpServiceStartName
,
3199 LPSC_RPC_HANDLE lpServiceHandle
)
3202 return ERROR_CALL_NOT_IMPLEMENTED
;
3207 DWORD
REnumDependentServicesA(
3208 SC_RPC_HANDLE hService
,
3209 DWORD dwServiceState
,
3212 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
3213 LPBOUNDED_DWORD_256K lpServicesReturned
)
3215 DWORD dwError
= ERROR_SUCCESS
;
3216 DWORD dwServicesReturned
= 0;
3217 DWORD dwServiceCount
;
3218 HKEY hServicesKey
= NULL
;
3219 LPSC_RPC_HANDLE hSCObject
;
3220 PSERVICE_HANDLE hSvc
;
3221 PSERVICE lpService
= NULL
;
3222 PSERVICE
*lpServicesArray
= NULL
;
3223 LPENUM_SERVICE_STATUSA lpServicesPtr
= NULL
;
3226 *pcbBytesNeeded
= 0;
3227 *lpServicesReturned
= 0;
3229 DPRINT("REnumDependentServicesA() called\n");
3231 hSCObject
= &hService
;
3232 hSvc
= (PSERVICE_HANDLE
) *hSCObject
;
3233 lpService
= hSvc
->ServiceEntry
;
3235 /* Check access rights */
3236 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
3237 SC_MANAGER_ENUMERATE_SERVICE
))
3239 DPRINT1("Insufficient access rights! 0x%lx\n",
3240 hSvc
->Handle
.DesiredAccess
);
3241 return ERROR_ACCESS_DENIED
;
3244 /* Open the Services Reg key */
3245 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3246 L
"System\\CurrentControlSet\\Services",
3251 if (dwError
!= ERROR_SUCCESS
)
3254 /* NOTE: Windows calculates the pcbBytesNeeded based on WCHAR strings for
3255 both EnumDependentServicesA and EnumDependentServicesW. So returned pcbBytesNeeded
3256 are the same for both. Verified in WINXP. */
3258 /* First determine the bytes needed and get the number of dependent services*/
3259 dwError
= Int_EnumDependentServicesW(hServicesKey
,
3264 &dwServicesReturned
);
3265 if (dwError
!= ERROR_SUCCESS
)
3268 /* If buffer size is less than the bytes needed or pointer is null*/
3269 if ((!lpServices
) || (cbBufSize
< *pcbBytesNeeded
))
3271 dwError
= ERROR_MORE_DATA
;
3275 /* Allocate memory for array of service pointers */
3276 lpServicesArray
= HeapAlloc(GetProcessHeap(),
3278 (dwServicesReturned
+ 1) * sizeof(PSERVICE
));
3279 if (!lpServicesArray
)
3281 DPRINT1("Could not allocate a buffer!!\n");
3282 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
3286 dwServicesReturned
= 0;
3287 *pcbBytesNeeded
= 0;
3289 dwError
= Int_EnumDependentServicesW(hServicesKey
,
3294 &dwServicesReturned
);
3295 if (dwError
!= ERROR_SUCCESS
)
3300 lpServicesPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
3301 lpStr
= (LPSTR
)(lpServices
+ (dwServicesReturned
* sizeof(ENUM_SERVICE_STATUSA
)));
3303 /* Copy EnumDepenedentService to Buffer */
3304 for (dwServiceCount
= 0; dwServiceCount
< dwServicesReturned
; dwServiceCount
++)
3306 lpService
= lpServicesArray
[dwServiceCount
];
3308 /* Copy the status info */
3309 memcpy(&lpServicesPtr
->ServiceStatus
,
3311 sizeof(SERVICE_STATUS
));
3313 /* Copy display name */
3314 WideCharToMultiByte(CP_ACP
,
3316 lpService
->lpDisplayName
,
3319 wcslen(lpService
->lpDisplayName
),
3322 lpServicesPtr
->lpDisplayName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServices
);
3323 lpStr
+= strlen(lpStr
) + 1;
3325 /* Copy service name */
3326 WideCharToMultiByte(CP_ACP
,
3328 lpService
->lpServiceName
,
3331 wcslen(lpService
->lpServiceName
),
3334 lpServicesPtr
->lpServiceName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServices
);
3335 lpStr
+= strlen(lpStr
) + 1;
3340 *lpServicesReturned
= dwServicesReturned
;
3343 if (lpServicesArray
)
3344 HeapFree(GetProcessHeap(), 0, lpServicesArray
);
3346 RegCloseKey(hServicesKey
);
3348 DPRINT("REnumDependentServicesA() done (Error %lu)\n", dwError
);
3355 DWORD
REnumServicesStatusA(
3356 SC_RPC_HANDLE hSCManager
,
3357 DWORD dwServiceType
,
3358 DWORD dwServiceState
,
3361 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
3362 LPBOUNDED_DWORD_256K lpServicesReturned
,
3363 LPBOUNDED_DWORD_256K lpResumeHandle
)
3365 LPENUM_SERVICE_STATUSW lpStatusPtrW
= NULL
;
3366 LPENUM_SERVICE_STATUSA lpStatusPtrA
= NULL
;
3367 LPWSTR lpStringPtrW
;
3370 DWORD dwServiceCount
;
3372 DPRINT("REnumServicesStatusA() called\n");
3374 if ((dwBufSize
> 0) && (lpBuffer
))
3376 lpStatusPtrW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwBufSize
);
3379 DPRINT1("Failed to allocate buffer!\n");
3380 return ERROR_NOT_ENOUGH_MEMORY
;
3384 dwError
= REnumServicesStatusW(hSCManager
,
3387 (LPBYTE
)lpStatusPtrW
,
3393 /* if no services were returned then we are Done */
3394 if (*lpServicesReturned
== 0)
3397 lpStatusPtrA
= (LPENUM_SERVICE_STATUSA
)lpBuffer
;
3398 lpStringPtrA
= (LPSTR
)((ULONG_PTR
)lpBuffer
+
3399 *lpServicesReturned
* sizeof(ENUM_SERVICE_STATUSA
));
3400 lpStringPtrW
= (LPWSTR
)((ULONG_PTR
)lpStatusPtrW
+
3401 *lpServicesReturned
* sizeof(ENUM_SERVICE_STATUSW
));
3403 for (dwServiceCount
= 0; dwServiceCount
< *lpServicesReturned
; dwServiceCount
++)
3405 /* Copy the service name */
3406 WideCharToMultiByte(CP_ACP
,
3411 wcslen(lpStringPtrW
),
3415 lpStatusPtrA
->lpServiceName
= (LPSTR
)((ULONG_PTR
)lpStringPtrA
- (ULONG_PTR
)lpBuffer
);
3416 lpStringPtrA
+= wcslen(lpStringPtrW
) + 1;
3417 lpStringPtrW
+= wcslen(lpStringPtrW
) + 1;
3419 /* Copy the display name */
3420 WideCharToMultiByte(CP_ACP
,
3425 wcslen(lpStringPtrW
),
3429 lpStatusPtrA
->lpDisplayName
= (LPSTR
)((ULONG_PTR
)lpStringPtrA
- (ULONG_PTR
)lpBuffer
);
3430 lpStringPtrA
+= wcslen(lpStringPtrW
) + 1;
3431 lpStringPtrW
+= wcslen(lpStringPtrW
) + 1;
3433 /* Copy the status information */
3434 memcpy(&lpStatusPtrA
->ServiceStatus
,
3435 &lpStatusPtrW
->ServiceStatus
,
3436 sizeof(SERVICE_STATUS
));
3443 HeapFree(GetProcessHeap(), 0, lpStatusPtrW
);
3445 DPRINT("REnumServicesStatusA() done (Error %lu)\n", dwError
);
3452 DWORD
ROpenSCManagerA(
3453 LPSTR lpMachineName
,
3454 LPSTR lpDatabaseName
,
3455 DWORD dwDesiredAccess
,
3456 LPSC_RPC_HANDLE lpScHandle
)
3458 UNICODE_STRING MachineName
;
3459 UNICODE_STRING DatabaseName
;
3462 DPRINT("ROpenSCManagerA() called\n");
3465 RtlCreateUnicodeStringFromAsciiz(&MachineName
,
3469 RtlCreateUnicodeStringFromAsciiz(&DatabaseName
,
3472 dwError
= ROpenSCManagerW(//BindingHandle,
3473 lpMachineName
? MachineName
.Buffer
: NULL
,
3474 lpDatabaseName
? DatabaseName
.Buffer
: NULL
,
3479 RtlFreeUnicodeString(&MachineName
);
3482 RtlFreeUnicodeString(&DatabaseName
);
3489 DWORD
ROpenServiceA(
3490 SC_RPC_HANDLE hSCManager
,
3491 LPSTR lpServiceName
,
3492 DWORD dwDesiredAccess
,
3493 LPSC_RPC_HANDLE lpServiceHandle
)
3495 UNICODE_STRING ServiceName
;
3498 DPRINT("ROpenServiceA() called\n");
3501 RtlCreateUnicodeStringFromAsciiz(&ServiceName
,
3504 dwError
= ROpenServiceW(//BindingHandle,
3506 lpServiceName
? ServiceName
.Buffer
: NULL
,
3511 RtlFreeUnicodeString(&ServiceName
);
3518 DWORD
RQueryServiceConfigA(
3519 SC_RPC_HANDLE hService
,
3520 LPBYTE lpBuf
, //LPQUERY_SERVICE_CONFIGA lpServiceConfig,
3522 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
3524 LPQUERY_SERVICE_CONFIGA lpServiceConfig
= (LPQUERY_SERVICE_CONFIGA
)lpBuf
;
3525 DWORD dwError
= ERROR_SUCCESS
;
3526 PSERVICE_HANDLE hSvc
;
3527 PSERVICE lpService
= NULL
;
3528 HKEY hServiceKey
= NULL
;
3529 LPWSTR lpImagePath
= NULL
;
3530 LPWSTR lpServiceStartName
= NULL
;
3531 DWORD dwRequiredSize
;
3532 LPQUERY_SERVICE_CONFIGA lpConfig
= NULL
;
3533 CHAR lpEmptyString
[]={0,0};
3536 DPRINT("RQueryServiceConfigA() called\n");
3539 return ERROR_SHUTDOWN_IN_PROGRESS
;
3541 hSvc
= (PSERVICE_HANDLE
)hService
;
3542 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
3544 DPRINT1("Invalid handle tag!\n");
3545 return ERROR_INVALID_HANDLE
;
3548 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
3549 SERVICE_QUERY_CONFIG
))
3551 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
3552 return ERROR_ACCESS_DENIED
;
3555 lpService
= hSvc
->ServiceEntry
;
3556 if (lpService
== NULL
)
3558 DPRINT1("lpService == NULL!\n");
3559 return ERROR_INVALID_HANDLE
;
3562 /* FIXME: Lock the service database shared */
3564 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
3567 if (dwError
!= ERROR_SUCCESS
)
3570 dwError
= ScmReadString(hServiceKey
,
3573 if (dwError
!= ERROR_SUCCESS
)
3576 ScmReadString(hServiceKey
,
3578 &lpServiceStartName
);
3580 dwRequiredSize
= sizeof(QUERY_SERVICE_CONFIGW
);
3582 if (lpImagePath
!= NULL
)
3583 dwRequiredSize
+= wcslen(lpImagePath
) + 1;
3585 dwRequiredSize
+= 2;
3587 if ((lpService
->lpGroup
!= NULL
) && (lpService
->lpGroup
->lpGroupName
!= NULL
))
3588 dwRequiredSize
+= wcslen(lpService
->lpGroup
->lpGroupName
) + 1;
3590 dwRequiredSize
+= 2;
3592 /* FIXME: Add Dependencies length*/
3593 dwRequiredSize
+= 2;
3595 if (lpServiceStartName
!= NULL
)
3596 dwRequiredSize
+= wcslen(lpServiceStartName
) + 1;
3598 dwRequiredSize
+= 2;
3600 if (lpService
->lpDisplayName
!= NULL
)
3601 dwRequiredSize
+= wcslen(lpService
->lpDisplayName
) + 1;
3603 dwRequiredSize
+= 2;
3605 if (lpServiceConfig
== NULL
|| cbBufSize
< dwRequiredSize
)
3607 dwError
= ERROR_INSUFFICIENT_BUFFER
;
3611 lpConfig
= (LPQUERY_SERVICE_CONFIGA
)lpServiceConfig
;
3612 lpConfig
->dwServiceType
= lpService
->Status
.dwServiceType
;
3613 lpConfig
->dwStartType
= lpService
->dwStartType
;
3614 lpConfig
->dwErrorControl
= lpService
->dwErrorControl
;
3615 lpConfig
->dwTagId
= lpService
->dwTag
;
3617 lpStr
= (LPSTR
)(lpServiceConfig
+ 1);
3619 /* NOTE: Strings that are NULL for QUERY_SERVICE_CONFIG are pointers to empty strings.
3624 WideCharToMultiByte(CP_ACP
,
3629 wcslen(lpImagePath
)+1,
3635 strcpy(lpStr
, lpEmptyString
);
3638 lpConfig
->lpBinaryPathName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
3639 lpStr
+= (strlen((LPSTR
)lpStr
) + 1);
3641 if (lpService
->lpGroup
&& lpService
->lpGroup
->lpGroupName
)
3643 WideCharToMultiByte(CP_ACP
,
3645 lpService
->lpGroup
->lpGroupName
,
3648 wcslen(lpService
->lpGroup
->lpGroupName
)+1,
3654 strcpy(lpStr
, lpEmptyString
);
3657 lpConfig
->lpLoadOrderGroup
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
3658 lpStr
+= (strlen(lpStr
) + 1);
3660 /* FIXME: Append Dependencies */
3661 strcpy(lpStr
, lpEmptyString
);
3663 lpConfig
->lpDependencies
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
3664 lpStr
+= (strlen(lpStr
) + 1);
3666 if (lpServiceStartName
)
3668 WideCharToMultiByte(CP_ACP
,
3673 wcslen(lpServiceStartName
)+1,
3679 strcpy(lpStr
, lpEmptyString
);
3682 lpConfig
->lpServiceStartName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
3683 lpStr
+= (strlen(lpStr
) + 1);
3685 if (lpService
->lpDisplayName
)
3687 WideCharToMultiByte(CP_ACP
,
3689 lpService
->lpDisplayName
,
3692 wcslen(lpService
->lpDisplayName
)+1,
3698 strcpy(lpStr
, lpEmptyString
);
3701 lpConfig
->lpDisplayName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
3704 if (pcbBytesNeeded
!= NULL
)
3705 *pcbBytesNeeded
= dwRequiredSize
;
3708 if (lpImagePath
!= NULL
)
3709 HeapFree(GetProcessHeap(), 0, lpImagePath
);
3711 if (lpServiceStartName
!= NULL
)
3712 HeapFree(GetProcessHeap(), 0, lpServiceStartName
);
3714 if (hServiceKey
!= NULL
)
3715 RegCloseKey(hServiceKey
);
3717 /* FIXME: Unlock the service database */
3719 DPRINT("RQueryServiceConfigA() done\n");
3726 DWORD
RQueryServiceLockStatusA(
3727 SC_RPC_HANDLE hSCManager
,
3728 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
3730 LPBOUNDED_DWORD_4K pcbBytesNeeded
)
3733 return ERROR_CALL_NOT_IMPLEMENTED
;
3738 DWORD
RStartServiceA(
3739 SC_RPC_HANDLE hService
,
3741 LPSTRING_PTRSA argv
)
3743 DWORD dwError
= ERROR_SUCCESS
;
3744 PSERVICE_HANDLE hSvc
;
3745 PSERVICE lpService
= NULL
;
3747 DPRINT1("RStartServiceA() called\n");
3750 return ERROR_SHUTDOWN_IN_PROGRESS
;
3752 hSvc
= (PSERVICE_HANDLE
)hService
;
3753 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
3755 DPRINT1("Invalid handle tag!\n");
3756 return ERROR_INVALID_HANDLE
;
3759 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
3762 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
3763 return ERROR_ACCESS_DENIED
;
3766 lpService
= hSvc
->ServiceEntry
;
3767 if (lpService
== NULL
)
3769 DPRINT1("lpService == NULL!\n");
3770 return ERROR_INVALID_HANDLE
;
3773 if (lpService
->dwStartType
== SERVICE_DISABLED
)
3774 return ERROR_SERVICE_DISABLED
;
3776 if (lpService
->bDeleted
)
3777 return ERROR_SERVICE_MARKED_FOR_DELETE
;
3779 /* FIXME: Convert argument vector to Unicode */
3781 /* Start the service */
3782 dwError
= ScmStartService(lpService
, 0, NULL
);
3784 /* FIXME: Free argument vector */
3791 DWORD
RGetServiceDisplayNameA(
3792 SC_RPC_HANDLE hSCManager
,
3793 LPCSTR lpServiceName
,
3794 LPSTR lpDisplayName
,
3795 LPBOUNDED_DWORD_4K lpcchBuffer
)
3797 // PMANAGER_HANDLE hManager;
3798 PSERVICE lpService
= NULL
;
3801 LPWSTR lpServiceNameW
;
3803 DPRINT("RGetServiceDisplayNameA() called\n");
3804 DPRINT("hSCManager = %p\n", hSCManager
);
3805 DPRINT("lpServiceName: %s\n", lpServiceName
);
3806 DPRINT("lpDisplayName: %p\n", lpDisplayName
);
3807 DPRINT("*lpcchBuffer: %lu\n", *lpcchBuffer
);
3809 // hManager = (PMANAGER_HANDLE)hSCManager;
3810 // if (hManager->Handle.Tag != MANAGER_TAG)
3812 // DPRINT1("Invalid manager handle!\n");
3813 // return ERROR_INVALID_HANDLE;
3816 if (lpServiceName
!= NULL
)
3818 dwLength
= strlen(lpServiceName
) + 1;
3819 lpServiceNameW
= HeapAlloc(GetProcessHeap(),
3821 dwLength
* sizeof(WCHAR
));
3822 if (!lpServiceNameW
)
3823 return ERROR_NOT_ENOUGH_MEMORY
;
3825 MultiByteToWideChar(CP_ACP
,
3832 lpService
= ScmGetServiceEntryByName(lpServiceNameW
);
3834 HeapFree(GetProcessHeap(), 0, lpServiceNameW
);
3837 if (lpService
== NULL
)
3839 DPRINT1("Could not find a service!\n");
3841 /* If the service could not be found and lpcchBuffer is 0, windows
3842 puts null in lpDisplayName and puts 1 in lpcchBuffer */
3843 if (*lpcchBuffer
== 0)
3846 if (lpDisplayName
!= NULL
)
3848 *lpDisplayName
= '\0';
3851 return ERROR_SERVICE_DOES_NOT_EXIST
;
3854 if (!lpService
->lpDisplayName
)
3856 dwLength
= wcslen(lpService
->lpServiceName
);
3857 if (lpDisplayName
!= NULL
&&
3858 *lpcchBuffer
> dwLength
)
3860 WideCharToMultiByte(CP_ACP
,
3862 lpService
->lpServiceName
,
3863 wcslen(lpService
->lpServiceName
),
3868 return ERROR_SUCCESS
;
3873 dwLength
= wcslen(lpService
->lpDisplayName
);
3874 if (lpDisplayName
!= NULL
&&
3875 *lpcchBuffer
> dwLength
)
3877 WideCharToMultiByte(CP_ACP
,
3879 lpService
->lpDisplayName
,
3880 wcslen(lpService
->lpDisplayName
),
3885 return ERROR_SUCCESS
;
3889 dwError
= (*lpcchBuffer
> dwLength
) ? ERROR_SUCCESS
: ERROR_INSUFFICIENT_BUFFER
;
3891 *lpcchBuffer
= dwLength
* 2;
3898 DWORD
RGetServiceKeyNameA(
3899 SC_RPC_HANDLE hSCManager
,
3900 LPCSTR lpDisplayName
,
3901 LPSTR lpServiceName
,
3902 LPBOUNDED_DWORD_4K lpcchBuffer
)
3907 LPWSTR lpDisplayNameW
;
3909 DPRINT("RGetServiceKeyNameA() called\n");
3910 DPRINT("hSCManager = %p\n", hSCManager
);
3911 DPRINT("lpDisplayName: %s\n", lpDisplayName
);
3912 DPRINT("lpServiceName: %p\n", lpServiceName
);
3913 DPRINT("*lpcchBuffer: %lu\n", *lpcchBuffer
);
3915 dwLength
= strlen(lpDisplayName
) + 1;
3916 lpDisplayNameW
= HeapAlloc(GetProcessHeap(),
3918 dwLength
* sizeof(WCHAR
));
3919 if (!lpDisplayNameW
)
3920 return ERROR_NOT_ENOUGH_MEMORY
;
3922 MultiByteToWideChar(CP_ACP
,
3929 lpService
= ScmGetServiceEntryByDisplayName(lpDisplayNameW
);
3931 HeapFree(GetProcessHeap(), 0, lpDisplayNameW
);
3933 if (lpService
== NULL
)
3935 DPRINT1("Could not find the service!\n");
3937 /* If the service could not be found and lpcchBuffer is 0,
3938 put null in lpDisplayName and puts 1 in lpcchBuffer, verified WINXP. */
3939 if (*lpcchBuffer
== 0)
3942 if (lpServiceName
!= NULL
)
3944 *lpServiceName
= '\0';
3948 return ERROR_SERVICE_DOES_NOT_EXIST
;
3951 dwLength
= wcslen(lpService
->lpServiceName
);
3952 if (lpServiceName
!= NULL
&&
3953 *lpcchBuffer
> dwLength
)
3955 WideCharToMultiByte(CP_ACP
,
3957 lpService
->lpServiceName
,
3958 wcslen(lpService
->lpServiceName
),
3963 return ERROR_SUCCESS
;
3966 dwError
= (*lpcchBuffer
> dwLength
) ? ERROR_SUCCESS
: ERROR_INSUFFICIENT_BUFFER
;
3968 *lpcchBuffer
= dwLength
* 2;
3975 DWORD
RI_ScGetCurrentGroupStateW(
3976 SC_RPC_HANDLE hSCManager
,
3977 LPWSTR lpLoadOrderGroup
,
3981 return ERROR_CALL_NOT_IMPLEMENTED
;
3986 DWORD
REnumServiceGroupW(
3987 SC_RPC_HANDLE hSCManager
,
3988 DWORD dwServiceType
,
3989 DWORD dwServiceState
,
3992 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
3993 LPBOUNDED_DWORD_256K lpServicesReturned
,
3994 LPBOUNDED_DWORD_256K lpResumeIndex
,
3995 LPCWSTR pszGroupName
)
3998 return ERROR_CALL_NOT_IMPLEMENTED
;
4003 // WARNING: This function is untested
4006 DWORD
RChangeServiceConfig2A(
4007 SC_RPC_HANDLE hService
,
4008 SC_RPC_CONFIG_INFOA Info
)
4010 SC_RPC_CONFIG_INFOW InfoW
;
4011 DWORD dwRet
, dwLength
;
4014 DPRINT("RChangeServiceConfig2A() called\n");
4015 DPRINT("dwInfoLevel = %lu\n", Info
.dwInfoLevel
);
4017 InfoW
.dwInfoLevel
= Info
.dwInfoLevel
;
4019 if (InfoW
.dwInfoLevel
== SERVICE_CONFIG_DESCRIPTION
)
4021 LPSERVICE_DESCRIPTIONW lpServiceDescriptonW
;
4022 LPSERVICE_DESCRIPTIONA lpServiceDescriptonA
;
4024 lpServiceDescriptonA
= Info
.psd
;
4026 ///if (lpServiceDescriptonA &&
4027 ///lpServiceDescriptonA->lpDescription)
4029 dwLength
= (strlen(Info
.lpDescription
) + 1) * sizeof(WCHAR
);
4031 lpServiceDescriptonW
= HeapAlloc(GetProcessHeap(),
4033 dwLength
+ sizeof(SERVICE_DESCRIPTIONW
));
4034 if (!lpServiceDescriptonW
)
4036 return ERROR_NOT_ENOUGH_MEMORY
;
4039 lpServiceDescriptonW
->lpDescription
= (LPWSTR
)(lpServiceDescriptonW
+ 1);
4041 MultiByteToWideChar(CP_ACP
,
4045 lpServiceDescriptonW
->lpDescription
,
4048 ptr
= lpServiceDescriptonW
;
4049 InfoW
.psd
= lpServiceDescriptonW
;
4052 else if (Info
.dwInfoLevel
== SERVICE_CONFIG_FAILURE_ACTIONS
)
4054 LPSERVICE_FAILURE_ACTIONSW lpServiceFailureActionsW
;
4055 LPSERVICE_FAILURE_ACTIONSA lpServiceFailureActionsA
;
4056 DWORD dwRebootLen
= 0;
4057 DWORD dwCommandLen
= 0;
4059 lpServiceFailureActionsA
= Info
.psfa
;
4061 if (lpServiceFailureActionsA
)
4063 if (lpServiceFailureActionsA
->lpRebootMsg
)
4065 dwRebootLen
= (strlen(lpServiceFailureActionsA
->lpRebootMsg
) + 1) * sizeof(WCHAR
);
4067 if (lpServiceFailureActionsA
->lpCommand
)
4069 dwCommandLen
= (strlen(lpServiceFailureActionsA
->lpCommand
) + 1) * sizeof(WCHAR
);
4071 dwLength
= dwRebootLen
+ dwCommandLen
+ sizeof(SERVICE_FAILURE_ACTIONSW
);
4073 lpServiceFailureActionsW
= HeapAlloc(GetProcessHeap(),
4076 if (!lpServiceFailureActionsW
)
4078 return ERROR_NOT_ENOUGH_MEMORY
;
4081 lpServiceFailureActionsW
->cActions
= lpServiceFailureActionsA
->cActions
;
4082 lpServiceFailureActionsW
->dwResetPeriod
= lpServiceFailureActionsA
->dwResetPeriod
;
4083 CopyMemory(lpServiceFailureActionsW
->lpsaActions
, lpServiceFailureActionsA
->lpsaActions
, sizeof(SC_ACTION
));
4085 if (lpServiceFailureActionsA
->lpRebootMsg
)
4087 MultiByteToWideChar(CP_ACP
,
4089 lpServiceFailureActionsA
->lpRebootMsg
,
4091 lpServiceFailureActionsW
->lpRebootMsg
,
4095 if (lpServiceFailureActionsA
->lpCommand
)
4097 MultiByteToWideChar(CP_ACP
,
4099 lpServiceFailureActionsA
->lpCommand
,
4101 lpServiceFailureActionsW
->lpCommand
,
4105 ptr
= lpServiceFailureActionsW
;
4109 dwRet
= RChangeServiceConfig2W(hService
, InfoW
);
4111 HeapFree(GetProcessHeap(), 0, ptr
);
4118 DWORD
RChangeServiceConfig2W(
4119 SC_RPC_HANDLE hService
,
4120 SC_RPC_CONFIG_INFOW Info
)
4122 DWORD dwError
= ERROR_SUCCESS
;
4123 PSERVICE_HANDLE hSvc
;
4124 PSERVICE lpService
= NULL
;
4125 HKEY hServiceKey
= NULL
;
4127 DPRINT("RChangeServiceConfig2W() called\n");
4128 DPRINT("dwInfoLevel = %lu\n", Info
.dwInfoLevel
);
4131 return ERROR_SHUTDOWN_IN_PROGRESS
;
4133 hSvc
= (PSERVICE_HANDLE
)hService
;
4134 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
4136 DPRINT1("Invalid handle tag!\n");
4137 return ERROR_INVALID_HANDLE
;
4140 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
4141 SERVICE_CHANGE_CONFIG
))
4143 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
4144 return ERROR_ACCESS_DENIED
;
4147 lpService
= hSvc
->ServiceEntry
;
4148 if (lpService
== NULL
)
4150 DPRINT1("lpService == NULL!\n");
4151 return ERROR_INVALID_HANDLE
;
4154 /* FIXME: Lock database exclusively */
4156 if (lpService
->bDeleted
)
4158 /* FIXME: Unlock database */
4159 DPRINT1("The service has already been marked for delete!\n");
4160 return ERROR_SERVICE_MARKED_FOR_DELETE
;
4163 /* Open the service key */
4164 dwError
= ScmOpenServiceKey(lpService
->szServiceName
,
4167 if (dwError
!= ERROR_SUCCESS
)
4170 if (Info
.dwInfoLevel
== SERVICE_CONFIG_DESCRIPTION
)
4172 LPSERVICE_DESCRIPTIONW lpServiceDescription
;
4174 lpServiceDescription
= (LPSERVICE_DESCRIPTIONW
)Info
.psd
;
4175 lpServiceDescription
->lpDescription
= (LPWSTR
)((ULONG_PTR
)lpServiceDescription
+ sizeof(LPSERVICE_DESCRIPTIONW
));
4177 if (lpServiceDescription
!= NULL
&&
4178 lpServiceDescription
->lpDescription
!= NULL
)
4180 DPRINT1("Setting value %S\n", lpServiceDescription
->lpDescription
);
4181 RegSetValueExW(hServiceKey
,
4185 (LPBYTE
)lpServiceDescription
->lpDescription
,
4186 (wcslen(lpServiceDescription
->lpDescription
) + 1) * sizeof(WCHAR
));
4188 if (dwError
!= ERROR_SUCCESS
)
4192 else if (Info
.dwInfoLevel
== SERVICE_CONFIG_FAILURE_ACTIONS
)
4195 dwError
= ERROR_CALL_NOT_IMPLEMENTED
;
4200 /* FIXME: Unlock database */
4201 if (hServiceKey
!= NULL
)
4202 RegCloseKey(hServiceKey
);
4204 DPRINT("RChangeServiceConfig2W() done (Error %lu)\n", dwError
);
4211 DWORD
RQueryServiceConfig2A(
4212 SC_RPC_HANDLE hService
,
4216 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
4218 DWORD dwError
= ERROR_SUCCESS
;
4219 PSERVICE_HANDLE hSvc
;
4220 PSERVICE lpService
= NULL
;
4221 HKEY hServiceKey
= NULL
;
4222 LPWSTR lpDescriptionW
= NULL
;
4223 LPSTR lpDescription
= NULL
;
4225 DPRINT1("RQueryServiceConfig2A() called hService %p dwInfoLevel %u, lpBuffer %p cbBufSize %u pcbBytesNeeded %p\n",hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
4228 return ERROR_INVALID_ADDRESS
;
4231 return ERROR_SHUTDOWN_IN_PROGRESS
;
4233 hSvc
= (PSERVICE_HANDLE
)hService
;
4234 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
4236 DPRINT1("Invalid handle tag!\n");
4237 return ERROR_INVALID_HANDLE
;
4240 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
4241 SERVICE_QUERY_CONFIG
))
4243 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
4244 return ERROR_ACCESS_DENIED
;
4247 lpService
= hSvc
->ServiceEntry
;
4248 if (lpService
== NULL
)
4250 DPRINT1("lpService == NULL!\n");
4251 return ERROR_INVALID_HANDLE
;
4254 /* FIXME: Lock the service database shared */
4256 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
4259 if (dwError
!= ERROR_SUCCESS
)
4262 if (dwInfoLevel
& SERVICE_CONFIG_DESCRIPTION
)
4264 LPSERVICE_DESCRIPTIONA lpServiceDescription
= (LPSERVICE_DESCRIPTIONA
)lpBuffer
;
4267 *pcbBytesNeeded
= sizeof(SERVICE_DESCRIPTIONA
);
4269 dwError
= ScmReadString(hServiceKey
,
4272 if (dwError
== ERROR_SUCCESS
)
4274 *pcbBytesNeeded
+= ((wcslen(lpDescriptionW
) + 1) * sizeof(WCHAR
));
4277 if (cbBufSize
>= *pcbBytesNeeded
)
4280 if (dwError
== ERROR_SUCCESS
)
4282 lpStr
= (LPSTR
)(lpServiceDescription
+ 1);
4284 WideCharToMultiByte(CP_ACP
,
4289 wcslen(lpDescriptionW
),
4292 lpServiceDescription
->lpDescription
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServiceDescription
);
4296 lpServiceDescription
->lpDescription
= NULL
;
4302 dwError
= ERROR_INSUFFICIENT_BUFFER
;
4306 else if (dwInfoLevel
& SERVICE_CONFIG_FAILURE_ACTIONS
)
4309 dwError
= ERROR_CALL_NOT_IMPLEMENTED
;
4314 if (lpDescription
!= NULL
)
4315 HeapFree(GetProcessHeap(), 0, lpDescription
);
4317 if (hServiceKey
!= NULL
)
4318 RegCloseKey(hServiceKey
);
4320 /* FIXME: Unlock database */
4322 DPRINT("RQueryServiceConfig2W() done (Error %lu)\n", dwError
);
4329 DWORD
RQueryServiceConfig2W(
4330 SC_RPC_HANDLE hService
,
4334 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
4336 DWORD dwError
= ERROR_SUCCESS
;
4337 PSERVICE_HANDLE hSvc
;
4338 PSERVICE lpService
= NULL
;
4339 HKEY hServiceKey
= NULL
;
4340 DWORD dwRequiredSize
;
4341 LPWSTR lpDescription
= NULL
;
4342 LPWSTR lpFailureCommand
= NULL
;
4343 LPWSTR lpRebootMessage
= NULL
;
4345 DPRINT("RQueryServiceConfig2W() called\n");
4348 return ERROR_INVALID_ADDRESS
;
4351 return ERROR_SHUTDOWN_IN_PROGRESS
;
4353 hSvc
= (PSERVICE_HANDLE
)hService
;
4354 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
4356 DPRINT1("Invalid handle tag!\n");
4357 return ERROR_INVALID_HANDLE
;
4360 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
4361 SERVICE_QUERY_CONFIG
))
4363 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
4364 return ERROR_ACCESS_DENIED
;
4367 lpService
= hSvc
->ServiceEntry
;
4368 if (lpService
== NULL
)
4370 DPRINT1("lpService == NULL!\n");
4371 return ERROR_INVALID_HANDLE
;
4374 /* FIXME: Lock the service database shared */
4376 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
4379 if (dwError
!= ERROR_SUCCESS
)
4382 if (dwInfoLevel
& SERVICE_CONFIG_DESCRIPTION
)
4384 LPSERVICE_DESCRIPTIONW lpServiceDescription
= (LPSERVICE_DESCRIPTIONW
)lpBuffer
;
4387 dwError
= ScmReadString(hServiceKey
,
4390 if (dwError
!= ERROR_SUCCESS
)
4393 dwRequiredSize
= sizeof(SERVICE_DESCRIPTIONW
) + ((wcslen(lpDescription
) + 1) * sizeof(WCHAR
));
4395 if (cbBufSize
< dwRequiredSize
)
4397 *pcbBytesNeeded
= dwRequiredSize
;
4398 dwError
= ERROR_INSUFFICIENT_BUFFER
;
4402 lpStr
= (LPWSTR
)(lpServiceDescription
+ 1);
4403 wcscpy(lpStr
, lpDescription
);
4404 lpServiceDescription
->lpDescription
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServiceDescription
);
4406 else if (dwInfoLevel
& SERVICE_CONFIG_FAILURE_ACTIONS
)
4409 LPSERVICE_FAILURE_ACTIONSW lpFailureActions
= (LPSERVICE_FAILURE_ACTIONSW
)lpBuffer
;
4413 dwError
= ScmReadString(hServiceKey
,
4417 dwError
= ScmReadString(hServiceKey
,
4421 dwRequiredSize
= sizeof(SERVICE_FAILURE_ACTIONSW
);
4423 if (lpFailureCommand
)
4424 dwRequiredSize
+= (wcslen(lpFailureCommand
) + 1) * sizeof(WCHAR
);
4426 if (lpRebootMessage
)
4427 dwRequiredSize
+= (wcslen(lpRebootMessage
) + 1) * sizeof(WCHAR
);
4429 if (cbBufSize
< dwRequiredSize
)
4431 *pcbBytesNeeded
= dwRequiredSize
;
4432 dwError
= ERROR_INSUFFICIENT_BUFFER
;
4436 lpFailureActions
->cActions
= 0;
4437 lpFailureActions
->dwResetPeriod
= 0;
4438 lpFailureActions
->lpCommand
= NULL
;
4439 lpFailureActions
->lpRebootMsg
= NULL
;
4440 lpFailureActions
->lpsaActions
= NULL
;
4442 lpStr
= (LPWSTR
)(lpFailureActions
+ 1);
4443 if (lpRebootMessage
)
4445 wcscpy(lpStr
, lpRebootMessage
);
4446 lpFailureActions
->lpRebootMsg
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpRebootMessage
);
4447 lpStr
+= wcslen(lpRebootMessage
) + 1;
4450 if (lpFailureCommand
)
4452 wcscpy(lpStr
, lpFailureCommand
);
4453 lpFailureActions
->lpCommand
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpFailureCommand
);
4454 lpStr
+= wcslen(lpRebootMessage
) + 1;
4456 dwError
= STATUS_SUCCESS
;
4461 if (lpDescription
!= NULL
)
4462 HeapFree(GetProcessHeap(), 0, lpDescription
);
4464 if (lpRebootMessage
!= NULL
)
4465 HeapFree(GetProcessHeap(), 0, lpRebootMessage
);
4467 if (lpFailureCommand
!= NULL
)
4468 HeapFree(GetProcessHeap(), 0, lpFailureCommand
);
4470 if (hServiceKey
!= NULL
)
4471 RegCloseKey(hServiceKey
);
4473 /* FIXME: Unlock database */
4475 DPRINT("RQueryServiceConfig2W() done (Error %lu)\n", dwError
);
4482 DWORD
RQueryServiceStatusEx(
4483 SC_RPC_HANDLE hService
,
4484 SC_STATUS_TYPE InfoLevel
,
4487 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
4489 LPSERVICE_STATUS_PROCESS lpStatus
;
4490 PSERVICE_HANDLE hSvc
;
4493 DPRINT("RQueryServiceStatusEx() called\n");
4496 return ERROR_SHUTDOWN_IN_PROGRESS
;
4498 if (InfoLevel
!= SC_STATUS_PROCESS_INFO
)
4499 return ERROR_INVALID_LEVEL
;
4501 *pcbBytesNeeded
= sizeof(SERVICE_STATUS_PROCESS
);
4503 if (cbBufSize
< sizeof(SERVICE_STATUS_PROCESS
))
4504 return ERROR_INSUFFICIENT_BUFFER
;
4506 hSvc
= (PSERVICE_HANDLE
)hService
;
4507 if (!hSvc
|| hSvc
->Handle
.Tag
!= SERVICE_TAG
)
4509 DPRINT1("Invalid handle tag!\n");
4510 return ERROR_INVALID_HANDLE
;
4513 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
4514 SERVICE_QUERY_STATUS
))
4516 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
4517 return ERROR_ACCESS_DENIED
;
4520 lpService
= hSvc
->ServiceEntry
;
4521 if (lpService
== NULL
)
4523 DPRINT1("lpService == NULL!\n");
4524 return ERROR_INVALID_HANDLE
;
4527 lpStatus
= (LPSERVICE_STATUS_PROCESS
)lpBuffer
;
4529 /* Return service status information */
4530 RtlCopyMemory(lpStatus
,
4532 sizeof(SERVICE_STATUS
));
4534 lpStatus
->dwProcessId
= lpService
->ProcessId
; /* FIXME */
4535 lpStatus
->dwServiceFlags
= 0; /* FIXME */
4537 return ERROR_SUCCESS
;
4542 DWORD
REnumServicesStatusExA(
4543 SC_RPC_HANDLE hSCManager
,
4544 SC_ENUM_TYPE InfoLevel
,
4545 DWORD dwServiceType
,
4546 DWORD dwServiceState
,
4549 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
4550 LPBOUNDED_DWORD_256K lpServicesReturned
,
4551 LPBOUNDED_DWORD_256K lpResumeIndex
,
4552 LPCSTR pszGroupName
)
4554 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtrW
= NULL
;
4555 LPENUM_SERVICE_STATUS_PROCESSA lpStatusPtrA
= NULL
;
4556 LPWSTR lpStringPtrW
;
4558 LPWSTR pszGroupNameW
= NULL
;
4560 DWORD dwServiceCount
;
4562 DPRINT("REnumServicesStatusExA() called\n");
4566 pszGroupNameW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (strlen(pszGroupName
) + 1) * sizeof(WCHAR
));
4569 DPRINT1("Failed to allocate buffer!\n");
4570 return ERROR_NOT_ENOUGH_MEMORY
;
4572 MultiByteToWideChar(CP_ACP
,
4577 strlen(pszGroupName
) + 1);
4580 if ((cbBufSize
> 0) && (lpBuffer
))
4582 lpStatusPtrW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, cbBufSize
);
4585 DPRINT1("Failed to allocate buffer!\n");
4586 return ERROR_NOT_ENOUGH_MEMORY
;
4590 dwError
= REnumServicesStatusExW(hSCManager
,
4594 (LPBYTE
)lpStatusPtrW
,
4601 /* if no services were returned then we are Done */
4602 if (*lpServicesReturned
== 0) goto Done
;
4604 lpStatusPtrA
= (LPENUM_SERVICE_STATUS_PROCESSA
)lpBuffer
;
4605 lpStringPtrA
= (LPSTR
)((ULONG_PTR
)lpBuffer
+
4606 *lpServicesReturned
* sizeof(ENUM_SERVICE_STATUS_PROCESSA
));
4607 lpStringPtrW
= (LPWSTR
)((ULONG_PTR
)lpStatusPtrW
+
4608 *lpServicesReturned
* sizeof(ENUM_SERVICE_STATUS_PROCESSW
));
4610 for (dwServiceCount
= 0; dwServiceCount
< *lpServicesReturned
; dwServiceCount
++)
4612 /* Copy the service name */
4613 WideCharToMultiByte(CP_ACP
,
4618 wcslen(lpStringPtrW
),
4622 lpStatusPtrA
->lpServiceName
= (LPSTR
)((ULONG_PTR
)lpStringPtrA
- (ULONG_PTR
)lpBuffer
);
4623 lpStringPtrA
+= wcslen(lpStringPtrW
) + 1;
4624 lpStringPtrW
+= wcslen(lpStringPtrW
) + 1;
4626 /* Copy the display name */
4627 WideCharToMultiByte(CP_ACP
,
4632 wcslen(lpStringPtrW
),
4636 lpStatusPtrA
->lpDisplayName
= (LPSTR
)((ULONG_PTR
)lpStringPtrA
- (ULONG_PTR
)lpBuffer
);
4637 lpStringPtrA
+= wcslen(lpStringPtrW
) + 1;
4638 lpStringPtrW
+= wcslen(lpStringPtrW
) + 1;
4640 /* Copy the status information */
4641 memcpy(&lpStatusPtrA
->ServiceStatusProcess
,
4642 &lpStatusPtrW
->ServiceStatusProcess
,
4643 sizeof(SERVICE_STATUS
));
4645 lpStatusPtrA
->ServiceStatusProcess
.dwProcessId
= lpStatusPtrW
->ServiceStatusProcess
.dwProcessId
; /* FIXME */
4646 lpStatusPtrA
->ServiceStatusProcess
.dwServiceFlags
= 0; /* FIXME */
4651 if (pszGroupNameW
) HeapFree(GetProcessHeap(), 0, pszGroupNameW
);
4653 if (lpStatusPtrW
) HeapFree(GetProcessHeap(), 0, lpStatusPtrW
);
4655 DPRINT("REnumServicesStatusExA() done (Error %lu)\n", dwError
);
4662 DWORD
REnumServicesStatusExW(
4663 SC_RPC_HANDLE hSCManager
,
4664 SC_ENUM_TYPE InfoLevel
,
4665 DWORD dwServiceType
,
4666 DWORD dwServiceState
,
4669 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
4670 LPBOUNDED_DWORD_256K lpServicesReturned
,
4671 LPBOUNDED_DWORD_256K lpResumeIndex
,
4672 LPCWSTR pszGroupName
)
4674 PMANAGER_HANDLE hManager
;
4676 DWORD dwError
= ERROR_SUCCESS
;
4677 PLIST_ENTRY ServiceEntry
;
4678 PSERVICE CurrentService
;
4680 DWORD dwRequiredSize
;
4681 DWORD dwServiceCount
;
4683 DWORD dwLastResumeCount
= 0;
4684 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
4687 DPRINT("REnumServicesStatusExW() called\n");
4690 return ERROR_SHUTDOWN_IN_PROGRESS
;
4692 if (InfoLevel
!= SC_ENUM_PROCESS_INFO
)
4693 return ERROR_INVALID_LEVEL
;
4695 hManager
= (PMANAGER_HANDLE
)hSCManager
;
4696 if (!hManager
|| hManager
->Handle
.Tag
!= MANAGER_TAG
)
4698 DPRINT1("Invalid manager handle!\n");
4699 return ERROR_INVALID_HANDLE
;
4702 *pcbBytesNeeded
= 0;
4703 *lpServicesReturned
= 0;
4705 if ((dwServiceType
!=SERVICE_DRIVER
) && (dwServiceType
!=SERVICE_WIN32
))
4707 DPRINT1("Not a valid Service Type!\n");
4708 return ERROR_INVALID_PARAMETER
;
4711 if ((dwServiceState
<SERVICE_ACTIVE
) || (dwServiceState
>SERVICE_STATE_ALL
))
4713 DPRINT1("Not a valid Service State!\n");
4714 return ERROR_INVALID_PARAMETER
;
4717 /* Check access rights */
4718 if (!RtlAreAllAccessesGranted(hManager
->Handle
.DesiredAccess
,
4719 SC_MANAGER_ENUMERATE_SERVICE
))
4721 DPRINT1("Insufficient access rights! 0x%lx\n",
4722 hManager
->Handle
.DesiredAccess
);
4723 return ERROR_ACCESS_DENIED
;
4726 if (lpResumeIndex
) dwLastResumeCount
= *lpResumeIndex
;
4728 /* Lock the service list shared */
4730 lpService
= ScmGetServiceEntryByResumeCount(dwLastResumeCount
);
4731 if (lpService
== NULL
)
4733 dwError
= ERROR_SUCCESS
;
4740 for (ServiceEntry
= &lpService
->ServiceListEntry
;
4741 ServiceEntry
!= &ServiceListHead
;
4742 ServiceEntry
= ServiceEntry
->Flink
)
4744 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
4748 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
4751 dwState
= SERVICE_ACTIVE
;
4752 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
4753 dwState
= SERVICE_INACTIVE
;
4755 if ((dwState
& dwServiceState
) == 0)
4760 if (*pszGroupName
== 0)
4762 if (CurrentService
->lpGroup
!= NULL
)
4767 if ((CurrentService
->lpGroup
== NULL
) ||
4768 _wcsicmp(pszGroupName
, CurrentService
->lpGroup
->lpGroupName
))
4773 dwSize
= sizeof(ENUM_SERVICE_STATUS_PROCESSW
) +
4774 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
4775 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
4777 if (dwRequiredSize
+ dwSize
<= cbBufSize
)
4779 DPRINT("Service name: %S fit\n", CurrentService
->lpServiceName
);
4780 dwRequiredSize
+= dwSize
;
4782 dwLastResumeCount
= CurrentService
->dwResumeCount
;
4786 DPRINT("Service name: %S no fit\n", CurrentService
->lpServiceName
);
4792 DPRINT("dwRequiredSize: %lu\n", dwRequiredSize
);
4793 DPRINT("dwServiceCount: %lu\n", dwServiceCount
);
4796 ServiceEntry
!= &ServiceListHead
;
4797 ServiceEntry
= ServiceEntry
->Flink
)
4799 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
4803 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
4806 dwState
= SERVICE_ACTIVE
;
4807 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
4808 dwState
= SERVICE_INACTIVE
;
4810 if ((dwState
& dwServiceState
) == 0)
4815 if (*pszGroupName
== 0)
4817 if (CurrentService
->lpGroup
!= NULL
)
4822 if ((CurrentService
->lpGroup
== NULL
) ||
4823 _wcsicmp(pszGroupName
, CurrentService
->lpGroup
->lpGroupName
))
4828 dwRequiredSize
+= (sizeof(ENUM_SERVICE_STATUS_PROCESSW
) +
4829 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
4830 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
)));
4832 dwError
= ERROR_MORE_DATA
;
4835 DPRINT("*pcbBytesNeeded: %lu\n", dwRequiredSize
);
4837 if (lpResumeIndex
) *lpResumeIndex
= dwLastResumeCount
;
4838 *lpServicesReturned
= dwServiceCount
;
4839 *pcbBytesNeeded
= dwRequiredSize
;
4841 /* If there was no services that matched */
4842 if ((!dwServiceCount
) && (dwError
!= ERROR_MORE_DATA
))
4844 dwError
= ERROR_SERVICE_DOES_NOT_EXIST
;
4848 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpBuffer
;
4849 lpStringPtr
= (LPWSTR
)((ULONG_PTR
)lpBuffer
+
4850 dwServiceCount
* sizeof(ENUM_SERVICE_STATUS_PROCESSW
));
4853 for (ServiceEntry
= &lpService
->ServiceListEntry
;
4854 ServiceEntry
!= &ServiceListHead
;
4855 ServiceEntry
= ServiceEntry
->Flink
)
4857 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
4861 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
4864 dwState
= SERVICE_ACTIVE
;
4865 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
4866 dwState
= SERVICE_INACTIVE
;
4868 if ((dwState
& dwServiceState
) == 0)
4873 if (*pszGroupName
== 0)
4875 if (CurrentService
->lpGroup
!= NULL
)
4880 if ((CurrentService
->lpGroup
== NULL
) ||
4881 _wcsicmp(pszGroupName
, CurrentService
->lpGroup
->lpGroupName
))
4886 dwSize
= sizeof(ENUM_SERVICE_STATUS_PROCESSW
) +
4887 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
4888 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
4890 if (dwRequiredSize
+ dwSize
<= cbBufSize
)
4892 /* Copy the service name */
4894 CurrentService
->lpServiceName
);
4895 lpStatusPtr
->lpServiceName
= (LPWSTR
)((ULONG_PTR
)lpStringPtr
- (ULONG_PTR
)lpBuffer
);
4896 lpStringPtr
+= (wcslen(CurrentService
->lpServiceName
) + 1);
4898 /* Copy the display name */
4900 CurrentService
->lpDisplayName
);
4901 lpStatusPtr
->lpDisplayName
= (LPWSTR
)((ULONG_PTR
)lpStringPtr
- (ULONG_PTR
)lpBuffer
);
4902 lpStringPtr
+= (wcslen(CurrentService
->lpDisplayName
) + 1);
4904 /* Copy the status information */
4905 memcpy(&lpStatusPtr
->ServiceStatusProcess
,
4906 &CurrentService
->Status
,
4907 sizeof(SERVICE_STATUS
));
4908 lpStatusPtr
->ServiceStatusProcess
.dwProcessId
= CurrentService
->ProcessId
; /* FIXME */
4909 lpStatusPtr
->ServiceStatusProcess
.dwServiceFlags
= 0; /* FIXME */
4912 dwRequiredSize
+= dwSize
;
4922 *pcbBytesNeeded
= 0;
4923 if (lpResumeIndex
) *lpResumeIndex
= 0;
4927 /* Unlock the service list */
4929 DPRINT("REnumServicesStatusExW() done (Error %lu)\n", dwError
);
4936 DWORD
RSendTSMessage(
4937 handle_t BindingHandle
) /* FIXME */
4940 return ERROR_CALL_NOT_IMPLEMENTED
;
4945 DWORD
RCreateServiceWOW64A(
4946 handle_t BindingHandle
,
4947 LPSTR lpServiceName
,
4948 LPSTR lpDisplayName
,
4949 DWORD dwDesiredAccess
,
4950 DWORD dwServiceType
,
4952 DWORD dwErrorControl
,
4953 LPSTR lpBinaryPathName
,
4954 LPSTR lpLoadOrderGroup
,
4956 LPBYTE lpDependencies
,
4958 LPSTR lpServiceStartName
,
4961 LPSC_RPC_HANDLE lpServiceHandle
)
4964 return ERROR_CALL_NOT_IMPLEMENTED
;
4969 DWORD
RCreateServiceWOW64W(
4970 handle_t BindingHandle
,
4971 LPWSTR lpServiceName
,
4972 LPWSTR lpDisplayName
,
4973 DWORD dwDesiredAccess
,
4974 DWORD dwServiceType
,
4976 DWORD dwErrorControl
,
4977 LPWSTR lpBinaryPathName
,
4978 LPWSTR lpLoadOrderGroup
,
4980 LPBYTE lpDependencies
,
4982 LPWSTR lpServiceStartName
,
4985 LPSC_RPC_HANDLE lpServiceHandle
)
4988 return ERROR_CALL_NOT_IMPLEMENTED
;
4993 DWORD
RQueryServiceTagInfo(
4994 handle_t BindingHandle
) /* FIXME */
4997 return ERROR_CALL_NOT_IMPLEMENTED
;
5002 DWORD
RNotifyServiceStatusChange(
5003 SC_RPC_HANDLE hService
,
5004 SC_RPC_NOTIFY_PARAMS NotifyParams
,
5005 GUID
*pClientProcessGuid
,
5006 GUID
*pSCMProcessGuid
,
5007 PBOOL pfCreateRemoteQueue
,
5008 LPSC_NOTIFY_RPC_HANDLE phNotify
)
5011 return ERROR_CALL_NOT_IMPLEMENTED
;
5016 DWORD
RGetNotifyResults(
5017 SC_NOTIFY_RPC_HANDLE hNotify
,
5018 PSC_RPC_NOTIFY_PARAMS_LIST
*ppNotifyParams
)
5021 return ERROR_CALL_NOT_IMPLEMENTED
;
5026 DWORD
RCloseNotifyHandle(
5027 LPSC_NOTIFY_RPC_HANDLE phNotify
,
5031 return ERROR_CALL_NOT_IMPLEMENTED
;
5036 DWORD
RControlServiceExA(
5037 SC_RPC_HANDLE hService
,
5042 return ERROR_CALL_NOT_IMPLEMENTED
;
5047 DWORD
RControlServiceExW(
5048 SC_RPC_HANDLE hService
,
5053 return ERROR_CALL_NOT_IMPLEMENTED
;
5058 DWORD
RSendPnPMessage(
5059 handle_t BindingHandle
) /* FIXME */
5062 return ERROR_CALL_NOT_IMPLEMENTED
;
5067 DWORD
RValidatePnPService(
5068 handle_t BindingHandle
) /* FIXME */
5071 return ERROR_CALL_NOT_IMPLEMENTED
;
5076 DWORD
ROpenServiceStatusHandle(
5077 handle_t BindingHandle
) /* FIXME */
5080 return ERROR_CALL_NOT_IMPLEMENTED
;
5086 handle_t BindingHandle
) /* FIXME */
5089 return ERROR_CALL_NOT_IMPLEMENTED
;
5093 void __RPC_FAR
* __RPC_USER
midl_user_allocate(SIZE_T len
)
5095 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
5099 void __RPC_USER
midl_user_free(void __RPC_FAR
* ptr
)
5101 HeapFree(GetProcessHeap(), 0, ptr
);
5105 void __RPC_USER
SC_RPC_HANDLE_rundown(SC_RPC_HANDLE hSCObject
)
5110 void __RPC_USER
SC_RPC_LOCK_rundown(SC_RPC_LOCK Lock
)
5115 void __RPC_USER
SC_NOTIFY_RPC_HANDLE_rundown(SC_NOTIFY_RPC_HANDLE hNotify
)