gdiplus: In GdipImageSelectActiveFrame rely on codec->select_func() to fail.
[wine.git] / programs / services / rpc.c
blobb8e42f1393835fa34de69e4b0d98d4f98e471b13
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
23 #include <stdarg.h>
24 #include <windows.h>
25 #include <winternl.h>
26 #include <winsvc.h>
27 #include <ntsecapi.h>
28 #include <rpc.h>
30 #include "wine/list.h"
31 #include "wine/debug.h"
33 #include "services.h"
34 #include "svcctl.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(service);
38 static const GENERIC_MAPPING g_scm_generic =
40 (STANDARD_RIGHTS_READ | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS),
41 (STANDARD_RIGHTS_WRITE | SC_MANAGER_CREATE_SERVICE | SC_MANAGER_MODIFY_BOOT_CONFIG),
42 (STANDARD_RIGHTS_EXECUTE | SC_MANAGER_CONNECT | SC_MANAGER_LOCK),
43 SC_MANAGER_ALL_ACCESS
46 static const GENERIC_MAPPING g_svc_generic =
48 (STANDARD_RIGHTS_READ | SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS | SERVICE_INTERROGATE | SERVICE_ENUMERATE_DEPENDENTS),
49 (STANDARD_RIGHTS_WRITE | SERVICE_CHANGE_CONFIG),
50 (STANDARD_RIGHTS_EXECUTE | SERVICE_START | SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_USER_DEFINED_CONTROL),
51 SERVICE_ALL_ACCESS
54 typedef enum
56 SC_HTYPE_DONT_CARE = 0,
57 SC_HTYPE_MANAGER,
58 SC_HTYPE_SERVICE,
59 SC_HTYPE_NOTIFY
60 } SC_HANDLE_TYPE;
62 struct sc_handle
64 SC_HANDLE_TYPE type;
65 DWORD access;
68 struct sc_manager_handle /* service control manager handle */
70 struct sc_handle hdr;
71 struct scmdatabase *db;
74 struct sc_notify_handle
76 struct sc_handle hdr;
77 HANDLE event;
78 DWORD notify_mask;
79 LONG ref;
80 SC_RPC_NOTIFY_PARAMS_LIST *params_list;
83 struct sc_service_handle /* service handle */
85 struct sc_handle hdr;
86 struct list entry;
87 BOOL status_notified;
88 struct service_entry *service_entry;
89 struct sc_notify_handle *notify;
92 static void sc_notify_retain(struct sc_notify_handle *notify)
94 InterlockedIncrement(&notify->ref);
97 static void sc_notify_release(struct sc_notify_handle *notify)
99 ULONG r = InterlockedDecrement(&notify->ref);
100 if (r == 0)
102 CloseHandle(notify->event);
103 if (notify->params_list)
104 free(notify->params_list->NotifyParamsArray[0].params);
105 free(notify->params_list);
106 free(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 free(old_cfg->lpBinaryPathName);
202 if (old_cfg->lpLoadOrderGroup != new_cfg->lpLoadOrderGroup)
203 free(old_cfg->lpLoadOrderGroup);
205 if (old_cfg->lpServiceStartName != new_cfg->lpServiceStartName)
206 free(old_cfg->lpServiceStartName);
208 if (old_cfg->lpDisplayName != new_cfg->lpDisplayName)
209 free(old_cfg->lpDisplayName);
211 if (old->dependOnServices != new->dependOnServices)
212 free(old->dependOnServices);
214 if (old->dependOnGroups != new->dependOnGroups)
215 free(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 = malloc(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 free(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 free(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 = malloc(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 = malloc((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 = malloc((len_groups + 1) * sizeof(WCHAR));
520 if (!groups)
522 free(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 = wcsdup(lpBinaryPathName);
595 entry->config.lpLoadOrderGroup = wcsdup(lpLoadOrderGroup);
596 entry->config.lpServiceStartName = wcsdup(lpServiceStartName);
597 entry->config.lpDisplayName = wcsdup(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 = wcsdup(service->service_entry->config.lpBinaryPathName);
706 config->lpLoadOrderGroup = wcsdup(service->service_entry->config.lpLoadOrderGroup);
707 config->dwTagId = service->service_entry->config.dwTagId;
708 config->lpDependencies = NULL; /* TODO */
709 config->lpServiceStartName = wcsdup(service->service_entry->config.lpServiceStartName);
710 config->lpDisplayName = wcsdup(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 = wcsdup(lpBinaryPathName);
807 if (lpLoadOrderGroup != NULL)
808 new_entry.config.lpLoadOrderGroup = wcsdup(lpLoadOrderGroup);
810 if (lpServiceStartName != NULL)
811 new_entry.config.lpServiceStartName = wcsdup(lpServiceStartName);
813 if (lpDisplayName != NULL)
814 new_entry.config.lpDisplayName = wcsdup(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 = calloc(1, sizeof(SC_RPC_NOTIFY_PARAMS_LIST));
845 if (!list)
846 return;
847 if (!(cparams = calloc(1, sizeof(SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2))))
849 free(list);
850 return;
853 cparams->dwNotifyMask = notify->notify_mask;
854 fill_status_process(&cparams->ServiceStatus, service);
855 cparams->dwNotificationStatus = ERROR_SUCCESS;
856 cparams->dwNotificationTriggered = 1 << (cparams->ServiceStatus.dwCurrentState - SERVICE_STOPPED);
857 cparams->pszServiceNames = NULL;
859 list->cElements = 1;
861 list->NotifyParamsArray[0].dwInfoLevel = 2;
862 list->NotifyParamsArray[0].params = cparams;
864 InterlockedExchangePointer((void**)&notify->params_list, list);
866 SetEvent(notify->event);
869 void notify_service_state(struct service_entry *service)
871 struct sc_service_handle *service_handle;
872 DWORD mask;
874 mask = 1 << (service->status.dwCurrentState - SERVICE_STOPPED);
875 LIST_FOR_EACH_ENTRY(service_handle, &service->handles, struct sc_service_handle, entry)
877 struct sc_notify_handle *notify = service_handle->notify;
878 if (notify && (notify->notify_mask & mask))
880 fill_notify(notify, service);
881 sc_notify_release(notify);
882 service_handle->notify = NULL;
883 service_handle->status_notified = TRUE;
885 else
886 service_handle->status_notified = FALSE;
890 DWORD __cdecl svcctl_SetServiceStatus(SC_RPC_HANDLE handle, SERVICE_STATUS *status)
892 struct sc_service_handle *service;
893 struct process_entry *process;
894 DWORD err;
896 WINE_TRACE("(%p, %p)\n", handle, status);
898 if ((err = validate_service_handle(handle, SERVICE_SET_STATUS, &service)) != 0)
899 return err;
901 service_lock(service->service_entry);
903 /* FIXME: be a bit more discriminant about what parts of the status we set
904 * and check that fields are valid */
905 service->service_entry->status.dwCurrentState = status->dwCurrentState;
906 service->service_entry->status.dwControlsAccepted = status->dwControlsAccepted;
907 service->service_entry->status.dwWin32ExitCode = status->dwWin32ExitCode;
908 service->service_entry->status.dwServiceSpecificExitCode = status->dwServiceSpecificExitCode;
909 service->service_entry->status.dwCheckPoint = status->dwCheckPoint;
910 service->service_entry->status.dwWaitHint = status->dwWaitHint;
911 SetEvent(service->service_entry->status_changed_event);
913 if ((process = service->service_entry->process) &&
914 status->dwCurrentState == SERVICE_STOPPED)
916 service->service_entry->process = NULL;
917 if (!--process->use_count)
918 terminate_after_timeout(process, service_kill_timeout);
919 if (service->service_entry->shared_process && process->use_count <= 1)
920 shutdown_shared_process(process);
921 release_process(process);
924 notify_service_state(service->service_entry);
925 service_unlock(service->service_entry);
927 return ERROR_SUCCESS;
930 DWORD __cdecl svcctl_ChangeServiceConfig2W( SC_RPC_HANDLE hService, SC_RPC_CONFIG_INFOW config )
932 struct sc_service_handle *service;
933 DWORD err;
935 if ((err = validate_service_handle(hService, SERVICE_CHANGE_CONFIG, &service)) != 0)
936 return err;
938 switch (config.dwInfoLevel)
940 case SERVICE_CONFIG_DESCRIPTION:
942 WCHAR *descr = NULL;
944 if (!config.descr->lpDescription)
945 break;
947 if (config.descr->lpDescription[0])
949 if (!(descr = wcsdup( config.descr->lpDescription )))
950 return ERROR_NOT_ENOUGH_MEMORY;
953 WINE_TRACE( "changing service %p descr to %s\n", service, wine_dbgstr_w(descr) );
954 service_lock( service->service_entry );
955 free( service->service_entry->description );
956 service->service_entry->description = descr;
957 save_service_config( service->service_entry );
958 service_unlock( service->service_entry );
960 break;
961 case SERVICE_CONFIG_FAILURE_ACTIONS:
962 WINE_FIXME( "SERVICE_CONFIG_FAILURE_ACTIONS not implemented: period %lu msg %s cmd %s\n",
963 config.actions->dwResetPeriod,
964 wine_dbgstr_w(config.actions->lpRebootMsg),
965 wine_dbgstr_w(config.actions->lpCommand) );
966 break;
967 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
968 WINE_TRACE( "changing service %p preshutdown timeout to %ld\n",
969 service, config.preshutdown->dwPreshutdownTimeout );
970 service_lock( service->service_entry );
971 service->service_entry->preshutdown_timeout = config.preshutdown->dwPreshutdownTimeout;
972 save_service_config( service->service_entry );
973 service_unlock( service->service_entry );
974 break;
975 default:
976 WINE_FIXME("level %lu not implemented\n", config.dwInfoLevel);
977 err = ERROR_INVALID_LEVEL;
978 break;
980 return err;
983 DWORD __cdecl svcctl_QueryServiceConfig2W( SC_RPC_HANDLE hService, DWORD level,
984 BYTE *buffer, DWORD size, LPDWORD needed )
986 struct sc_service_handle *service;
987 DWORD err;
989 memset(buffer, 0, size);
991 if ((err = validate_service_handle(hService, SERVICE_QUERY_CONFIG, &service)) != 0)
992 return err;
994 switch (level)
996 case SERVICE_CONFIG_DESCRIPTION:
998 struct service_description *desc = (struct service_description *)buffer;
999 DWORD total_size = sizeof(*desc);
1001 service_lock(service->service_entry);
1002 if (service->service_entry->description)
1003 total_size += lstrlenW(service->service_entry->description) * sizeof(WCHAR);
1005 *needed = total_size;
1006 if (size >= total_size)
1008 if (service->service_entry->description)
1010 lstrcpyW( desc->description, service->service_entry->description );
1011 desc->size = total_size - FIELD_OFFSET(struct service_description, description);
1013 else
1015 desc->description[0] = 0;
1016 desc->size = 0;
1019 else err = ERROR_INSUFFICIENT_BUFFER;
1020 service_unlock(service->service_entry);
1022 break;
1024 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
1025 service_lock(service->service_entry);
1027 *needed = sizeof(SERVICE_PRESHUTDOWN_INFO);
1028 if (size >= *needed)
1029 ((LPSERVICE_PRESHUTDOWN_INFO)buffer)->dwPreshutdownTimeout =
1030 service->service_entry->preshutdown_timeout;
1031 else err = ERROR_INSUFFICIENT_BUFFER;
1033 service_unlock(service->service_entry);
1034 break;
1036 default:
1037 WINE_FIXME("level %lu not implemented\n", level);
1038 err = ERROR_INVALID_LEVEL;
1039 break;
1041 return err;
1044 DWORD __cdecl svcctl_QueryServiceStatusEx(
1045 SC_RPC_HANDLE hService,
1046 SC_STATUS_TYPE InfoLevel,
1047 BYTE *lpBuffer,
1048 DWORD cbBufSize,
1049 LPDWORD pcbBytesNeeded)
1051 struct sc_service_handle *service;
1052 DWORD err;
1053 LPSERVICE_STATUS_PROCESS pSvcStatusData;
1055 memset(lpBuffer, 0, cbBufSize);
1057 if ((err = validate_service_handle(hService, SERVICE_QUERY_STATUS, &service)) != 0)
1058 return err;
1060 if (InfoLevel != SC_STATUS_PROCESS_INFO)
1061 return ERROR_INVALID_LEVEL;
1063 pSvcStatusData = (LPSERVICE_STATUS_PROCESS) lpBuffer;
1064 if (pSvcStatusData == NULL)
1065 return ERROR_INVALID_PARAMETER;
1067 if (cbBufSize < sizeof(SERVICE_STATUS_PROCESS))
1069 if( pcbBytesNeeded != NULL)
1070 *pcbBytesNeeded = sizeof(SERVICE_STATUS_PROCESS);
1072 return ERROR_INSUFFICIENT_BUFFER;
1075 service_lock(service->service_entry);
1076 fill_status_process(pSvcStatusData, service->service_entry);
1077 service_unlock(service->service_entry);
1079 return ERROR_SUCCESS;
1082 /******************************************************************************
1083 * service_accepts_control
1085 static BOOL service_accepts_control(const struct service_entry *service, DWORD dwControl)
1087 DWORD a = service->status.dwControlsAccepted;
1089 if (dwControl >= 128 && dwControl <= 255)
1090 return TRUE;
1092 switch (dwControl)
1094 case SERVICE_CONTROL_INTERROGATE:
1095 return TRUE;
1096 case SERVICE_CONTROL_STOP:
1097 if (a&SERVICE_ACCEPT_STOP)
1098 return TRUE;
1099 break;
1100 case SERVICE_CONTROL_SHUTDOWN:
1101 if (a&SERVICE_ACCEPT_SHUTDOWN)
1102 return TRUE;
1103 break;
1104 case SERVICE_CONTROL_PAUSE:
1105 case SERVICE_CONTROL_CONTINUE:
1106 if (a&SERVICE_ACCEPT_PAUSE_CONTINUE)
1107 return TRUE;
1108 break;
1109 case SERVICE_CONTROL_PARAMCHANGE:
1110 if (a&SERVICE_ACCEPT_PARAMCHANGE)
1111 return TRUE;
1112 break;
1113 case SERVICE_CONTROL_NETBINDADD:
1114 case SERVICE_CONTROL_NETBINDREMOVE:
1115 case SERVICE_CONTROL_NETBINDENABLE:
1116 case SERVICE_CONTROL_NETBINDDISABLE:
1117 if (a&SERVICE_ACCEPT_NETBINDCHANGE)
1118 return TRUE;
1119 case SERVICE_CONTROL_HARDWAREPROFILECHANGE:
1120 if (a&SERVICE_ACCEPT_HARDWAREPROFILECHANGE)
1121 return TRUE;
1122 break;
1123 case SERVICE_CONTROL_POWEREVENT:
1124 if (a&SERVICE_ACCEPT_POWEREVENT)
1125 return TRUE;
1126 break;
1127 case SERVICE_CONTROL_SESSIONCHANGE:
1128 if (a&SERVICE_ACCEPT_SESSIONCHANGE)
1129 return TRUE;
1130 break;
1132 return FALSE;
1135 /******************************************************************************
1136 * process_send_command
1138 static BOOL process_send_command(struct process_entry *process, const void *data, DWORD size, DWORD *result)
1140 OVERLAPPED overlapped;
1141 DWORD count, ret;
1142 BOOL r;
1144 overlapped.Offset = 0;
1145 overlapped.OffsetHigh = 0;
1146 overlapped.hEvent = process->overlapped_event;
1147 r = WriteFile(process->control_pipe, data, size, &count, &overlapped);
1148 if (!r && GetLastError() == ERROR_IO_PENDING)
1150 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1151 if (ret == WAIT_TIMEOUT)
1153 WINE_ERR("sending command timed out\n");
1154 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1155 return FALSE;
1157 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1159 if (!r || count != size)
1161 WINE_ERR("service protocol error - failed to write pipe!\n");
1162 *result = (!r ? GetLastError() : ERROR_WRITE_FAULT);
1163 return FALSE;
1165 r = ReadFile(process->control_pipe, result, sizeof *result, &count, &overlapped);
1166 if (!r && GetLastError() == ERROR_IO_PENDING)
1168 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1169 if (ret == WAIT_TIMEOUT)
1171 WINE_ERR("receiving command result timed out\n");
1172 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1173 return FALSE;
1175 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1177 if (!r || count != sizeof *result)
1179 WINE_ERR("service protocol error - failed to read pipe "
1180 "r = %d count = %ld!\n", r, count);
1181 *result = (!r ? GetLastError() : ERROR_READ_FAULT);
1182 return FALSE;
1185 return TRUE;
1188 /******************************************************************************
1189 * process_send_control
1191 BOOL process_send_control(struct process_entry *process, BOOL shared_process, const WCHAR *name,
1192 DWORD control, const BYTE *data, DWORD data_size, DWORD *result)
1194 service_start_info *ssi;
1195 DWORD len;
1196 BOOL r;
1198 if (shared_process)
1200 control |= SERVICE_CONTROL_FORWARD_FLAG;
1201 data = (BYTE *)name;
1202 data_size = (lstrlenW(name) + 1) * sizeof(WCHAR);
1203 name = emptyW;
1206 /* calculate how much space we need to send the startup info */
1207 len = (lstrlenW(name) + 1) * sizeof(WCHAR) + data_size;
1209 ssi = malloc(FIELD_OFFSET(service_start_info, data[len]));
1210 ssi->magic = SERVICE_PROTOCOL_MAGIC;
1211 ssi->control = control;
1212 ssi->total_size = FIELD_OFFSET(service_start_info, data[len]);
1213 ssi->name_size = lstrlenW(name) + 1;
1214 lstrcpyW((WCHAR *)ssi->data, name);
1215 if (data_size) memcpy(&ssi->data[ssi->name_size * sizeof(WCHAR)], data, data_size);
1217 r = process_send_command(process, ssi, ssi->total_size, result);
1218 free(ssi);
1219 return r;
1222 DWORD __cdecl svcctl_StartServiceW(
1223 SC_RPC_HANDLE hService,
1224 DWORD dwNumServiceArgs,
1225 LPCWSTR *lpServiceArgVectors)
1227 struct sc_service_handle *service;
1228 DWORD err;
1230 WINE_TRACE("(%p, %ld, %p)\n", hService, dwNumServiceArgs, lpServiceArgVectors);
1232 if ((err = validate_service_handle(hService, SERVICE_START, &service)) != 0)
1233 return err;
1235 if (service->service_entry->config.dwStartType == SERVICE_DISABLED)
1236 return ERROR_SERVICE_DISABLED;
1238 if (!scmdatabase_lock_startup(service->service_entry->db, 3000))
1239 return ERROR_SERVICE_DATABASE_LOCKED;
1241 err = service_start(service->service_entry, dwNumServiceArgs, lpServiceArgVectors);
1243 scmdatabase_unlock_startup(service->service_entry->db);
1244 return err;
1247 DWORD __cdecl svcctl_ControlService(
1248 SC_RPC_HANDLE hService,
1249 DWORD dwControl,
1250 SERVICE_STATUS *lpServiceStatus)
1252 DWORD access_required;
1253 struct sc_service_handle *service;
1254 struct process_entry *process;
1255 BOOL shared_process;
1256 DWORD result;
1258 WINE_TRACE("(%p, %ld, %p)\n", hService, dwControl, lpServiceStatus);
1260 switch (dwControl)
1262 case SERVICE_CONTROL_CONTINUE:
1263 case SERVICE_CONTROL_NETBINDADD:
1264 case SERVICE_CONTROL_NETBINDDISABLE:
1265 case SERVICE_CONTROL_NETBINDENABLE:
1266 case SERVICE_CONTROL_NETBINDREMOVE:
1267 case SERVICE_CONTROL_PARAMCHANGE:
1268 case SERVICE_CONTROL_PAUSE:
1269 access_required = SERVICE_PAUSE_CONTINUE;
1270 break;
1271 case SERVICE_CONTROL_INTERROGATE:
1272 access_required = SERVICE_INTERROGATE;
1273 break;
1274 case SERVICE_CONTROL_STOP:
1275 access_required = SERVICE_STOP;
1276 break;
1277 default:
1278 if (dwControl >= 128 && dwControl <= 255)
1279 access_required = SERVICE_USER_DEFINED_CONTROL;
1280 else
1281 return ERROR_INVALID_PARAMETER;
1284 if ((result = validate_service_handle(hService, access_required, &service)) != 0)
1285 return result;
1287 service_lock(service->service_entry);
1289 result = ERROR_SUCCESS;
1290 switch (service->service_entry->status.dwCurrentState)
1292 case SERVICE_STOPPED:
1293 result = ERROR_SERVICE_NOT_ACTIVE;
1294 break;
1295 case SERVICE_START_PENDING:
1296 if (dwControl==SERVICE_CONTROL_STOP)
1297 break;
1298 /* fall through */
1299 case SERVICE_STOP_PENDING:
1300 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1301 break;
1304 if (result == ERROR_SUCCESS && service->service_entry->force_shutdown)
1306 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1307 if ((process = service->service_entry->process))
1309 service->service_entry->process = NULL;
1310 if (!--process->use_count) process_terminate(process);
1311 release_process(process);
1315 if (result != ERROR_SUCCESS)
1317 if (lpServiceStatus) *lpServiceStatus = service->service_entry->status;
1318 service_unlock(service->service_entry);
1319 return result;
1322 if (!service_accepts_control(service->service_entry, dwControl))
1324 service_unlock(service->service_entry);
1325 return ERROR_INVALID_SERVICE_CONTROL;
1328 /* Remember that we tried to shutdown this service. When the service is
1329 * still running on the second invocation, it will be forcefully killed. */
1330 if (dwControl == SERVICE_CONTROL_STOP)
1331 service->service_entry->force_shutdown = TRUE;
1333 /* Hold a reference to the process while sending the command. */
1334 process = grab_process(service->service_entry->process);
1335 shared_process = service->service_entry->shared_process;
1336 service_unlock(service->service_entry);
1338 if (!process)
1339 return ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1341 result = WaitForSingleObject(process->control_mutex, 30000);
1342 if (result != WAIT_OBJECT_0)
1344 release_process(process);
1345 return ERROR_SERVICE_REQUEST_TIMEOUT;
1348 if (process_send_control(process, shared_process, service->service_entry->name,
1349 dwControl, NULL, 0, &result))
1350 result = ERROR_SUCCESS;
1352 if (lpServiceStatus)
1354 service_lock(service->service_entry);
1355 *lpServiceStatus = service->service_entry->status;
1356 service_unlock(service->service_entry);
1359 ReleaseMutex(process->control_mutex);
1360 release_process(process);
1361 return result;
1364 DWORD __cdecl svcctl_CloseServiceHandle(
1365 SC_RPC_HANDLE *handle)
1367 WINE_TRACE("(&%p)\n", *handle);
1369 SC_RPC_HANDLE_destroy(*handle);
1370 *handle = NULL;
1372 return ERROR_SUCCESS;
1375 void __RPC_USER SC_RPC_LOCK_rundown(SC_RPC_LOCK hLock)
1379 DWORD __cdecl svcctl_LockServiceDatabase(SC_RPC_HANDLE manager, SC_RPC_LOCK *lock)
1381 TRACE("(%p, %p)\n", manager, lock);
1383 *lock = (SC_RPC_LOCK)0xdeadbeef;
1384 return ERROR_SUCCESS;
1387 DWORD __cdecl svcctl_UnlockServiceDatabase(SC_RPC_LOCK *lock)
1389 TRACE("(&%p)\n", *lock);
1391 *lock = NULL;
1392 return ERROR_SUCCESS;
1395 static BOOL map_state(DWORD state, DWORD mask)
1397 switch (state)
1399 case SERVICE_START_PENDING:
1400 case SERVICE_STOP_PENDING:
1401 case SERVICE_RUNNING:
1402 case SERVICE_CONTINUE_PENDING:
1403 case SERVICE_PAUSE_PENDING:
1404 case SERVICE_PAUSED:
1405 if (SERVICE_ACTIVE & mask) return TRUE;
1406 break;
1407 case SERVICE_STOPPED:
1408 if (SERVICE_INACTIVE & mask) return TRUE;
1409 break;
1410 default:
1411 WINE_ERR("unknown state %lu\n", state);
1412 break;
1414 return FALSE;
1417 DWORD __cdecl svcctl_EnumServicesStatusW(
1418 SC_RPC_HANDLE hmngr,
1419 DWORD type,
1420 DWORD state,
1421 BYTE *buffer,
1422 DWORD size,
1423 LPDWORD needed,
1424 LPDWORD returned,
1425 LPDWORD resume)
1427 DWORD err, sz, total_size, num_services, offset;
1428 struct sc_manager_handle *manager;
1429 struct service_entry *service;
1430 struct enum_service_status *s;
1432 WINE_TRACE("(%p, 0x%lx, 0x%lx, %p, %lu, %p, %p, %p)\n", hmngr, type, state, buffer, size, needed, returned, resume);
1434 if (!type || !state)
1435 return ERROR_INVALID_PARAMETER;
1437 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1438 return err;
1440 if (resume)
1441 WINE_FIXME("resume index not supported\n");
1443 scmdatabase_lock(manager->db);
1445 total_size = num_services = 0;
1446 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1448 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1450 total_size += sizeof(*s);
1451 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1452 if (service->config.lpDisplayName)
1454 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1456 num_services++;
1459 *returned = 0;
1460 *needed = total_size;
1461 if (total_size > size)
1463 scmdatabase_unlock(manager->db);
1464 return ERROR_MORE_DATA;
1466 s = (struct enum_service_status *)buffer;
1467 offset = num_services * sizeof(struct enum_service_status);
1468 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1470 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1472 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1473 memcpy(buffer + offset, service->name, sz);
1474 s->service_name = offset;
1475 offset += sz;
1477 if (!service->config.lpDisplayName) s->display_name = 0;
1478 else
1480 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1481 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1482 s->display_name = offset;
1483 offset += sz;
1485 s->service_status = service->status;
1486 s++;
1489 *returned = num_services;
1490 *needed = 0;
1491 scmdatabase_unlock(manager->db);
1492 return ERROR_SUCCESS;
1495 static struct service_entry *find_service_by_group(struct scmdatabase *db, const WCHAR *group)
1497 struct service_entry *service;
1498 LIST_FOR_EACH_ENTRY(service, &db->services, struct service_entry, entry)
1500 if (service->config.lpLoadOrderGroup && !wcsicmp(group, service->config.lpLoadOrderGroup))
1501 return service;
1503 return NULL;
1506 static BOOL match_group(const WCHAR *g1, const WCHAR *g2)
1508 if (!g2) return TRUE;
1509 if (!g2[0] && (!g1 || !g1[0])) return TRUE;
1510 if (g1 && !lstrcmpW(g1, g2)) return TRUE;
1511 return FALSE;
1514 DWORD __cdecl svcctl_EnumServicesStatusExA(
1515 SC_RPC_HANDLE scmanager,
1516 SC_ENUM_TYPE info_level,
1517 DWORD service_type,
1518 DWORD service_state,
1519 BYTE *buffer,
1520 DWORD buf_size,
1521 DWORD *needed_size,
1522 DWORD *services_count,
1523 DWORD *resume_index,
1524 LPCSTR groupname)
1526 WINE_FIXME("\n");
1527 return ERROR_CALL_NOT_IMPLEMENTED;
1530 DWORD __cdecl svcctl_EnumServicesStatusExW(
1531 SC_RPC_HANDLE hmngr,
1532 SC_ENUM_TYPE info_level,
1533 DWORD type,
1534 DWORD state,
1535 BYTE *buffer,
1536 DWORD size,
1537 LPDWORD needed,
1538 LPDWORD returned,
1539 DWORD *resume_handle,
1540 LPCWSTR group)
1542 DWORD err, sz, total_size, num_services;
1543 DWORD_PTR offset;
1544 struct sc_manager_handle *manager;
1545 struct service_entry *service;
1546 struct enum_service_status_process *s;
1548 WINE_TRACE("(%p, 0x%lx, 0x%lx, %p, %lu, %p, %p, %s)\n", hmngr, type, state, buffer, size,
1549 needed, returned, wine_dbgstr_w(group));
1551 if (resume_handle)
1552 FIXME("resume handle not supported\n");
1554 if (!type || !state)
1555 return ERROR_INVALID_PARAMETER;
1557 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1558 return err;
1560 scmdatabase_lock(manager->db);
1562 if (group && !find_service_by_group(manager->db, group))
1564 scmdatabase_unlock(manager->db);
1565 return ERROR_SERVICE_DOES_NOT_EXIST;
1568 total_size = num_services = 0;
1569 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1571 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1572 && match_group(service->config.lpLoadOrderGroup, group))
1574 total_size += sizeof(*s);
1575 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1576 if (service->config.lpDisplayName)
1578 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1580 num_services++;
1583 *returned = 0;
1584 *needed = total_size;
1585 if (total_size > size)
1587 scmdatabase_unlock(manager->db);
1588 return ERROR_MORE_DATA;
1590 s = (struct enum_service_status_process *)buffer;
1591 offset = num_services * sizeof(*s);
1592 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1594 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1595 && match_group(service->config.lpLoadOrderGroup, group))
1597 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1598 memcpy(buffer + offset, service->name, sz);
1599 s->service_name = offset;
1600 offset += sz;
1602 if (!service->config.lpDisplayName) s->display_name = 0;
1603 else
1605 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1606 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1607 s->display_name = offset;
1608 offset += sz;
1610 fill_status_process(&s->service_status_process, service);
1611 s++;
1614 *returned = num_services;
1615 *needed = 0;
1616 scmdatabase_unlock(manager->db);
1617 return ERROR_SUCCESS;
1620 DWORD __cdecl svcctl_unknown43(void)
1622 WINE_FIXME("\n");
1623 return ERROR_CALL_NOT_IMPLEMENTED;
1626 DWORD __cdecl svcctl_CreateServiceWOW64A(
1627 SC_RPC_HANDLE scmanager,
1628 LPCSTR servicename,
1629 LPCSTR displayname,
1630 DWORD accessmask,
1631 DWORD service_type,
1632 DWORD start_type,
1633 DWORD error_control,
1634 LPCSTR imagepath,
1635 LPCSTR loadordergroup,
1636 DWORD *tagid,
1637 const BYTE *dependencies,
1638 DWORD depend_size,
1639 LPCSTR start_name,
1640 const BYTE *password,
1641 DWORD password_size,
1642 SC_RPC_HANDLE *service)
1644 WINE_FIXME("\n");
1645 return ERROR_CALL_NOT_IMPLEMENTED;
1648 DWORD __cdecl svcctl_CreateServiceWOW64W(
1649 SC_RPC_HANDLE scmanager,
1650 LPCWSTR servicename,
1651 LPCWSTR displayname,
1652 DWORD accessmask,
1653 DWORD service_type,
1654 DWORD start_type,
1655 DWORD error_control,
1656 LPCWSTR imagepath,
1657 LPCWSTR loadordergroup,
1658 DWORD *tagid,
1659 const BYTE *dependencies,
1660 DWORD depend_size,
1661 LPCWSTR start_name,
1662 const BYTE *password,
1663 DWORD password_size,
1664 SC_RPC_HANDLE *service)
1666 WINE_TRACE("(%s, %s, 0x%lx, %s)\n", wine_dbgstr_w(servicename), wine_dbgstr_w(displayname), accessmask, wine_dbgstr_w(imagepath));
1667 return create_serviceW(scmanager, servicename, displayname, accessmask, service_type, start_type, error_control, imagepath,
1668 loadordergroup, tagid, dependencies, depend_size, start_name, password, password_size, service, TRUE);
1671 DWORD __cdecl svcctl_unknown46(void)
1673 WINE_FIXME("\n");
1674 return ERROR_CALL_NOT_IMPLEMENTED;
1677 DWORD __cdecl svcctl_NotifyServiceStatusChange(
1678 SC_RPC_HANDLE handle,
1679 SC_RPC_NOTIFY_PARAMS params,
1680 GUID *clientprocessguid,
1681 GUID *scmprocessguid,
1682 BOOL *createremotequeue,
1683 SC_NOTIFY_RPC_HANDLE *hNotify)
1685 DWORD err, mask;
1686 struct sc_manager_handle *manager = NULL;
1687 struct sc_service_handle *service = NULL;
1688 struct sc_notify_handle *notify;
1689 struct sc_handle *hdr = handle;
1691 WINE_TRACE("(%p, NotifyMask: 0x%lx, %p, %p, %p, %p)\n", handle,
1692 params.params->dwNotifyMask, clientprocessguid, scmprocessguid,
1693 createremotequeue, hNotify);
1695 switch (hdr->type)
1697 case SC_HTYPE_SERVICE:
1698 err = validate_service_handle(handle, SERVICE_QUERY_STATUS, &service);
1699 break;
1700 case SC_HTYPE_MANAGER:
1701 err = validate_scm_handle(handle, SC_MANAGER_ENUMERATE_SERVICE, &manager);
1702 break;
1703 default:
1704 err = ERROR_INVALID_HANDLE;
1705 break;
1708 if (err != ERROR_SUCCESS)
1709 return err;
1711 if (manager)
1713 WARN("Need support for service creation/deletion notifications\n");
1714 return ERROR_CALL_NOT_IMPLEMENTED;
1717 notify = calloc(1, sizeof(*notify));
1718 if (!notify)
1719 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
1721 notify->hdr.type = SC_HTYPE_NOTIFY;
1722 notify->hdr.access = 0;
1724 notify->event = CreateEventW(NULL, TRUE, FALSE, NULL);
1726 notify->notify_mask = params.params->dwNotifyMask;
1728 service_lock(service->service_entry);
1730 if (service->notify)
1732 service_unlock(service->service_entry);
1733 sc_notify_release(notify);
1734 return ERROR_ALREADY_REGISTERED;
1737 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
1738 if (!service->status_notified && (notify->notify_mask & mask))
1740 fill_notify(notify, service->service_entry);
1741 service->status_notified = TRUE;
1743 else
1745 sc_notify_retain(notify);
1746 service->notify = notify;
1749 sc_notify_retain(notify);
1750 *hNotify = &notify->hdr;
1752 service_unlock(service->service_entry);
1754 return ERROR_SUCCESS;
1757 DWORD __cdecl svcctl_GetNotifyResults(
1758 SC_NOTIFY_RPC_HANDLE hNotify,
1759 SC_RPC_NOTIFY_PARAMS_LIST **pList)
1761 DWORD err;
1762 struct sc_notify_handle *notify;
1764 WINE_TRACE("(%p, %p)\n", hNotify, pList);
1766 if (!pList)
1767 return ERROR_INVALID_PARAMETER;
1769 *pList = NULL;
1771 if ((err = validate_notify_handle(hNotify, 0, &notify)) != 0)
1772 return err;
1774 sc_notify_retain(notify);
1775 /* block until there is a result */
1776 err = WaitForSingleObject(notify->event, INFINITE);
1778 if (err != WAIT_OBJECT_0)
1780 sc_notify_release(notify);
1781 return err;
1784 *pList = InterlockedExchangePointer((void**)&notify->params_list, NULL);
1785 if (!*pList)
1787 sc_notify_release(notify);
1788 return ERROR_REQUEST_ABORTED;
1791 sc_notify_release(notify);
1793 return ERROR_SUCCESS;
1796 DWORD __cdecl svcctl_CloseNotifyHandle(
1797 SC_NOTIFY_RPC_HANDLE *hNotify,
1798 BOOL *apc_fired)
1800 struct sc_notify_handle *notify;
1801 DWORD err;
1803 WINE_TRACE("(%p, %p)\n", hNotify, apc_fired);
1805 if ((err = validate_notify_handle(*hNotify, 0, &notify)) != 0)
1806 return err;
1808 sc_notify_release(notify);
1810 return ERROR_SUCCESS;
1813 DWORD __cdecl svcctl_ControlServiceExA(
1814 SC_RPC_HANDLE service,
1815 DWORD control,
1816 DWORD info_level,
1817 SC_RPC_SERVICE_CONTROL_IN_PARAMSA *in_params,
1818 SC_RPC_SERVICE_CONTROL_OUT_PARAMSA *out_params)
1820 WINE_FIXME("\n");
1821 return ERROR_CALL_NOT_IMPLEMENTED;
1824 DWORD __cdecl svcctl_ControlServiceExW(
1825 SC_RPC_HANDLE service,
1826 DWORD control,
1827 DWORD info_level,
1828 SC_RPC_SERVICE_CONTROL_IN_PARAMSW *in_params,
1829 SC_RPC_SERVICE_CONTROL_OUT_PARAMSW *out_params)
1831 WINE_FIXME("\n");
1832 return ERROR_CALL_NOT_IMPLEMENTED;
1835 DWORD __cdecl svcctl_unknown52(void)
1837 WINE_FIXME("\n");
1838 return ERROR_CALL_NOT_IMPLEMENTED;
1841 DWORD __cdecl svcctl_unknown53(void)
1843 WINE_FIXME("\n");
1844 return ERROR_CALL_NOT_IMPLEMENTED;
1847 DWORD __cdecl svcctl_unknown54(void)
1849 WINE_FIXME("\n");
1850 return ERROR_CALL_NOT_IMPLEMENTED;
1853 DWORD __cdecl svcctl_unknown55(void)
1855 WINE_FIXME("\n");
1856 return ERROR_CALL_NOT_IMPLEMENTED;
1859 DWORD __cdecl svcctl_QueryServiceConfigEx(
1860 SC_RPC_HANDLE service,
1861 DWORD info_level,
1862 SC_RPC_CONFIG_INFOW *info)
1864 WINE_FIXME("\n");
1865 return ERROR_CALL_NOT_IMPLEMENTED;
1868 DWORD __cdecl svcctl_QueryServiceObjectSecurity(
1869 SC_RPC_HANDLE service,
1870 SECURITY_INFORMATION info,
1871 BYTE *descriptor,
1872 DWORD buf_size,
1873 DWORD *needed_size)
1875 WINE_FIXME("\n");
1876 return ERROR_CALL_NOT_IMPLEMENTED;
1879 DWORD __cdecl svcctl_SetServiceObjectSecurity(
1880 SC_RPC_HANDLE service,
1881 SECURITY_INFORMATION info,
1882 BYTE *descriptor,
1883 DWORD buf_size)
1885 WINE_FIXME("\n");
1886 return ERROR_CALL_NOT_IMPLEMENTED;
1889 DWORD __cdecl svcctl_QueryServiceStatus(
1890 SC_RPC_HANDLE service,
1891 SERVICE_STATUS *status)
1893 WINE_FIXME("\n");
1894 return ERROR_CALL_NOT_IMPLEMENTED;
1897 DWORD __cdecl svcctl_NotifyBootConfigStatus(
1898 SVCCTL_HANDLEW machinename,
1899 DWORD boot_acceptable)
1901 WINE_FIXME("\n");
1902 return ERROR_CALL_NOT_IMPLEMENTED;
1905 DWORD __cdecl svcctl_SCSetServiceBitsW(void)
1907 WINE_FIXME("\n");
1908 return ERROR_CALL_NOT_IMPLEMENTED;
1911 DWORD __cdecl svcctl_EnumDependentServicesW(
1912 SC_RPC_HANDLE service,
1913 DWORD state,
1914 BYTE *services,
1915 DWORD buf_size,
1916 DWORD *needed_size,
1917 DWORD *services_ret)
1919 WINE_FIXME("\n");
1920 return ERROR_CALL_NOT_IMPLEMENTED;
1923 DWORD __cdecl svcctl_QueryServiceLockStatusW(
1924 SC_RPC_HANDLE scmanager,
1925 QUERY_SERVICE_LOCK_STATUSW *status,
1926 DWORD buf_size,
1927 DWORD *needed_size)
1929 WINE_FIXME("\n");
1930 return ERROR_CALL_NOT_IMPLEMENTED;
1933 DWORD __cdecl svcctl_SCSetServiceBitsA(void)
1935 WINE_FIXME("\n");
1936 return ERROR_CALL_NOT_IMPLEMENTED;
1939 DWORD __cdecl svcctl_ChangeServiceConfigA(
1940 SC_RPC_HANDLE service,
1941 DWORD service_type,
1942 DWORD start_type,
1943 DWORD error_control,
1944 LPSTR binarypath,
1945 LPSTR loadordergroup,
1946 DWORD *tagid,
1947 BYTE *dependencies,
1948 DWORD depend_size,
1949 LPSTR startname,
1950 BYTE *password,
1951 DWORD password_size,
1952 LPSTR displayname)
1954 WINE_FIXME("\n");
1955 return ERROR_CALL_NOT_IMPLEMENTED;
1958 DWORD __cdecl svcctl_CreateServiceA(
1959 SC_RPC_HANDLE scmanager,
1960 LPCSTR servicename,
1961 LPCSTR displayname,
1962 DWORD desiredaccess,
1963 DWORD service_type,
1964 DWORD start_type,
1965 DWORD error_control,
1966 LPCSTR binarypath,
1967 LPCSTR loadordergroup,
1968 DWORD *tagid,
1969 const BYTE *dependencies,
1970 DWORD depend_size,
1971 LPCSTR startname,
1972 const BYTE *password,
1973 DWORD password_size,
1974 SC_RPC_HANDLE *service)
1976 WINE_FIXME("\n");
1977 return ERROR_CALL_NOT_IMPLEMENTED;
1980 DWORD __cdecl svcctl_EnumDependentServicesA(
1981 SC_RPC_HANDLE service,
1982 DWORD state,
1983 BYTE *services,
1984 DWORD buf_size,
1985 DWORD *needed_size,
1986 DWORD *services_ret)
1988 WINE_FIXME("\n");
1989 return ERROR_CALL_NOT_IMPLEMENTED;
1992 DWORD __cdecl svcctl_EnumServicesStatusA(
1993 SC_RPC_HANDLE hmngr,
1994 DWORD type,
1995 DWORD state,
1996 BYTE *buffer,
1997 DWORD size,
1998 DWORD *needed,
1999 DWORD *returned,
2000 DWORD *resume)
2002 WINE_FIXME("\n");
2003 return ERROR_CALL_NOT_IMPLEMENTED;
2006 DWORD __cdecl svcctl_OpenSCManagerA(
2007 MACHINE_HANDLEA MachineName,
2008 LPCSTR DatabaseName,
2009 DWORD dwAccessMask,
2010 SC_RPC_HANDLE *handle)
2012 WINE_FIXME("\n");
2013 return ERROR_CALL_NOT_IMPLEMENTED;
2016 DWORD __cdecl svcctl_OpenServiceA(
2017 SC_RPC_HANDLE hSCManager,
2018 LPCSTR lpServiceName,
2019 DWORD dwDesiredAccess,
2020 SC_RPC_HANDLE *phService)
2022 WINE_FIXME("\n");
2023 return ERROR_CALL_NOT_IMPLEMENTED;
2026 DWORD __cdecl svcctl_QueryServiceConfigA(
2027 SC_RPC_HANDLE hService,
2028 QUERY_SERVICE_CONFIGA *config,
2029 DWORD buf_size,
2030 DWORD *needed_size)
2032 WINE_FIXME("\n");
2033 return ERROR_CALL_NOT_IMPLEMENTED;
2036 DWORD __cdecl svcctl_QueryServiceLockStatusA(
2037 SC_RPC_HANDLE scmanager,
2038 QUERY_SERVICE_LOCK_STATUSA *status,
2039 DWORD buf_size,
2040 DWORD *needed_size)
2042 WINE_FIXME("\n");
2043 return ERROR_CALL_NOT_IMPLEMENTED;
2046 DWORD __cdecl svcctl_StartServiceA(
2047 SC_RPC_HANDLE service,
2048 DWORD argc,
2049 LPCSTR *args)
2051 WINE_FIXME("\n");
2052 return ERROR_CALL_NOT_IMPLEMENTED;
2055 DWORD __cdecl svcctl_GetServiceDisplayNameA(
2056 SC_RPC_HANDLE hSCManager,
2057 LPCSTR servicename,
2058 CHAR buffer[],
2059 DWORD *buf_size)
2061 WINE_FIXME("\n");
2062 return ERROR_CALL_NOT_IMPLEMENTED;
2065 DWORD __cdecl svcctl_GetServiceKeyNameA(
2066 SC_RPC_HANDLE hSCManager,
2067 LPCSTR servicename,
2068 CHAR buffer[],
2069 DWORD *buf_size)
2071 WINE_FIXME("\n");
2072 return ERROR_CALL_NOT_IMPLEMENTED;
2075 DWORD __cdecl svcctl_GetCurrentGroupStateW(void)
2077 WINE_FIXME("\n");
2078 return ERROR_CALL_NOT_IMPLEMENTED;
2081 DWORD __cdecl svcctl_EnumServiceGroupW(
2082 SC_RPC_HANDLE scmanager,
2083 DWORD service_type,
2084 DWORD service_state,
2085 BYTE *buffer,
2086 DWORD buf_size,
2087 DWORD *needed_size,
2088 DWORD *returned_size,
2089 DWORD *resume_index,
2090 LPCWSTR groupname)
2092 WINE_FIXME("\n");
2093 return ERROR_CALL_NOT_IMPLEMENTED;
2096 DWORD __cdecl svcctl_ChangeServiceConfig2A(
2097 SC_RPC_HANDLE service,
2098 SC_RPC_CONFIG_INFOA info)
2100 WINE_FIXME("\n");
2101 return ERROR_CALL_NOT_IMPLEMENTED;
2104 DWORD __cdecl svcctl_QueryServiceConfig2A(
2105 SC_RPC_HANDLE service,
2106 DWORD info_level,
2107 BYTE *buffer,
2108 DWORD buf_size,
2109 DWORD *needed_size)
2111 WINE_FIXME("\n");
2112 return ERROR_CALL_NOT_IMPLEMENTED;
2115 DWORD RPC_Init(void)
2117 WCHAR transport[] = SVCCTL_TRANSPORT;
2118 WCHAR endpoint[] = SVCCTL_ENDPOINT;
2119 DWORD err;
2121 if (!(cleanup_group = CreateThreadpoolCleanupGroup()))
2123 WINE_ERR("CreateThreadpoolCleanupGroup failed with error %lu\n", GetLastError());
2124 return GetLastError();
2127 if ((err = RpcServerUseProtseqEpW(transport, 0, endpoint, NULL)) != ERROR_SUCCESS)
2129 WINE_ERR("RpcServerUseProtseq failed with error %lu\n", err);
2130 return err;
2133 if ((err = RpcServerRegisterIf(svcctl_v2_0_s_ifspec, 0, 0)) != ERROR_SUCCESS)
2135 WINE_ERR("RpcServerRegisterIf failed with error %lu\n", err);
2136 return err;
2139 if ((err = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE)) != ERROR_SUCCESS)
2141 WINE_ERR("RpcServerListen failed with error %lu\n", err);
2142 return err;
2145 NtSetInformationProcess( GetCurrentProcess(), ProcessWineMakeProcessSystem,
2146 &exit_event, sizeof(HANDLE *) );
2147 return ERROR_SUCCESS;
2150 void RPC_Stop(void)
2152 RpcMgmtStopServerListening(NULL);
2153 RpcServerUnregisterIf(svcctl_v2_0_s_ifspec, NULL, TRUE);
2154 RpcMgmtWaitServerListen();
2156 CloseThreadpoolCleanupGroupMembers(cleanup_group, TRUE, NULL);
2157 CloseThreadpoolCleanupGroup(cleanup_group);
2158 CloseHandle(exit_event);
2161 void __RPC_USER SC_RPC_HANDLE_rundown(SC_RPC_HANDLE handle)
2163 SC_RPC_HANDLE_destroy(handle);
2166 void __RPC_USER SC_NOTIFY_RPC_HANDLE_rundown(SC_NOTIFY_RPC_HANDLE handle)
2170 void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
2172 return malloc(len);
2175 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
2177 free(ptr);