msvcp110: Use _Condition_variable in _Cnd_t implementation.
[wine.git] / programs / services / rpc.c
blob7e09abaab12ea12c4ea6939b551a221eaff7c044
1 /*
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
22 #define NONAMELESSSTRUCT
23 #define NONAMELESSUNION
25 #include <stdarg.h>
26 #include <windows.h>
27 #include <winternl.h>
28 #include <winsvc.h>
29 #include <ntsecapi.h>
30 #include <rpc.h>
32 #include "wine/list.h"
33 #include "wine/debug.h"
35 #include "services.h"
36 #include "svcctl.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(service);
40 static const GENERIC_MAPPING g_scm_generic =
42 (STANDARD_RIGHTS_READ | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS),
43 (STANDARD_RIGHTS_WRITE | SC_MANAGER_CREATE_SERVICE | SC_MANAGER_MODIFY_BOOT_CONFIG),
44 (STANDARD_RIGHTS_EXECUTE | SC_MANAGER_CONNECT | SC_MANAGER_LOCK),
45 SC_MANAGER_ALL_ACCESS
48 static const GENERIC_MAPPING g_svc_generic =
50 (STANDARD_RIGHTS_READ | SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS | SERVICE_INTERROGATE | SERVICE_ENUMERATE_DEPENDENTS),
51 (STANDARD_RIGHTS_WRITE | SERVICE_CHANGE_CONFIG),
52 (STANDARD_RIGHTS_EXECUTE | SERVICE_START | SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_USER_DEFINED_CONTROL),
53 SERVICE_ALL_ACCESS
56 typedef enum
58 SC_HTYPE_DONT_CARE = 0,
59 SC_HTYPE_MANAGER,
60 SC_HTYPE_SERVICE,
61 SC_HTYPE_NOTIFY
62 } SC_HANDLE_TYPE;
64 struct sc_handle
66 SC_HANDLE_TYPE type;
67 DWORD access;
70 struct sc_manager_handle /* service control manager handle */
72 struct sc_handle hdr;
73 struct scmdatabase *db;
76 struct sc_notify_handle
78 struct sc_handle hdr;
79 HANDLE event;
80 DWORD notify_mask;
81 LONG ref;
82 SC_RPC_NOTIFY_PARAMS_LIST *params_list;
85 struct sc_service_handle /* service handle */
87 struct sc_handle hdr;
88 struct list entry;
89 BOOL status_notified;
90 struct service_entry *service_entry;
91 struct sc_notify_handle *notify;
94 static void sc_notify_retain(struct sc_notify_handle *notify)
96 InterlockedIncrement(&notify->ref);
99 static void sc_notify_release(struct sc_notify_handle *notify)
101 ULONG r = InterlockedDecrement(&notify->ref);
102 if (r == 0)
104 CloseHandle(notify->event);
105 HeapFree(GetProcessHeap(), 0, notify->params_list);
106 HeapFree(GetProcessHeap(), 0, notify);
110 struct sc_lock
112 struct scmdatabase *db;
115 static const WCHAR emptyW[] = {0};
116 static PTP_CLEANUP_GROUP cleanup_group;
117 HANDLE exit_event;
119 static void CALLBACK group_cancel_callback(void *object, void *userdata)
121 struct process_entry *process = object;
122 release_process(process);
125 static void CALLBACK terminate_callback(TP_CALLBACK_INSTANCE *instance, void *context,
126 TP_WAIT *wait, TP_WAIT_RESULT result)
128 struct process_entry *process = context;
129 if (result == WAIT_TIMEOUT) process_terminate(process);
130 release_process(process);
131 CloseThreadpoolWait(wait);
134 static void terminate_after_timeout(struct process_entry *process, DWORD timeout)
136 TP_CALLBACK_ENVIRON environment;
137 LARGE_INTEGER timestamp;
138 TP_WAIT *wait;
139 FILETIME ft;
141 memset(&environment, 0, sizeof(environment));
142 environment.Version = 1;
143 environment.CleanupGroup = cleanup_group;
144 environment.CleanupGroupCancelCallback = group_cancel_callback;
146 timestamp.QuadPart = (ULONGLONG)timeout * -10000;
147 ft.dwLowDateTime = timestamp.u.LowPart;
148 ft.dwHighDateTime = timestamp.u.HighPart;
150 if ((wait = CreateThreadpoolWait(terminate_callback, grab_process(process), &environment)))
151 SetThreadpoolWait(wait, process->process, &ft);
152 else
153 release_process(process);
156 static void CALLBACK shutdown_callback(TP_CALLBACK_INSTANCE *instance, void *context)
158 struct process_entry *process = context;
159 DWORD result;
161 result = WaitForSingleObject(process->control_mutex, 30000);
162 if (result == WAIT_OBJECT_0)
164 process_send_control(process, FALSE, emptyW, SERVICE_CONTROL_STOP, NULL, 0, &result);
165 ReleaseMutex(process->control_mutex);
168 release_process(process);
171 static void shutdown_shared_process(struct process_entry *process)
173 TP_CALLBACK_ENVIRON environment;
174 struct service_entry *service;
175 struct scmdatabase *db = process->db;
177 scmdatabase_lock(db);
178 LIST_FOR_EACH_ENTRY(service, &db->services, struct service_entry, entry)
180 if (service->process != process) continue;
181 service->status.dwCurrentState = SERVICE_STOP_PENDING;
183 scmdatabase_unlock(db);
185 memset(&environment, 0, sizeof(environment));
186 environment.Version = 1;
187 environment.CleanupGroup = cleanup_group;
188 environment.CleanupGroupCancelCallback = group_cancel_callback;
190 if (!TrySubmitThreadpoolCallback(shutdown_callback, grab_process(process), &environment))
191 release_process(process);
194 static void free_service_strings(struct service_entry *old, struct service_entry *new)
196 QUERY_SERVICE_CONFIGW *old_cfg = &old->config;
197 QUERY_SERVICE_CONFIGW *new_cfg = &new->config;
199 if (old_cfg->lpBinaryPathName != new_cfg->lpBinaryPathName)
200 HeapFree(GetProcessHeap(), 0, old_cfg->lpBinaryPathName);
202 if (old_cfg->lpLoadOrderGroup != new_cfg->lpLoadOrderGroup)
203 HeapFree(GetProcessHeap(), 0, old_cfg->lpLoadOrderGroup);
205 if (old_cfg->lpServiceStartName != new_cfg->lpServiceStartName)
206 HeapFree(GetProcessHeap(), 0, old_cfg->lpServiceStartName);
208 if (old_cfg->lpDisplayName != new_cfg->lpDisplayName)
209 HeapFree(GetProcessHeap(), 0, old_cfg->lpDisplayName);
211 if (old->dependOnServices != new->dependOnServices)
212 HeapFree(GetProcessHeap(), 0, old->dependOnServices);
214 if (old->dependOnGroups != new->dependOnGroups)
215 HeapFree(GetProcessHeap(), 0, old->dependOnGroups);
218 /* Check if the given handle is of the required type and allows the requested access. */
219 static DWORD validate_context_handle(SC_RPC_HANDLE handle, DWORD type, DWORD needed_access, struct sc_handle **out_hdr)
221 struct sc_handle *hdr = handle;
223 if (type != SC_HTYPE_DONT_CARE && hdr->type != type)
225 WINE_ERR("Handle is of an invalid type (%d, %ld)\n", hdr->type, type);
226 return ERROR_INVALID_HANDLE;
229 if ((needed_access & hdr->access) != needed_access)
231 WINE_ERR("Access denied - handle created with access %lx, needed %lx\n", hdr->access, needed_access);
232 return ERROR_ACCESS_DENIED;
235 *out_hdr = hdr;
236 return ERROR_SUCCESS;
239 static DWORD validate_scm_handle(SC_RPC_HANDLE handle, DWORD needed_access, struct sc_manager_handle **manager)
241 struct sc_handle *hdr;
242 DWORD err = validate_context_handle(handle, SC_HTYPE_MANAGER, needed_access, &hdr);
243 if (err == ERROR_SUCCESS)
244 *manager = (struct sc_manager_handle *)hdr;
245 return err;
248 static DWORD validate_service_handle(SC_RPC_HANDLE handle, DWORD needed_access, struct sc_service_handle **service)
250 struct sc_handle *hdr;
251 DWORD err = validate_context_handle(handle, SC_HTYPE_SERVICE, needed_access, &hdr);
252 if (err == ERROR_SUCCESS)
253 *service = (struct sc_service_handle *)hdr;
254 return err;
257 static DWORD validate_notify_handle(SC_RPC_HANDLE handle, DWORD needed_access, struct sc_notify_handle **notify)
259 struct sc_handle *hdr;
260 DWORD err = validate_context_handle(handle, SC_HTYPE_NOTIFY, needed_access, &hdr);
261 if (err == ERROR_SUCCESS)
262 *notify = (struct sc_notify_handle *)hdr;
263 return err;
266 DWORD __cdecl svcctl_OpenSCManagerW(
267 MACHINE_HANDLEW MachineName, /* Note: this parameter is ignored */
268 LPCWSTR DatabaseName,
269 DWORD dwAccessMask,
270 SC_RPC_HANDLE *handle)
272 struct sc_manager_handle *manager;
274 WINE_TRACE("(%s, %s, %lx)\n", wine_dbgstr_w(MachineName), wine_dbgstr_w(DatabaseName), dwAccessMask);
276 if (DatabaseName != NULL && DatabaseName[0])
278 if (lstrcmpW(DatabaseName, SERVICES_FAILED_DATABASEW) == 0)
279 return ERROR_DATABASE_DOES_NOT_EXIST;
280 if (lstrcmpW(DatabaseName, SERVICES_ACTIVE_DATABASEW) != 0)
281 return ERROR_INVALID_NAME;
284 if (!(manager = HeapAlloc(GetProcessHeap(), 0, sizeof(*manager))))
285 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
287 manager->hdr.type = SC_HTYPE_MANAGER;
289 if (dwAccessMask & MAXIMUM_ALLOWED)
290 dwAccessMask |= SC_MANAGER_ALL_ACCESS;
291 manager->hdr.access = dwAccessMask;
292 RtlMapGenericMask(&manager->hdr.access, &g_scm_generic);
293 manager->db = active_database;
294 *handle = &manager->hdr;
296 return ERROR_SUCCESS;
299 static void SC_RPC_HANDLE_destroy(SC_RPC_HANDLE handle)
301 struct sc_handle *hdr = handle;
302 switch (hdr->type)
304 case SC_HTYPE_MANAGER:
306 struct sc_manager_handle *manager = (struct sc_manager_handle *)hdr;
307 HeapFree(GetProcessHeap(), 0, manager);
308 break;
310 case SC_HTYPE_SERVICE:
312 struct sc_service_handle *service = (struct sc_service_handle *)hdr;
313 service_lock(service->service_entry);
314 list_remove(&service->entry);
315 if (service->notify)
317 SetEvent(service->notify->event);
318 sc_notify_release(service->notify);
320 service_unlock(service->service_entry);
321 release_service(service->service_entry);
322 HeapFree(GetProcessHeap(), 0, service);
323 break;
325 default:
326 WINE_ERR("invalid handle type %d\n", hdr->type);
327 RpcRaiseException(ERROR_INVALID_HANDLE);
331 DWORD __cdecl svcctl_GetServiceDisplayNameW(
332 SC_RPC_HANDLE hSCManager,
333 LPCWSTR lpServiceName,
334 WCHAR *lpBuffer,
335 DWORD *cchBufSize)
337 struct sc_manager_handle *manager;
338 struct service_entry *entry;
339 DWORD err;
341 WINE_TRACE("(%s, %ld)\n", wine_dbgstr_w(lpServiceName), *cchBufSize);
343 if ((err = validate_scm_handle(hSCManager, 0, &manager)) != ERROR_SUCCESS)
344 return err;
346 scmdatabase_lock(manager->db);
348 entry = scmdatabase_find_service(manager->db, lpServiceName);
349 if (entry != NULL)
351 LPCWSTR name;
352 int len;
353 name = get_display_name(entry);
354 len = lstrlenW(name);
355 if (len <= *cchBufSize)
357 err = ERROR_SUCCESS;
358 memcpy(lpBuffer, name, (len + 1)*sizeof(*name));
360 else
361 err = ERROR_INSUFFICIENT_BUFFER;
362 *cchBufSize = len;
364 else
365 err = ERROR_SERVICE_DOES_NOT_EXIST;
367 scmdatabase_unlock(manager->db);
369 if (err != ERROR_SUCCESS)
370 lpBuffer[0] = 0;
372 return err;
375 DWORD __cdecl svcctl_GetServiceKeyNameW(
376 SC_RPC_HANDLE hSCManager,
377 LPCWSTR lpServiceDisplayName,
378 WCHAR *lpBuffer,
379 DWORD *cchBufSize)
381 struct service_entry *entry;
382 struct sc_manager_handle *manager;
383 DWORD err;
385 WINE_TRACE("(%s, %ld)\n", wine_dbgstr_w(lpServiceDisplayName), *cchBufSize);
387 if ((err = validate_scm_handle(hSCManager, 0, &manager)) != ERROR_SUCCESS)
388 return err;
390 scmdatabase_lock(manager->db);
392 entry = scmdatabase_find_service_by_displayname(manager->db, lpServiceDisplayName);
393 if (entry != NULL)
395 int len;
396 len = lstrlenW(entry->name);
397 if (len <= *cchBufSize)
399 err = ERROR_SUCCESS;
400 memcpy(lpBuffer, entry->name, (len + 1)*sizeof(*entry->name));
402 else
403 err = ERROR_INSUFFICIENT_BUFFER;
404 *cchBufSize = len;
406 else
407 err = ERROR_SERVICE_DOES_NOT_EXIST;
409 scmdatabase_unlock(manager->db);
411 if (err != ERROR_SUCCESS)
412 lpBuffer[0] = 0;
414 return err;
417 static DWORD create_handle_for_service(struct service_entry *entry, DWORD dwDesiredAccess, SC_RPC_HANDLE *phService)
419 struct sc_service_handle *service;
421 if (!(service = HeapAlloc(GetProcessHeap(), 0, sizeof(*service))))
423 release_service(entry);
424 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
427 if (dwDesiredAccess & MAXIMUM_ALLOWED)
428 dwDesiredAccess |= SERVICE_ALL_ACCESS;
430 service->hdr.type = SC_HTYPE_SERVICE;
431 service->hdr.access = dwDesiredAccess;
432 service->notify = NULL;
433 service->status_notified = FALSE;
434 RtlMapGenericMask(&service->hdr.access, &g_svc_generic);
436 service_lock(entry);
437 service->service_entry = entry;
438 list_add_tail(&entry->handles, &service->entry);
439 service_unlock(entry);
441 *phService = &service->hdr;
442 return ERROR_SUCCESS;
445 DWORD __cdecl svcctl_OpenServiceW(
446 SC_RPC_HANDLE hSCManager,
447 LPCWSTR lpServiceName,
448 DWORD dwDesiredAccess,
449 SC_RPC_HANDLE *phService)
451 struct sc_manager_handle *manager;
452 struct service_entry *entry;
453 DWORD err;
455 WINE_TRACE("(%s, 0x%lx)\n", wine_dbgstr_w(lpServiceName), dwDesiredAccess);
457 if ((err = validate_scm_handle(hSCManager, 0, &manager)) != ERROR_SUCCESS)
458 return err;
459 if (!validate_service_name(lpServiceName))
460 return ERROR_INVALID_NAME;
462 scmdatabase_lock(manager->db);
463 entry = grab_service(scmdatabase_find_service(manager->db, lpServiceName));
464 scmdatabase_unlock(manager->db);
466 if (entry == NULL)
467 return ERROR_SERVICE_DOES_NOT_EXIST;
469 return create_handle_for_service(entry, dwDesiredAccess, phService);
472 static DWORD parse_dependencies(const WCHAR *dependencies, struct service_entry *entry)
474 WCHAR *services = NULL, *groups, *s;
475 DWORD len, len_services = 0, len_groups = 0;
476 const WCHAR *ptr = dependencies;
478 if (!dependencies || !dependencies[0])
480 entry->dependOnServices = NULL;
481 entry->dependOnGroups = NULL;
482 return ERROR_SUCCESS;
485 while (*ptr)
487 len = lstrlenW(ptr) + 1;
488 if (ptr[0] == '+' && ptr[1])
489 len_groups += len - 1;
490 else
491 len_services += len;
492 ptr += len;
494 if (!len_services) entry->dependOnServices = NULL;
495 else
497 services = HeapAlloc(GetProcessHeap(), 0, (len_services + 1) * sizeof(WCHAR));
498 if (!services)
499 return ERROR_OUTOFMEMORY;
501 s = services;
502 ptr = dependencies;
503 while (*ptr)
505 len = lstrlenW(ptr) + 1;
506 if (*ptr != '+')
508 lstrcpyW(s, ptr);
509 s += len;
511 ptr += len;
513 *s = 0;
514 entry->dependOnServices = services;
516 if (!len_groups) entry->dependOnGroups = NULL;
517 else
519 groups = HeapAlloc(GetProcessHeap(), 0, (len_groups + 1) * sizeof(WCHAR));
520 if (!groups)
522 HeapFree(GetProcessHeap(), 0, services);
523 return ERROR_OUTOFMEMORY;
525 s = groups;
526 ptr = dependencies;
527 while (*ptr)
529 len = lstrlenW(ptr) + 1;
530 if (ptr[0] == '+' && ptr[1])
532 lstrcpyW(s, ptr + 1);
533 s += len - 1;
535 ptr += len;
537 *s = 0;
538 entry->dependOnGroups = groups;
541 return ERROR_SUCCESS;
544 static DWORD create_serviceW(
545 SC_RPC_HANDLE hSCManager,
546 LPCWSTR lpServiceName,
547 LPCWSTR lpDisplayName,
548 DWORD dwDesiredAccess,
549 DWORD dwServiceType,
550 DWORD dwStartType,
551 DWORD dwErrorControl,
552 LPCWSTR lpBinaryPathName,
553 LPCWSTR lpLoadOrderGroup,
554 DWORD *lpdwTagId,
555 const BYTE *lpDependencies,
556 DWORD dwDependenciesSize,
557 LPCWSTR lpServiceStartName,
558 const BYTE *lpPassword,
559 DWORD dwPasswordSize,
560 SC_RPC_HANDLE *phService,
561 BOOL is_wow64)
563 struct service_entry *entry, *found;
564 struct sc_manager_handle *manager;
565 DWORD err;
567 WINE_TRACE("(%s, %s, 0x%lx, %s)\n", wine_dbgstr_w(lpServiceName), wine_dbgstr_w(lpDisplayName), dwDesiredAccess, wine_dbgstr_w(lpBinaryPathName));
569 if ((err = validate_scm_handle(hSCManager, SC_MANAGER_CREATE_SERVICE, &manager)) != ERROR_SUCCESS)
570 return err;
572 if (!validate_service_name(lpServiceName))
573 return ERROR_INVALID_NAME;
574 if (!check_multisz((LPCWSTR)lpDependencies, dwDependenciesSize) || !lpServiceName[0] || !lpBinaryPathName[0])
575 return ERROR_INVALID_PARAMETER;
577 if (lpPassword)
578 WINE_FIXME("Don't know how to add a password\n"); /* I always get ERROR_GEN_FAILURE */
580 err = service_create(lpServiceName, &entry);
581 if (err != ERROR_SUCCESS)
582 return err;
584 err = parse_dependencies((LPCWSTR)lpDependencies, entry);
585 if (err != ERROR_SUCCESS) {
586 free_service_entry(entry);
587 return err;
590 entry->is_wow64 = is_wow64;
591 entry->config.dwServiceType = entry->status.dwServiceType = dwServiceType;
592 entry->config.dwStartType = dwStartType;
593 entry->config.dwErrorControl = dwErrorControl;
594 entry->config.lpBinaryPathName = strdupW(lpBinaryPathName);
595 entry->config.lpLoadOrderGroup = strdupW(lpLoadOrderGroup);
596 entry->config.lpServiceStartName = strdupW(lpServiceStartName);
597 entry->config.lpDisplayName = strdupW(lpDisplayName);
599 if (lpdwTagId) /* TODO: In most situations a non-NULL TagId will generate an ERROR_INVALID_PARAMETER. */
600 entry->config.dwTagId = *lpdwTagId;
601 else
602 entry->config.dwTagId = 0;
604 /* other fields NULL*/
606 if (!validate_service_config(entry))
608 WINE_ERR("Invalid data while trying to create service\n");
609 free_service_entry(entry);
610 return ERROR_INVALID_PARAMETER;
613 scmdatabase_lock(manager->db);
615 if ((found = scmdatabase_find_service(manager->db, lpServiceName)))
617 err = is_marked_for_delete(found) ? ERROR_SERVICE_MARKED_FOR_DELETE : ERROR_SERVICE_EXISTS;
618 scmdatabase_unlock(manager->db);
619 free_service_entry(entry);
620 return err;
623 if (scmdatabase_find_service_by_displayname(manager->db, get_display_name(entry)))
625 scmdatabase_unlock(manager->db);
626 free_service_entry(entry);
627 return ERROR_DUPLICATE_SERVICE_NAME;
630 err = scmdatabase_add_service(manager->db, entry);
631 if (err != ERROR_SUCCESS)
633 scmdatabase_unlock(manager->db);
634 free_service_entry(entry);
635 return err;
637 scmdatabase_unlock(manager->db);
639 return create_handle_for_service(entry, dwDesiredAccess, phService);
642 DWORD __cdecl svcctl_CreateServiceW(
643 SC_RPC_HANDLE hSCManager,
644 LPCWSTR lpServiceName,
645 LPCWSTR lpDisplayName,
646 DWORD dwDesiredAccess,
647 DWORD dwServiceType,
648 DWORD dwStartType,
649 DWORD dwErrorControl,
650 LPCWSTR lpBinaryPathName,
651 LPCWSTR lpLoadOrderGroup,
652 DWORD *lpdwTagId,
653 const BYTE *lpDependencies,
654 DWORD dwDependenciesSize,
655 LPCWSTR lpServiceStartName,
656 const BYTE *lpPassword,
657 DWORD dwPasswordSize,
658 SC_RPC_HANDLE *phService)
660 WINE_TRACE("(%s, %s, 0x%lx, %s)\n", wine_dbgstr_w(lpServiceName), wine_dbgstr_w(lpDisplayName), dwDesiredAccess, wine_dbgstr_w(lpBinaryPathName));
661 return create_serviceW(hSCManager, lpServiceName, lpDisplayName, dwDesiredAccess, dwServiceType, dwStartType,
662 dwErrorControl, lpBinaryPathName, lpLoadOrderGroup, lpdwTagId, lpDependencies, dwDependenciesSize, lpServiceStartName,
663 lpPassword, dwPasswordSize, phService, FALSE);
666 DWORD __cdecl svcctl_DeleteService(
667 SC_RPC_HANDLE hService)
669 struct sc_service_handle *service;
670 DWORD err;
672 if ((err = validate_service_handle(hService, DELETE, &service)) != ERROR_SUCCESS)
673 return err;
675 service_lock(service->service_entry);
677 if (!is_marked_for_delete(service->service_entry))
678 err = mark_for_delete(service->service_entry);
679 else
680 err = ERROR_SERVICE_MARKED_FOR_DELETE;
682 service_unlock(service->service_entry);
684 return err;
687 DWORD __cdecl svcctl_QueryServiceConfigW(
688 SC_RPC_HANDLE hService,
689 QUERY_SERVICE_CONFIGW *config,
690 DWORD buf_size,
691 DWORD *needed_size)
693 struct sc_service_handle *service;
694 DWORD err;
696 WINE_TRACE("(%p)\n", config);
698 if ((err = validate_service_handle(hService, SERVICE_QUERY_CONFIG, &service)) != 0)
699 return err;
701 service_lock(service->service_entry);
702 config->dwServiceType = service->service_entry->config.dwServiceType;
703 config->dwStartType = service->service_entry->config.dwStartType;
704 config->dwErrorControl = service->service_entry->config.dwErrorControl;
705 config->lpBinaryPathName = strdupW(service->service_entry->config.lpBinaryPathName);
706 config->lpLoadOrderGroup = strdupW(service->service_entry->config.lpLoadOrderGroup);
707 config->dwTagId = service->service_entry->config.dwTagId;
708 config->lpDependencies = NULL; /* TODO */
709 config->lpServiceStartName = strdupW(service->service_entry->config.lpServiceStartName);
710 config->lpDisplayName = strdupW(service->service_entry->config.lpDisplayName);
711 service_unlock(service->service_entry);
713 return ERROR_SUCCESS;
716 DWORD __cdecl svcctl_ChangeServiceConfigW(
717 SC_RPC_HANDLE hService,
718 DWORD dwServiceType,
719 DWORD dwStartType,
720 DWORD dwErrorControl,
721 LPCWSTR lpBinaryPathName,
722 LPCWSTR lpLoadOrderGroup,
723 DWORD *lpdwTagId,
724 const BYTE *lpDependencies,
725 DWORD dwDependenciesSize,
726 LPCWSTR lpServiceStartName,
727 const BYTE *lpPassword,
728 DWORD dwPasswordSize,
729 LPCWSTR lpDisplayName)
731 struct service_entry new_entry, *entry;
732 struct sc_service_handle *service;
733 DWORD err;
735 WINE_TRACE("\n");
737 if ((err = validate_service_handle(hService, SERVICE_CHANGE_CONFIG, &service)) != 0)
738 return err;
740 if (!check_multisz((LPCWSTR)lpDependencies, dwDependenciesSize))
741 return ERROR_INVALID_PARAMETER;
743 /* first check if the new configuration is correct */
744 service_lock(service->service_entry);
746 if (is_marked_for_delete(service->service_entry))
748 service_unlock(service->service_entry);
749 return ERROR_SERVICE_MARKED_FOR_DELETE;
752 if (lpDisplayName != NULL &&
753 (entry = scmdatabase_find_service_by_displayname(service->service_entry->db, lpDisplayName)) &&
754 (entry != service->service_entry))
756 service_unlock(service->service_entry);
757 return ERROR_DUPLICATE_SERVICE_NAME;
760 new_entry = *service->service_entry;
762 if (dwServiceType != SERVICE_NO_CHANGE)
763 new_entry.config.dwServiceType = dwServiceType;
765 if (dwStartType != SERVICE_NO_CHANGE)
766 new_entry.config.dwStartType = dwStartType;
768 if (dwErrorControl != SERVICE_NO_CHANGE)
769 new_entry.config.dwErrorControl = dwErrorControl;
771 if (lpBinaryPathName != NULL)
772 new_entry.config.lpBinaryPathName = (LPWSTR)lpBinaryPathName;
774 if (lpLoadOrderGroup != NULL)
775 new_entry.config.lpLoadOrderGroup = (LPWSTR)lpLoadOrderGroup;
777 if (lpdwTagId != NULL)
778 WINE_FIXME("Changing tag id not supported\n");
780 if (lpServiceStartName != NULL)
781 new_entry.config.lpServiceStartName = (LPWSTR)lpServiceStartName;
783 if (lpPassword != NULL)
784 WINE_FIXME("Setting password not supported\n");
786 if (lpDisplayName != NULL)
787 new_entry.config.lpDisplayName = (LPWSTR)lpDisplayName;
789 err = parse_dependencies((LPCWSTR)lpDependencies, &new_entry);
790 if (err != ERROR_SUCCESS)
792 service_unlock(service->service_entry);
793 return err;
796 if (!validate_service_config(&new_entry))
798 WINE_ERR("The configuration after the change wouldn't be valid\n");
799 service_unlock(service->service_entry);
800 return ERROR_INVALID_PARAMETER;
803 /* configuration OK. The strings needs to be duplicated */
804 if (lpBinaryPathName != NULL)
805 new_entry.config.lpBinaryPathName = strdupW(lpBinaryPathName);
807 if (lpLoadOrderGroup != NULL)
808 new_entry.config.lpLoadOrderGroup = strdupW(lpLoadOrderGroup);
810 if (lpServiceStartName != NULL)
811 new_entry.config.lpServiceStartName = strdupW(lpServiceStartName);
813 if (lpDisplayName != NULL)
814 new_entry.config.lpDisplayName = strdupW(lpDisplayName);
816 /* try to save to Registry, commit or rollback depending on success */
817 err = save_service_config(&new_entry);
818 if (ERROR_SUCCESS == err)
820 free_service_strings(service->service_entry, &new_entry);
821 *service->service_entry = new_entry;
823 else free_service_strings(&new_entry, service->service_entry);
824 service_unlock(service->service_entry);
826 return err;
829 static void fill_status_process(SERVICE_STATUS_PROCESS *status, struct service_entry *service)
831 struct process_entry *process = service->process;
832 memcpy(status, &service->status, sizeof(service->status));
833 status->dwProcessId = 0;
834 if (process && !(service->status.dwServiceType & SERVICE_DRIVER))
835 status->dwProcessId = process->process_id;
836 status->dwServiceFlags = 0;
839 static void fill_notify(struct sc_notify_handle *notify, struct service_entry *service)
841 SC_RPC_NOTIFY_PARAMS_LIST *list;
842 SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2 *cparams;
844 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
845 sizeof(SC_RPC_NOTIFY_PARAMS_LIST) + sizeof(SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2));
846 if (!list)
847 return;
849 cparams = (SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2 *)(list + 1);
851 cparams->dwNotifyMask = notify->notify_mask;
852 fill_status_process(&cparams->ServiceStatus, service);
853 cparams->dwNotificationStatus = ERROR_SUCCESS;
854 cparams->dwNotificationTriggered = 1 << (cparams->ServiceStatus.dwCurrentState - SERVICE_STOPPED);
855 cparams->pszServiceNames = NULL;
857 list->cElements = 1;
859 list->NotifyParamsArray[0].dwInfoLevel = 2;
860 list->NotifyParamsArray[0].params = cparams;
862 InterlockedExchangePointer((void**)&notify->params_list, list);
864 SetEvent(notify->event);
867 DWORD __cdecl svcctl_SetServiceStatus(SC_RPC_HANDLE handle, SERVICE_STATUS *status)
869 struct sc_service_handle *service, *service_handle;
870 struct process_entry *process;
871 DWORD err, mask;
873 WINE_TRACE("(%p, %p)\n", handle, status);
875 if ((err = validate_service_handle(handle, SERVICE_SET_STATUS, &service)) != 0)
876 return err;
878 service_lock(service->service_entry);
880 /* FIXME: be a bit more discriminant about what parts of the status we set
881 * and check that fields are valid */
882 service->service_entry->status.dwCurrentState = status->dwCurrentState;
883 service->service_entry->status.dwControlsAccepted = status->dwControlsAccepted;
884 service->service_entry->status.dwWin32ExitCode = status->dwWin32ExitCode;
885 service->service_entry->status.dwServiceSpecificExitCode = status->dwServiceSpecificExitCode;
886 service->service_entry->status.dwCheckPoint = status->dwCheckPoint;
887 service->service_entry->status.dwWaitHint = status->dwWaitHint;
888 SetEvent(service->service_entry->status_changed_event);
890 if ((process = service->service_entry->process) &&
891 status->dwCurrentState == SERVICE_STOPPED)
893 service->service_entry->process = NULL;
894 if (!--process->use_count)
895 terminate_after_timeout(process, service_kill_timeout);
896 if (service->service_entry->shared_process && process->use_count <= 1)
897 shutdown_shared_process(process);
898 release_process(process);
901 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
902 LIST_FOR_EACH_ENTRY(service_handle, &service->service_entry->handles, struct sc_service_handle, entry)
904 struct sc_notify_handle *notify = service_handle->notify;
905 if (notify && (notify->notify_mask & mask))
907 fill_notify(notify, service->service_entry);
908 sc_notify_release(notify);
909 service_handle->notify = NULL;
910 service_handle->status_notified = TRUE;
912 else
913 service_handle->status_notified = FALSE;
916 service_unlock(service->service_entry);
918 return ERROR_SUCCESS;
921 DWORD __cdecl svcctl_ChangeServiceConfig2W( SC_RPC_HANDLE hService, SC_RPC_CONFIG_INFOW config )
923 struct sc_service_handle *service;
924 DWORD err;
926 if ((err = validate_service_handle(hService, SERVICE_CHANGE_CONFIG, &service)) != 0)
927 return err;
929 switch (config.dwInfoLevel)
931 case SERVICE_CONFIG_DESCRIPTION:
933 WCHAR *descr = NULL;
935 if (!config.descr->lpDescription)
936 break;
938 if (config.descr->lpDescription[0])
940 if (!(descr = strdupW( config.descr->lpDescription )))
941 return ERROR_NOT_ENOUGH_MEMORY;
944 WINE_TRACE( "changing service %p descr to %s\n", service, wine_dbgstr_w(descr) );
945 service_lock( service->service_entry );
946 HeapFree( GetProcessHeap(), 0, service->service_entry->description );
947 service->service_entry->description = descr;
948 save_service_config( service->service_entry );
949 service_unlock( service->service_entry );
951 break;
952 case SERVICE_CONFIG_FAILURE_ACTIONS:
953 WINE_FIXME( "SERVICE_CONFIG_FAILURE_ACTIONS not implemented: period %lu msg %s cmd %s\n",
954 config.actions->dwResetPeriod,
955 wine_dbgstr_w(config.actions->lpRebootMsg),
956 wine_dbgstr_w(config.actions->lpCommand) );
957 break;
958 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
959 WINE_TRACE( "changing service %p preshutdown timeout to %ld\n",
960 service, config.preshutdown->dwPreshutdownTimeout );
961 service_lock( service->service_entry );
962 service->service_entry->preshutdown_timeout = config.preshutdown->dwPreshutdownTimeout;
963 save_service_config( service->service_entry );
964 service_unlock( service->service_entry );
965 break;
966 default:
967 WINE_FIXME("level %lu not implemented\n", config.dwInfoLevel);
968 err = ERROR_INVALID_LEVEL;
969 break;
971 return err;
974 DWORD __cdecl svcctl_QueryServiceConfig2W( SC_RPC_HANDLE hService, DWORD level,
975 BYTE *buffer, DWORD size, LPDWORD needed )
977 struct sc_service_handle *service;
978 DWORD err;
980 memset(buffer, 0, size);
982 if ((err = validate_service_handle(hService, SERVICE_QUERY_CONFIG, &service)) != 0)
983 return err;
985 switch (level)
987 case SERVICE_CONFIG_DESCRIPTION:
989 struct service_description *desc = (struct service_description *)buffer;
990 DWORD total_size = sizeof(*desc);
992 service_lock(service->service_entry);
993 if (service->service_entry->description)
994 total_size += lstrlenW(service->service_entry->description) * sizeof(WCHAR);
996 *needed = total_size;
997 if (size >= total_size)
999 if (service->service_entry->description)
1001 lstrcpyW( desc->description, service->service_entry->description );
1002 desc->size = total_size - FIELD_OFFSET(struct service_description, description);
1004 else
1006 desc->description[0] = 0;
1007 desc->size = 0;
1010 else err = ERROR_INSUFFICIENT_BUFFER;
1011 service_unlock(service->service_entry);
1013 break;
1015 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
1016 service_lock(service->service_entry);
1018 *needed = sizeof(SERVICE_PRESHUTDOWN_INFO);
1019 if (size >= *needed)
1020 ((LPSERVICE_PRESHUTDOWN_INFO)buffer)->dwPreshutdownTimeout =
1021 service->service_entry->preshutdown_timeout;
1022 else err = ERROR_INSUFFICIENT_BUFFER;
1024 service_unlock(service->service_entry);
1025 break;
1027 default:
1028 WINE_FIXME("level %lu not implemented\n", level);
1029 err = ERROR_INVALID_LEVEL;
1030 break;
1032 return err;
1035 DWORD __cdecl svcctl_QueryServiceStatusEx(
1036 SC_RPC_HANDLE hService,
1037 SC_STATUS_TYPE InfoLevel,
1038 BYTE *lpBuffer,
1039 DWORD cbBufSize,
1040 LPDWORD pcbBytesNeeded)
1042 struct sc_service_handle *service;
1043 DWORD err;
1044 LPSERVICE_STATUS_PROCESS pSvcStatusData;
1046 memset(lpBuffer, 0, cbBufSize);
1048 if ((err = validate_service_handle(hService, SERVICE_QUERY_STATUS, &service)) != 0)
1049 return err;
1051 if (InfoLevel != SC_STATUS_PROCESS_INFO)
1052 return ERROR_INVALID_LEVEL;
1054 pSvcStatusData = (LPSERVICE_STATUS_PROCESS) lpBuffer;
1055 if (pSvcStatusData == NULL)
1056 return ERROR_INVALID_PARAMETER;
1058 if (cbBufSize < sizeof(SERVICE_STATUS_PROCESS))
1060 if( pcbBytesNeeded != NULL)
1061 *pcbBytesNeeded = sizeof(SERVICE_STATUS_PROCESS);
1063 return ERROR_INSUFFICIENT_BUFFER;
1066 service_lock(service->service_entry);
1067 fill_status_process(pSvcStatusData, service->service_entry);
1068 service_unlock(service->service_entry);
1070 return ERROR_SUCCESS;
1073 /******************************************************************************
1074 * service_accepts_control
1076 static BOOL service_accepts_control(const struct service_entry *service, DWORD dwControl)
1078 DWORD a = service->status.dwControlsAccepted;
1080 if (dwControl >= 128 && dwControl <= 255)
1081 return TRUE;
1083 switch (dwControl)
1085 case SERVICE_CONTROL_INTERROGATE:
1086 return TRUE;
1087 case SERVICE_CONTROL_STOP:
1088 if (a&SERVICE_ACCEPT_STOP)
1089 return TRUE;
1090 break;
1091 case SERVICE_CONTROL_SHUTDOWN:
1092 if (a&SERVICE_ACCEPT_SHUTDOWN)
1093 return TRUE;
1094 break;
1095 case SERVICE_CONTROL_PAUSE:
1096 case SERVICE_CONTROL_CONTINUE:
1097 if (a&SERVICE_ACCEPT_PAUSE_CONTINUE)
1098 return TRUE;
1099 break;
1100 case SERVICE_CONTROL_PARAMCHANGE:
1101 if (a&SERVICE_ACCEPT_PARAMCHANGE)
1102 return TRUE;
1103 break;
1104 case SERVICE_CONTROL_NETBINDADD:
1105 case SERVICE_CONTROL_NETBINDREMOVE:
1106 case SERVICE_CONTROL_NETBINDENABLE:
1107 case SERVICE_CONTROL_NETBINDDISABLE:
1108 if (a&SERVICE_ACCEPT_NETBINDCHANGE)
1109 return TRUE;
1110 case SERVICE_CONTROL_HARDWAREPROFILECHANGE:
1111 if (a&SERVICE_ACCEPT_HARDWAREPROFILECHANGE)
1112 return TRUE;
1113 break;
1114 case SERVICE_CONTROL_POWEREVENT:
1115 if (a&SERVICE_ACCEPT_POWEREVENT)
1116 return TRUE;
1117 break;
1118 case SERVICE_CONTROL_SESSIONCHANGE:
1119 if (a&SERVICE_ACCEPT_SESSIONCHANGE)
1120 return TRUE;
1121 break;
1123 return FALSE;
1126 /******************************************************************************
1127 * process_send_command
1129 static BOOL process_send_command(struct process_entry *process, const void *data, DWORD size, DWORD *result)
1131 OVERLAPPED overlapped;
1132 DWORD count, ret;
1133 BOOL r;
1135 overlapped.u.s.Offset = 0;
1136 overlapped.u.s.OffsetHigh = 0;
1137 overlapped.hEvent = process->overlapped_event;
1138 r = WriteFile(process->control_pipe, data, size, &count, &overlapped);
1139 if (!r && GetLastError() == ERROR_IO_PENDING)
1141 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1142 if (ret == WAIT_TIMEOUT)
1144 WINE_ERR("sending command timed out\n");
1145 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1146 return FALSE;
1148 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1150 if (!r || count != size)
1152 WINE_ERR("service protocol error - failed to write pipe!\n");
1153 *result = (!r ? GetLastError() : ERROR_WRITE_FAULT);
1154 return FALSE;
1156 r = ReadFile(process->control_pipe, result, sizeof *result, &count, &overlapped);
1157 if (!r && GetLastError() == ERROR_IO_PENDING)
1159 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1160 if (ret == WAIT_TIMEOUT)
1162 WINE_ERR("receiving command result timed out\n");
1163 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1164 return FALSE;
1166 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1168 if (!r || count != sizeof *result)
1170 WINE_ERR("service protocol error - failed to read pipe "
1171 "r = %d count = %ld!\n", r, count);
1172 *result = (!r ? GetLastError() : ERROR_READ_FAULT);
1173 return FALSE;
1176 return TRUE;
1179 /******************************************************************************
1180 * process_send_control
1182 BOOL process_send_control(struct process_entry *process, BOOL shared_process, const WCHAR *name,
1183 DWORD control, const BYTE *data, DWORD data_size, DWORD *result)
1185 service_start_info *ssi;
1186 DWORD len;
1187 BOOL r;
1189 if (shared_process)
1191 control |= SERVICE_CONTROL_FORWARD_FLAG;
1192 data = (BYTE *)name;
1193 data_size = (lstrlenW(name) + 1) * sizeof(WCHAR);
1194 name = emptyW;
1197 /* calculate how much space we need to send the startup info */
1198 len = (lstrlenW(name) + 1) * sizeof(WCHAR) + data_size;
1200 ssi = HeapAlloc(GetProcessHeap(),0,FIELD_OFFSET(service_start_info, data[len]));
1201 ssi->magic = SERVICE_PROTOCOL_MAGIC;
1202 ssi->control = control;
1203 ssi->total_size = FIELD_OFFSET(service_start_info, data[len]);
1204 ssi->name_size = lstrlenW(name) + 1;
1205 lstrcpyW((WCHAR *)ssi->data, name);
1206 if (data_size) memcpy(&ssi->data[ssi->name_size * sizeof(WCHAR)], data, data_size);
1208 r = process_send_command(process, ssi, ssi->total_size, result);
1209 HeapFree( GetProcessHeap(), 0, ssi );
1210 return r;
1213 DWORD __cdecl svcctl_StartServiceW(
1214 SC_RPC_HANDLE hService,
1215 DWORD dwNumServiceArgs,
1216 LPCWSTR *lpServiceArgVectors)
1218 struct sc_service_handle *service;
1219 DWORD err;
1221 WINE_TRACE("(%p, %ld, %p)\n", hService, dwNumServiceArgs, lpServiceArgVectors);
1223 if ((err = validate_service_handle(hService, SERVICE_START, &service)) != 0)
1224 return err;
1226 if (service->service_entry->config.dwStartType == SERVICE_DISABLED)
1227 return ERROR_SERVICE_DISABLED;
1229 if (!scmdatabase_lock_startup(service->service_entry->db, 3000))
1230 return ERROR_SERVICE_DATABASE_LOCKED;
1232 err = service_start(service->service_entry, dwNumServiceArgs, lpServiceArgVectors);
1234 scmdatabase_unlock_startup(service->service_entry->db);
1235 return err;
1238 DWORD __cdecl svcctl_ControlService(
1239 SC_RPC_HANDLE hService,
1240 DWORD dwControl,
1241 SERVICE_STATUS *lpServiceStatus)
1243 DWORD access_required;
1244 struct sc_service_handle *service;
1245 struct process_entry *process;
1246 BOOL shared_process;
1247 DWORD result;
1249 WINE_TRACE("(%p, %ld, %p)\n", hService, dwControl, lpServiceStatus);
1251 switch (dwControl)
1253 case SERVICE_CONTROL_CONTINUE:
1254 case SERVICE_CONTROL_NETBINDADD:
1255 case SERVICE_CONTROL_NETBINDDISABLE:
1256 case SERVICE_CONTROL_NETBINDENABLE:
1257 case SERVICE_CONTROL_NETBINDREMOVE:
1258 case SERVICE_CONTROL_PARAMCHANGE:
1259 case SERVICE_CONTROL_PAUSE:
1260 access_required = SERVICE_PAUSE_CONTINUE;
1261 break;
1262 case SERVICE_CONTROL_INTERROGATE:
1263 access_required = SERVICE_INTERROGATE;
1264 break;
1265 case SERVICE_CONTROL_STOP:
1266 access_required = SERVICE_STOP;
1267 break;
1268 default:
1269 if (dwControl >= 128 && dwControl <= 255)
1270 access_required = SERVICE_USER_DEFINED_CONTROL;
1271 else
1272 return ERROR_INVALID_PARAMETER;
1275 if ((result = validate_service_handle(hService, access_required, &service)) != 0)
1276 return result;
1278 service_lock(service->service_entry);
1280 result = ERROR_SUCCESS;
1281 switch (service->service_entry->status.dwCurrentState)
1283 case SERVICE_STOPPED:
1284 result = ERROR_SERVICE_NOT_ACTIVE;
1285 break;
1286 case SERVICE_START_PENDING:
1287 if (dwControl==SERVICE_CONTROL_STOP)
1288 break;
1289 /* fall through */
1290 case SERVICE_STOP_PENDING:
1291 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1292 break;
1295 if (result == ERROR_SUCCESS && service->service_entry->force_shutdown)
1297 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1298 if ((process = service->service_entry->process))
1300 service->service_entry->process = NULL;
1301 if (!--process->use_count) process_terminate(process);
1302 release_process(process);
1306 if (result != ERROR_SUCCESS)
1308 if (lpServiceStatus) *lpServiceStatus = service->service_entry->status;
1309 service_unlock(service->service_entry);
1310 return result;
1313 if (!service_accepts_control(service->service_entry, dwControl))
1315 service_unlock(service->service_entry);
1316 return ERROR_INVALID_SERVICE_CONTROL;
1319 /* Remember that we tried to shutdown this service. When the service is
1320 * still running on the second invocation, it will be forcefully killed. */
1321 if (dwControl == SERVICE_CONTROL_STOP)
1322 service->service_entry->force_shutdown = TRUE;
1324 /* Hold a reference to the process while sending the command. */
1325 process = grab_process(service->service_entry->process);
1326 shared_process = service->service_entry->shared_process;
1327 service_unlock(service->service_entry);
1329 if (!process)
1330 return ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1332 result = WaitForSingleObject(process->control_mutex, 30000);
1333 if (result != WAIT_OBJECT_0)
1335 release_process(process);
1336 return ERROR_SERVICE_REQUEST_TIMEOUT;
1339 if (process_send_control(process, shared_process, service->service_entry->name,
1340 dwControl, NULL, 0, &result))
1341 result = ERROR_SUCCESS;
1343 if (lpServiceStatus)
1345 service_lock(service->service_entry);
1346 *lpServiceStatus = service->service_entry->status;
1347 service_unlock(service->service_entry);
1350 ReleaseMutex(process->control_mutex);
1351 release_process(process);
1352 return result;
1355 DWORD __cdecl svcctl_CloseServiceHandle(
1356 SC_RPC_HANDLE *handle)
1358 WINE_TRACE("(&%p)\n", *handle);
1360 SC_RPC_HANDLE_destroy(*handle);
1361 *handle = NULL;
1363 return ERROR_SUCCESS;
1366 void __RPC_USER SC_RPC_LOCK_rundown(SC_RPC_LOCK hLock)
1370 DWORD __cdecl svcctl_LockServiceDatabase(SC_RPC_HANDLE manager, SC_RPC_LOCK *lock)
1372 TRACE("(%p, %p)\n", manager, lock);
1374 *lock = (SC_RPC_LOCK)0xdeadbeef;
1375 return ERROR_SUCCESS;
1378 DWORD __cdecl svcctl_UnlockServiceDatabase(SC_RPC_LOCK *lock)
1380 TRACE("(&%p)\n", *lock);
1382 *lock = NULL;
1383 return ERROR_SUCCESS;
1386 static BOOL map_state(DWORD state, DWORD mask)
1388 switch (state)
1390 case SERVICE_START_PENDING:
1391 case SERVICE_STOP_PENDING:
1392 case SERVICE_RUNNING:
1393 case SERVICE_CONTINUE_PENDING:
1394 case SERVICE_PAUSE_PENDING:
1395 case SERVICE_PAUSED:
1396 if (SERVICE_ACTIVE & mask) return TRUE;
1397 break;
1398 case SERVICE_STOPPED:
1399 if (SERVICE_INACTIVE & mask) return TRUE;
1400 break;
1401 default:
1402 WINE_ERR("unknown state %lu\n", state);
1403 break;
1405 return FALSE;
1408 DWORD __cdecl svcctl_EnumServicesStatusW(
1409 SC_RPC_HANDLE hmngr,
1410 DWORD type,
1411 DWORD state,
1412 BYTE *buffer,
1413 DWORD size,
1414 LPDWORD needed,
1415 LPDWORD returned,
1416 LPDWORD resume)
1418 DWORD err, sz, total_size, num_services, offset;
1419 struct sc_manager_handle *manager;
1420 struct service_entry *service;
1421 struct enum_service_status *s;
1423 WINE_TRACE("(%p, 0x%lx, 0x%lx, %p, %lu, %p, %p, %p)\n", hmngr, type, state, buffer, size, needed, returned, resume);
1425 if (!type || !state)
1426 return ERROR_INVALID_PARAMETER;
1428 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1429 return err;
1431 if (resume)
1432 WINE_FIXME("resume index not supported\n");
1434 scmdatabase_lock(manager->db);
1436 total_size = num_services = 0;
1437 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1439 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1441 total_size += sizeof(*s);
1442 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1443 if (service->config.lpDisplayName)
1445 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1447 num_services++;
1450 *returned = 0;
1451 *needed = total_size;
1452 if (total_size > size)
1454 scmdatabase_unlock(manager->db);
1455 return ERROR_MORE_DATA;
1457 s = (struct enum_service_status *)buffer;
1458 offset = num_services * sizeof(struct enum_service_status);
1459 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1461 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1463 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1464 memcpy(buffer + offset, service->name, sz);
1465 s->service_name = offset;
1466 offset += sz;
1468 if (!service->config.lpDisplayName) s->display_name = 0;
1469 else
1471 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1472 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1473 s->display_name = offset;
1474 offset += sz;
1476 s->service_status = service->status;
1477 s++;
1480 *returned = num_services;
1481 *needed = 0;
1482 scmdatabase_unlock(manager->db);
1483 return ERROR_SUCCESS;
1486 static struct service_entry *find_service_by_group(struct scmdatabase *db, const WCHAR *group)
1488 struct service_entry *service;
1489 LIST_FOR_EACH_ENTRY(service, &db->services, struct service_entry, entry)
1491 if (service->config.lpLoadOrderGroup && !wcsicmp(group, service->config.lpLoadOrderGroup))
1492 return service;
1494 return NULL;
1497 static BOOL match_group(const WCHAR *g1, const WCHAR *g2)
1499 if (!g2) return TRUE;
1500 if (!g2[0] && (!g1 || !g1[0])) return TRUE;
1501 if (g1 && !lstrcmpW(g1, g2)) return TRUE;
1502 return FALSE;
1505 DWORD __cdecl svcctl_EnumServicesStatusExA(
1506 SC_RPC_HANDLE scmanager,
1507 SC_ENUM_TYPE info_level,
1508 DWORD service_type,
1509 DWORD service_state,
1510 BYTE *buffer,
1511 DWORD buf_size,
1512 DWORD *needed_size,
1513 DWORD *services_count,
1514 DWORD *resume_index,
1515 LPCSTR groupname)
1517 WINE_FIXME("\n");
1518 return ERROR_CALL_NOT_IMPLEMENTED;
1521 DWORD __cdecl svcctl_EnumServicesStatusExW(
1522 SC_RPC_HANDLE hmngr,
1523 SC_ENUM_TYPE info_level,
1524 DWORD type,
1525 DWORD state,
1526 BYTE *buffer,
1527 DWORD size,
1528 LPDWORD needed,
1529 LPDWORD returned,
1530 DWORD *resume_handle,
1531 LPCWSTR group)
1533 DWORD err, sz, total_size, num_services;
1534 DWORD_PTR offset;
1535 struct sc_manager_handle *manager;
1536 struct service_entry *service;
1537 struct enum_service_status_process *s;
1539 WINE_TRACE("(%p, 0x%lx, 0x%lx, %p, %lu, %p, %p, %s)\n", hmngr, type, state, buffer, size,
1540 needed, returned, wine_dbgstr_w(group));
1542 if (resume_handle)
1543 FIXME("resume handle not supported\n");
1545 if (!type || !state)
1546 return ERROR_INVALID_PARAMETER;
1548 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1549 return err;
1551 scmdatabase_lock(manager->db);
1553 if (group && !find_service_by_group(manager->db, group))
1555 scmdatabase_unlock(manager->db);
1556 return ERROR_SERVICE_DOES_NOT_EXIST;
1559 total_size = num_services = 0;
1560 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1562 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1563 && match_group(service->config.lpLoadOrderGroup, group))
1565 total_size += sizeof(*s);
1566 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1567 if (service->config.lpDisplayName)
1569 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1571 num_services++;
1574 *returned = 0;
1575 *needed = total_size;
1576 if (total_size > size)
1578 scmdatabase_unlock(manager->db);
1579 return ERROR_MORE_DATA;
1581 s = (struct enum_service_status_process *)buffer;
1582 offset = num_services * sizeof(*s);
1583 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1585 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1586 && match_group(service->config.lpLoadOrderGroup, group))
1588 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1589 memcpy(buffer + offset, service->name, sz);
1590 s->service_name = offset;
1591 offset += sz;
1593 if (!service->config.lpDisplayName) s->display_name = 0;
1594 else
1596 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1597 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1598 s->display_name = offset;
1599 offset += sz;
1601 fill_status_process(&s->service_status_process, service);
1602 s++;
1605 *returned = num_services;
1606 *needed = 0;
1607 scmdatabase_unlock(manager->db);
1608 return ERROR_SUCCESS;
1611 DWORD __cdecl svcctl_unknown43(void)
1613 WINE_FIXME("\n");
1614 return ERROR_CALL_NOT_IMPLEMENTED;
1617 DWORD __cdecl svcctl_CreateServiceWOW64A(
1618 SC_RPC_HANDLE scmanager,
1619 LPCSTR servicename,
1620 LPCSTR displayname,
1621 DWORD accessmask,
1622 DWORD service_type,
1623 DWORD start_type,
1624 DWORD error_control,
1625 LPCSTR imagepath,
1626 LPCSTR loadordergroup,
1627 DWORD *tagid,
1628 const BYTE *dependencies,
1629 DWORD depend_size,
1630 LPCSTR start_name,
1631 const BYTE *password,
1632 DWORD password_size,
1633 SC_RPC_HANDLE *service)
1635 WINE_FIXME("\n");
1636 return ERROR_CALL_NOT_IMPLEMENTED;
1639 DWORD __cdecl svcctl_CreateServiceWOW64W(
1640 SC_RPC_HANDLE scmanager,
1641 LPCWSTR servicename,
1642 LPCWSTR displayname,
1643 DWORD accessmask,
1644 DWORD service_type,
1645 DWORD start_type,
1646 DWORD error_control,
1647 LPCWSTR imagepath,
1648 LPCWSTR loadordergroup,
1649 DWORD *tagid,
1650 const BYTE *dependencies,
1651 DWORD depend_size,
1652 LPCWSTR start_name,
1653 const BYTE *password,
1654 DWORD password_size,
1655 SC_RPC_HANDLE *service)
1657 WINE_TRACE("(%s, %s, 0x%lx, %s)\n", wine_dbgstr_w(servicename), wine_dbgstr_w(displayname), accessmask, wine_dbgstr_w(imagepath));
1658 return create_serviceW(scmanager, servicename, displayname, accessmask, service_type, start_type, error_control, imagepath,
1659 loadordergroup, tagid, dependencies, depend_size, start_name, password, password_size, service, TRUE);
1662 DWORD __cdecl svcctl_unknown46(void)
1664 WINE_FIXME("\n");
1665 return ERROR_CALL_NOT_IMPLEMENTED;
1668 DWORD __cdecl svcctl_NotifyServiceStatusChange(
1669 SC_RPC_HANDLE handle,
1670 SC_RPC_NOTIFY_PARAMS params,
1671 GUID *clientprocessguid,
1672 GUID *scmprocessguid,
1673 BOOL *createremotequeue,
1674 SC_NOTIFY_RPC_HANDLE *hNotify)
1676 DWORD err, mask;
1677 struct sc_manager_handle *manager = NULL;
1678 struct sc_service_handle *service = NULL;
1679 struct sc_notify_handle *notify;
1680 struct sc_handle *hdr = handle;
1682 WINE_TRACE("(%p, NotifyMask: 0x%lx, %p, %p, %p, %p)\n", handle,
1683 params.params->dwNotifyMask, clientprocessguid, scmprocessguid,
1684 createremotequeue, hNotify);
1686 switch (hdr->type)
1688 case SC_HTYPE_SERVICE:
1689 err = validate_service_handle(handle, SERVICE_QUERY_STATUS, &service);
1690 break;
1691 case SC_HTYPE_MANAGER:
1692 err = validate_scm_handle(handle, SC_MANAGER_ENUMERATE_SERVICE, &manager);
1693 break;
1694 default:
1695 err = ERROR_INVALID_HANDLE;
1696 break;
1699 if (err != ERROR_SUCCESS)
1700 return err;
1702 if (manager)
1704 WARN("Need support for service creation/deletion notifications\n");
1705 return ERROR_CALL_NOT_IMPLEMENTED;
1708 notify = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*notify));
1709 if (!notify)
1710 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
1712 notify->hdr.type = SC_HTYPE_NOTIFY;
1713 notify->hdr.access = 0;
1715 notify->event = CreateEventW(NULL, TRUE, FALSE, NULL);
1717 notify->notify_mask = params.params->dwNotifyMask;
1719 service_lock(service->service_entry);
1721 if (service->notify)
1723 service_unlock(service->service_entry);
1724 sc_notify_release(notify);
1725 return ERROR_ALREADY_REGISTERED;
1728 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
1729 if (!service->status_notified && (notify->notify_mask & mask))
1731 fill_notify(notify, service->service_entry);
1732 service->status_notified = TRUE;
1734 else
1736 sc_notify_retain(notify);
1737 service->notify = notify;
1740 sc_notify_retain(notify);
1741 *hNotify = &notify->hdr;
1743 service_unlock(service->service_entry);
1745 return ERROR_SUCCESS;
1748 DWORD __cdecl svcctl_GetNotifyResults(
1749 SC_NOTIFY_RPC_HANDLE hNotify,
1750 SC_RPC_NOTIFY_PARAMS_LIST **pList)
1752 DWORD err;
1753 struct sc_notify_handle *notify;
1755 WINE_TRACE("(%p, %p)\n", hNotify, pList);
1757 if (!pList)
1758 return ERROR_INVALID_PARAMETER;
1760 *pList = NULL;
1762 if ((err = validate_notify_handle(hNotify, 0, &notify)) != 0)
1763 return err;
1765 sc_notify_retain(notify);
1766 /* block until there is a result */
1767 err = WaitForSingleObject(notify->event, INFINITE);
1769 if (err != WAIT_OBJECT_0)
1771 sc_notify_release(notify);
1772 return err;
1775 *pList = InterlockedExchangePointer((void**)&notify->params_list, NULL);
1776 if (!*pList)
1778 sc_notify_release(notify);
1779 return ERROR_REQUEST_ABORTED;
1782 sc_notify_release(notify);
1784 return ERROR_SUCCESS;
1787 DWORD __cdecl svcctl_CloseNotifyHandle(
1788 SC_NOTIFY_RPC_HANDLE *hNotify,
1789 BOOL *apc_fired)
1791 struct sc_notify_handle *notify;
1792 DWORD err;
1794 WINE_TRACE("(%p, %p)\n", hNotify, apc_fired);
1796 if ((err = validate_notify_handle(*hNotify, 0, &notify)) != 0)
1797 return err;
1799 sc_notify_release(notify);
1801 return ERROR_SUCCESS;
1804 DWORD __cdecl svcctl_ControlServiceExA(
1805 SC_RPC_HANDLE service,
1806 DWORD control,
1807 DWORD info_level,
1808 SC_RPC_SERVICE_CONTROL_IN_PARAMSA *in_params,
1809 SC_RPC_SERVICE_CONTROL_OUT_PARAMSA *out_params)
1811 WINE_FIXME("\n");
1812 return ERROR_CALL_NOT_IMPLEMENTED;
1815 DWORD __cdecl svcctl_ControlServiceExW(
1816 SC_RPC_HANDLE service,
1817 DWORD control,
1818 DWORD info_level,
1819 SC_RPC_SERVICE_CONTROL_IN_PARAMSW *in_params,
1820 SC_RPC_SERVICE_CONTROL_OUT_PARAMSW *out_params)
1822 WINE_FIXME("\n");
1823 return ERROR_CALL_NOT_IMPLEMENTED;
1826 DWORD __cdecl svcctl_unknown52(void)
1828 WINE_FIXME("\n");
1829 return ERROR_CALL_NOT_IMPLEMENTED;
1832 DWORD __cdecl svcctl_unknown53(void)
1834 WINE_FIXME("\n");
1835 return ERROR_CALL_NOT_IMPLEMENTED;
1838 DWORD __cdecl svcctl_unknown54(void)
1840 WINE_FIXME("\n");
1841 return ERROR_CALL_NOT_IMPLEMENTED;
1844 DWORD __cdecl svcctl_unknown55(void)
1846 WINE_FIXME("\n");
1847 return ERROR_CALL_NOT_IMPLEMENTED;
1850 DWORD __cdecl svcctl_QueryServiceConfigEx(
1851 SC_RPC_HANDLE service,
1852 DWORD info_level,
1853 SC_RPC_CONFIG_INFOW *info)
1855 WINE_FIXME("\n");
1856 return ERROR_CALL_NOT_IMPLEMENTED;
1859 DWORD __cdecl svcctl_QueryServiceObjectSecurity(
1860 SC_RPC_HANDLE service,
1861 SECURITY_INFORMATION info,
1862 BYTE *descriptor,
1863 DWORD buf_size,
1864 DWORD *needed_size)
1866 WINE_FIXME("\n");
1867 return ERROR_CALL_NOT_IMPLEMENTED;
1870 DWORD __cdecl svcctl_SetServiceObjectSecurity(
1871 SC_RPC_HANDLE service,
1872 SECURITY_INFORMATION info,
1873 BYTE *descriptor,
1874 DWORD buf_size)
1876 WINE_FIXME("\n");
1877 return ERROR_CALL_NOT_IMPLEMENTED;
1880 DWORD __cdecl svcctl_QueryServiceStatus(
1881 SC_RPC_HANDLE service,
1882 SERVICE_STATUS *status)
1884 WINE_FIXME("\n");
1885 return ERROR_CALL_NOT_IMPLEMENTED;
1888 DWORD __cdecl svcctl_NotifyBootConfigStatus(
1889 SVCCTL_HANDLEW machinename,
1890 DWORD boot_acceptable)
1892 WINE_FIXME("\n");
1893 return ERROR_CALL_NOT_IMPLEMENTED;
1896 DWORD __cdecl svcctl_SCSetServiceBitsW(void)
1898 WINE_FIXME("\n");
1899 return ERROR_CALL_NOT_IMPLEMENTED;
1902 DWORD __cdecl svcctl_EnumDependentServicesW(
1903 SC_RPC_HANDLE service,
1904 DWORD state,
1905 BYTE *services,
1906 DWORD buf_size,
1907 DWORD *needed_size,
1908 DWORD *services_ret)
1910 WINE_FIXME("\n");
1911 return ERROR_CALL_NOT_IMPLEMENTED;
1914 DWORD __cdecl svcctl_QueryServiceLockStatusW(
1915 SC_RPC_HANDLE scmanager,
1916 QUERY_SERVICE_LOCK_STATUSW *status,
1917 DWORD buf_size,
1918 DWORD *needed_size)
1920 WINE_FIXME("\n");
1921 return ERROR_CALL_NOT_IMPLEMENTED;
1924 DWORD __cdecl svcctl_SCSetServiceBitsA(void)
1926 WINE_FIXME("\n");
1927 return ERROR_CALL_NOT_IMPLEMENTED;
1930 DWORD __cdecl svcctl_ChangeServiceConfigA(
1931 SC_RPC_HANDLE service,
1932 DWORD service_type,
1933 DWORD start_type,
1934 DWORD error_control,
1935 LPSTR binarypath,
1936 LPSTR loadordergroup,
1937 DWORD *tagid,
1938 BYTE *dependencies,
1939 DWORD depend_size,
1940 LPSTR startname,
1941 BYTE *password,
1942 DWORD password_size,
1943 LPSTR displayname)
1945 WINE_FIXME("\n");
1946 return ERROR_CALL_NOT_IMPLEMENTED;
1949 DWORD __cdecl svcctl_CreateServiceA(
1950 SC_RPC_HANDLE scmanager,
1951 LPCSTR servicename,
1952 LPCSTR displayname,
1953 DWORD desiredaccess,
1954 DWORD service_type,
1955 DWORD start_type,
1956 DWORD error_control,
1957 LPCSTR binarypath,
1958 LPCSTR loadordergroup,
1959 DWORD *tagid,
1960 const BYTE *dependencies,
1961 DWORD depend_size,
1962 LPCSTR startname,
1963 const BYTE *password,
1964 DWORD password_size,
1965 SC_RPC_HANDLE *service)
1967 WINE_FIXME("\n");
1968 return ERROR_CALL_NOT_IMPLEMENTED;
1971 DWORD __cdecl svcctl_EnumDependentServicesA(
1972 SC_RPC_HANDLE service,
1973 DWORD state,
1974 BYTE *services,
1975 DWORD buf_size,
1976 DWORD *needed_size,
1977 DWORD *services_ret)
1979 WINE_FIXME("\n");
1980 return ERROR_CALL_NOT_IMPLEMENTED;
1983 DWORD __cdecl svcctl_EnumServicesStatusA(
1984 SC_RPC_HANDLE hmngr,
1985 DWORD type,
1986 DWORD state,
1987 BYTE *buffer,
1988 DWORD size,
1989 DWORD *needed,
1990 DWORD *returned,
1991 DWORD *resume)
1993 WINE_FIXME("\n");
1994 return ERROR_CALL_NOT_IMPLEMENTED;
1997 DWORD __cdecl svcctl_OpenSCManagerA(
1998 MACHINE_HANDLEA MachineName,
1999 LPCSTR DatabaseName,
2000 DWORD dwAccessMask,
2001 SC_RPC_HANDLE *handle)
2003 WINE_FIXME("\n");
2004 return ERROR_CALL_NOT_IMPLEMENTED;
2007 DWORD __cdecl svcctl_OpenServiceA(
2008 SC_RPC_HANDLE hSCManager,
2009 LPCSTR lpServiceName,
2010 DWORD dwDesiredAccess,
2011 SC_RPC_HANDLE *phService)
2013 WINE_FIXME("\n");
2014 return ERROR_CALL_NOT_IMPLEMENTED;
2017 DWORD __cdecl svcctl_QueryServiceConfigA(
2018 SC_RPC_HANDLE hService,
2019 QUERY_SERVICE_CONFIGA *config,
2020 DWORD buf_size,
2021 DWORD *needed_size)
2023 WINE_FIXME("\n");
2024 return ERROR_CALL_NOT_IMPLEMENTED;
2027 DWORD __cdecl svcctl_QueryServiceLockStatusA(
2028 SC_RPC_HANDLE scmanager,
2029 QUERY_SERVICE_LOCK_STATUSA *status,
2030 DWORD buf_size,
2031 DWORD *needed_size)
2033 WINE_FIXME("\n");
2034 return ERROR_CALL_NOT_IMPLEMENTED;
2037 DWORD __cdecl svcctl_StartServiceA(
2038 SC_RPC_HANDLE service,
2039 DWORD argc,
2040 LPCSTR *args)
2042 WINE_FIXME("\n");
2043 return ERROR_CALL_NOT_IMPLEMENTED;
2046 DWORD __cdecl svcctl_GetServiceDisplayNameA(
2047 SC_RPC_HANDLE hSCManager,
2048 LPCSTR servicename,
2049 CHAR buffer[],
2050 DWORD *buf_size)
2052 WINE_FIXME("\n");
2053 return ERROR_CALL_NOT_IMPLEMENTED;
2056 DWORD __cdecl svcctl_GetServiceKeyNameA(
2057 SC_RPC_HANDLE hSCManager,
2058 LPCSTR servicename,
2059 CHAR buffer[],
2060 DWORD *buf_size)
2062 WINE_FIXME("\n");
2063 return ERROR_CALL_NOT_IMPLEMENTED;
2066 DWORD __cdecl svcctl_GetCurrentGroupStateW(void)
2068 WINE_FIXME("\n");
2069 return ERROR_CALL_NOT_IMPLEMENTED;
2072 DWORD __cdecl svcctl_EnumServiceGroupW(
2073 SC_RPC_HANDLE scmanager,
2074 DWORD service_type,
2075 DWORD service_state,
2076 BYTE *buffer,
2077 DWORD buf_size,
2078 DWORD *needed_size,
2079 DWORD *returned_size,
2080 DWORD *resume_index,
2081 LPCWSTR groupname)
2083 WINE_FIXME("\n");
2084 return ERROR_CALL_NOT_IMPLEMENTED;
2087 DWORD __cdecl svcctl_ChangeServiceConfig2A(
2088 SC_RPC_HANDLE service,
2089 SC_RPC_CONFIG_INFOA info)
2091 WINE_FIXME("\n");
2092 return ERROR_CALL_NOT_IMPLEMENTED;
2095 DWORD __cdecl svcctl_QueryServiceConfig2A(
2096 SC_RPC_HANDLE service,
2097 DWORD info_level,
2098 BYTE *buffer,
2099 DWORD buf_size,
2100 DWORD *needed_size)
2102 WINE_FIXME("\n");
2103 return ERROR_CALL_NOT_IMPLEMENTED;
2106 DWORD RPC_Init(void)
2108 WCHAR transport[] = SVCCTL_TRANSPORT;
2109 WCHAR endpoint[] = SVCCTL_ENDPOINT;
2110 DWORD err;
2112 if (!(cleanup_group = CreateThreadpoolCleanupGroup()))
2114 WINE_ERR("CreateThreadpoolCleanupGroup failed with error %lu\n", GetLastError());
2115 return GetLastError();
2118 if ((err = RpcServerUseProtseqEpW(transport, 0, endpoint, NULL)) != ERROR_SUCCESS)
2120 WINE_ERR("RpcServerUseProtseq failed with error %lu\n", err);
2121 return err;
2124 if ((err = RpcServerRegisterIf(svcctl_v2_0_s_ifspec, 0, 0)) != ERROR_SUCCESS)
2126 WINE_ERR("RpcServerRegisterIf failed with error %lu\n", err);
2127 return err;
2130 if ((err = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE)) != ERROR_SUCCESS)
2132 WINE_ERR("RpcServerListen failed with error %lu\n", err);
2133 return err;
2136 NtSetInformationProcess( GetCurrentProcess(), ProcessWineMakeProcessSystem,
2137 &exit_event, sizeof(HANDLE *) );
2138 return ERROR_SUCCESS;
2141 void RPC_Stop(void)
2143 RpcMgmtStopServerListening(NULL);
2144 RpcServerUnregisterIf(svcctl_v2_0_s_ifspec, NULL, TRUE);
2145 RpcMgmtWaitServerListen();
2147 CloseThreadpoolCleanupGroupMembers(cleanup_group, TRUE, NULL);
2148 CloseThreadpoolCleanupGroup(cleanup_group);
2149 CloseHandle(exit_event);
2152 void __RPC_USER SC_RPC_HANDLE_rundown(SC_RPC_HANDLE handle)
2154 SC_RPC_HANDLE_destroy(handle);
2157 void __RPC_USER SC_NOTIFY_RPC_HANDLE_rundown(SC_NOTIFY_RPC_HANDLE handle)
2161 void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
2163 return HeapAlloc(GetProcessHeap(), 0, len);
2166 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
2168 HeapFree(GetProcessHeap(), 0, ptr);