crypt32: Keep root certs cached in registry unless some are deleted on host.
[wine.git] / programs / services / rpc.c
blobe56d25ea1afe0f3847c84eaf7eb5a3e3927364e7
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 if (notify->params_list)
106 free(notify->params_list->NotifyParamsArray[0].params);
107 free(notify->params_list);
108 free(notify);
112 struct sc_lock
114 struct scmdatabase *db;
117 static const WCHAR emptyW[] = {0};
118 static PTP_CLEANUP_GROUP cleanup_group;
119 HANDLE exit_event;
121 static void CALLBACK group_cancel_callback(void *object, void *userdata)
123 struct process_entry *process = object;
124 release_process(process);
127 static void CALLBACK terminate_callback(TP_CALLBACK_INSTANCE *instance, void *context,
128 TP_WAIT *wait, TP_WAIT_RESULT result)
130 struct process_entry *process = context;
131 if (result == WAIT_TIMEOUT) process_terminate(process);
132 release_process(process);
133 CloseThreadpoolWait(wait);
136 static void terminate_after_timeout(struct process_entry *process, DWORD timeout)
138 TP_CALLBACK_ENVIRON environment;
139 LARGE_INTEGER timestamp;
140 TP_WAIT *wait;
141 FILETIME ft;
143 memset(&environment, 0, sizeof(environment));
144 environment.Version = 1;
145 environment.CleanupGroup = cleanup_group;
146 environment.CleanupGroupCancelCallback = group_cancel_callback;
148 timestamp.QuadPart = (ULONGLONG)timeout * -10000;
149 ft.dwLowDateTime = timestamp.u.LowPart;
150 ft.dwHighDateTime = timestamp.u.HighPart;
152 if ((wait = CreateThreadpoolWait(terminate_callback, grab_process(process), &environment)))
153 SetThreadpoolWait(wait, process->process, &ft);
154 else
155 release_process(process);
158 static void CALLBACK shutdown_callback(TP_CALLBACK_INSTANCE *instance, void *context)
160 struct process_entry *process = context;
161 DWORD result;
163 result = WaitForSingleObject(process->control_mutex, 30000);
164 if (result == WAIT_OBJECT_0)
166 process_send_control(process, FALSE, emptyW, SERVICE_CONTROL_STOP, NULL, 0, &result);
167 ReleaseMutex(process->control_mutex);
170 release_process(process);
173 static void shutdown_shared_process(struct process_entry *process)
175 TP_CALLBACK_ENVIRON environment;
176 struct service_entry *service;
177 struct scmdatabase *db = process->db;
179 scmdatabase_lock(db);
180 LIST_FOR_EACH_ENTRY(service, &db->services, struct service_entry, entry)
182 if (service->process != process) continue;
183 service->status.dwCurrentState = SERVICE_STOP_PENDING;
185 scmdatabase_unlock(db);
187 memset(&environment, 0, sizeof(environment));
188 environment.Version = 1;
189 environment.CleanupGroup = cleanup_group;
190 environment.CleanupGroupCancelCallback = group_cancel_callback;
192 if (!TrySubmitThreadpoolCallback(shutdown_callback, grab_process(process), &environment))
193 release_process(process);
196 static void free_service_strings(struct service_entry *old, struct service_entry *new)
198 QUERY_SERVICE_CONFIGW *old_cfg = &old->config;
199 QUERY_SERVICE_CONFIGW *new_cfg = &new->config;
201 if (old_cfg->lpBinaryPathName != new_cfg->lpBinaryPathName)
202 free(old_cfg->lpBinaryPathName);
204 if (old_cfg->lpLoadOrderGroup != new_cfg->lpLoadOrderGroup)
205 free(old_cfg->lpLoadOrderGroup);
207 if (old_cfg->lpServiceStartName != new_cfg->lpServiceStartName)
208 free(old_cfg->lpServiceStartName);
210 if (old_cfg->lpDisplayName != new_cfg->lpDisplayName)
211 free(old_cfg->lpDisplayName);
213 if (old->dependOnServices != new->dependOnServices)
214 free(old->dependOnServices);
216 if (old->dependOnGroups != new->dependOnGroups)
217 free(old->dependOnGroups);
220 /* Check if the given handle is of the required type and allows the requested access. */
221 static DWORD validate_context_handle(SC_RPC_HANDLE handle, DWORD type, DWORD needed_access, struct sc_handle **out_hdr)
223 struct sc_handle *hdr = handle;
225 if (type != SC_HTYPE_DONT_CARE && hdr->type != type)
227 WINE_ERR("Handle is of an invalid type (%d, %ld)\n", hdr->type, type);
228 return ERROR_INVALID_HANDLE;
231 if ((needed_access & hdr->access) != needed_access)
233 WINE_ERR("Access denied - handle created with access %lx, needed %lx\n", hdr->access, needed_access);
234 return ERROR_ACCESS_DENIED;
237 *out_hdr = hdr;
238 return ERROR_SUCCESS;
241 static DWORD validate_scm_handle(SC_RPC_HANDLE handle, DWORD needed_access, struct sc_manager_handle **manager)
243 struct sc_handle *hdr;
244 DWORD err = validate_context_handle(handle, SC_HTYPE_MANAGER, needed_access, &hdr);
245 if (err == ERROR_SUCCESS)
246 *manager = (struct sc_manager_handle *)hdr;
247 return err;
250 static DWORD validate_service_handle(SC_RPC_HANDLE handle, DWORD needed_access, struct sc_service_handle **service)
252 struct sc_handle *hdr;
253 DWORD err = validate_context_handle(handle, SC_HTYPE_SERVICE, needed_access, &hdr);
254 if (err == ERROR_SUCCESS)
255 *service = (struct sc_service_handle *)hdr;
256 return err;
259 static DWORD validate_notify_handle(SC_RPC_HANDLE handle, DWORD needed_access, struct sc_notify_handle **notify)
261 struct sc_handle *hdr;
262 DWORD err = validate_context_handle(handle, SC_HTYPE_NOTIFY, needed_access, &hdr);
263 if (err == ERROR_SUCCESS)
264 *notify = (struct sc_notify_handle *)hdr;
265 return err;
268 DWORD __cdecl svcctl_OpenSCManagerW(
269 MACHINE_HANDLEW MachineName, /* Note: this parameter is ignored */
270 LPCWSTR DatabaseName,
271 DWORD dwAccessMask,
272 SC_RPC_HANDLE *handle)
274 struct sc_manager_handle *manager;
276 WINE_TRACE("(%s, %s, %lx)\n", wine_dbgstr_w(MachineName), wine_dbgstr_w(DatabaseName), dwAccessMask);
278 if (DatabaseName != NULL && DatabaseName[0])
280 if (lstrcmpW(DatabaseName, SERVICES_FAILED_DATABASEW) == 0)
281 return ERROR_DATABASE_DOES_NOT_EXIST;
282 if (lstrcmpW(DatabaseName, SERVICES_ACTIVE_DATABASEW) != 0)
283 return ERROR_INVALID_NAME;
286 if (!(manager = malloc(sizeof(*manager))))
287 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
289 manager->hdr.type = SC_HTYPE_MANAGER;
291 if (dwAccessMask & MAXIMUM_ALLOWED)
292 dwAccessMask |= SC_MANAGER_ALL_ACCESS;
293 manager->hdr.access = dwAccessMask;
294 RtlMapGenericMask(&manager->hdr.access, &g_scm_generic);
295 manager->db = active_database;
296 *handle = &manager->hdr;
298 return ERROR_SUCCESS;
301 static void SC_RPC_HANDLE_destroy(SC_RPC_HANDLE handle)
303 struct sc_handle *hdr = handle;
304 switch (hdr->type)
306 case SC_HTYPE_MANAGER:
308 struct sc_manager_handle *manager = (struct sc_manager_handle *)hdr;
309 free(manager);
310 break;
312 case SC_HTYPE_SERVICE:
314 struct sc_service_handle *service = (struct sc_service_handle *)hdr;
315 service_lock(service->service_entry);
316 list_remove(&service->entry);
317 if (service->notify)
319 SetEvent(service->notify->event);
320 sc_notify_release(service->notify);
322 service_unlock(service->service_entry);
323 release_service(service->service_entry);
324 free(service);
325 break;
327 default:
328 WINE_ERR("invalid handle type %d\n", hdr->type);
329 RpcRaiseException(ERROR_INVALID_HANDLE);
333 DWORD __cdecl svcctl_GetServiceDisplayNameW(
334 SC_RPC_HANDLE hSCManager,
335 LPCWSTR lpServiceName,
336 WCHAR *lpBuffer,
337 DWORD *cchBufSize)
339 struct sc_manager_handle *manager;
340 struct service_entry *entry;
341 DWORD err;
343 WINE_TRACE("(%s, %ld)\n", wine_dbgstr_w(lpServiceName), *cchBufSize);
345 if ((err = validate_scm_handle(hSCManager, 0, &manager)) != ERROR_SUCCESS)
346 return err;
348 scmdatabase_lock(manager->db);
350 entry = scmdatabase_find_service(manager->db, lpServiceName);
351 if (entry != NULL)
353 LPCWSTR name;
354 int len;
355 name = get_display_name(entry);
356 len = lstrlenW(name);
357 if (len <= *cchBufSize)
359 err = ERROR_SUCCESS;
360 memcpy(lpBuffer, name, (len + 1)*sizeof(*name));
362 else
363 err = ERROR_INSUFFICIENT_BUFFER;
364 *cchBufSize = len;
366 else
367 err = ERROR_SERVICE_DOES_NOT_EXIST;
369 scmdatabase_unlock(manager->db);
371 if (err != ERROR_SUCCESS)
372 lpBuffer[0] = 0;
374 return err;
377 DWORD __cdecl svcctl_GetServiceKeyNameW(
378 SC_RPC_HANDLE hSCManager,
379 LPCWSTR lpServiceDisplayName,
380 WCHAR *lpBuffer,
381 DWORD *cchBufSize)
383 struct service_entry *entry;
384 struct sc_manager_handle *manager;
385 DWORD err;
387 WINE_TRACE("(%s, %ld)\n", wine_dbgstr_w(lpServiceDisplayName), *cchBufSize);
389 if ((err = validate_scm_handle(hSCManager, 0, &manager)) != ERROR_SUCCESS)
390 return err;
392 scmdatabase_lock(manager->db);
394 entry = scmdatabase_find_service_by_displayname(manager->db, lpServiceDisplayName);
395 if (entry != NULL)
397 int len;
398 len = lstrlenW(entry->name);
399 if (len <= *cchBufSize)
401 err = ERROR_SUCCESS;
402 memcpy(lpBuffer, entry->name, (len + 1)*sizeof(*entry->name));
404 else
405 err = ERROR_INSUFFICIENT_BUFFER;
406 *cchBufSize = len;
408 else
409 err = ERROR_SERVICE_DOES_NOT_EXIST;
411 scmdatabase_unlock(manager->db);
413 if (err != ERROR_SUCCESS)
414 lpBuffer[0] = 0;
416 return err;
419 static DWORD create_handle_for_service(struct service_entry *entry, DWORD dwDesiredAccess, SC_RPC_HANDLE *phService)
421 struct sc_service_handle *service;
423 if (!(service = malloc(sizeof(*service))))
425 release_service(entry);
426 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
429 if (dwDesiredAccess & MAXIMUM_ALLOWED)
430 dwDesiredAccess |= SERVICE_ALL_ACCESS;
432 service->hdr.type = SC_HTYPE_SERVICE;
433 service->hdr.access = dwDesiredAccess;
434 service->notify = NULL;
435 service->status_notified = FALSE;
436 RtlMapGenericMask(&service->hdr.access, &g_svc_generic);
438 service_lock(entry);
439 service->service_entry = entry;
440 list_add_tail(&entry->handles, &service->entry);
441 service_unlock(entry);
443 *phService = &service->hdr;
444 return ERROR_SUCCESS;
447 DWORD __cdecl svcctl_OpenServiceW(
448 SC_RPC_HANDLE hSCManager,
449 LPCWSTR lpServiceName,
450 DWORD dwDesiredAccess,
451 SC_RPC_HANDLE *phService)
453 struct sc_manager_handle *manager;
454 struct service_entry *entry;
455 DWORD err;
457 WINE_TRACE("(%s, 0x%lx)\n", wine_dbgstr_w(lpServiceName), dwDesiredAccess);
459 if ((err = validate_scm_handle(hSCManager, 0, &manager)) != ERROR_SUCCESS)
460 return err;
461 if (!validate_service_name(lpServiceName))
462 return ERROR_INVALID_NAME;
464 scmdatabase_lock(manager->db);
465 entry = grab_service(scmdatabase_find_service(manager->db, lpServiceName));
466 scmdatabase_unlock(manager->db);
468 if (entry == NULL)
469 return ERROR_SERVICE_DOES_NOT_EXIST;
471 return create_handle_for_service(entry, dwDesiredAccess, phService);
474 static DWORD parse_dependencies(const WCHAR *dependencies, struct service_entry *entry)
476 WCHAR *services = NULL, *groups, *s;
477 DWORD len, len_services = 0, len_groups = 0;
478 const WCHAR *ptr = dependencies;
480 if (!dependencies || !dependencies[0])
482 entry->dependOnServices = NULL;
483 entry->dependOnGroups = NULL;
484 return ERROR_SUCCESS;
487 while (*ptr)
489 len = lstrlenW(ptr) + 1;
490 if (ptr[0] == '+' && ptr[1])
491 len_groups += len - 1;
492 else
493 len_services += len;
494 ptr += len;
496 if (!len_services) entry->dependOnServices = NULL;
497 else
499 services = malloc((len_services + 1) * sizeof(WCHAR));
500 if (!services)
501 return ERROR_OUTOFMEMORY;
503 s = services;
504 ptr = dependencies;
505 while (*ptr)
507 len = lstrlenW(ptr) + 1;
508 if (*ptr != '+')
510 lstrcpyW(s, ptr);
511 s += len;
513 ptr += len;
515 *s = 0;
516 entry->dependOnServices = services;
518 if (!len_groups) entry->dependOnGroups = NULL;
519 else
521 groups = malloc((len_groups + 1) * sizeof(WCHAR));
522 if (!groups)
524 free(services);
525 return ERROR_OUTOFMEMORY;
527 s = groups;
528 ptr = dependencies;
529 while (*ptr)
531 len = lstrlenW(ptr) + 1;
532 if (ptr[0] == '+' && ptr[1])
534 lstrcpyW(s, ptr + 1);
535 s += len - 1;
537 ptr += len;
539 *s = 0;
540 entry->dependOnGroups = groups;
543 return ERROR_SUCCESS;
546 static DWORD create_serviceW(
547 SC_RPC_HANDLE hSCManager,
548 LPCWSTR lpServiceName,
549 LPCWSTR lpDisplayName,
550 DWORD dwDesiredAccess,
551 DWORD dwServiceType,
552 DWORD dwStartType,
553 DWORD dwErrorControl,
554 LPCWSTR lpBinaryPathName,
555 LPCWSTR lpLoadOrderGroup,
556 DWORD *lpdwTagId,
557 const BYTE *lpDependencies,
558 DWORD dwDependenciesSize,
559 LPCWSTR lpServiceStartName,
560 const BYTE *lpPassword,
561 DWORD dwPasswordSize,
562 SC_RPC_HANDLE *phService,
563 BOOL is_wow64)
565 struct service_entry *entry, *found;
566 struct sc_manager_handle *manager;
567 DWORD err;
569 WINE_TRACE("(%s, %s, 0x%lx, %s)\n", wine_dbgstr_w(lpServiceName), wine_dbgstr_w(lpDisplayName), dwDesiredAccess, wine_dbgstr_w(lpBinaryPathName));
571 if ((err = validate_scm_handle(hSCManager, SC_MANAGER_CREATE_SERVICE, &manager)) != ERROR_SUCCESS)
572 return err;
574 if (!validate_service_name(lpServiceName))
575 return ERROR_INVALID_NAME;
576 if (!check_multisz((LPCWSTR)lpDependencies, dwDependenciesSize) || !lpServiceName[0] || !lpBinaryPathName[0])
577 return ERROR_INVALID_PARAMETER;
579 if (lpPassword)
580 WINE_FIXME("Don't know how to add a password\n"); /* I always get ERROR_GEN_FAILURE */
582 err = service_create(lpServiceName, &entry);
583 if (err != ERROR_SUCCESS)
584 return err;
586 err = parse_dependencies((LPCWSTR)lpDependencies, entry);
587 if (err != ERROR_SUCCESS) {
588 free_service_entry(entry);
589 return err;
592 entry->is_wow64 = is_wow64;
593 entry->config.dwServiceType = entry->status.dwServiceType = dwServiceType;
594 entry->config.dwStartType = dwStartType;
595 entry->config.dwErrorControl = dwErrorControl;
596 entry->config.lpBinaryPathName = wcsdup(lpBinaryPathName);
597 entry->config.lpLoadOrderGroup = wcsdup(lpLoadOrderGroup);
598 entry->config.lpServiceStartName = wcsdup(lpServiceStartName);
599 entry->config.lpDisplayName = wcsdup(lpDisplayName);
601 if (lpdwTagId) /* TODO: In most situations a non-NULL TagId will generate an ERROR_INVALID_PARAMETER. */
602 entry->config.dwTagId = *lpdwTagId;
603 else
604 entry->config.dwTagId = 0;
606 /* other fields NULL*/
608 if (!validate_service_config(entry))
610 WINE_ERR("Invalid data while trying to create service\n");
611 free_service_entry(entry);
612 return ERROR_INVALID_PARAMETER;
615 scmdatabase_lock(manager->db);
617 if ((found = scmdatabase_find_service(manager->db, lpServiceName)))
619 err = is_marked_for_delete(found) ? ERROR_SERVICE_MARKED_FOR_DELETE : ERROR_SERVICE_EXISTS;
620 scmdatabase_unlock(manager->db);
621 free_service_entry(entry);
622 return err;
625 if (scmdatabase_find_service_by_displayname(manager->db, get_display_name(entry)))
627 scmdatabase_unlock(manager->db);
628 free_service_entry(entry);
629 return ERROR_DUPLICATE_SERVICE_NAME;
632 err = scmdatabase_add_service(manager->db, entry);
633 if (err != ERROR_SUCCESS)
635 scmdatabase_unlock(manager->db);
636 free_service_entry(entry);
637 return err;
639 scmdatabase_unlock(manager->db);
641 return create_handle_for_service(entry, dwDesiredAccess, phService);
644 DWORD __cdecl svcctl_CreateServiceW(
645 SC_RPC_HANDLE hSCManager,
646 LPCWSTR lpServiceName,
647 LPCWSTR lpDisplayName,
648 DWORD dwDesiredAccess,
649 DWORD dwServiceType,
650 DWORD dwStartType,
651 DWORD dwErrorControl,
652 LPCWSTR lpBinaryPathName,
653 LPCWSTR lpLoadOrderGroup,
654 DWORD *lpdwTagId,
655 const BYTE *lpDependencies,
656 DWORD dwDependenciesSize,
657 LPCWSTR lpServiceStartName,
658 const BYTE *lpPassword,
659 DWORD dwPasswordSize,
660 SC_RPC_HANDLE *phService)
662 WINE_TRACE("(%s, %s, 0x%lx, %s)\n", wine_dbgstr_w(lpServiceName), wine_dbgstr_w(lpDisplayName), dwDesiredAccess, wine_dbgstr_w(lpBinaryPathName));
663 return create_serviceW(hSCManager, lpServiceName, lpDisplayName, dwDesiredAccess, dwServiceType, dwStartType,
664 dwErrorControl, lpBinaryPathName, lpLoadOrderGroup, lpdwTagId, lpDependencies, dwDependenciesSize, lpServiceStartName,
665 lpPassword, dwPasswordSize, phService, FALSE);
668 DWORD __cdecl svcctl_DeleteService(
669 SC_RPC_HANDLE hService)
671 struct sc_service_handle *service;
672 DWORD err;
674 if ((err = validate_service_handle(hService, DELETE, &service)) != ERROR_SUCCESS)
675 return err;
677 service_lock(service->service_entry);
679 if (!is_marked_for_delete(service->service_entry))
680 err = mark_for_delete(service->service_entry);
681 else
682 err = ERROR_SERVICE_MARKED_FOR_DELETE;
684 service_unlock(service->service_entry);
686 return err;
689 DWORD __cdecl svcctl_QueryServiceConfigW(
690 SC_RPC_HANDLE hService,
691 QUERY_SERVICE_CONFIGW *config,
692 DWORD buf_size,
693 DWORD *needed_size)
695 struct sc_service_handle *service;
696 DWORD err;
698 WINE_TRACE("(%p)\n", config);
700 if ((err = validate_service_handle(hService, SERVICE_QUERY_CONFIG, &service)) != 0)
701 return err;
703 service_lock(service->service_entry);
704 config->dwServiceType = service->service_entry->config.dwServiceType;
705 config->dwStartType = service->service_entry->config.dwStartType;
706 config->dwErrorControl = service->service_entry->config.dwErrorControl;
707 config->lpBinaryPathName = wcsdup(service->service_entry->config.lpBinaryPathName);
708 config->lpLoadOrderGroup = wcsdup(service->service_entry->config.lpLoadOrderGroup);
709 config->dwTagId = service->service_entry->config.dwTagId;
710 config->lpDependencies = NULL; /* TODO */
711 config->lpServiceStartName = wcsdup(service->service_entry->config.lpServiceStartName);
712 config->lpDisplayName = wcsdup(service->service_entry->config.lpDisplayName);
713 service_unlock(service->service_entry);
715 return ERROR_SUCCESS;
718 DWORD __cdecl svcctl_ChangeServiceConfigW(
719 SC_RPC_HANDLE hService,
720 DWORD dwServiceType,
721 DWORD dwStartType,
722 DWORD dwErrorControl,
723 LPCWSTR lpBinaryPathName,
724 LPCWSTR lpLoadOrderGroup,
725 DWORD *lpdwTagId,
726 const BYTE *lpDependencies,
727 DWORD dwDependenciesSize,
728 LPCWSTR lpServiceStartName,
729 const BYTE *lpPassword,
730 DWORD dwPasswordSize,
731 LPCWSTR lpDisplayName)
733 struct service_entry new_entry, *entry;
734 struct sc_service_handle *service;
735 DWORD err;
737 WINE_TRACE("\n");
739 if ((err = validate_service_handle(hService, SERVICE_CHANGE_CONFIG, &service)) != 0)
740 return err;
742 if (!check_multisz((LPCWSTR)lpDependencies, dwDependenciesSize))
743 return ERROR_INVALID_PARAMETER;
745 /* first check if the new configuration is correct */
746 service_lock(service->service_entry);
748 if (is_marked_for_delete(service->service_entry))
750 service_unlock(service->service_entry);
751 return ERROR_SERVICE_MARKED_FOR_DELETE;
754 if (lpDisplayName != NULL &&
755 (entry = scmdatabase_find_service_by_displayname(service->service_entry->db, lpDisplayName)) &&
756 (entry != service->service_entry))
758 service_unlock(service->service_entry);
759 return ERROR_DUPLICATE_SERVICE_NAME;
762 new_entry = *service->service_entry;
764 if (dwServiceType != SERVICE_NO_CHANGE)
765 new_entry.config.dwServiceType = dwServiceType;
767 if (dwStartType != SERVICE_NO_CHANGE)
768 new_entry.config.dwStartType = dwStartType;
770 if (dwErrorControl != SERVICE_NO_CHANGE)
771 new_entry.config.dwErrorControl = dwErrorControl;
773 if (lpBinaryPathName != NULL)
774 new_entry.config.lpBinaryPathName = (LPWSTR)lpBinaryPathName;
776 if (lpLoadOrderGroup != NULL)
777 new_entry.config.lpLoadOrderGroup = (LPWSTR)lpLoadOrderGroup;
779 if (lpdwTagId != NULL)
780 WINE_FIXME("Changing tag id not supported\n");
782 if (lpServiceStartName != NULL)
783 new_entry.config.lpServiceStartName = (LPWSTR)lpServiceStartName;
785 if (lpPassword != NULL)
786 WINE_FIXME("Setting password not supported\n");
788 if (lpDisplayName != NULL)
789 new_entry.config.lpDisplayName = (LPWSTR)lpDisplayName;
791 err = parse_dependencies((LPCWSTR)lpDependencies, &new_entry);
792 if (err != ERROR_SUCCESS)
794 service_unlock(service->service_entry);
795 return err;
798 if (!validate_service_config(&new_entry))
800 WINE_ERR("The configuration after the change wouldn't be valid\n");
801 service_unlock(service->service_entry);
802 return ERROR_INVALID_PARAMETER;
805 /* configuration OK. The strings needs to be duplicated */
806 if (lpBinaryPathName != NULL)
807 new_entry.config.lpBinaryPathName = wcsdup(lpBinaryPathName);
809 if (lpLoadOrderGroup != NULL)
810 new_entry.config.lpLoadOrderGroup = wcsdup(lpLoadOrderGroup);
812 if (lpServiceStartName != NULL)
813 new_entry.config.lpServiceStartName = wcsdup(lpServiceStartName);
815 if (lpDisplayName != NULL)
816 new_entry.config.lpDisplayName = wcsdup(lpDisplayName);
818 /* try to save to Registry, commit or rollback depending on success */
819 err = save_service_config(&new_entry);
820 if (ERROR_SUCCESS == err)
822 free_service_strings(service->service_entry, &new_entry);
823 *service->service_entry = new_entry;
825 else free_service_strings(&new_entry, service->service_entry);
826 service_unlock(service->service_entry);
828 return err;
831 static void fill_status_process(SERVICE_STATUS_PROCESS *status, struct service_entry *service)
833 struct process_entry *process = service->process;
834 memcpy(status, &service->status, sizeof(service->status));
835 status->dwProcessId = 0;
836 if (process && !(service->status.dwServiceType & SERVICE_DRIVER))
837 status->dwProcessId = process->process_id;
838 status->dwServiceFlags = 0;
841 static void fill_notify(struct sc_notify_handle *notify, struct service_entry *service)
843 SC_RPC_NOTIFY_PARAMS_LIST *list;
844 SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2 *cparams;
846 list = calloc(1, sizeof(SC_RPC_NOTIFY_PARAMS_LIST));
847 if (!list)
848 return;
849 if (!(cparams = calloc(1, sizeof(SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2))))
851 free(list);
852 return;
855 cparams->dwNotifyMask = notify->notify_mask;
856 fill_status_process(&cparams->ServiceStatus, service);
857 cparams->dwNotificationStatus = ERROR_SUCCESS;
858 cparams->dwNotificationTriggered = 1 << (cparams->ServiceStatus.dwCurrentState - SERVICE_STOPPED);
859 cparams->pszServiceNames = NULL;
861 list->cElements = 1;
863 list->NotifyParamsArray[0].dwInfoLevel = 2;
864 list->NotifyParamsArray[0].params = cparams;
866 InterlockedExchangePointer((void**)&notify->params_list, list);
868 SetEvent(notify->event);
871 DWORD __cdecl svcctl_SetServiceStatus(SC_RPC_HANDLE handle, SERVICE_STATUS *status)
873 struct sc_service_handle *service, *service_handle;
874 struct process_entry *process;
875 DWORD err, mask;
877 WINE_TRACE("(%p, %p)\n", handle, status);
879 if ((err = validate_service_handle(handle, SERVICE_SET_STATUS, &service)) != 0)
880 return err;
882 service_lock(service->service_entry);
884 /* FIXME: be a bit more discriminant about what parts of the status we set
885 * and check that fields are valid */
886 service->service_entry->status.dwCurrentState = status->dwCurrentState;
887 service->service_entry->status.dwControlsAccepted = status->dwControlsAccepted;
888 service->service_entry->status.dwWin32ExitCode = status->dwWin32ExitCode;
889 service->service_entry->status.dwServiceSpecificExitCode = status->dwServiceSpecificExitCode;
890 service->service_entry->status.dwCheckPoint = status->dwCheckPoint;
891 service->service_entry->status.dwWaitHint = status->dwWaitHint;
892 SetEvent(service->service_entry->status_changed_event);
894 if ((process = service->service_entry->process) &&
895 status->dwCurrentState == SERVICE_STOPPED)
897 service->service_entry->process = NULL;
898 if (!--process->use_count)
899 terminate_after_timeout(process, service_kill_timeout);
900 if (service->service_entry->shared_process && process->use_count <= 1)
901 shutdown_shared_process(process);
902 release_process(process);
905 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
906 LIST_FOR_EACH_ENTRY(service_handle, &service->service_entry->handles, struct sc_service_handle, entry)
908 struct sc_notify_handle *notify = service_handle->notify;
909 if (notify && (notify->notify_mask & mask))
911 fill_notify(notify, service->service_entry);
912 sc_notify_release(notify);
913 service_handle->notify = NULL;
914 service_handle->status_notified = TRUE;
916 else
917 service_handle->status_notified = FALSE;
920 service_unlock(service->service_entry);
922 return ERROR_SUCCESS;
925 DWORD __cdecl svcctl_ChangeServiceConfig2W( SC_RPC_HANDLE hService, SC_RPC_CONFIG_INFOW config )
927 struct sc_service_handle *service;
928 DWORD err;
930 if ((err = validate_service_handle(hService, SERVICE_CHANGE_CONFIG, &service)) != 0)
931 return err;
933 switch (config.dwInfoLevel)
935 case SERVICE_CONFIG_DESCRIPTION:
937 WCHAR *descr = NULL;
939 if (!config.descr->lpDescription)
940 break;
942 if (config.descr->lpDescription[0])
944 if (!(descr = wcsdup( config.descr->lpDescription )))
945 return ERROR_NOT_ENOUGH_MEMORY;
948 WINE_TRACE( "changing service %p descr to %s\n", service, wine_dbgstr_w(descr) );
949 service_lock( service->service_entry );
950 free( service->service_entry->description );
951 service->service_entry->description = descr;
952 save_service_config( service->service_entry );
953 service_unlock( service->service_entry );
955 break;
956 case SERVICE_CONFIG_FAILURE_ACTIONS:
957 WINE_FIXME( "SERVICE_CONFIG_FAILURE_ACTIONS not implemented: period %lu msg %s cmd %s\n",
958 config.actions->dwResetPeriod,
959 wine_dbgstr_w(config.actions->lpRebootMsg),
960 wine_dbgstr_w(config.actions->lpCommand) );
961 break;
962 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
963 WINE_TRACE( "changing service %p preshutdown timeout to %ld\n",
964 service, config.preshutdown->dwPreshutdownTimeout );
965 service_lock( service->service_entry );
966 service->service_entry->preshutdown_timeout = config.preshutdown->dwPreshutdownTimeout;
967 save_service_config( service->service_entry );
968 service_unlock( service->service_entry );
969 break;
970 default:
971 WINE_FIXME("level %lu not implemented\n", config.dwInfoLevel);
972 err = ERROR_INVALID_LEVEL;
973 break;
975 return err;
978 DWORD __cdecl svcctl_QueryServiceConfig2W( SC_RPC_HANDLE hService, DWORD level,
979 BYTE *buffer, DWORD size, LPDWORD needed )
981 struct sc_service_handle *service;
982 DWORD err;
984 memset(buffer, 0, size);
986 if ((err = validate_service_handle(hService, SERVICE_QUERY_CONFIG, &service)) != 0)
987 return err;
989 switch (level)
991 case SERVICE_CONFIG_DESCRIPTION:
993 struct service_description *desc = (struct service_description *)buffer;
994 DWORD total_size = sizeof(*desc);
996 service_lock(service->service_entry);
997 if (service->service_entry->description)
998 total_size += lstrlenW(service->service_entry->description) * sizeof(WCHAR);
1000 *needed = total_size;
1001 if (size >= total_size)
1003 if (service->service_entry->description)
1005 lstrcpyW( desc->description, service->service_entry->description );
1006 desc->size = total_size - FIELD_OFFSET(struct service_description, description);
1008 else
1010 desc->description[0] = 0;
1011 desc->size = 0;
1014 else err = ERROR_INSUFFICIENT_BUFFER;
1015 service_unlock(service->service_entry);
1017 break;
1019 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
1020 service_lock(service->service_entry);
1022 *needed = sizeof(SERVICE_PRESHUTDOWN_INFO);
1023 if (size >= *needed)
1024 ((LPSERVICE_PRESHUTDOWN_INFO)buffer)->dwPreshutdownTimeout =
1025 service->service_entry->preshutdown_timeout;
1026 else err = ERROR_INSUFFICIENT_BUFFER;
1028 service_unlock(service->service_entry);
1029 break;
1031 default:
1032 WINE_FIXME("level %lu not implemented\n", level);
1033 err = ERROR_INVALID_LEVEL;
1034 break;
1036 return err;
1039 DWORD __cdecl svcctl_QueryServiceStatusEx(
1040 SC_RPC_HANDLE hService,
1041 SC_STATUS_TYPE InfoLevel,
1042 BYTE *lpBuffer,
1043 DWORD cbBufSize,
1044 LPDWORD pcbBytesNeeded)
1046 struct sc_service_handle *service;
1047 DWORD err;
1048 LPSERVICE_STATUS_PROCESS pSvcStatusData;
1050 memset(lpBuffer, 0, cbBufSize);
1052 if ((err = validate_service_handle(hService, SERVICE_QUERY_STATUS, &service)) != 0)
1053 return err;
1055 if (InfoLevel != SC_STATUS_PROCESS_INFO)
1056 return ERROR_INVALID_LEVEL;
1058 pSvcStatusData = (LPSERVICE_STATUS_PROCESS) lpBuffer;
1059 if (pSvcStatusData == NULL)
1060 return ERROR_INVALID_PARAMETER;
1062 if (cbBufSize < sizeof(SERVICE_STATUS_PROCESS))
1064 if( pcbBytesNeeded != NULL)
1065 *pcbBytesNeeded = sizeof(SERVICE_STATUS_PROCESS);
1067 return ERROR_INSUFFICIENT_BUFFER;
1070 service_lock(service->service_entry);
1071 fill_status_process(pSvcStatusData, service->service_entry);
1072 service_unlock(service->service_entry);
1074 return ERROR_SUCCESS;
1077 /******************************************************************************
1078 * service_accepts_control
1080 static BOOL service_accepts_control(const struct service_entry *service, DWORD dwControl)
1082 DWORD a = service->status.dwControlsAccepted;
1084 if (dwControl >= 128 && dwControl <= 255)
1085 return TRUE;
1087 switch (dwControl)
1089 case SERVICE_CONTROL_INTERROGATE:
1090 return TRUE;
1091 case SERVICE_CONTROL_STOP:
1092 if (a&SERVICE_ACCEPT_STOP)
1093 return TRUE;
1094 break;
1095 case SERVICE_CONTROL_SHUTDOWN:
1096 if (a&SERVICE_ACCEPT_SHUTDOWN)
1097 return TRUE;
1098 break;
1099 case SERVICE_CONTROL_PAUSE:
1100 case SERVICE_CONTROL_CONTINUE:
1101 if (a&SERVICE_ACCEPT_PAUSE_CONTINUE)
1102 return TRUE;
1103 break;
1104 case SERVICE_CONTROL_PARAMCHANGE:
1105 if (a&SERVICE_ACCEPT_PARAMCHANGE)
1106 return TRUE;
1107 break;
1108 case SERVICE_CONTROL_NETBINDADD:
1109 case SERVICE_CONTROL_NETBINDREMOVE:
1110 case SERVICE_CONTROL_NETBINDENABLE:
1111 case SERVICE_CONTROL_NETBINDDISABLE:
1112 if (a&SERVICE_ACCEPT_NETBINDCHANGE)
1113 return TRUE;
1114 case SERVICE_CONTROL_HARDWAREPROFILECHANGE:
1115 if (a&SERVICE_ACCEPT_HARDWAREPROFILECHANGE)
1116 return TRUE;
1117 break;
1118 case SERVICE_CONTROL_POWEREVENT:
1119 if (a&SERVICE_ACCEPT_POWEREVENT)
1120 return TRUE;
1121 break;
1122 case SERVICE_CONTROL_SESSIONCHANGE:
1123 if (a&SERVICE_ACCEPT_SESSIONCHANGE)
1124 return TRUE;
1125 break;
1127 return FALSE;
1130 /******************************************************************************
1131 * process_send_command
1133 static BOOL process_send_command(struct process_entry *process, const void *data, DWORD size, DWORD *result)
1135 OVERLAPPED overlapped;
1136 DWORD count, ret;
1137 BOOL r;
1139 overlapped.u.s.Offset = 0;
1140 overlapped.u.s.OffsetHigh = 0;
1141 overlapped.hEvent = process->overlapped_event;
1142 r = WriteFile(process->control_pipe, data, size, &count, &overlapped);
1143 if (!r && GetLastError() == ERROR_IO_PENDING)
1145 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1146 if (ret == WAIT_TIMEOUT)
1148 WINE_ERR("sending command timed out\n");
1149 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1150 return FALSE;
1152 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1154 if (!r || count != size)
1156 WINE_ERR("service protocol error - failed to write pipe!\n");
1157 *result = (!r ? GetLastError() : ERROR_WRITE_FAULT);
1158 return FALSE;
1160 r = ReadFile(process->control_pipe, result, sizeof *result, &count, &overlapped);
1161 if (!r && GetLastError() == ERROR_IO_PENDING)
1163 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1164 if (ret == WAIT_TIMEOUT)
1166 WINE_ERR("receiving command result timed out\n");
1167 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1168 return FALSE;
1170 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1172 if (!r || count != sizeof *result)
1174 WINE_ERR("service protocol error - failed to read pipe "
1175 "r = %d count = %ld!\n", r, count);
1176 *result = (!r ? GetLastError() : ERROR_READ_FAULT);
1177 return FALSE;
1180 return TRUE;
1183 /******************************************************************************
1184 * process_send_control
1186 BOOL process_send_control(struct process_entry *process, BOOL shared_process, const WCHAR *name,
1187 DWORD control, const BYTE *data, DWORD data_size, DWORD *result)
1189 service_start_info *ssi;
1190 DWORD len;
1191 BOOL r;
1193 if (shared_process)
1195 control |= SERVICE_CONTROL_FORWARD_FLAG;
1196 data = (BYTE *)name;
1197 data_size = (lstrlenW(name) + 1) * sizeof(WCHAR);
1198 name = emptyW;
1201 /* calculate how much space we need to send the startup info */
1202 len = (lstrlenW(name) + 1) * sizeof(WCHAR) + data_size;
1204 ssi = malloc(FIELD_OFFSET(service_start_info, data[len]));
1205 ssi->magic = SERVICE_PROTOCOL_MAGIC;
1206 ssi->control = control;
1207 ssi->total_size = FIELD_OFFSET(service_start_info, data[len]);
1208 ssi->name_size = lstrlenW(name) + 1;
1209 lstrcpyW((WCHAR *)ssi->data, name);
1210 if (data_size) memcpy(&ssi->data[ssi->name_size * sizeof(WCHAR)], data, data_size);
1212 r = process_send_command(process, ssi, ssi->total_size, result);
1213 free(ssi);
1214 return r;
1217 DWORD __cdecl svcctl_StartServiceW(
1218 SC_RPC_HANDLE hService,
1219 DWORD dwNumServiceArgs,
1220 LPCWSTR *lpServiceArgVectors)
1222 struct sc_service_handle *service;
1223 DWORD err;
1225 WINE_TRACE("(%p, %ld, %p)\n", hService, dwNumServiceArgs, lpServiceArgVectors);
1227 if ((err = validate_service_handle(hService, SERVICE_START, &service)) != 0)
1228 return err;
1230 if (service->service_entry->config.dwStartType == SERVICE_DISABLED)
1231 return ERROR_SERVICE_DISABLED;
1233 if (!scmdatabase_lock_startup(service->service_entry->db, 3000))
1234 return ERROR_SERVICE_DATABASE_LOCKED;
1236 err = service_start(service->service_entry, dwNumServiceArgs, lpServiceArgVectors);
1238 scmdatabase_unlock_startup(service->service_entry->db);
1239 return err;
1242 DWORD __cdecl svcctl_ControlService(
1243 SC_RPC_HANDLE hService,
1244 DWORD dwControl,
1245 SERVICE_STATUS *lpServiceStatus)
1247 DWORD access_required;
1248 struct sc_service_handle *service;
1249 struct process_entry *process;
1250 BOOL shared_process;
1251 DWORD result;
1253 WINE_TRACE("(%p, %ld, %p)\n", hService, dwControl, lpServiceStatus);
1255 switch (dwControl)
1257 case SERVICE_CONTROL_CONTINUE:
1258 case SERVICE_CONTROL_NETBINDADD:
1259 case SERVICE_CONTROL_NETBINDDISABLE:
1260 case SERVICE_CONTROL_NETBINDENABLE:
1261 case SERVICE_CONTROL_NETBINDREMOVE:
1262 case SERVICE_CONTROL_PARAMCHANGE:
1263 case SERVICE_CONTROL_PAUSE:
1264 access_required = SERVICE_PAUSE_CONTINUE;
1265 break;
1266 case SERVICE_CONTROL_INTERROGATE:
1267 access_required = SERVICE_INTERROGATE;
1268 break;
1269 case SERVICE_CONTROL_STOP:
1270 access_required = SERVICE_STOP;
1271 break;
1272 default:
1273 if (dwControl >= 128 && dwControl <= 255)
1274 access_required = SERVICE_USER_DEFINED_CONTROL;
1275 else
1276 return ERROR_INVALID_PARAMETER;
1279 if ((result = validate_service_handle(hService, access_required, &service)) != 0)
1280 return result;
1282 service_lock(service->service_entry);
1284 result = ERROR_SUCCESS;
1285 switch (service->service_entry->status.dwCurrentState)
1287 case SERVICE_STOPPED:
1288 result = ERROR_SERVICE_NOT_ACTIVE;
1289 break;
1290 case SERVICE_START_PENDING:
1291 if (dwControl==SERVICE_CONTROL_STOP)
1292 break;
1293 /* fall through */
1294 case SERVICE_STOP_PENDING:
1295 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1296 break;
1299 if (result == ERROR_SUCCESS && service->service_entry->force_shutdown)
1301 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1302 if ((process = service->service_entry->process))
1304 service->service_entry->process = NULL;
1305 if (!--process->use_count) process_terminate(process);
1306 release_process(process);
1310 if (result != ERROR_SUCCESS)
1312 if (lpServiceStatus) *lpServiceStatus = service->service_entry->status;
1313 service_unlock(service->service_entry);
1314 return result;
1317 if (!service_accepts_control(service->service_entry, dwControl))
1319 service_unlock(service->service_entry);
1320 return ERROR_INVALID_SERVICE_CONTROL;
1323 /* Remember that we tried to shutdown this service. When the service is
1324 * still running on the second invocation, it will be forcefully killed. */
1325 if (dwControl == SERVICE_CONTROL_STOP)
1326 service->service_entry->force_shutdown = TRUE;
1328 /* Hold a reference to the process while sending the command. */
1329 process = grab_process(service->service_entry->process);
1330 shared_process = service->service_entry->shared_process;
1331 service_unlock(service->service_entry);
1333 if (!process)
1334 return ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1336 result = WaitForSingleObject(process->control_mutex, 30000);
1337 if (result != WAIT_OBJECT_0)
1339 release_process(process);
1340 return ERROR_SERVICE_REQUEST_TIMEOUT;
1343 if (process_send_control(process, shared_process, service->service_entry->name,
1344 dwControl, NULL, 0, &result))
1345 result = ERROR_SUCCESS;
1347 if (lpServiceStatus)
1349 service_lock(service->service_entry);
1350 *lpServiceStatus = service->service_entry->status;
1351 service_unlock(service->service_entry);
1354 ReleaseMutex(process->control_mutex);
1355 release_process(process);
1356 return result;
1359 DWORD __cdecl svcctl_CloseServiceHandle(
1360 SC_RPC_HANDLE *handle)
1362 WINE_TRACE("(&%p)\n", *handle);
1364 SC_RPC_HANDLE_destroy(*handle);
1365 *handle = NULL;
1367 return ERROR_SUCCESS;
1370 void __RPC_USER SC_RPC_LOCK_rundown(SC_RPC_LOCK hLock)
1374 DWORD __cdecl svcctl_LockServiceDatabase(SC_RPC_HANDLE manager, SC_RPC_LOCK *lock)
1376 TRACE("(%p, %p)\n", manager, lock);
1378 *lock = (SC_RPC_LOCK)0xdeadbeef;
1379 return ERROR_SUCCESS;
1382 DWORD __cdecl svcctl_UnlockServiceDatabase(SC_RPC_LOCK *lock)
1384 TRACE("(&%p)\n", *lock);
1386 *lock = NULL;
1387 return ERROR_SUCCESS;
1390 static BOOL map_state(DWORD state, DWORD mask)
1392 switch (state)
1394 case SERVICE_START_PENDING:
1395 case SERVICE_STOP_PENDING:
1396 case SERVICE_RUNNING:
1397 case SERVICE_CONTINUE_PENDING:
1398 case SERVICE_PAUSE_PENDING:
1399 case SERVICE_PAUSED:
1400 if (SERVICE_ACTIVE & mask) return TRUE;
1401 break;
1402 case SERVICE_STOPPED:
1403 if (SERVICE_INACTIVE & mask) return TRUE;
1404 break;
1405 default:
1406 WINE_ERR("unknown state %lu\n", state);
1407 break;
1409 return FALSE;
1412 DWORD __cdecl svcctl_EnumServicesStatusW(
1413 SC_RPC_HANDLE hmngr,
1414 DWORD type,
1415 DWORD state,
1416 BYTE *buffer,
1417 DWORD size,
1418 LPDWORD needed,
1419 LPDWORD returned,
1420 LPDWORD resume)
1422 DWORD err, sz, total_size, num_services, offset;
1423 struct sc_manager_handle *manager;
1424 struct service_entry *service;
1425 struct enum_service_status *s;
1427 WINE_TRACE("(%p, 0x%lx, 0x%lx, %p, %lu, %p, %p, %p)\n", hmngr, type, state, buffer, size, needed, returned, resume);
1429 if (!type || !state)
1430 return ERROR_INVALID_PARAMETER;
1432 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1433 return err;
1435 if (resume)
1436 WINE_FIXME("resume index not supported\n");
1438 scmdatabase_lock(manager->db);
1440 total_size = num_services = 0;
1441 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1443 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1445 total_size += sizeof(*s);
1446 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1447 if (service->config.lpDisplayName)
1449 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1451 num_services++;
1454 *returned = 0;
1455 *needed = total_size;
1456 if (total_size > size)
1458 scmdatabase_unlock(manager->db);
1459 return ERROR_MORE_DATA;
1461 s = (struct enum_service_status *)buffer;
1462 offset = num_services * sizeof(struct enum_service_status);
1463 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1465 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1467 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1468 memcpy(buffer + offset, service->name, sz);
1469 s->service_name = offset;
1470 offset += sz;
1472 if (!service->config.lpDisplayName) s->display_name = 0;
1473 else
1475 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1476 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1477 s->display_name = offset;
1478 offset += sz;
1480 s->service_status = service->status;
1481 s++;
1484 *returned = num_services;
1485 *needed = 0;
1486 scmdatabase_unlock(manager->db);
1487 return ERROR_SUCCESS;
1490 static struct service_entry *find_service_by_group(struct scmdatabase *db, const WCHAR *group)
1492 struct service_entry *service;
1493 LIST_FOR_EACH_ENTRY(service, &db->services, struct service_entry, entry)
1495 if (service->config.lpLoadOrderGroup && !wcsicmp(group, service->config.lpLoadOrderGroup))
1496 return service;
1498 return NULL;
1501 static BOOL match_group(const WCHAR *g1, const WCHAR *g2)
1503 if (!g2) return TRUE;
1504 if (!g2[0] && (!g1 || !g1[0])) return TRUE;
1505 if (g1 && !lstrcmpW(g1, g2)) return TRUE;
1506 return FALSE;
1509 DWORD __cdecl svcctl_EnumServicesStatusExA(
1510 SC_RPC_HANDLE scmanager,
1511 SC_ENUM_TYPE info_level,
1512 DWORD service_type,
1513 DWORD service_state,
1514 BYTE *buffer,
1515 DWORD buf_size,
1516 DWORD *needed_size,
1517 DWORD *services_count,
1518 DWORD *resume_index,
1519 LPCSTR groupname)
1521 WINE_FIXME("\n");
1522 return ERROR_CALL_NOT_IMPLEMENTED;
1525 DWORD __cdecl svcctl_EnumServicesStatusExW(
1526 SC_RPC_HANDLE hmngr,
1527 SC_ENUM_TYPE info_level,
1528 DWORD type,
1529 DWORD state,
1530 BYTE *buffer,
1531 DWORD size,
1532 LPDWORD needed,
1533 LPDWORD returned,
1534 DWORD *resume_handle,
1535 LPCWSTR group)
1537 DWORD err, sz, total_size, num_services;
1538 DWORD_PTR offset;
1539 struct sc_manager_handle *manager;
1540 struct service_entry *service;
1541 struct enum_service_status_process *s;
1543 WINE_TRACE("(%p, 0x%lx, 0x%lx, %p, %lu, %p, %p, %s)\n", hmngr, type, state, buffer, size,
1544 needed, returned, wine_dbgstr_w(group));
1546 if (resume_handle)
1547 FIXME("resume handle not supported\n");
1549 if (!type || !state)
1550 return ERROR_INVALID_PARAMETER;
1552 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1553 return err;
1555 scmdatabase_lock(manager->db);
1557 if (group && !find_service_by_group(manager->db, group))
1559 scmdatabase_unlock(manager->db);
1560 return ERROR_SERVICE_DOES_NOT_EXIST;
1563 total_size = num_services = 0;
1564 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1566 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1567 && match_group(service->config.lpLoadOrderGroup, group))
1569 total_size += sizeof(*s);
1570 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1571 if (service->config.lpDisplayName)
1573 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1575 num_services++;
1578 *returned = 0;
1579 *needed = total_size;
1580 if (total_size > size)
1582 scmdatabase_unlock(manager->db);
1583 return ERROR_MORE_DATA;
1585 s = (struct enum_service_status_process *)buffer;
1586 offset = num_services * sizeof(*s);
1587 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1589 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1590 && match_group(service->config.lpLoadOrderGroup, group))
1592 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1593 memcpy(buffer + offset, service->name, sz);
1594 s->service_name = offset;
1595 offset += sz;
1597 if (!service->config.lpDisplayName) s->display_name = 0;
1598 else
1600 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1601 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1602 s->display_name = offset;
1603 offset += sz;
1605 fill_status_process(&s->service_status_process, service);
1606 s++;
1609 *returned = num_services;
1610 *needed = 0;
1611 scmdatabase_unlock(manager->db);
1612 return ERROR_SUCCESS;
1615 DWORD __cdecl svcctl_unknown43(void)
1617 WINE_FIXME("\n");
1618 return ERROR_CALL_NOT_IMPLEMENTED;
1621 DWORD __cdecl svcctl_CreateServiceWOW64A(
1622 SC_RPC_HANDLE scmanager,
1623 LPCSTR servicename,
1624 LPCSTR displayname,
1625 DWORD accessmask,
1626 DWORD service_type,
1627 DWORD start_type,
1628 DWORD error_control,
1629 LPCSTR imagepath,
1630 LPCSTR loadordergroup,
1631 DWORD *tagid,
1632 const BYTE *dependencies,
1633 DWORD depend_size,
1634 LPCSTR start_name,
1635 const BYTE *password,
1636 DWORD password_size,
1637 SC_RPC_HANDLE *service)
1639 WINE_FIXME("\n");
1640 return ERROR_CALL_NOT_IMPLEMENTED;
1643 DWORD __cdecl svcctl_CreateServiceWOW64W(
1644 SC_RPC_HANDLE scmanager,
1645 LPCWSTR servicename,
1646 LPCWSTR displayname,
1647 DWORD accessmask,
1648 DWORD service_type,
1649 DWORD start_type,
1650 DWORD error_control,
1651 LPCWSTR imagepath,
1652 LPCWSTR loadordergroup,
1653 DWORD *tagid,
1654 const BYTE *dependencies,
1655 DWORD depend_size,
1656 LPCWSTR start_name,
1657 const BYTE *password,
1658 DWORD password_size,
1659 SC_RPC_HANDLE *service)
1661 WINE_TRACE("(%s, %s, 0x%lx, %s)\n", wine_dbgstr_w(servicename), wine_dbgstr_w(displayname), accessmask, wine_dbgstr_w(imagepath));
1662 return create_serviceW(scmanager, servicename, displayname, accessmask, service_type, start_type, error_control, imagepath,
1663 loadordergroup, tagid, dependencies, depend_size, start_name, password, password_size, service, TRUE);
1666 DWORD __cdecl svcctl_unknown46(void)
1668 WINE_FIXME("\n");
1669 return ERROR_CALL_NOT_IMPLEMENTED;
1672 DWORD __cdecl svcctl_NotifyServiceStatusChange(
1673 SC_RPC_HANDLE handle,
1674 SC_RPC_NOTIFY_PARAMS params,
1675 GUID *clientprocessguid,
1676 GUID *scmprocessguid,
1677 BOOL *createremotequeue,
1678 SC_NOTIFY_RPC_HANDLE *hNotify)
1680 DWORD err, mask;
1681 struct sc_manager_handle *manager = NULL;
1682 struct sc_service_handle *service = NULL;
1683 struct sc_notify_handle *notify;
1684 struct sc_handle *hdr = handle;
1686 WINE_TRACE("(%p, NotifyMask: 0x%lx, %p, %p, %p, %p)\n", handle,
1687 params.params->dwNotifyMask, clientprocessguid, scmprocessguid,
1688 createremotequeue, hNotify);
1690 switch (hdr->type)
1692 case SC_HTYPE_SERVICE:
1693 err = validate_service_handle(handle, SERVICE_QUERY_STATUS, &service);
1694 break;
1695 case SC_HTYPE_MANAGER:
1696 err = validate_scm_handle(handle, SC_MANAGER_ENUMERATE_SERVICE, &manager);
1697 break;
1698 default:
1699 err = ERROR_INVALID_HANDLE;
1700 break;
1703 if (err != ERROR_SUCCESS)
1704 return err;
1706 if (manager)
1708 WARN("Need support for service creation/deletion notifications\n");
1709 return ERROR_CALL_NOT_IMPLEMENTED;
1712 notify = calloc(1, sizeof(*notify));
1713 if (!notify)
1714 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
1716 notify->hdr.type = SC_HTYPE_NOTIFY;
1717 notify->hdr.access = 0;
1719 notify->event = CreateEventW(NULL, TRUE, FALSE, NULL);
1721 notify->notify_mask = params.params->dwNotifyMask;
1723 service_lock(service->service_entry);
1725 if (service->notify)
1727 service_unlock(service->service_entry);
1728 sc_notify_release(notify);
1729 return ERROR_ALREADY_REGISTERED;
1732 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
1733 if (!service->status_notified && (notify->notify_mask & mask))
1735 fill_notify(notify, service->service_entry);
1736 service->status_notified = TRUE;
1738 else
1740 sc_notify_retain(notify);
1741 service->notify = notify;
1744 sc_notify_retain(notify);
1745 *hNotify = &notify->hdr;
1747 service_unlock(service->service_entry);
1749 return ERROR_SUCCESS;
1752 DWORD __cdecl svcctl_GetNotifyResults(
1753 SC_NOTIFY_RPC_HANDLE hNotify,
1754 SC_RPC_NOTIFY_PARAMS_LIST **pList)
1756 DWORD err;
1757 struct sc_notify_handle *notify;
1759 WINE_TRACE("(%p, %p)\n", hNotify, pList);
1761 if (!pList)
1762 return ERROR_INVALID_PARAMETER;
1764 *pList = NULL;
1766 if ((err = validate_notify_handle(hNotify, 0, &notify)) != 0)
1767 return err;
1769 sc_notify_retain(notify);
1770 /* block until there is a result */
1771 err = WaitForSingleObject(notify->event, INFINITE);
1773 if (err != WAIT_OBJECT_0)
1775 sc_notify_release(notify);
1776 return err;
1779 *pList = InterlockedExchangePointer((void**)&notify->params_list, NULL);
1780 if (!*pList)
1782 sc_notify_release(notify);
1783 return ERROR_REQUEST_ABORTED;
1786 sc_notify_release(notify);
1788 return ERROR_SUCCESS;
1791 DWORD __cdecl svcctl_CloseNotifyHandle(
1792 SC_NOTIFY_RPC_HANDLE *hNotify,
1793 BOOL *apc_fired)
1795 struct sc_notify_handle *notify;
1796 DWORD err;
1798 WINE_TRACE("(%p, %p)\n", hNotify, apc_fired);
1800 if ((err = validate_notify_handle(*hNotify, 0, &notify)) != 0)
1801 return err;
1803 sc_notify_release(notify);
1805 return ERROR_SUCCESS;
1808 DWORD __cdecl svcctl_ControlServiceExA(
1809 SC_RPC_HANDLE service,
1810 DWORD control,
1811 DWORD info_level,
1812 SC_RPC_SERVICE_CONTROL_IN_PARAMSA *in_params,
1813 SC_RPC_SERVICE_CONTROL_OUT_PARAMSA *out_params)
1815 WINE_FIXME("\n");
1816 return ERROR_CALL_NOT_IMPLEMENTED;
1819 DWORD __cdecl svcctl_ControlServiceExW(
1820 SC_RPC_HANDLE service,
1821 DWORD control,
1822 DWORD info_level,
1823 SC_RPC_SERVICE_CONTROL_IN_PARAMSW *in_params,
1824 SC_RPC_SERVICE_CONTROL_OUT_PARAMSW *out_params)
1826 WINE_FIXME("\n");
1827 return ERROR_CALL_NOT_IMPLEMENTED;
1830 DWORD __cdecl svcctl_unknown52(void)
1832 WINE_FIXME("\n");
1833 return ERROR_CALL_NOT_IMPLEMENTED;
1836 DWORD __cdecl svcctl_unknown53(void)
1838 WINE_FIXME("\n");
1839 return ERROR_CALL_NOT_IMPLEMENTED;
1842 DWORD __cdecl svcctl_unknown54(void)
1844 WINE_FIXME("\n");
1845 return ERROR_CALL_NOT_IMPLEMENTED;
1848 DWORD __cdecl svcctl_unknown55(void)
1850 WINE_FIXME("\n");
1851 return ERROR_CALL_NOT_IMPLEMENTED;
1854 DWORD __cdecl svcctl_QueryServiceConfigEx(
1855 SC_RPC_HANDLE service,
1856 DWORD info_level,
1857 SC_RPC_CONFIG_INFOW *info)
1859 WINE_FIXME("\n");
1860 return ERROR_CALL_NOT_IMPLEMENTED;
1863 DWORD __cdecl svcctl_QueryServiceObjectSecurity(
1864 SC_RPC_HANDLE service,
1865 SECURITY_INFORMATION info,
1866 BYTE *descriptor,
1867 DWORD buf_size,
1868 DWORD *needed_size)
1870 WINE_FIXME("\n");
1871 return ERROR_CALL_NOT_IMPLEMENTED;
1874 DWORD __cdecl svcctl_SetServiceObjectSecurity(
1875 SC_RPC_HANDLE service,
1876 SECURITY_INFORMATION info,
1877 BYTE *descriptor,
1878 DWORD buf_size)
1880 WINE_FIXME("\n");
1881 return ERROR_CALL_NOT_IMPLEMENTED;
1884 DWORD __cdecl svcctl_QueryServiceStatus(
1885 SC_RPC_HANDLE service,
1886 SERVICE_STATUS *status)
1888 WINE_FIXME("\n");
1889 return ERROR_CALL_NOT_IMPLEMENTED;
1892 DWORD __cdecl svcctl_NotifyBootConfigStatus(
1893 SVCCTL_HANDLEW machinename,
1894 DWORD boot_acceptable)
1896 WINE_FIXME("\n");
1897 return ERROR_CALL_NOT_IMPLEMENTED;
1900 DWORD __cdecl svcctl_SCSetServiceBitsW(void)
1902 WINE_FIXME("\n");
1903 return ERROR_CALL_NOT_IMPLEMENTED;
1906 DWORD __cdecl svcctl_EnumDependentServicesW(
1907 SC_RPC_HANDLE service,
1908 DWORD state,
1909 BYTE *services,
1910 DWORD buf_size,
1911 DWORD *needed_size,
1912 DWORD *services_ret)
1914 WINE_FIXME("\n");
1915 return ERROR_CALL_NOT_IMPLEMENTED;
1918 DWORD __cdecl svcctl_QueryServiceLockStatusW(
1919 SC_RPC_HANDLE scmanager,
1920 QUERY_SERVICE_LOCK_STATUSW *status,
1921 DWORD buf_size,
1922 DWORD *needed_size)
1924 WINE_FIXME("\n");
1925 return ERROR_CALL_NOT_IMPLEMENTED;
1928 DWORD __cdecl svcctl_SCSetServiceBitsA(void)
1930 WINE_FIXME("\n");
1931 return ERROR_CALL_NOT_IMPLEMENTED;
1934 DWORD __cdecl svcctl_ChangeServiceConfigA(
1935 SC_RPC_HANDLE service,
1936 DWORD service_type,
1937 DWORD start_type,
1938 DWORD error_control,
1939 LPSTR binarypath,
1940 LPSTR loadordergroup,
1941 DWORD *tagid,
1942 BYTE *dependencies,
1943 DWORD depend_size,
1944 LPSTR startname,
1945 BYTE *password,
1946 DWORD password_size,
1947 LPSTR displayname)
1949 WINE_FIXME("\n");
1950 return ERROR_CALL_NOT_IMPLEMENTED;
1953 DWORD __cdecl svcctl_CreateServiceA(
1954 SC_RPC_HANDLE scmanager,
1955 LPCSTR servicename,
1956 LPCSTR displayname,
1957 DWORD desiredaccess,
1958 DWORD service_type,
1959 DWORD start_type,
1960 DWORD error_control,
1961 LPCSTR binarypath,
1962 LPCSTR loadordergroup,
1963 DWORD *tagid,
1964 const BYTE *dependencies,
1965 DWORD depend_size,
1966 LPCSTR startname,
1967 const BYTE *password,
1968 DWORD password_size,
1969 SC_RPC_HANDLE *service)
1971 WINE_FIXME("\n");
1972 return ERROR_CALL_NOT_IMPLEMENTED;
1975 DWORD __cdecl svcctl_EnumDependentServicesA(
1976 SC_RPC_HANDLE service,
1977 DWORD state,
1978 BYTE *services,
1979 DWORD buf_size,
1980 DWORD *needed_size,
1981 DWORD *services_ret)
1983 WINE_FIXME("\n");
1984 return ERROR_CALL_NOT_IMPLEMENTED;
1987 DWORD __cdecl svcctl_EnumServicesStatusA(
1988 SC_RPC_HANDLE hmngr,
1989 DWORD type,
1990 DWORD state,
1991 BYTE *buffer,
1992 DWORD size,
1993 DWORD *needed,
1994 DWORD *returned,
1995 DWORD *resume)
1997 WINE_FIXME("\n");
1998 return ERROR_CALL_NOT_IMPLEMENTED;
2001 DWORD __cdecl svcctl_OpenSCManagerA(
2002 MACHINE_HANDLEA MachineName,
2003 LPCSTR DatabaseName,
2004 DWORD dwAccessMask,
2005 SC_RPC_HANDLE *handle)
2007 WINE_FIXME("\n");
2008 return ERROR_CALL_NOT_IMPLEMENTED;
2011 DWORD __cdecl svcctl_OpenServiceA(
2012 SC_RPC_HANDLE hSCManager,
2013 LPCSTR lpServiceName,
2014 DWORD dwDesiredAccess,
2015 SC_RPC_HANDLE *phService)
2017 WINE_FIXME("\n");
2018 return ERROR_CALL_NOT_IMPLEMENTED;
2021 DWORD __cdecl svcctl_QueryServiceConfigA(
2022 SC_RPC_HANDLE hService,
2023 QUERY_SERVICE_CONFIGA *config,
2024 DWORD buf_size,
2025 DWORD *needed_size)
2027 WINE_FIXME("\n");
2028 return ERROR_CALL_NOT_IMPLEMENTED;
2031 DWORD __cdecl svcctl_QueryServiceLockStatusA(
2032 SC_RPC_HANDLE scmanager,
2033 QUERY_SERVICE_LOCK_STATUSA *status,
2034 DWORD buf_size,
2035 DWORD *needed_size)
2037 WINE_FIXME("\n");
2038 return ERROR_CALL_NOT_IMPLEMENTED;
2041 DWORD __cdecl svcctl_StartServiceA(
2042 SC_RPC_HANDLE service,
2043 DWORD argc,
2044 LPCSTR *args)
2046 WINE_FIXME("\n");
2047 return ERROR_CALL_NOT_IMPLEMENTED;
2050 DWORD __cdecl svcctl_GetServiceDisplayNameA(
2051 SC_RPC_HANDLE hSCManager,
2052 LPCSTR servicename,
2053 CHAR buffer[],
2054 DWORD *buf_size)
2056 WINE_FIXME("\n");
2057 return ERROR_CALL_NOT_IMPLEMENTED;
2060 DWORD __cdecl svcctl_GetServiceKeyNameA(
2061 SC_RPC_HANDLE hSCManager,
2062 LPCSTR servicename,
2063 CHAR buffer[],
2064 DWORD *buf_size)
2066 WINE_FIXME("\n");
2067 return ERROR_CALL_NOT_IMPLEMENTED;
2070 DWORD __cdecl svcctl_GetCurrentGroupStateW(void)
2072 WINE_FIXME("\n");
2073 return ERROR_CALL_NOT_IMPLEMENTED;
2076 DWORD __cdecl svcctl_EnumServiceGroupW(
2077 SC_RPC_HANDLE scmanager,
2078 DWORD service_type,
2079 DWORD service_state,
2080 BYTE *buffer,
2081 DWORD buf_size,
2082 DWORD *needed_size,
2083 DWORD *returned_size,
2084 DWORD *resume_index,
2085 LPCWSTR groupname)
2087 WINE_FIXME("\n");
2088 return ERROR_CALL_NOT_IMPLEMENTED;
2091 DWORD __cdecl svcctl_ChangeServiceConfig2A(
2092 SC_RPC_HANDLE service,
2093 SC_RPC_CONFIG_INFOA info)
2095 WINE_FIXME("\n");
2096 return ERROR_CALL_NOT_IMPLEMENTED;
2099 DWORD __cdecl svcctl_QueryServiceConfig2A(
2100 SC_RPC_HANDLE service,
2101 DWORD info_level,
2102 BYTE *buffer,
2103 DWORD buf_size,
2104 DWORD *needed_size)
2106 WINE_FIXME("\n");
2107 return ERROR_CALL_NOT_IMPLEMENTED;
2110 DWORD RPC_Init(void)
2112 WCHAR transport[] = SVCCTL_TRANSPORT;
2113 WCHAR endpoint[] = SVCCTL_ENDPOINT;
2114 DWORD err;
2116 if (!(cleanup_group = CreateThreadpoolCleanupGroup()))
2118 WINE_ERR("CreateThreadpoolCleanupGroup failed with error %lu\n", GetLastError());
2119 return GetLastError();
2122 if ((err = RpcServerUseProtseqEpW(transport, 0, endpoint, NULL)) != ERROR_SUCCESS)
2124 WINE_ERR("RpcServerUseProtseq failed with error %lu\n", err);
2125 return err;
2128 if ((err = RpcServerRegisterIf(svcctl_v2_0_s_ifspec, 0, 0)) != ERROR_SUCCESS)
2130 WINE_ERR("RpcServerRegisterIf failed with error %lu\n", err);
2131 return err;
2134 if ((err = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE)) != ERROR_SUCCESS)
2136 WINE_ERR("RpcServerListen failed with error %lu\n", err);
2137 return err;
2140 NtSetInformationProcess( GetCurrentProcess(), ProcessWineMakeProcessSystem,
2141 &exit_event, sizeof(HANDLE *) );
2142 return ERROR_SUCCESS;
2145 void RPC_Stop(void)
2147 RpcMgmtStopServerListening(NULL);
2148 RpcServerUnregisterIf(svcctl_v2_0_s_ifspec, NULL, TRUE);
2149 RpcMgmtWaitServerListen();
2151 CloseThreadpoolCleanupGroupMembers(cleanup_group, TRUE, NULL);
2152 CloseThreadpoolCleanupGroup(cleanup_group);
2153 CloseHandle(exit_event);
2156 void __RPC_USER SC_RPC_HANDLE_rundown(SC_RPC_HANDLE handle)
2158 SC_RPC_HANDLE_destroy(handle);
2161 void __RPC_USER SC_NOTIFY_RPC_HANDLE_rundown(SC_NOTIFY_RPC_HANDLE handle)
2165 void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
2167 return malloc(len);
2170 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
2172 free(ptr);