5 /* INCLUDES ****************************************************************/
14 /* GLOBALS *****************************************************************/
16 #define MANAGER_TAG 0x72674D68 /* 'hMgr' */
17 #define SERVICE_TAG 0x63765368 /* 'hSvc' */
19 typedef struct _SCMGR_HANDLE
27 typedef struct _MANAGER_HANDLE
31 /* FIXME: Insert more data here */
33 WCHAR DatabaseName
[1];
34 } MANAGER_HANDLE
, *PMANAGER_HANDLE
;
37 typedef struct _SERVICE_HANDLE
42 PSERVICE ServiceEntry
;
44 /* FIXME: Insert more data here */
46 } SERVICE_HANDLE
, *PSERVICE_HANDLE
;
49 #define SC_MANAGER_READ \
50 (STANDARD_RIGHTS_READ | \
51 SC_MANAGER_QUERY_LOCK_STATUS | \
52 SC_MANAGER_ENUMERATE_SERVICE)
54 #define SC_MANAGER_WRITE \
55 (STANDARD_RIGHTS_WRITE | \
56 SC_MANAGER_MODIFY_BOOT_CONFIG | \
57 SC_MANAGER_CREATE_SERVICE)
59 #define SC_MANAGER_EXECUTE \
60 (STANDARD_RIGHTS_EXECUTE | \
62 SC_MANAGER_ENUMERATE_SERVICE | \
63 SC_MANAGER_CONNECT | \
64 SC_MANAGER_CREATE_SERVICE)
67 #define SERVICE_READ \
68 (STANDARD_RIGHTS_READ | \
69 SERVICE_INTERROGATE | \
70 SERVICE_ENUMERATE_DEPENDENTS | \
71 SERVICE_QUERY_STATUS | \
74 #define SERVICE_WRITE \
75 (STANDARD_RIGHTS_WRITE | \
76 SERVICE_CHANGE_CONFIG)
78 #define SERVICE_EXECUTE \
79 (STANDARD_RIGHTS_EXECUTE | \
80 SERVICE_USER_DEFINED_CONTROL | \
81 SERVICE_PAUSE_CONTINUE | \
86 /* VARIABLES ***************************************************************/
88 static GENERIC_MAPPING
89 ScmManagerMapping
= {SC_MANAGER_READ
,
92 SC_MANAGER_ALL_ACCESS
};
94 static GENERIC_MAPPING
95 ScmServiceMapping
= {SERVICE_READ
,
98 SC_MANAGER_ALL_ACCESS
};
101 /* FUNCTIONS ***************************************************************/
104 ScmStartRpcServer(VOID
)
108 DPRINT("ScmStartRpcServer() called");
110 Status
= RpcServerUseProtseqEpW(L
"ncacn_np",
114 if (Status
!= RPC_S_OK
)
116 DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status
);
120 Status
= RpcServerRegisterIf(svcctl_ServerIfHandle
,
123 if (Status
!= RPC_S_OK
)
125 DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status
);
129 Status
= RpcServerListen(1, 20, TRUE
);
130 if (Status
!= RPC_S_OK
)
132 DPRINT1("RpcServerListen() failed (Status %lx)\n", Status
);
136 DPRINT("ScmStartRpcServer() done");
141 ScmCreateManagerHandle(LPWSTR lpDatabaseName
,
146 if (lpDatabaseName
== NULL
)
147 lpDatabaseName
= SERVICES_ACTIVE_DATABASEW
;
149 Ptr
= HeapAlloc(GetProcessHeap(),
151 sizeof(MANAGER_HANDLE
) + wcslen(lpDatabaseName
) * sizeof(WCHAR
));
153 return ERROR_NOT_ENOUGH_MEMORY
;
155 Ptr
->Handle
.Tag
= MANAGER_TAG
;
156 Ptr
->Handle
.RefCount
= 1;
158 /* FIXME: initialize more data here */
160 wcscpy(Ptr
->DatabaseName
, lpDatabaseName
);
162 *Handle
= (SC_HANDLE
)Ptr
;
164 return ERROR_SUCCESS
;
169 ScmCreateServiceHandle(PSERVICE lpServiceEntry
,
174 Ptr
= HeapAlloc(GetProcessHeap(),
176 sizeof(SERVICE_HANDLE
));
178 return ERROR_NOT_ENOUGH_MEMORY
;
180 Ptr
->Handle
.Tag
= SERVICE_TAG
;
181 Ptr
->Handle
.RefCount
= 1;
183 /* FIXME: initialize more data here */
184 Ptr
->ServiceEntry
= lpServiceEntry
;
186 *Handle
= (SC_HANDLE
)Ptr
;
188 return ERROR_SUCCESS
;
193 ScmCheckAccess(SC_HANDLE Handle
,
194 DWORD dwDesiredAccess
)
196 PMANAGER_HANDLE hMgr
;
198 hMgr
= (PMANAGER_HANDLE
)Handle
;
199 if (hMgr
->Handle
.Tag
== MANAGER_TAG
)
201 RtlMapGenericMask(&dwDesiredAccess
,
204 hMgr
->Handle
.DesiredAccess
= dwDesiredAccess
;
206 return ERROR_SUCCESS
;
208 else if (hMgr
->Handle
.Tag
== SERVICE_TAG
)
210 RtlMapGenericMask(&dwDesiredAccess
,
213 hMgr
->Handle
.DesiredAccess
= dwDesiredAccess
;
215 return ERROR_SUCCESS
;
218 return ERROR_INVALID_HANDLE
;
224 ScmrCloseServiceHandle(handle_t BindingHandle
,
225 unsigned int hScObject
)
227 PMANAGER_HANDLE hManager
;
229 DPRINT("ScmrCloseServiceHandle() called\n");
231 DPRINT("hScObject = %X\n", hScObject
);
234 return ERROR_INVALID_HANDLE
;
236 hManager
= (PMANAGER_HANDLE
)hScObject
;
237 if (hManager
->Handle
.Tag
== MANAGER_TAG
)
239 DPRINT("Found manager handle\n");
241 hManager
->Handle
.RefCount
--;
242 if (hManager
->Handle
.RefCount
== 0)
244 /* FIXME: add cleanup code */
246 HeapFree(GetProcessHeap(), 0, hManager
);
249 DPRINT("ScmrCloseServiceHandle() done\n");
250 return ERROR_SUCCESS
;
252 else if (hManager
->Handle
.Tag
== SERVICE_TAG
)
254 DPRINT("Found service handle\n");
256 hManager
->Handle
.RefCount
--;
257 if (hManager
->Handle
.RefCount
== 0)
259 /* FIXME: add cleanup code */
261 HeapFree(GetProcessHeap(), 0, hManager
);
264 DPRINT("ScmrCloseServiceHandle() done\n");
265 return ERROR_SUCCESS
;
268 DPRINT1("Invalid handle tag (Tag %lx)\n", hManager
->Handle
.Tag
);
270 return ERROR_INVALID_HANDLE
;
276 ScmrControlService(handle_t BindingHandle
,
277 unsigned int hService
,
278 unsigned long dwControl
,
279 LPSERVICE_STATUS lpServiceStatus
)
281 PSERVICE_HANDLE hSvc
;
284 DPRINT1("ScmrControlService() called\n");
287 return ERROR_SHUTDOWN_IN_PROGRESS
;
289 hSvc
= (PSERVICE_HANDLE
)hService
;
290 if (hSvc
->Handle
.Tag
!= SERVICE_TAG
)
292 DPRINT1("Invalid handle tag!\n");
293 return ERROR_INVALID_HANDLE
;
297 /* FIXME: Check access rights */
300 lpService
= hSvc
->ServiceEntry
;
301 if (lpService
== NULL
)
303 DPRINT1("lpService == NULL!\n");
304 return ERROR_INVALID_HANDLE
;
308 /* FIXME: Send control code to the service */
311 /* Return service status information */
312 RtlCopyMemory(lpServiceStatus
,
314 sizeof(SERVICE_STATUS
));
316 return ERROR_SUCCESS
;
322 ScmrDeleteService(handle_t BindingHandle
,
323 unsigned int hService
)
325 PSERVICE_HANDLE hSvc
;
329 DPRINT1("ScmrDeleteService() called\n");
332 return ERROR_SHUTDOWN_IN_PROGRESS
;
334 hSvc
= (PSERVICE_HANDLE
)hService
;
335 if (hSvc
->Handle
.Tag
!= SERVICE_TAG
)
336 return ERROR_INVALID_HANDLE
;
338 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
339 STANDARD_RIGHTS_REQUIRED
))
340 return ERROR_ACCESS_DENIED
;
342 lpService
= hSvc
->ServiceEntry
;
343 if (lpService
== NULL
)
345 DPRINT1("lpService == NULL!\n");
346 return ERROR_INVALID_HANDLE
;
349 /* FIXME: Acquire service database lock exclusively */
351 /* Mark service for delete */
352 dwError
= ScmMarkServiceForDelete(lpService
);
354 /* FIXME: Release service database lock */
356 DPRINT1("ScmrDeleteService() done\n");
364 ScmrLockServiceDatabase(handle_t BindingHandle
,
365 unsigned int hSCManager
,
368 PMANAGER_HANDLE hMgr
;
370 DPRINT("ScmrLockServiceDatabase() called\n");
374 hMgr
= (PMANAGER_HANDLE
)hSCManager
;
375 if (hMgr
->Handle
.Tag
!= MANAGER_TAG
)
376 return ERROR_INVALID_HANDLE
;
378 if (!RtlAreAllAccessesGranted(hMgr
->Handle
.DesiredAccess
,
380 return ERROR_ACCESS_DENIED
;
382 /* FIXME: Lock the database */
383 *hLock
= 0x12345678; /* Dummy! */
385 return ERROR_SUCCESS
;
391 ScmrQueryServiceObjectSecurity(handle_t BindingHandle
)
393 DPRINT1("ScmrQueryServiceSecurity() is unimplemented\n");
394 return ERROR_CALL_NOT_IMPLEMENTED
;
400 ScmrSetServiceObjectSecurity(handle_t BindingHandle
)
402 DPRINT1("ScmrSetServiceSecurity() is unimplemented\n");
403 return ERROR_CALL_NOT_IMPLEMENTED
;
409 ScmrQueryServiceStatus(handle_t BindingHandle
,
410 unsigned int hService
,
411 LPSERVICE_STATUS lpServiceStatus
)
413 PSERVICE_HANDLE hSvc
;
416 DPRINT("ScmrQueryServiceStatus() called\n");
419 return ERROR_SHUTDOWN_IN_PROGRESS
;
421 hSvc
= (PSERVICE_HANDLE
)hService
;
422 if (hSvc
->Handle
.Tag
!= SERVICE_TAG
)
424 DPRINT1("Invalid handle tag!\n");
425 return ERROR_INVALID_HANDLE
;
428 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
429 SERVICE_QUERY_STATUS
))
431 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
432 return ERROR_ACCESS_DENIED
;
435 lpService
= hSvc
->ServiceEntry
;
436 if (lpService
== NULL
)
438 DPRINT1("lpService == NULL!\n");
439 return ERROR_INVALID_HANDLE
;
442 /* Return service status information */
443 RtlCopyMemory(lpServiceStatus
,
445 sizeof(SERVICE_STATUS
));
447 return ERROR_SUCCESS
;
453 ScmrSetServiceStatus(handle_t BindingHandle
)
455 DPRINT1("ScmrSetServiceStatus() is unimplemented\n");
457 return ERROR_CALL_NOT_IMPLEMENTED
;
463 ScmrUnlockServiceDatabase(handle_t BindingHandle
,
466 DPRINT1("ScmrUnlockServiceDatabase() called\n");
468 return ERROR_SUCCESS
;
474 ScmrNotifyBootConfigStatus(handle_t BindingHandle
,
475 unsigned long BootAcceptable
)
477 DPRINT1("ScmrNotifyBootConfigStatus() called\n");
479 return ERROR_SUCCESS
;
485 ScmrChangeServiceConfigW(handle_t BiningHandle
,
486 unsigned int hService
,
487 unsigned long dwServiceType
,
488 unsigned long dwStartType
,
489 unsigned long dwErrorControl
,
490 wchar_t *lpBinaryPathName
,
491 wchar_t *lpLoadOrderGroup
,
492 unsigned long *lpdwTagId
, /* in, out, unique */
493 wchar_t *lpDependencies
,
494 unsigned long dwDependenciesLength
,
495 wchar_t *lpServiceStartName
,
497 unsigned long dwPasswordLength
,
498 wchar_t *lpDisplayName
)
500 DWORD dwError
= ERROR_SUCCESS
;
501 PSERVICE_HANDLE hSvc
;
502 PSERVICE lpService
= NULL
;
504 DPRINT1("ScmrChangeServiceConfigW() called\n");
505 DPRINT1("dwServiceType = %lu\n", dwServiceType
);
506 DPRINT1("dwStartType = %lu\n", dwStartType
);
507 DPRINT1("dwErrorControl = %lu\n", dwErrorControl
);
508 DPRINT1("lpBinaryPathName = %S\n", lpBinaryPathName
);
509 DPRINT1("lpLoadOrderGroup = %S\n", lpLoadOrderGroup
);
510 DPRINT1("lpDisplayName = %S\n", lpDisplayName
);
513 return ERROR_SHUTDOWN_IN_PROGRESS
;
515 hSvc
= (PSERVICE_HANDLE
)hService
;
516 if (hSvc
->Handle
.Tag
!= SERVICE_TAG
)
518 DPRINT1("Invalid handle tag!\n");
519 return ERROR_INVALID_HANDLE
;
522 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
523 SERVICE_CHANGE_CONFIG
))
525 DPRINT1("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
526 return ERROR_ACCESS_DENIED
;
529 lpService
= hSvc
->ServiceEntry
;
530 if (lpService
== NULL
)
532 DPRINT1("lpService == NULL!\n");
533 return ERROR_INVALID_HANDLE
;
538 DPRINT1("ScmrChangeServiceConfigW() done (Error %lu)\n", dwError
);
545 CreateServiceKey(LPWSTR lpServiceName
,
548 HKEY hServicesKey
= NULL
;
554 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
555 L
"System\\CurrentControlSet\\Services",
559 if (dwError
!= ERROR_SUCCESS
)
562 dwError
= RegCreateKeyExW(hServicesKey
,
566 REG_OPTION_NON_VOLATILE
,
572 if ((dwError
== ERROR_SUCCESS
) &&
573 (dwDisposition
== REG_OPENED_EXISTING_KEY
))
577 dwError
= ERROR_SERVICE_EXISTS
;
581 RegCloseKey(hServicesKey
);
589 ScmrCreateServiceW(handle_t BindingHandle
,
590 unsigned int hSCManager
,
591 wchar_t *lpServiceName
,
592 wchar_t *lpDisplayName
,
593 unsigned long dwDesiredAccess
,
594 unsigned long dwServiceType
,
595 unsigned long dwStartType
,
596 unsigned long dwErrorControl
,
597 wchar_t *lpBinaryPathName
,
598 wchar_t *lpLoadOrderGroup
,
599 unsigned long *lpdwTagId
, /* in, out */
600 wchar_t *lpDependencies
,
601 unsigned long dwDependenciesLength
,
602 wchar_t *lpServiceStartName
,
604 unsigned long dwPasswordLength
,
605 unsigned int *hService
) /* out */
607 PMANAGER_HANDLE hManager
;
608 DWORD dwError
= ERROR_SUCCESS
;
609 PSERVICE lpService
= NULL
;
610 SC_HANDLE hServiceHandle
= NULL
;
611 LPWSTR lpImagePath
= NULL
;
612 HKEY hServiceKey
= NULL
;
614 DPRINT1("ScmrCreateServiceW() called\n");
615 DPRINT1("lpServiceName = %S\n", lpServiceName
);
616 DPRINT1("lpDisplayName = %S\n", lpDisplayName
);
617 DPRINT1("dwDesiredAccess = %lx\n", dwDesiredAccess
);
618 DPRINT1("dwServiceType = %lu\n", dwServiceType
);
619 DPRINT1("dwStartType = %lu\n", dwStartType
);
620 DPRINT1("dwErrorControl = %lu\n", dwErrorControl
);
621 DPRINT1("lpBinaryPathName = %S\n", lpBinaryPathName
);
622 DPRINT1("lpLoadOrderGroup = %S\n", lpLoadOrderGroup
);
625 return ERROR_SHUTDOWN_IN_PROGRESS
;
627 hManager
= (PMANAGER_HANDLE
)hSCManager
;
628 if (hManager
->Handle
.Tag
!= MANAGER_TAG
)
630 DPRINT1("Invalid manager handle!\n");
631 return ERROR_INVALID_HANDLE
;
634 /* Check access rights */
635 if (!RtlAreAllAccessesGranted(hManager
->Handle
.DesiredAccess
,
636 SC_MANAGER_CREATE_SERVICE
))
638 DPRINT1("Insufficient access rights! 0x%lx\n",
639 hManager
->Handle
.DesiredAccess
);
640 return ERROR_ACCESS_DENIED
;
643 /* Fail if the service already exists! */
644 if (ScmGetServiceEntryByName(lpServiceName
) != NULL
)
645 return ERROR_SERVICE_EXISTS
;
647 if (dwServiceType
& SERVICE_DRIVER
)
649 /* FIXME: Adjust the image path */
650 lpImagePath
= HeapAlloc(GetProcessHeap(),
652 (wcslen(lpBinaryPathName
) + 1) * sizeof(WCHAR
));
653 if (lpImagePath
== NULL
)
655 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
658 wcscpy(lpImagePath
, lpBinaryPathName
);
661 /* Allocate a new service entry */
662 dwError
= ScmCreateNewServiceRecord(lpServiceName
,
664 if (dwError
!= ERROR_SUCCESS
)
667 /* Fill the new service entry */
668 lpService
->Status
.dwServiceType
= dwServiceType
;
669 lpService
->dwStartType
= dwStartType
;
670 lpService
->dwErrorControl
= dwErrorControl
;
672 /* Fill the display name */
673 if (lpDisplayName
!= NULL
&&
674 *lpDisplayName
!= 0 &&
675 wcsicmp(lpService
->lpDisplayName
, lpDisplayName
) != 0)
677 lpService
->lpDisplayName
= HeapAlloc(GetProcessHeap
, 0,
678 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
679 if (lpService
->lpDisplayName
== NULL
)
681 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
684 wcscpy(lpService
->lpDisplayName
, lpDisplayName
);
689 /* FIXME: set lpLoadOrderGroup, lpDependencies etc. */
692 /* Write service data to the registry */
693 /* Create the service key */
694 dwError
= CreateServiceKey(lpServiceName
, &hServiceKey
);
695 if (dwError
!= ERROR_SUCCESS
)
698 /* Set the display name */
699 if (lpDisplayName
!= NULL
&& *lpDisplayName
!= 0)
701 RegSetValueExW(hServiceKey
,
705 (LPBYTE
)lpDisplayName
,
706 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
709 /* Set the service type */
710 dwError
= RegSetValueExW(hServiceKey
,
714 (LPBYTE
)&dwServiceType
,
716 if (dwError
!= ERROR_SUCCESS
)
719 /* Set the start value */
720 dwError
= RegSetValueExW(hServiceKey
,
724 (LPBYTE
)&dwStartType
,
726 if (dwError
!= ERROR_SUCCESS
)
729 /* Set the error control value */
730 dwError
= RegSetValueExW(hServiceKey
,
734 (LPBYTE
)&dwErrorControl
,
736 if (dwError
!= ERROR_SUCCESS
)
739 /* Set the image path */
740 if (dwServiceType
& SERVICE_WIN32
)
742 dwError
= RegSetValueExW(hServiceKey
,
746 (LPBYTE
)lpBinaryPathName
,
747 (wcslen(lpBinaryPathName
) + 1) * sizeof(WCHAR
));
748 if (dwError
!= ERROR_SUCCESS
)
751 else if (dwServiceType
& SERVICE_DRIVER
)
753 dwError
= RegSetValueExW(hServiceKey
,
758 (wcslen(lpImagePath
) + 1) *sizeof(WCHAR
));
759 if (dwError
!= ERROR_SUCCESS
)
763 /* Set the group name */
764 if (lpLoadOrderGroup
!= NULL
&& *lpLoadOrderGroup
!= 0)
766 dwError
= RegSetValueExW(hServiceKey
,
770 (LPBYTE
)lpLoadOrderGroup
,
771 (wcslen(lpLoadOrderGroup
) + 1) * sizeof(WCHAR
));
772 if (dwError
!= ERROR_SUCCESS
)
776 if (lpdwTagId
!= NULL
)
778 /* FIXME: Write tag */
781 /* Write dependencies */
782 if (lpDependencies
!= NULL
&& *lpDependencies
!= 0)
784 dwError
= ScmWriteDependencies(hServiceKey
,
786 dwDependenciesLength
);
787 if (dwError
!= ERROR_SUCCESS
)
791 if (lpPassword
!= NULL
)
793 /* FIXME: Write password */
796 dwError
= ScmCreateServiceHandle(lpService
,
798 if (dwError
!= ERROR_SUCCESS
)
801 dwError
= ScmCheckAccess(hServiceHandle
,
803 if (dwError
!= ERROR_SUCCESS
)
807 if (hServiceKey
!= NULL
)
808 RegCloseKey(hServiceKey
);
810 if (dwError
== ERROR_SUCCESS
)
812 DPRINT1("hService %lx\n", hServiceHandle
);
813 *hService
= (unsigned int)hServiceHandle
;
815 if (lpdwTagId
!= NULL
)
816 *lpdwTagId
= 0; /* FIXME */
820 /* Release the display name buffer */
821 if (lpService
->lpServiceName
!= lpService
->lpDisplayName
)
822 HeapFree(GetProcessHeap(), 0, lpService
->lpDisplayName
);
824 if (hServiceHandle
!= NULL
)
826 /* Remove the service handle */
827 HeapFree(GetProcessHeap(), 0, hServiceHandle
);
830 if (lpService
!= NULL
)
832 /* FIXME: remove the service entry */
836 if (lpImagePath
!= NULL
)
837 HeapFree(GetProcessHeap(), 0, lpImagePath
);
839 DPRINT1("ScmrCreateServiceW() done (Error %lu)\n", dwError
);
847 ScmrOpenSCManagerW(handle_t BindingHandle
,
848 wchar_t *lpMachineName
,
849 wchar_t *lpDatabaseName
,
850 unsigned long dwDesiredAccess
,
856 DPRINT("ScmrOpenSCManagerW() called\n");
857 DPRINT("lpMachineName = %p\n", lpMachineName
);
858 DPRINT("lpMachineName: %S\n", lpMachineName
);
859 DPRINT("lpDataBaseName = %p\n", lpDatabaseName
);
860 DPRINT("lpDataBaseName: %S\n", lpDatabaseName
);
861 DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess
);
864 return ERROR_SHUTDOWN_IN_PROGRESS
;
866 dwError
= ScmCreateManagerHandle(lpDatabaseName
,
868 if (dwError
!= ERROR_SUCCESS
)
870 DPRINT1("ScmCreateManagerHandle() failed (Error %lu)\n", dwError
);
874 /* Check the desired access */
875 dwError
= ScmCheckAccess(hHandle
,
876 dwDesiredAccess
| SC_MANAGER_CONNECT
);
877 if (dwError
!= ERROR_SUCCESS
)
879 DPRINT1("ScmCheckAccess() failed (Error %lu)\n", dwError
);
880 HeapFree(GetProcessHeap(), 0, hHandle
);
884 *hScm
= (unsigned int)hHandle
;
885 DPRINT("*hScm = %x\n", *hScm
);
887 DPRINT("ScmrOpenSCManagerW() done\n");
889 return ERROR_SUCCESS
;
895 ScmrOpenServiceW(handle_t BindingHandle
,
896 unsigned int hSCManager
,
897 wchar_t *lpServiceName
,
898 unsigned long dwDesiredAccess
,
899 unsigned int *hService
)
902 PMANAGER_HANDLE hManager
;
906 DPRINT("ScmrOpenServiceW() called\n");
907 DPRINT("hSCManager = %x\n", hSCManager
);
908 DPRINT("lpServiceName = %p\n", lpServiceName
);
909 DPRINT("lpServiceName: %S\n", lpServiceName
);
910 DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess
);
913 return ERROR_SHUTDOWN_IN_PROGRESS
;
915 hManager
= (PMANAGER_HANDLE
)hSCManager
;
916 if (hManager
->Handle
.Tag
!= MANAGER_TAG
)
918 DPRINT1("Invalid manager handle!\n");
919 return ERROR_INVALID_HANDLE
;
922 /* FIXME: Lock the service list */
924 /* Get service database entry */
925 lpService
= ScmGetServiceEntryByName(lpServiceName
);
926 if (lpService
== NULL
)
928 DPRINT1("Could not find a service!\n");
929 return ERROR_SERVICE_DOES_NOT_EXIST
;
932 /* Create a service handle */
933 dwError
= ScmCreateServiceHandle(lpService
,
935 if (dwError
!= ERROR_SUCCESS
)
937 DPRINT1("ScmCreateServiceHandle() failed (Error %lu)\n", dwError
);
941 /* Check the desired access */
942 dwError
= ScmCheckAccess(hHandle
,
944 if (dwError
!= ERROR_SUCCESS
)
946 DPRINT1("ScmCheckAccess() failed (Error %lu)\n", dwError
);
947 HeapFree(GetProcessHeap(), 0, hHandle
);
951 *hService
= (unsigned int)hHandle
;
952 DPRINT("*hService = %x\n", *hService
);
954 DPRINT("ScmrOpenServiceW() done\n");
956 return ERROR_SUCCESS
;
962 ScmrGetServiceDisplayNameW(handle_t BindingHandle
,
963 unsigned int hSCManager
,
964 wchar_t *lpServiceName
,
965 wchar_t *lpDisplayName
, /* [out, unique] */
966 unsigned long *lpcchBuffer
)
968 // PMANAGER_HANDLE hManager;
973 DPRINT1("ScmrGetServiceDisplayNameW() called\n");
974 DPRINT1("hSCManager = %x\n", hSCManager
);
975 DPRINT1("lpServiceName: %S\n", lpServiceName
);
976 DPRINT1("lpDisplayName: %p\n", lpDisplayName
);
977 DPRINT1("*lpcchBuffer: %lu\n", *lpcchBuffer
);
979 // hManager = (PMANAGER_HANDLE)hSCManager;
980 // if (hManager->Handle.Tag != MANAGER_TAG)
982 // DPRINT1("Invalid manager handle!\n");
983 // return ERROR_INVALID_HANDLE;
986 /* Get service database entry */
987 lpService
= ScmGetServiceEntryByName(lpServiceName
);
988 if (lpService
== NULL
)
990 DPRINT1("Could not find a service!\n");
991 return ERROR_SERVICE_DOES_NOT_EXIST
;
994 dwLength
= wcslen(lpService
->lpDisplayName
);
996 if (lpDisplayName
!= NULL
&&
997 *lpcchBuffer
> dwLength
)
999 wcscpy(lpDisplayName
, lpService
->lpDisplayName
);
1002 dwError
= (*lpcchBuffer
> dwLength
) ? ERROR_SUCCESS
: ERROR_INSUFFICIENT_BUFFER
;
1004 *lpcchBuffer
= dwLength
;
1012 ScmrOpenSCManagerA(handle_t BindingHandle
,
1013 char *lpMachineName
,
1014 char *lpDatabaseName
,
1015 unsigned long dwDesiredAccess
,
1018 UNICODE_STRING MachineName
;
1019 UNICODE_STRING DatabaseName
;
1022 DPRINT("ScmrOpenSCManagerA() called\n");
1025 RtlCreateUnicodeStringFromAsciiz(&MachineName
,
1029 RtlCreateUnicodeStringFromAsciiz(&DatabaseName
,
1032 dwError
= ScmrOpenSCManagerW(BindingHandle
,
1033 lpMachineName
? MachineName
.Buffer
: NULL
,
1034 lpDatabaseName
? DatabaseName
.Buffer
: NULL
,
1039 RtlFreeUnicodeString(&MachineName
);
1042 RtlFreeUnicodeString(&DatabaseName
);
1050 ScmrOpenServiceA(handle_t BindingHandle
,
1051 unsigned int hSCManager
,
1052 char *lpServiceName
,
1053 unsigned long dwDesiredAccess
,
1054 unsigned int *hService
)
1056 UNICODE_STRING ServiceName
;
1059 DPRINT("ScmrOpenServiceA() called\n");
1061 RtlCreateUnicodeStringFromAsciiz(&ServiceName
,
1064 dwError
= ScmrOpenServiceW(BindingHandle
,
1070 RtlFreeUnicodeString(&ServiceName
);
1077 void __RPC_FAR
* __RPC_USER
midl_user_allocate(size_t len
)
1079 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
1083 void __RPC_USER
midl_user_free(void __RPC_FAR
* ptr
)
1085 HeapFree(GetProcessHeap(), 0, ptr
);