2 * Services.exe - RPC functions
4 * Copyright 2007 Google (Mikolaj Zalewski)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN
30 #include "wine/list.h"
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
37 extern HANDLE CDECL
__wine_make_process_system(void);
39 WINE_DEFAULT_DEBUG_CHANNEL(service
);
41 static const GENERIC_MAPPING g_scm_generic
=
43 (STANDARD_RIGHTS_READ
| SC_MANAGER_ENUMERATE_SERVICE
| SC_MANAGER_QUERY_LOCK_STATUS
),
44 (STANDARD_RIGHTS_WRITE
| SC_MANAGER_CREATE_SERVICE
| SC_MANAGER_MODIFY_BOOT_CONFIG
),
45 (STANDARD_RIGHTS_EXECUTE
| SC_MANAGER_CONNECT
| SC_MANAGER_LOCK
),
49 static const GENERIC_MAPPING g_svc_generic
=
51 (STANDARD_RIGHTS_READ
| SERVICE_QUERY_CONFIG
| SERVICE_QUERY_STATUS
| SERVICE_INTERROGATE
| SERVICE_ENUMERATE_DEPENDENTS
),
52 (STANDARD_RIGHTS_WRITE
| SERVICE_CHANGE_CONFIG
),
53 (STANDARD_RIGHTS_EXECUTE
| SERVICE_START
| SERVICE_STOP
| SERVICE_PAUSE_CONTINUE
| SERVICE_USER_DEFINED_CONTROL
),
59 SC_HTYPE_DONT_CARE
= 0,
70 struct sc_manager_handle
/* service control manager handle */
73 struct scmdatabase
*db
;
76 struct sc_service_handle
/* service handle */
79 struct service_entry
*service_entry
;
84 struct scmdatabase
*db
;
87 static void free_service_strings(struct service_entry
*old
, struct service_entry
*new)
89 QUERY_SERVICE_CONFIGW
*old_cfg
= &old
->config
;
90 QUERY_SERVICE_CONFIGW
*new_cfg
= &new->config
;
92 if (old_cfg
->lpBinaryPathName
!= new_cfg
->lpBinaryPathName
)
93 HeapFree(GetProcessHeap(), 0, old_cfg
->lpBinaryPathName
);
95 if (old_cfg
->lpLoadOrderGroup
!= new_cfg
->lpLoadOrderGroup
)
96 HeapFree(GetProcessHeap(), 0, old_cfg
->lpLoadOrderGroup
);
98 if (old_cfg
->lpServiceStartName
!= new_cfg
->lpServiceStartName
)
99 HeapFree(GetProcessHeap(), 0, old_cfg
->lpServiceStartName
);
101 if (old_cfg
->lpDisplayName
!= new_cfg
->lpDisplayName
)
102 HeapFree(GetProcessHeap(), 0, old_cfg
->lpDisplayName
);
104 if (old
->dependOnServices
!= new->dependOnServices
)
105 HeapFree(GetProcessHeap(), 0, old
->dependOnServices
);
107 if (old
->dependOnGroups
!= new->dependOnGroups
)
108 HeapFree(GetProcessHeap(), 0, old
->dependOnGroups
);
111 /* Check if the given handle is of the required type and allows the requested access. */
112 static DWORD
validate_context_handle(SC_RPC_HANDLE handle
, DWORD type
, DWORD needed_access
, struct sc_handle
**out_hdr
)
114 struct sc_handle
*hdr
= handle
;
116 if (type
!= SC_HTYPE_DONT_CARE
&& hdr
->type
!= type
)
118 WINE_ERR("Handle is of an invalid type (%d, %d)\n", hdr
->type
, type
);
119 return ERROR_INVALID_HANDLE
;
122 if ((needed_access
& hdr
->access
) != needed_access
)
124 WINE_ERR("Access denied - handle created with access %x, needed %x\n", hdr
->access
, needed_access
);
125 return ERROR_ACCESS_DENIED
;
129 return ERROR_SUCCESS
;
132 static DWORD
validate_scm_handle(SC_RPC_HANDLE handle
, DWORD needed_access
, struct sc_manager_handle
**manager
)
134 struct sc_handle
*hdr
;
135 DWORD err
= validate_context_handle(handle
, SC_HTYPE_MANAGER
, needed_access
, &hdr
);
136 if (err
== ERROR_SUCCESS
)
137 *manager
= (struct sc_manager_handle
*)hdr
;
141 static DWORD
validate_service_handle(SC_RPC_HANDLE handle
, DWORD needed_access
, struct sc_service_handle
**service
)
143 struct sc_handle
*hdr
;
144 DWORD err
= validate_context_handle(handle
, SC_HTYPE_SERVICE
, needed_access
, &hdr
);
145 if (err
== ERROR_SUCCESS
)
146 *service
= (struct sc_service_handle
*)hdr
;
150 DWORD
svcctl_OpenSCManagerW(
151 MACHINE_HANDLEW MachineName
, /* Note: this parameter is ignored */
152 LPCWSTR DatabaseName
,
154 SC_RPC_HANDLE
*handle
)
156 struct sc_manager_handle
*manager
;
158 WINE_TRACE("(%s, %s, %x)\n", wine_dbgstr_w(MachineName
), wine_dbgstr_w(DatabaseName
), dwAccessMask
);
160 if (DatabaseName
!= NULL
&& DatabaseName
[0])
162 if (strcmpW(DatabaseName
, SERVICES_FAILED_DATABASEW
) == 0)
163 return ERROR_DATABASE_DOES_NOT_EXIST
;
164 if (strcmpW(DatabaseName
, SERVICES_ACTIVE_DATABASEW
) != 0)
165 return ERROR_INVALID_NAME
;
168 if (!(manager
= HeapAlloc(GetProcessHeap(), 0, sizeof(*manager
))))
169 return ERROR_NOT_ENOUGH_SERVER_MEMORY
;
171 manager
->hdr
.type
= SC_HTYPE_MANAGER
;
173 if (dwAccessMask
& MAXIMUM_ALLOWED
)
174 dwAccessMask
|= SC_MANAGER_ALL_ACCESS
;
175 manager
->hdr
.access
= dwAccessMask
;
176 RtlMapGenericMask(&manager
->hdr
.access
, &g_scm_generic
);
177 manager
->db
= active_database
;
178 *handle
= &manager
->hdr
;
180 return ERROR_SUCCESS
;
183 static void SC_RPC_HANDLE_destroy(SC_RPC_HANDLE handle
)
185 struct sc_handle
*hdr
= handle
;
188 case SC_HTYPE_MANAGER
:
190 struct sc_manager_handle
*manager
= (struct sc_manager_handle
*)hdr
;
191 HeapFree(GetProcessHeap(), 0, manager
);
194 case SC_HTYPE_SERVICE
:
196 struct sc_service_handle
*service
= (struct sc_service_handle
*)hdr
;
197 release_service(service
->service_entry
);
198 HeapFree(GetProcessHeap(), 0, service
);
202 WINE_ERR("invalid handle type %d\n", hdr
->type
);
203 RpcRaiseException(ERROR_INVALID_HANDLE
);
207 DWORD
svcctl_GetServiceDisplayNameW(
208 SC_RPC_HANDLE hSCManager
,
209 LPCWSTR lpServiceName
,
213 struct sc_manager_handle
*manager
;
214 struct service_entry
*entry
;
217 WINE_TRACE("(%s, %d)\n", wine_dbgstr_w(lpServiceName
), *cchBufSize
);
219 if ((err
= validate_scm_handle(hSCManager
, 0, &manager
)) != ERROR_SUCCESS
)
222 scmdatabase_lock_shared(manager
->db
);
224 entry
= scmdatabase_find_service(manager
->db
, lpServiceName
);
229 service_lock_shared(entry
);
230 name
= get_display_name(entry
);
232 if (len
<= *cchBufSize
)
235 memcpy(lpBuffer
, name
, (len
+ 1)*sizeof(*name
));
238 err
= ERROR_INSUFFICIENT_BUFFER
;
240 service_unlock(entry
);
243 err
= ERROR_SERVICE_DOES_NOT_EXIST
;
245 scmdatabase_unlock(manager
->db
);
247 if (err
!= ERROR_SUCCESS
)
253 DWORD
svcctl_GetServiceKeyNameW(
254 SC_RPC_HANDLE hSCManager
,
255 LPCWSTR lpServiceDisplayName
,
259 struct service_entry
*entry
;
260 struct sc_manager_handle
*manager
;
263 WINE_TRACE("(%s, %d)\n", wine_dbgstr_w(lpServiceDisplayName
), *cchBufSize
);
265 if ((err
= validate_scm_handle(hSCManager
, 0, &manager
)) != ERROR_SUCCESS
)
268 scmdatabase_lock_shared(manager
->db
);
270 entry
= scmdatabase_find_service_by_displayname(manager
->db
, lpServiceDisplayName
);
274 service_lock_shared(entry
);
275 len
= strlenW(entry
->name
);
276 if (len
<= *cchBufSize
)
279 memcpy(lpBuffer
, entry
->name
, (len
+ 1)*sizeof(*entry
->name
));
282 err
= ERROR_INSUFFICIENT_BUFFER
;
284 service_unlock(entry
);
287 err
= ERROR_SERVICE_DOES_NOT_EXIST
;
289 scmdatabase_unlock(manager
->db
);
291 if (err
!= ERROR_SUCCESS
)
297 static DWORD
create_handle_for_service(struct service_entry
*entry
, DWORD dwDesiredAccess
, SC_RPC_HANDLE
*phService
)
299 struct sc_service_handle
*service
;
301 if (!(service
= HeapAlloc(GetProcessHeap(), 0, sizeof(*service
))))
303 release_service(entry
);
304 return ERROR_NOT_ENOUGH_SERVER_MEMORY
;
307 service
->hdr
.type
= SC_HTYPE_SERVICE
;
308 service
->hdr
.access
= dwDesiredAccess
;
309 RtlMapGenericMask(&service
->hdr
.access
, &g_svc_generic
);
310 service
->service_entry
= entry
;
311 if (dwDesiredAccess
& MAXIMUM_ALLOWED
)
312 dwDesiredAccess
|= SERVICE_ALL_ACCESS
;
314 *phService
= &service
->hdr
;
315 return ERROR_SUCCESS
;
318 DWORD
svcctl_OpenServiceW(
319 SC_RPC_HANDLE hSCManager
,
320 LPCWSTR lpServiceName
,
321 DWORD dwDesiredAccess
,
322 SC_RPC_HANDLE
*phService
)
324 struct sc_manager_handle
*manager
;
325 struct service_entry
*entry
;
328 WINE_TRACE("(%s, 0x%x)\n", wine_dbgstr_w(lpServiceName
), dwDesiredAccess
);
330 if ((err
= validate_scm_handle(hSCManager
, 0, &manager
)) != ERROR_SUCCESS
)
332 if (!validate_service_name(lpServiceName
))
333 return ERROR_INVALID_NAME
;
335 scmdatabase_lock_shared(manager
->db
);
336 entry
= scmdatabase_find_service(manager
->db
, lpServiceName
);
338 InterlockedIncrement(&entry
->ref_count
);
339 scmdatabase_unlock(manager
->db
);
342 return ERROR_SERVICE_DOES_NOT_EXIST
;
344 return create_handle_for_service(entry
, dwDesiredAccess
, phService
);
347 static DWORD
parse_dependencies(const WCHAR
*dependencies
, struct service_entry
*entry
)
349 WCHAR
*services
= NULL
, *groups
, *s
;
350 DWORD len
, len_services
= 0, len_groups
= 0;
351 const WCHAR
*ptr
= dependencies
;
353 if (!dependencies
|| !dependencies
[0])
355 entry
->dependOnServices
= NULL
;
356 entry
->dependOnGroups
= NULL
;
357 return ERROR_SUCCESS
;
362 len
= strlenW(ptr
) + 1;
363 if (ptr
[0] == '+' && ptr
[1])
364 len_groups
+= len
- 1;
369 if (!len_services
) entry
->dependOnServices
= NULL
;
372 services
= HeapAlloc(GetProcessHeap(), 0, (len_services
+ 1) * sizeof(WCHAR
));
374 return ERROR_OUTOFMEMORY
;
380 len
= strlenW(ptr
) + 1;
389 entry
->dependOnServices
= services
;
391 if (!len_groups
) entry
->dependOnGroups
= NULL
;
394 groups
= HeapAlloc(GetProcessHeap(), 0, (len_groups
+ 1) * sizeof(WCHAR
));
397 HeapFree(GetProcessHeap(), 0, services
);
398 return ERROR_OUTOFMEMORY
;
404 len
= strlenW(ptr
) + 1;
405 if (ptr
[0] == '+' && ptr
[1])
413 entry
->dependOnGroups
= groups
;
416 return ERROR_SUCCESS
;
419 DWORD
svcctl_CreateServiceW(
420 SC_RPC_HANDLE hSCManager
,
421 LPCWSTR lpServiceName
,
422 LPCWSTR lpDisplayName
,
423 DWORD dwDesiredAccess
,
426 DWORD dwErrorControl
,
427 LPCWSTR lpBinaryPathName
,
428 LPCWSTR lpLoadOrderGroup
,
430 const BYTE
*lpDependencies
,
431 DWORD dwDependenciesSize
,
432 LPCWSTR lpServiceStartName
,
433 const BYTE
*lpPassword
,
434 DWORD dwPasswordSize
,
435 SC_RPC_HANDLE
*phService
)
437 struct sc_manager_handle
*manager
;
438 struct service_entry
*entry
;
441 WINE_TRACE("(%s, %s, 0x%x, %s)\n", wine_dbgstr_w(lpServiceName
), wine_dbgstr_w(lpDisplayName
), dwDesiredAccess
, wine_dbgstr_w(lpBinaryPathName
));
443 if ((err
= validate_scm_handle(hSCManager
, SC_MANAGER_CREATE_SERVICE
, &manager
)) != ERROR_SUCCESS
)
446 if (!validate_service_name(lpServiceName
))
447 return ERROR_INVALID_NAME
;
448 if (!check_multisz((LPCWSTR
)lpDependencies
, dwDependenciesSize
) || !lpServiceName
[0] || !lpBinaryPathName
[0])
449 return ERROR_INVALID_PARAMETER
;
452 WINE_FIXME("Don't know how to add a password\n"); /* I always get ERROR_GEN_FAILURE */
454 err
= service_create(lpServiceName
, &entry
);
455 if (err
!= ERROR_SUCCESS
)
458 err
= parse_dependencies((LPCWSTR
)lpDependencies
, entry
);
459 if (err
!= ERROR_SUCCESS
)
462 entry
->ref_count
= 1;
463 entry
->config
.dwServiceType
= entry
->status
.dwServiceType
= dwServiceType
;
464 entry
->config
.dwStartType
= dwStartType
;
465 entry
->config
.dwErrorControl
= dwErrorControl
;
466 entry
->config
.lpBinaryPathName
= strdupW(lpBinaryPathName
);
467 entry
->config
.lpLoadOrderGroup
= strdupW(lpLoadOrderGroup
);
468 entry
->config
.lpServiceStartName
= strdupW(lpServiceStartName
);
469 entry
->config
.lpDisplayName
= strdupW(lpDisplayName
);
471 if (lpdwTagId
) /* TODO: In most situations a non-NULL TagId will generate an ERROR_INVALID_PARAMETER. */
472 entry
->config
.dwTagId
= *lpdwTagId
;
474 entry
->config
.dwTagId
= 0;
476 /* other fields NULL*/
478 if (!validate_service_config(entry
))
480 WINE_ERR("Invalid data while trying to create service\n");
481 free_service_entry(entry
);
482 return ERROR_INVALID_PARAMETER
;
485 scmdatabase_lock_exclusive(manager
->db
);
487 if (scmdatabase_find_service(manager
->db
, lpServiceName
))
489 scmdatabase_unlock(manager
->db
);
490 free_service_entry(entry
);
491 return ERROR_SERVICE_EXISTS
;
494 if (scmdatabase_find_service_by_displayname(manager
->db
, get_display_name(entry
)))
496 scmdatabase_unlock(manager
->db
);
497 free_service_entry(entry
);
498 return ERROR_DUPLICATE_SERVICE_NAME
;
501 err
= scmdatabase_add_service(manager
->db
, entry
);
502 if (err
!= ERROR_SUCCESS
)
504 scmdatabase_unlock(manager
->db
);
505 free_service_entry(entry
);
508 scmdatabase_unlock(manager
->db
);
510 return create_handle_for_service(entry
, dwDesiredAccess
, phService
);
513 DWORD
svcctl_DeleteService(
514 SC_RPC_HANDLE hService
)
516 struct sc_service_handle
*service
;
519 if ((err
= validate_service_handle(hService
, DELETE
, &service
)) != ERROR_SUCCESS
)
522 scmdatabase_lock_exclusive(service
->service_entry
->db
);
523 service_lock_exclusive(service
->service_entry
);
525 if (!is_marked_for_delete(service
->service_entry
))
526 err
= scmdatabase_remove_service(service
->service_entry
->db
, service
->service_entry
);
528 err
= ERROR_SERVICE_MARKED_FOR_DELETE
;
530 service_unlock(service
->service_entry
);
531 scmdatabase_unlock(service
->service_entry
->db
);
536 DWORD
svcctl_QueryServiceConfigW(
537 SC_RPC_HANDLE hService
,
538 QUERY_SERVICE_CONFIGW
*config
)
540 struct sc_service_handle
*service
;
543 WINE_TRACE("(%p)\n", config
);
545 if ((err
= validate_service_handle(hService
, SERVICE_QUERY_CONFIG
, &service
)) != 0)
548 service_lock_shared(service
->service_entry
);
549 config
->dwServiceType
= service
->service_entry
->config
.dwServiceType
;
550 config
->dwStartType
= service
->service_entry
->config
.dwStartType
;
551 config
->dwErrorControl
= service
->service_entry
->config
.dwErrorControl
;
552 config
->lpBinaryPathName
= strdupW(service
->service_entry
->config
.lpBinaryPathName
);
553 config
->lpLoadOrderGroup
= strdupW(service
->service_entry
->config
.lpLoadOrderGroup
);
554 config
->dwTagId
= service
->service_entry
->config
.dwTagId
;
555 config
->lpDependencies
= NULL
; /* TODO */
556 config
->lpServiceStartName
= strdupW(service
->service_entry
->config
.lpServiceStartName
);
557 config
->lpDisplayName
= strdupW(service
->service_entry
->config
.lpDisplayName
);
558 service_unlock(service
->service_entry
);
560 return ERROR_SUCCESS
;
563 DWORD
svcctl_ChangeServiceConfigW(
564 SC_RPC_HANDLE hService
,
567 DWORD dwErrorControl
,
568 LPCWSTR lpBinaryPathName
,
569 LPCWSTR lpLoadOrderGroup
,
571 const BYTE
*lpDependencies
,
572 DWORD dwDependenciesSize
,
573 LPCWSTR lpServiceStartName
,
574 const BYTE
*lpPassword
,
575 DWORD dwPasswordSize
,
576 LPCWSTR lpDisplayName
)
578 struct service_entry new_entry
, *entry
;
579 struct sc_service_handle
*service
;
584 if ((err
= validate_service_handle(hService
, SERVICE_CHANGE_CONFIG
, &service
)) != 0)
587 if (!check_multisz((LPCWSTR
)lpDependencies
, dwDependenciesSize
))
588 return ERROR_INVALID_PARAMETER
;
590 /* first check if the new configuration is correct */
591 service_lock_exclusive(service
->service_entry
);
593 if (is_marked_for_delete(service
->service_entry
))
595 service_unlock(service
->service_entry
);
596 return ERROR_SERVICE_MARKED_FOR_DELETE
;
599 if (lpDisplayName
!= NULL
&&
600 (entry
= scmdatabase_find_service_by_displayname(service
->service_entry
->db
, lpDisplayName
)) &&
601 (entry
!= service
->service_entry
))
603 service_unlock(service
->service_entry
);
604 return ERROR_DUPLICATE_SERVICE_NAME
;
607 new_entry
= *service
->service_entry
;
609 if (dwServiceType
!= SERVICE_NO_CHANGE
)
610 new_entry
.config
.dwServiceType
= dwServiceType
;
612 if (dwStartType
!= SERVICE_NO_CHANGE
)
613 new_entry
.config
.dwStartType
= dwStartType
;
615 if (dwErrorControl
!= SERVICE_NO_CHANGE
)
616 new_entry
.config
.dwErrorControl
= dwErrorControl
;
618 if (lpBinaryPathName
!= NULL
)
619 new_entry
.config
.lpBinaryPathName
= (LPWSTR
)lpBinaryPathName
;
621 if (lpLoadOrderGroup
!= NULL
)
622 new_entry
.config
.lpLoadOrderGroup
= (LPWSTR
)lpLoadOrderGroup
;
624 if (lpdwTagId
!= NULL
)
625 WINE_FIXME("Changing tag id not supported\n");
627 if (lpServiceStartName
!= NULL
)
628 new_entry
.config
.lpServiceStartName
= (LPWSTR
)lpServiceStartName
;
630 if (lpPassword
!= NULL
)
631 WINE_FIXME("Setting password not supported\n");
633 if (lpDisplayName
!= NULL
)
634 new_entry
.config
.lpDisplayName
= (LPWSTR
)lpDisplayName
;
636 err
= parse_dependencies((LPCWSTR
)lpDependencies
, &new_entry
);
637 if (err
!= ERROR_SUCCESS
)
639 service_unlock(service
->service_entry
);
643 if (!validate_service_config(&new_entry
))
645 WINE_ERR("The configuration after the change wouldn't be valid\n");
646 service_unlock(service
->service_entry
);
647 return ERROR_INVALID_PARAMETER
;
650 /* configuration OK. The strings needs to be duplicated */
651 if (lpBinaryPathName
!= NULL
)
652 new_entry
.config
.lpBinaryPathName
= strdupW(lpBinaryPathName
);
654 if (lpLoadOrderGroup
!= NULL
)
655 new_entry
.config
.lpLoadOrderGroup
= strdupW(lpLoadOrderGroup
);
657 if (lpServiceStartName
!= NULL
)
658 new_entry
.config
.lpServiceStartName
= strdupW(lpServiceStartName
);
660 if (lpDisplayName
!= NULL
)
661 new_entry
.config
.lpDisplayName
= strdupW(lpDisplayName
);
663 /* try to save to Registry, commit or rollback depending on success */
664 err
= save_service_config(&new_entry
);
665 if (ERROR_SUCCESS
== err
)
667 free_service_strings(service
->service_entry
, &new_entry
);
668 *service
->service_entry
= new_entry
;
670 else free_service_strings(&new_entry
, service
->service_entry
);
671 service_unlock(service
->service_entry
);
676 DWORD
svcctl_SetServiceStatus(
677 SC_RPC_HANDLE hServiceStatus
,
678 LPSERVICE_STATUS lpServiceStatus
)
680 struct sc_service_handle
*service
;
683 WINE_TRACE("(%p, %p)\n", hServiceStatus
, lpServiceStatus
);
685 if ((err
= validate_service_handle(hServiceStatus
, SERVICE_SET_STATUS
, &service
)) != 0)
688 service_lock_exclusive(service
->service_entry
);
689 /* FIXME: be a bit more discriminant about what parts of the status we set
690 * and check that fields are valid */
691 service
->service_entry
->status
.dwServiceType
= lpServiceStatus
->dwServiceType
;
692 service
->service_entry
->status
.dwCurrentState
= lpServiceStatus
->dwCurrentState
;
693 service
->service_entry
->status
.dwControlsAccepted
= lpServiceStatus
->dwControlsAccepted
;
694 service
->service_entry
->status
.dwWin32ExitCode
= lpServiceStatus
->dwWin32ExitCode
;
695 service
->service_entry
->status
.dwServiceSpecificExitCode
= lpServiceStatus
->dwServiceSpecificExitCode
;
696 service
->service_entry
->status
.dwCheckPoint
= lpServiceStatus
->dwCheckPoint
;
697 service
->service_entry
->status
.dwWaitHint
= lpServiceStatus
->dwWaitHint
;
698 service_unlock(service
->service_entry
);
700 if (service
->service_entry
->status_changed_event
)
701 SetEvent(service
->service_entry
->status_changed_event
);
703 return ERROR_SUCCESS
;
706 DWORD
svcctl_ChangeServiceConfig2W( SC_RPC_HANDLE hService
, DWORD level
, SERVICE_CONFIG2W
*config
)
708 struct sc_service_handle
*service
;
711 if ((err
= validate_service_handle(hService
, SERVICE_CHANGE_CONFIG
, &service
)) != 0)
716 case SERVICE_CONFIG_DESCRIPTION
:
720 if (config
->descr
.lpDescription
[0])
722 if (!(descr
= strdupW( config
->descr
.lpDescription
)))
723 return ERROR_NOT_ENOUGH_MEMORY
;
726 WINE_TRACE( "changing service %p descr to %s\n", service
, wine_dbgstr_w(descr
) );
727 service_lock_exclusive( service
->service_entry
);
728 HeapFree( GetProcessHeap(), 0, service
->service_entry
->description
);
729 service
->service_entry
->description
= descr
;
730 save_service_config( service
->service_entry
);
731 service_unlock( service
->service_entry
);
734 case SERVICE_CONFIG_FAILURE_ACTIONS
:
735 WINE_FIXME( "SERVICE_CONFIG_FAILURE_ACTIONS not implemented: period %u msg %s cmd %s\n",
736 config
->actions
.dwResetPeriod
,
737 wine_dbgstr_w(config
->actions
.lpRebootMsg
),
738 wine_dbgstr_w(config
->actions
.lpCommand
) );
741 WINE_FIXME("level %u not implemented\n", level
);
742 err
= ERROR_INVALID_LEVEL
;
748 DWORD
svcctl_QueryServiceConfig2W( SC_RPC_HANDLE hService
, DWORD level
,
749 BYTE
*buffer
, DWORD size
, LPDWORD needed
)
751 struct sc_service_handle
*service
;
754 memset(buffer
, 0, size
);
756 if ((err
= validate_service_handle(hService
, SERVICE_QUERY_STATUS
, &service
)) != 0)
761 case SERVICE_CONFIG_DESCRIPTION
:
763 SERVICE_DESCRIPTIONW
*descr
= (SERVICE_DESCRIPTIONW
*)buffer
;
765 service_lock_shared(service
->service_entry
);
766 *needed
= sizeof(*descr
);
767 if (service
->service_entry
->description
)
768 *needed
+= (strlenW(service
->service_entry
->description
) + 1) * sizeof(WCHAR
);
771 if (service
->service_entry
->description
)
773 /* store a buffer offset instead of a pointer */
774 descr
->lpDescription
= (WCHAR
*)((BYTE
*)(descr
+ 1) - buffer
);
775 strcpyW( (WCHAR
*)(descr
+ 1), service
->service_entry
->description
);
777 else descr
->lpDescription
= NULL
;
779 else err
= ERROR_INSUFFICIENT_BUFFER
;
780 service_unlock(service
->service_entry
);
785 WINE_FIXME("level %u not implemented\n", level
);
786 err
= ERROR_INVALID_LEVEL
;
792 DWORD
svcctl_QueryServiceStatusEx(
793 SC_RPC_HANDLE hService
,
794 SC_STATUS_TYPE InfoLevel
,
797 LPDWORD pcbBytesNeeded
)
799 struct sc_service_handle
*service
;
801 LPSERVICE_STATUS_PROCESS pSvcStatusData
;
803 memset(lpBuffer
, 0, cbBufSize
);
805 if ((err
= validate_service_handle(hService
, SERVICE_QUERY_STATUS
, &service
)) != 0)
808 if (InfoLevel
!= SC_STATUS_PROCESS_INFO
)
809 return ERROR_INVALID_LEVEL
;
811 pSvcStatusData
= (LPSERVICE_STATUS_PROCESS
) lpBuffer
;
812 if (pSvcStatusData
== NULL
)
813 return ERROR_INVALID_PARAMETER
;
815 if (cbBufSize
< sizeof(SERVICE_STATUS_PROCESS
))
817 if( pcbBytesNeeded
!= NULL
)
818 *pcbBytesNeeded
= sizeof(SERVICE_STATUS_PROCESS
);
820 return ERROR_INSUFFICIENT_BUFFER
;
823 service_lock_shared(service
->service_entry
);
825 pSvcStatusData
->dwServiceType
= service
->service_entry
->status
.dwServiceType
;
826 pSvcStatusData
->dwCurrentState
= service
->service_entry
->status
.dwCurrentState
;
827 pSvcStatusData
->dwControlsAccepted
= service
->service_entry
->status
.dwControlsAccepted
;
828 pSvcStatusData
->dwWin32ExitCode
= service
->service_entry
->status
.dwWin32ExitCode
;
829 pSvcStatusData
->dwServiceSpecificExitCode
= service
->service_entry
->status
.dwServiceSpecificExitCode
;
830 pSvcStatusData
->dwCheckPoint
= service
->service_entry
->status
.dwCheckPoint
;
831 pSvcStatusData
->dwWaitHint
= service
->service_entry
->status
.dwWaitHint
;
832 pSvcStatusData
->dwProcessId
= service
->service_entry
->status
.dwProcessId
;
833 pSvcStatusData
->dwServiceFlags
= service
->service_entry
->status
.dwServiceFlags
;
835 service_unlock(service
->service_entry
);
837 return ERROR_SUCCESS
;
840 /******************************************************************************
841 * service_accepts_control
843 static BOOL
service_accepts_control(const struct service_entry
*service
, DWORD dwControl
)
845 DWORD a
= service
->status
.dwControlsAccepted
;
849 case SERVICE_CONTROL_INTERROGATE
:
851 case SERVICE_CONTROL_STOP
:
852 if (a
&SERVICE_ACCEPT_STOP
)
855 case SERVICE_CONTROL_SHUTDOWN
:
856 if (a
&SERVICE_ACCEPT_SHUTDOWN
)
859 case SERVICE_CONTROL_PAUSE
:
860 case SERVICE_CONTROL_CONTINUE
:
861 if (a
&SERVICE_ACCEPT_PAUSE_CONTINUE
)
864 case SERVICE_CONTROL_PARAMCHANGE
:
865 if (a
&SERVICE_ACCEPT_PARAMCHANGE
)
868 case SERVICE_CONTROL_NETBINDADD
:
869 case SERVICE_CONTROL_NETBINDREMOVE
:
870 case SERVICE_CONTROL_NETBINDENABLE
:
871 case SERVICE_CONTROL_NETBINDDISABLE
:
872 if (a
&SERVICE_ACCEPT_NETBINDCHANGE
)
874 case SERVICE_CONTROL_HARDWAREPROFILECHANGE
:
875 if (a
&SERVICE_ACCEPT_HARDWAREPROFILECHANGE
)
878 case SERVICE_CONTROL_POWEREVENT
:
879 if (a
&SERVICE_ACCEPT_POWEREVENT
)
882 case SERVICE_CONTROL_SESSIONCHANGE
:
883 if (a
&SERVICE_ACCEPT_SESSIONCHANGE
)
890 /******************************************************************************
891 * service_send_control
893 static BOOL
service_send_control(struct service_entry
*service
, HANDLE pipe
, DWORD dwControl
, DWORD
*result
)
895 service_start_info
*ssi
;
896 DWORD len
, count
= 0;
899 /* calculate how much space we need to send the startup info */
900 len
= strlenW(service
->name
) + 1;
902 ssi
= HeapAlloc(GetProcessHeap(),0,FIELD_OFFSET(service_start_info
, data
[len
]));
903 ssi
->cmd
= WINESERV_SENDCONTROL
;
904 ssi
->control
= dwControl
;
905 ssi
->total_size
= FIELD_OFFSET(service_start_info
, data
[len
]);
906 ssi
->name_size
= strlenW(service
->name
) + 1;
907 strcpyW( ssi
->data
, service
->name
);
909 r
= WriteFile(pipe
, ssi
, ssi
->total_size
, &count
, NULL
);
910 if (!r
|| count
!= ssi
->total_size
)
912 WINE_ERR("service protocol error - failed to write pipe!\n");
915 r
= ReadFile(pipe
, result
, sizeof *result
, &count
, NULL
);
916 if (!r
|| count
!= sizeof *result
)
917 WINE_ERR("service protocol error - failed to read pipe "
918 "r = %d count = %d!\n", r
, count
);
922 DWORD
svcctl_StartServiceW(
923 SC_RPC_HANDLE hService
,
924 DWORD dwNumServiceArgs
,
925 LPCWSTR
*lpServiceArgVectors
)
927 struct sc_service_handle
*service
;
930 WINE_TRACE("(%p, %d, %p)\n", hService
, dwNumServiceArgs
, lpServiceArgVectors
);
932 if ((err
= validate_service_handle(hService
, SERVICE_START
, &service
)) != 0)
935 err
= service_start(service
->service_entry
, dwNumServiceArgs
, lpServiceArgVectors
);
940 DWORD
svcctl_ControlService(
941 SC_RPC_HANDLE hService
,
943 SERVICE_STATUS
*lpServiceStatus
)
945 DWORD access_required
;
946 struct sc_service_handle
*service
;
949 HANDLE control_mutex
;
952 WINE_TRACE("(%p, %d, %p)\n", hService
, dwControl
, lpServiceStatus
);
956 case SERVICE_CONTROL_CONTINUE
:
957 case SERVICE_CONTROL_NETBINDADD
:
958 case SERVICE_CONTROL_NETBINDDISABLE
:
959 case SERVICE_CONTROL_NETBINDENABLE
:
960 case SERVICE_CONTROL_NETBINDREMOVE
:
961 case SERVICE_CONTROL_PARAMCHANGE
:
962 case SERVICE_CONTROL_PAUSE
:
963 access_required
= SERVICE_PAUSE_CONTINUE
;
965 case SERVICE_CONTROL_INTERROGATE
:
966 access_required
= SERVICE_INTERROGATE
;
968 case SERVICE_CONTROL_STOP
:
969 access_required
= SERVICE_STOP
;
972 if (dwControl
>= 128 && dwControl
<= 255)
973 access_required
= SERVICE_USER_DEFINED_CONTROL
;
975 return ERROR_INVALID_PARAMETER
;
978 if ((err
= validate_service_handle(hService
, access_required
, &service
)) != 0)
981 service_lock_exclusive(service
->service_entry
);
985 lpServiceStatus
->dwServiceType
= service
->service_entry
->status
.dwServiceType
;
986 lpServiceStatus
->dwCurrentState
= service
->service_entry
->status
.dwCurrentState
;
987 lpServiceStatus
->dwControlsAccepted
= service
->service_entry
->status
.dwControlsAccepted
;
988 lpServiceStatus
->dwWin32ExitCode
= service
->service_entry
->status
.dwWin32ExitCode
;
989 lpServiceStatus
->dwServiceSpecificExitCode
= service
->service_entry
->status
.dwServiceSpecificExitCode
;
990 lpServiceStatus
->dwCheckPoint
= service
->service_entry
->status
.dwCheckPoint
;
991 lpServiceStatus
->dwWaitHint
= service
->service_entry
->status
.dwWaitHint
;
994 if (!service_accepts_control(service
->service_entry
, dwControl
))
996 service_unlock(service
->service_entry
);
997 return ERROR_INVALID_SERVICE_CONTROL
;
1000 switch (service
->service_entry
->status
.dwCurrentState
)
1002 case SERVICE_STOPPED
:
1003 service_unlock(service
->service_entry
);
1004 return ERROR_SERVICE_NOT_ACTIVE
;
1005 case SERVICE_START_PENDING
:
1006 if (dwControl
==SERVICE_CONTROL_STOP
)
1009 case SERVICE_STOP_PENDING
:
1010 service_unlock(service
->service_entry
);
1011 return ERROR_SERVICE_CANNOT_ACCEPT_CTRL
;
1014 /* prevent races by caching these variables and clearing them on
1015 * stop here instead of outside the services lock */
1016 control_mutex
= service
->service_entry
->control_mutex
;
1017 control_pipe
= service
->service_entry
->control_pipe
;
1018 if (dwControl
== SERVICE_CONTROL_STOP
)
1020 service
->service_entry
->control_mutex
= NULL
;
1021 service
->service_entry
->control_pipe
= INVALID_HANDLE_VALUE
;
1024 service_unlock(service
->service_entry
);
1026 ret
= WaitForSingleObject(control_mutex
, 30000);
1027 if (ret
== WAIT_OBJECT_0
)
1029 DWORD result
= ERROR_SUCCESS
;
1031 ret
= service_send_control(service
->service_entry
, control_pipe
, dwControl
, &result
);
1033 if (dwControl
== SERVICE_CONTROL_STOP
)
1035 CloseHandle(control_mutex
);
1036 CloseHandle(control_pipe
);
1039 ReleaseMutex(control_mutex
);
1045 if (dwControl
== SERVICE_CONTROL_STOP
)
1047 CloseHandle(control_mutex
);
1048 CloseHandle(control_pipe
);
1050 return ERROR_SERVICE_REQUEST_TIMEOUT
;
1054 DWORD
svcctl_CloseServiceHandle(
1055 SC_RPC_HANDLE
*handle
)
1057 WINE_TRACE("(&%p)\n", *handle
);
1059 SC_RPC_HANDLE_destroy(*handle
);
1062 return ERROR_SUCCESS
;
1065 static void SC_RPC_LOCK_destroy(SC_RPC_LOCK hLock
)
1067 struct sc_lock
*lock
= hLock
;
1068 scmdatabase_unlock_startup(lock
->db
);
1069 HeapFree(GetProcessHeap(), 0, lock
);
1072 void __RPC_USER
SC_RPC_LOCK_rundown(SC_RPC_LOCK hLock
)
1074 SC_RPC_LOCK_destroy(hLock
);
1077 DWORD
svcctl_LockServiceDatabase(
1078 SC_RPC_HANDLE hSCManager
,
1079 SC_RPC_LOCK
*phLock
)
1081 struct sc_manager_handle
*manager
;
1082 struct sc_lock
*lock
;
1085 WINE_TRACE("(%p, %p)\n", hSCManager
, phLock
);
1087 if ((err
= validate_scm_handle(hSCManager
, SC_MANAGER_LOCK
, &manager
)) != ERROR_SUCCESS
)
1090 err
= scmdatabase_lock_startup(manager
->db
);
1091 if (err
!= ERROR_SUCCESS
)
1094 lock
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct sc_lock
));
1097 scmdatabase_unlock_startup(manager
->db
);
1098 return ERROR_NOT_ENOUGH_SERVER_MEMORY
;
1101 lock
->db
= manager
->db
;
1104 return ERROR_SUCCESS
;
1107 DWORD
svcctl_UnlockServiceDatabase(
1108 SC_RPC_LOCK
*phLock
)
1110 WINE_TRACE("(&%p)\n", *phLock
);
1112 SC_RPC_LOCK_destroy(*phLock
);
1115 return ERROR_SUCCESS
;
1118 static BOOL
map_state(DWORD state
, DWORD mask
)
1122 case SERVICE_START_PENDING
:
1123 case SERVICE_STOP_PENDING
:
1124 case SERVICE_RUNNING
:
1125 case SERVICE_CONTINUE_PENDING
:
1126 case SERVICE_PAUSE_PENDING
:
1127 case SERVICE_PAUSED
:
1128 if (SERVICE_ACTIVE
& mask
) return TRUE
;
1130 case SERVICE_STOPPED
:
1131 if (SERVICE_INACTIVE
& mask
) return TRUE
;
1134 WINE_ERR("unknown state %u\n", state
);
1140 DWORD
svcctl_EnumServicesStatusW(
1141 SC_RPC_HANDLE hmngr
,
1149 DWORD err
, sz
, total_size
, num_services
;
1151 struct sc_manager_handle
*manager
;
1152 struct service_entry
*service
;
1153 ENUM_SERVICE_STATUSW
*s
;
1155 WINE_TRACE("(%p, 0x%x, 0x%x, %p, %u, %p, %p)\n", hmngr
, type
, state
, buffer
, size
, needed
, returned
);
1157 if (!type
|| !state
)
1158 return ERROR_INVALID_PARAMETER
;
1160 if ((err
= validate_scm_handle(hmngr
, SC_MANAGER_ENUMERATE_SERVICE
, &manager
)) != ERROR_SUCCESS
)
1163 scmdatabase_lock_exclusive(manager
->db
);
1165 total_size
= num_services
= 0;
1166 LIST_FOR_EACH_ENTRY(service
, &manager
->db
->services
, struct service_entry
, entry
)
1168 if ((service
->status
.dwServiceType
& type
) && map_state(service
->status
.dwCurrentState
, state
))
1170 total_size
+= sizeof(ENUM_SERVICE_STATUSW
);
1171 total_size
+= (strlenW(service
->name
) + 1) * sizeof(WCHAR
);
1172 if (service
->config
.lpDisplayName
)
1174 total_size
+= (strlenW(service
->config
.lpDisplayName
) + 1) * sizeof(WCHAR
);
1180 *needed
= total_size
;
1181 if (total_size
> size
)
1183 scmdatabase_unlock(manager
->db
);
1184 return ERROR_MORE_DATA
;
1186 s
= (ENUM_SERVICE_STATUSW
*)buffer
;
1187 offset
= num_services
* sizeof(ENUM_SERVICE_STATUSW
);
1188 LIST_FOR_EACH_ENTRY(service
, &manager
->db
->services
, struct service_entry
, entry
)
1190 if ((service
->status
.dwServiceType
& type
) && map_state(service
->status
.dwCurrentState
, state
))
1192 sz
= (strlenW(service
->name
) + 1) * sizeof(WCHAR
);
1193 memcpy(buffer
+ offset
, service
->name
, sz
);
1194 s
->lpServiceName
= (WCHAR
*)offset
; /* store a buffer offset instead of a pointer */
1197 if (!service
->config
.lpDisplayName
) s
->lpDisplayName
= NULL
;
1200 sz
= (strlenW(service
->config
.lpDisplayName
) + 1) * sizeof(WCHAR
);
1201 memcpy(buffer
+ offset
, service
->config
.lpDisplayName
, sz
);
1202 s
->lpDisplayName
= (WCHAR
*)offset
;
1205 memcpy(&s
->ServiceStatus
, &service
->status
, sizeof(SERVICE_STATUS
));
1209 *returned
= num_services
;
1211 scmdatabase_unlock(manager
->db
);
1212 return ERROR_SUCCESS
;
1215 struct service_entry
*find_service_by_group(struct scmdatabase
*db
, const WCHAR
*group
)
1217 struct service_entry
*service
;
1218 LIST_FOR_EACH_ENTRY(service
, &db
->services
, struct service_entry
, entry
)
1220 if (service
->config
.lpLoadOrderGroup
&& !strcmpiW(group
, service
->config
.lpLoadOrderGroup
))
1226 static BOOL
match_group(const WCHAR
*g1
, const WCHAR
*g2
)
1228 if (!g2
) return TRUE
;
1229 if (!g2
[0] && (!g1
|| !g1
[0])) return TRUE
;
1230 if (g1
&& !strcmpW(g1
, g2
)) return TRUE
;
1234 DWORD
svcctl_EnumServicesStatusExW(
1235 SC_RPC_HANDLE hmngr
,
1244 DWORD err
, sz
, total_size
, num_services
;
1246 struct sc_manager_handle
*manager
;
1247 struct service_entry
*service
;
1248 ENUM_SERVICE_STATUS_PROCESSW
*s
;
1250 WINE_TRACE("(%p, 0x%x, 0x%x, %p, %u, %p, %p, %s)\n", hmngr
, type
, state
, buffer
, size
,
1251 needed
, returned
, wine_dbgstr_w(group
));
1253 if (!type
|| !state
)
1254 return ERROR_INVALID_PARAMETER
;
1256 if ((err
= validate_scm_handle(hmngr
, SC_MANAGER_ENUMERATE_SERVICE
, &manager
)) != ERROR_SUCCESS
)
1259 scmdatabase_lock_exclusive(manager
->db
);
1261 if (group
&& !find_service_by_group(manager
->db
, group
))
1263 scmdatabase_unlock(manager
->db
);
1264 return ERROR_SERVICE_DOES_NOT_EXIST
;
1267 total_size
= num_services
= 0;
1268 LIST_FOR_EACH_ENTRY(service
, &manager
->db
->services
, struct service_entry
, entry
)
1270 if ((service
->status
.dwServiceType
& type
) && map_state(service
->status
.dwCurrentState
, state
)
1271 && match_group(service
->config
.lpLoadOrderGroup
, group
))
1273 total_size
+= sizeof(ENUM_SERVICE_STATUS_PROCESSW
);
1274 total_size
+= (strlenW(service
->name
) + 1) * sizeof(WCHAR
);
1275 if (service
->config
.lpDisplayName
)
1277 total_size
+= (strlenW(service
->config
.lpDisplayName
) + 1) * sizeof(WCHAR
);
1283 *needed
= total_size
;
1284 if (total_size
> size
)
1286 scmdatabase_unlock(manager
->db
);
1287 return ERROR_MORE_DATA
;
1289 s
= (ENUM_SERVICE_STATUS_PROCESSW
*)buffer
;
1290 offset
= num_services
* sizeof(ENUM_SERVICE_STATUS_PROCESSW
);
1291 LIST_FOR_EACH_ENTRY(service
, &manager
->db
->services
, struct service_entry
, entry
)
1293 if ((service
->status
.dwServiceType
& type
) && map_state(service
->status
.dwCurrentState
, state
)
1294 && match_group(service
->config
.lpLoadOrderGroup
, group
))
1296 sz
= (strlenW(service
->name
) + 1) * sizeof(WCHAR
);
1297 memcpy(buffer
+ offset
, service
->name
, sz
);
1298 s
->lpServiceName
= (WCHAR
*)offset
; /* store a buffer offset instead of a pointer */
1301 if (!service
->config
.lpDisplayName
) s
->lpDisplayName
= NULL
;
1304 sz
= (strlenW(service
->config
.lpDisplayName
) + 1) * sizeof(WCHAR
);
1305 memcpy(buffer
+ offset
, service
->config
.lpDisplayName
, sz
);
1306 s
->lpDisplayName
= (WCHAR
*)offset
;
1309 s
->ServiceStatusProcess
= service
->status
;
1313 *returned
= num_services
;
1315 scmdatabase_unlock(manager
->db
);
1316 return ERROR_SUCCESS
;
1319 DWORD
svcctl_QueryServiceObjectSecurity(
1323 return ERROR_CALL_NOT_IMPLEMENTED
;
1326 DWORD
svcctl_SetServiceObjectSecurity(
1330 return ERROR_CALL_NOT_IMPLEMENTED
;
1333 DWORD
svcctl_QueryServiceStatus(
1337 return ERROR_CALL_NOT_IMPLEMENTED
;
1341 DWORD
svcctl_NotifyBootConfigStatus(
1345 return ERROR_CALL_NOT_IMPLEMENTED
;
1348 DWORD
svcctl_SCSetServiceBitsW(
1352 return ERROR_CALL_NOT_IMPLEMENTED
;
1356 DWORD
svcctl_EnumDependentServicesW(
1360 return ERROR_CALL_NOT_IMPLEMENTED
;
1363 DWORD
svcctl_QueryServiceLockStatusW(
1367 return ERROR_CALL_NOT_IMPLEMENTED
;
1370 DWORD
svcctl_SCSetServiceBitsA(
1374 return ERROR_CALL_NOT_IMPLEMENTED
;
1377 DWORD
svcctl_ChangeServiceConfigA(
1381 return ERROR_CALL_NOT_IMPLEMENTED
;
1384 DWORD
svcctl_CreateServiceA(
1388 return ERROR_CALL_NOT_IMPLEMENTED
;
1391 DWORD
svcctl_EnumDependentServicesA(
1395 return ERROR_CALL_NOT_IMPLEMENTED
;
1398 DWORD
svcctl_EnumServicesStatusA(
1402 return ERROR_CALL_NOT_IMPLEMENTED
;
1405 DWORD
svcctl_OpenSCManagerA(
1409 return ERROR_CALL_NOT_IMPLEMENTED
;
1412 DWORD
svcctl_OpenServiceA(
1416 return ERROR_CALL_NOT_IMPLEMENTED
;
1419 DWORD
svcctl_QueryServiceConfigA(
1423 return ERROR_CALL_NOT_IMPLEMENTED
;
1426 DWORD
svcctl_QueryServiceLockStatusA(
1430 return ERROR_CALL_NOT_IMPLEMENTED
;
1433 DWORD
svcctl_StartServiceA(
1437 return ERROR_CALL_NOT_IMPLEMENTED
;
1440 DWORD
svcctl_GetServiceDisplayNameA(
1444 return ERROR_CALL_NOT_IMPLEMENTED
;
1447 DWORD
svcctl_GetServiceKeyNameA(
1451 return ERROR_CALL_NOT_IMPLEMENTED
;
1454 DWORD
svcctl_GetCurrentGroupStateW(
1458 return ERROR_CALL_NOT_IMPLEMENTED
;
1461 DWORD
svcctl_EnumServiceGroupW(
1465 return ERROR_CALL_NOT_IMPLEMENTED
;
1468 DWORD
svcctl_ChangeServiceConfig2A(
1472 return ERROR_CALL_NOT_IMPLEMENTED
;
1475 DWORD
svcctl_QueryServiceConfig2A(
1479 return ERROR_CALL_NOT_IMPLEMENTED
;
1483 DWORD
RPC_Init(void)
1485 WCHAR transport
[] = SVCCTL_TRANSPORT
;
1486 WCHAR endpoint
[] = SVCCTL_ENDPOINT
;
1489 if ((err
= RpcServerUseProtseqEpW(transport
, 0, endpoint
, NULL
)) != ERROR_SUCCESS
)
1491 WINE_ERR("RpcServerUseProtseq failed with error %u\n", err
);
1495 if ((err
= RpcServerRegisterIf(svcctl_v2_0_s_ifspec
, 0, 0)) != ERROR_SUCCESS
)
1497 WINE_ERR("RpcServerRegisterIf failed with error %u\n", err
);
1501 if ((err
= RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, TRUE
)) != ERROR_SUCCESS
)
1503 WINE_ERR("RpcServerListen failed with error %u\n", err
);
1506 return ERROR_SUCCESS
;
1509 DWORD
RPC_MainLoop(void)
1512 HANDLE hExitEvent
= __wine_make_process_system();
1514 SetEvent(g_hStartedEvent
);
1516 WINE_TRACE("Entered main loop\n");
1520 err
= WaitForSingleObjectEx(hExitEvent
, INFINITE
, TRUE
);
1521 WINE_TRACE("Wait returned %d\n", err
);
1522 } while (err
!= WAIT_OBJECT_0
);
1524 WINE_TRACE("Object signaled - wine shutdown\n");
1525 CloseHandle(hExitEvent
);
1526 return ERROR_SUCCESS
;
1529 void __RPC_USER
SC_RPC_HANDLE_rundown(SC_RPC_HANDLE handle
)
1531 SC_RPC_HANDLE_destroy(handle
);
1534 void __RPC_FAR
* __RPC_USER
MIDL_user_allocate(SIZE_T len
)
1536 return HeapAlloc(GetProcessHeap(), 0, len
);
1539 void __RPC_USER
MIDL_user_free(void __RPC_FAR
* ptr
)
1541 HeapFree(GetProcessHeap(), 0, ptr
);