wined3d: Fix / update reported driver model version.
[wine/zf.git] / programs / services / rpc.c
blobd0f85024191e3b64c5e517987ee946e826c8438c
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 extern HANDLE CDECL __wine_make_process_system(void);
40 WINE_DEFAULT_DEBUG_CHANNEL(service);
42 static const GENERIC_MAPPING g_scm_generic =
44 (STANDARD_RIGHTS_READ | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS),
45 (STANDARD_RIGHTS_WRITE | SC_MANAGER_CREATE_SERVICE | SC_MANAGER_MODIFY_BOOT_CONFIG),
46 (STANDARD_RIGHTS_EXECUTE | SC_MANAGER_CONNECT | SC_MANAGER_LOCK),
47 SC_MANAGER_ALL_ACCESS
50 static const GENERIC_MAPPING g_svc_generic =
52 (STANDARD_RIGHTS_READ | SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS | SERVICE_INTERROGATE | SERVICE_ENUMERATE_DEPENDENTS),
53 (STANDARD_RIGHTS_WRITE | SERVICE_CHANGE_CONFIG),
54 (STANDARD_RIGHTS_EXECUTE | SERVICE_START | SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_USER_DEFINED_CONTROL),
55 SERVICE_ALL_ACCESS
58 typedef enum
60 SC_HTYPE_DONT_CARE = 0,
61 SC_HTYPE_MANAGER,
62 SC_HTYPE_SERVICE,
63 SC_HTYPE_NOTIFY
64 } SC_HANDLE_TYPE;
66 struct sc_handle
68 SC_HANDLE_TYPE type;
69 DWORD access;
72 struct sc_manager_handle /* service control manager handle */
74 struct sc_handle hdr;
75 struct scmdatabase *db;
78 struct sc_notify_handle
80 struct sc_handle hdr;
81 HANDLE event;
82 DWORD notify_mask;
83 LONG ref;
84 SC_RPC_NOTIFY_PARAMS_LIST *params_list;
87 struct sc_service_handle /* service handle */
89 struct sc_handle hdr;
90 struct list entry;
91 BOOL status_notified;
92 struct service_entry *service_entry;
93 struct sc_notify_handle *notify;
96 static void sc_notify_retain(struct sc_notify_handle *notify)
98 InterlockedIncrement(&notify->ref);
101 static void sc_notify_release(struct sc_notify_handle *notify)
103 ULONG r = InterlockedDecrement(&notify->ref);
104 if (r == 0)
106 CloseHandle(notify->event);
107 HeapFree(GetProcessHeap(), 0, notify->params_list);
108 HeapFree(GetProcessHeap(), 0, 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 HeapFree(GetProcessHeap(), 0, old_cfg->lpBinaryPathName);
204 if (old_cfg->lpLoadOrderGroup != new_cfg->lpLoadOrderGroup)
205 HeapFree(GetProcessHeap(), 0, old_cfg->lpLoadOrderGroup);
207 if (old_cfg->lpServiceStartName != new_cfg->lpServiceStartName)
208 HeapFree(GetProcessHeap(), 0, old_cfg->lpServiceStartName);
210 if (old_cfg->lpDisplayName != new_cfg->lpDisplayName)
211 HeapFree(GetProcessHeap(), 0, old_cfg->lpDisplayName);
213 if (old->dependOnServices != new->dependOnServices)
214 HeapFree(GetProcessHeap(), 0, old->dependOnServices);
216 if (old->dependOnGroups != new->dependOnGroups)
217 HeapFree(GetProcessHeap(), 0, 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, %d)\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 %x, needed %x\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, %x)\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 = HeapAlloc(GetProcessHeap(), 0, 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 HeapFree(GetProcessHeap(), 0, 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 HeapFree(GetProcessHeap(), 0, 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, %d)\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, %d)\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 = HeapAlloc(GetProcessHeap(), 0, 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%x)\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 = HeapAlloc(GetProcessHeap(), 0, (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 = HeapAlloc(GetProcessHeap(), 0, (len_groups + 1) * sizeof(WCHAR));
522 if (!groups)
524 HeapFree(GetProcessHeap(), 0, 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%x, %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 = strdupW(lpBinaryPathName);
597 entry->config.lpLoadOrderGroup = strdupW(lpLoadOrderGroup);
598 entry->config.lpServiceStartName = strdupW(lpServiceStartName);
599 entry->config.lpDisplayName = strdupW(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%x, %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 = strdupW(service->service_entry->config.lpBinaryPathName);
708 config->lpLoadOrderGroup = strdupW(service->service_entry->config.lpLoadOrderGroup);
709 config->dwTagId = service->service_entry->config.dwTagId;
710 config->lpDependencies = NULL; /* TODO */
711 config->lpServiceStartName = strdupW(service->service_entry->config.lpServiceStartName);
712 config->lpDisplayName = strdupW(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 = strdupW(lpBinaryPathName);
809 if (lpLoadOrderGroup != NULL)
810 new_entry.config.lpLoadOrderGroup = strdupW(lpLoadOrderGroup);
812 if (lpServiceStartName != NULL)
813 new_entry.config.lpServiceStartName = strdupW(lpServiceStartName);
815 if (lpDisplayName != NULL)
816 new_entry.config.lpDisplayName = strdupW(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 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
847 sizeof(SC_RPC_NOTIFY_PARAMS_LIST) + sizeof(SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2));
848 if (!list)
849 return;
851 cparams = (SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2 *)(list + 1);
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].u.params = cparams;
864 InterlockedExchangePointer((void**)&notify->params_list, list);
866 SetEvent(notify->event);
869 DWORD __cdecl svcctl_SetServiceStatus(SC_RPC_HANDLE handle, SERVICE_STATUS *status)
871 struct sc_service_handle *service, *service_handle;
872 struct process_entry *process;
873 DWORD err, mask;
875 WINE_TRACE("(%p, %p)\n", handle, status);
877 if ((err = validate_service_handle(handle, SERVICE_SET_STATUS, &service)) != 0)
878 return err;
880 service_lock(service->service_entry);
882 /* FIXME: be a bit more discriminant about what parts of the status we set
883 * and check that fields are valid */
884 service->service_entry->status.dwCurrentState = status->dwCurrentState;
885 service->service_entry->status.dwControlsAccepted = status->dwControlsAccepted;
886 service->service_entry->status.dwWin32ExitCode = status->dwWin32ExitCode;
887 service->service_entry->status.dwServiceSpecificExitCode = status->dwServiceSpecificExitCode;
888 service->service_entry->status.dwCheckPoint = status->dwCheckPoint;
889 service->service_entry->status.dwWaitHint = status->dwWaitHint;
890 SetEvent(service->service_entry->status_changed_event);
892 if ((process = service->service_entry->process) &&
893 status->dwCurrentState == SERVICE_STOPPED)
895 service->service_entry->process = NULL;
896 if (!--process->use_count)
897 terminate_after_timeout(process, service_kill_timeout);
898 if (service->service_entry->shared_process && process->use_count <= 1)
899 shutdown_shared_process(process);
900 release_process(process);
903 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
904 LIST_FOR_EACH_ENTRY(service_handle, &service->service_entry->handles, struct sc_service_handle, entry)
906 struct sc_notify_handle *notify = service_handle->notify;
907 if (notify && (notify->notify_mask & mask))
909 fill_notify(notify, service->service_entry);
910 sc_notify_release(notify);
911 service_handle->notify = NULL;
912 service_handle->status_notified = TRUE;
914 else
915 service_handle->status_notified = FALSE;
918 service_unlock(service->service_entry);
920 return ERROR_SUCCESS;
923 DWORD __cdecl svcctl_ChangeServiceConfig2W( SC_RPC_HANDLE hService, SC_RPC_CONFIG_INFOW config )
925 struct sc_service_handle *service;
926 DWORD err;
928 if ((err = validate_service_handle(hService, SERVICE_CHANGE_CONFIG, &service)) != 0)
929 return err;
931 switch (config.dwInfoLevel)
933 case SERVICE_CONFIG_DESCRIPTION:
935 WCHAR *descr = NULL;
937 if (!config.u.descr->lpDescription)
938 break;
940 if (config.u.descr->lpDescription[0])
942 if (!(descr = strdupW( config.u.descr->lpDescription )))
943 return ERROR_NOT_ENOUGH_MEMORY;
946 WINE_TRACE( "changing service %p descr to %s\n", service, wine_dbgstr_w(descr) );
947 service_lock( service->service_entry );
948 HeapFree( GetProcessHeap(), 0, service->service_entry->description );
949 service->service_entry->description = descr;
950 save_service_config( service->service_entry );
951 service_unlock( service->service_entry );
953 break;
954 case SERVICE_CONFIG_FAILURE_ACTIONS:
955 WINE_FIXME( "SERVICE_CONFIG_FAILURE_ACTIONS not implemented: period %u msg %s cmd %s\n",
956 config.u.actions->dwResetPeriod,
957 wine_dbgstr_w(config.u.actions->lpRebootMsg),
958 wine_dbgstr_w(config.u.actions->lpCommand) );
959 break;
960 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
961 WINE_TRACE( "changing service %p preshutdown timeout to %d\n",
962 service, config.u.preshutdown->dwPreshutdownTimeout );
963 service_lock( service->service_entry );
964 service->service_entry->preshutdown_timeout = config.u.preshutdown->dwPreshutdownTimeout;
965 save_service_config( service->service_entry );
966 service_unlock( service->service_entry );
967 break;
968 default:
969 WINE_FIXME("level %u not implemented\n", config.dwInfoLevel);
970 err = ERROR_INVALID_LEVEL;
971 break;
973 return err;
976 DWORD __cdecl svcctl_QueryServiceConfig2W( SC_RPC_HANDLE hService, DWORD level,
977 BYTE *buffer, DWORD size, LPDWORD needed )
979 struct sc_service_handle *service;
980 DWORD err;
982 memset(buffer, 0, size);
984 if ((err = validate_service_handle(hService, SERVICE_QUERY_STATUS, &service)) != 0)
985 return err;
987 switch (level)
989 case SERVICE_CONFIG_DESCRIPTION:
991 struct service_description *desc = (struct service_description *)buffer;
992 DWORD total_size = sizeof(*desc);
994 service_lock(service->service_entry);
995 if (service->service_entry->description)
996 total_size += lstrlenW(service->service_entry->description) * sizeof(WCHAR);
998 *needed = total_size;
999 if (size >= total_size)
1001 if (service->service_entry->description)
1003 lstrcpyW( desc->description, service->service_entry->description );
1004 desc->size = total_size - FIELD_OFFSET(struct service_description, description);
1006 else
1008 desc->description[0] = 0;
1009 desc->size = 0;
1012 else err = ERROR_INSUFFICIENT_BUFFER;
1013 service_unlock(service->service_entry);
1015 break;
1017 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
1018 service_lock(service->service_entry);
1020 *needed = sizeof(SERVICE_PRESHUTDOWN_INFO);
1021 if (size >= *needed)
1022 ((LPSERVICE_PRESHUTDOWN_INFO)buffer)->dwPreshutdownTimeout =
1023 service->service_entry->preshutdown_timeout;
1024 else err = ERROR_INSUFFICIENT_BUFFER;
1026 service_unlock(service->service_entry);
1027 break;
1029 default:
1030 WINE_FIXME("level %u not implemented\n", level);
1031 err = ERROR_INVALID_LEVEL;
1032 break;
1034 return err;
1037 DWORD __cdecl svcctl_QueryServiceStatusEx(
1038 SC_RPC_HANDLE hService,
1039 SC_STATUS_TYPE InfoLevel,
1040 BYTE *lpBuffer,
1041 DWORD cbBufSize,
1042 LPDWORD pcbBytesNeeded)
1044 struct sc_service_handle *service;
1045 DWORD err;
1046 LPSERVICE_STATUS_PROCESS pSvcStatusData;
1048 memset(lpBuffer, 0, cbBufSize);
1050 if ((err = validate_service_handle(hService, SERVICE_QUERY_STATUS, &service)) != 0)
1051 return err;
1053 if (InfoLevel != SC_STATUS_PROCESS_INFO)
1054 return ERROR_INVALID_LEVEL;
1056 pSvcStatusData = (LPSERVICE_STATUS_PROCESS) lpBuffer;
1057 if (pSvcStatusData == NULL)
1058 return ERROR_INVALID_PARAMETER;
1060 if (cbBufSize < sizeof(SERVICE_STATUS_PROCESS))
1062 if( pcbBytesNeeded != NULL)
1063 *pcbBytesNeeded = sizeof(SERVICE_STATUS_PROCESS);
1065 return ERROR_INSUFFICIENT_BUFFER;
1068 service_lock(service->service_entry);
1069 fill_status_process(pSvcStatusData, service->service_entry);
1070 service_unlock(service->service_entry);
1072 return ERROR_SUCCESS;
1075 /******************************************************************************
1076 * service_accepts_control
1078 static BOOL service_accepts_control(const struct service_entry *service, DWORD dwControl)
1080 DWORD a = service->status.dwControlsAccepted;
1082 if (dwControl >= 128 && dwControl <= 255)
1083 return TRUE;
1085 switch (dwControl)
1087 case SERVICE_CONTROL_INTERROGATE:
1088 return TRUE;
1089 case SERVICE_CONTROL_STOP:
1090 if (a&SERVICE_ACCEPT_STOP)
1091 return TRUE;
1092 break;
1093 case SERVICE_CONTROL_SHUTDOWN:
1094 if (a&SERVICE_ACCEPT_SHUTDOWN)
1095 return TRUE;
1096 break;
1097 case SERVICE_CONTROL_PAUSE:
1098 case SERVICE_CONTROL_CONTINUE:
1099 if (a&SERVICE_ACCEPT_PAUSE_CONTINUE)
1100 return TRUE;
1101 break;
1102 case SERVICE_CONTROL_PARAMCHANGE:
1103 if (a&SERVICE_ACCEPT_PARAMCHANGE)
1104 return TRUE;
1105 break;
1106 case SERVICE_CONTROL_NETBINDADD:
1107 case SERVICE_CONTROL_NETBINDREMOVE:
1108 case SERVICE_CONTROL_NETBINDENABLE:
1109 case SERVICE_CONTROL_NETBINDDISABLE:
1110 if (a&SERVICE_ACCEPT_NETBINDCHANGE)
1111 return TRUE;
1112 case SERVICE_CONTROL_HARDWAREPROFILECHANGE:
1113 if (a&SERVICE_ACCEPT_HARDWAREPROFILECHANGE)
1114 return TRUE;
1115 break;
1116 case SERVICE_CONTROL_POWEREVENT:
1117 if (a&SERVICE_ACCEPT_POWEREVENT)
1118 return TRUE;
1119 break;
1120 case SERVICE_CONTROL_SESSIONCHANGE:
1121 if (a&SERVICE_ACCEPT_SESSIONCHANGE)
1122 return TRUE;
1123 break;
1125 return FALSE;
1128 /******************************************************************************
1129 * process_send_command
1131 static BOOL process_send_command(struct process_entry *process, const void *data, DWORD size, DWORD *result)
1133 OVERLAPPED overlapped;
1134 DWORD count, ret;
1135 BOOL r;
1137 overlapped.u.s.Offset = 0;
1138 overlapped.u.s.OffsetHigh = 0;
1139 overlapped.hEvent = process->overlapped_event;
1140 r = WriteFile(process->control_pipe, data, size, &count, &overlapped);
1141 if (!r && GetLastError() == ERROR_IO_PENDING)
1143 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1144 if (ret == WAIT_TIMEOUT)
1146 WINE_ERR("sending command timed out\n");
1147 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1148 return FALSE;
1150 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1152 if (!r || count != size)
1154 WINE_ERR("service protocol error - failed to write pipe!\n");
1155 *result = (!r ? GetLastError() : ERROR_WRITE_FAULT);
1156 return FALSE;
1158 r = ReadFile(process->control_pipe, result, sizeof *result, &count, &overlapped);
1159 if (!r && GetLastError() == ERROR_IO_PENDING)
1161 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1162 if (ret == WAIT_TIMEOUT)
1164 WINE_ERR("receiving command result timed out\n");
1165 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1166 return FALSE;
1168 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1170 if (!r || count != sizeof *result)
1172 WINE_ERR("service protocol error - failed to read pipe "
1173 "r = %d count = %d!\n", r, count);
1174 *result = (!r ? GetLastError() : ERROR_READ_FAULT);
1175 return FALSE;
1178 return TRUE;
1181 /******************************************************************************
1182 * process_send_control
1184 BOOL process_send_control(struct process_entry *process, BOOL shared_process, const WCHAR *name,
1185 DWORD control, const BYTE *data, DWORD data_size, DWORD *result)
1187 service_start_info *ssi;
1188 DWORD len;
1189 BOOL r;
1191 if (shared_process)
1193 control |= SERVICE_CONTROL_FORWARD_FLAG;
1194 data = (BYTE *)name;
1195 data_size = (lstrlenW(name) + 1) * sizeof(WCHAR);
1196 name = emptyW;
1199 /* calculate how much space we need to send the startup info */
1200 len = (lstrlenW(name) + 1) * sizeof(WCHAR) + data_size;
1202 ssi = HeapAlloc(GetProcessHeap(),0,FIELD_OFFSET(service_start_info, data[len]));
1203 ssi->magic = SERVICE_PROTOCOL_MAGIC;
1204 ssi->control = control;
1205 ssi->total_size = FIELD_OFFSET(service_start_info, data[len]);
1206 ssi->name_size = lstrlenW(name) + 1;
1207 lstrcpyW((WCHAR *)ssi->data, name);
1208 if (data_size) memcpy(&ssi->data[ssi->name_size * sizeof(WCHAR)], data, data_size);
1210 r = process_send_command(process, ssi, ssi->total_size, result);
1211 HeapFree( GetProcessHeap(), 0, ssi );
1212 return r;
1215 DWORD __cdecl svcctl_StartServiceW(
1216 SC_RPC_HANDLE hService,
1217 DWORD dwNumServiceArgs,
1218 LPCWSTR *lpServiceArgVectors)
1220 struct sc_service_handle *service;
1221 DWORD err;
1223 WINE_TRACE("(%p, %d, %p)\n", hService, dwNumServiceArgs, lpServiceArgVectors);
1225 if ((err = validate_service_handle(hService, SERVICE_START, &service)) != 0)
1226 return err;
1228 if (service->service_entry->config.dwStartType == SERVICE_DISABLED)
1229 return ERROR_SERVICE_DISABLED;
1231 if (!scmdatabase_lock_startup(service->service_entry->db, 3000))
1232 return ERROR_SERVICE_DATABASE_LOCKED;
1234 err = service_start(service->service_entry, dwNumServiceArgs, lpServiceArgVectors);
1236 scmdatabase_unlock_startup(service->service_entry->db);
1237 return err;
1240 DWORD __cdecl svcctl_ControlService(
1241 SC_RPC_HANDLE hService,
1242 DWORD dwControl,
1243 SERVICE_STATUS *lpServiceStatus)
1245 DWORD access_required;
1246 struct sc_service_handle *service;
1247 struct process_entry *process;
1248 BOOL shared_process;
1249 DWORD result;
1251 WINE_TRACE("(%p, %d, %p)\n", hService, dwControl, lpServiceStatus);
1253 switch (dwControl)
1255 case SERVICE_CONTROL_CONTINUE:
1256 case SERVICE_CONTROL_NETBINDADD:
1257 case SERVICE_CONTROL_NETBINDDISABLE:
1258 case SERVICE_CONTROL_NETBINDENABLE:
1259 case SERVICE_CONTROL_NETBINDREMOVE:
1260 case SERVICE_CONTROL_PARAMCHANGE:
1261 case SERVICE_CONTROL_PAUSE:
1262 access_required = SERVICE_PAUSE_CONTINUE;
1263 break;
1264 case SERVICE_CONTROL_INTERROGATE:
1265 access_required = SERVICE_INTERROGATE;
1266 break;
1267 case SERVICE_CONTROL_STOP:
1268 access_required = SERVICE_STOP;
1269 break;
1270 default:
1271 if (dwControl >= 128 && dwControl <= 255)
1272 access_required = SERVICE_USER_DEFINED_CONTROL;
1273 else
1274 return ERROR_INVALID_PARAMETER;
1277 if ((result = validate_service_handle(hService, access_required, &service)) != 0)
1278 return result;
1280 service_lock(service->service_entry);
1282 result = ERROR_SUCCESS;
1283 switch (service->service_entry->status.dwCurrentState)
1285 case SERVICE_STOPPED:
1286 result = ERROR_SERVICE_NOT_ACTIVE;
1287 break;
1288 case SERVICE_START_PENDING:
1289 if (dwControl==SERVICE_CONTROL_STOP)
1290 break;
1291 /* fall through */
1292 case SERVICE_STOP_PENDING:
1293 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1294 break;
1297 if (result == ERROR_SUCCESS && service->service_entry->force_shutdown)
1299 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1300 if ((process = service->service_entry->process))
1302 service->service_entry->process = NULL;
1303 if (!--process->use_count) process_terminate(process);
1304 release_process(process);
1308 if (result != ERROR_SUCCESS)
1310 if (lpServiceStatus) *lpServiceStatus = service->service_entry->status;
1311 service_unlock(service->service_entry);
1312 return result;
1315 if (!service_accepts_control(service->service_entry, dwControl))
1317 service_unlock(service->service_entry);
1318 return ERROR_INVALID_SERVICE_CONTROL;
1321 /* Remember that we tried to shutdown this service. When the service is
1322 * still running on the second invocation, it will be forcefully killed. */
1323 if (dwControl == SERVICE_CONTROL_STOP)
1324 service->service_entry->force_shutdown = TRUE;
1326 /* Hold a reference to the process while sending the command. */
1327 process = grab_process(service->service_entry->process);
1328 shared_process = service->service_entry->shared_process;
1329 service_unlock(service->service_entry);
1331 if (!process)
1332 return ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1334 result = WaitForSingleObject(process->control_mutex, 30000);
1335 if (result != WAIT_OBJECT_0)
1337 release_process(process);
1338 return ERROR_SERVICE_REQUEST_TIMEOUT;
1341 if (process_send_control(process, shared_process, service->service_entry->name,
1342 dwControl, NULL, 0, &result))
1343 result = ERROR_SUCCESS;
1345 if (lpServiceStatus)
1347 service_lock(service->service_entry);
1348 *lpServiceStatus = service->service_entry->status;
1349 service_unlock(service->service_entry);
1352 ReleaseMutex(process->control_mutex);
1353 release_process(process);
1354 return result;
1357 DWORD __cdecl svcctl_CloseServiceHandle(
1358 SC_RPC_HANDLE *handle)
1360 WINE_TRACE("(&%p)\n", *handle);
1362 SC_RPC_HANDLE_destroy(*handle);
1363 *handle = NULL;
1365 return ERROR_SUCCESS;
1368 void __RPC_USER SC_RPC_LOCK_rundown(SC_RPC_LOCK hLock)
1372 DWORD __cdecl svcctl_LockServiceDatabase(SC_RPC_HANDLE manager, SC_RPC_LOCK *lock)
1374 TRACE("(%p, %p)\n", manager, lock);
1376 *lock = (SC_RPC_LOCK)0xdeadbeef;
1377 return ERROR_SUCCESS;
1380 DWORD __cdecl svcctl_UnlockServiceDatabase(SC_RPC_LOCK *lock)
1382 TRACE("(&%p)\n", *lock);
1384 *lock = NULL;
1385 return ERROR_SUCCESS;
1388 static BOOL map_state(DWORD state, DWORD mask)
1390 switch (state)
1392 case SERVICE_START_PENDING:
1393 case SERVICE_STOP_PENDING:
1394 case SERVICE_RUNNING:
1395 case SERVICE_CONTINUE_PENDING:
1396 case SERVICE_PAUSE_PENDING:
1397 case SERVICE_PAUSED:
1398 if (SERVICE_ACTIVE & mask) return TRUE;
1399 break;
1400 case SERVICE_STOPPED:
1401 if (SERVICE_INACTIVE & mask) return TRUE;
1402 break;
1403 default:
1404 WINE_ERR("unknown state %u\n", state);
1405 break;
1407 return FALSE;
1410 DWORD __cdecl svcctl_EnumServicesStatusW(
1411 SC_RPC_HANDLE hmngr,
1412 DWORD type,
1413 DWORD state,
1414 BYTE *buffer,
1415 DWORD size,
1416 LPDWORD needed,
1417 LPDWORD returned,
1418 LPDWORD resume)
1420 DWORD err, sz, total_size, num_services, offset;
1421 struct sc_manager_handle *manager;
1422 struct service_entry *service;
1423 struct enum_service_status *s;
1425 WINE_TRACE("(%p, 0x%x, 0x%x, %p, %u, %p, %p, %p)\n", hmngr, type, state, buffer, size, needed, returned, resume);
1427 if (!type || !state)
1428 return ERROR_INVALID_PARAMETER;
1430 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1431 return err;
1433 if (resume)
1434 WINE_FIXME("resume index not supported\n");
1436 scmdatabase_lock(manager->db);
1438 total_size = num_services = 0;
1439 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1441 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1443 total_size += sizeof(*s);
1444 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1445 if (service->config.lpDisplayName)
1447 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1449 num_services++;
1452 *returned = 0;
1453 *needed = total_size;
1454 if (total_size > size)
1456 scmdatabase_unlock(manager->db);
1457 return ERROR_MORE_DATA;
1459 s = (struct enum_service_status *)buffer;
1460 offset = num_services * sizeof(struct enum_service_status);
1461 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1463 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1465 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1466 memcpy(buffer + offset, service->name, sz);
1467 s->service_name = offset;
1468 offset += sz;
1470 if (!service->config.lpDisplayName) s->display_name = 0;
1471 else
1473 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1474 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1475 s->display_name = offset;
1476 offset += sz;
1478 s->service_status = service->status;
1479 s++;
1482 *returned = num_services;
1483 *needed = 0;
1484 scmdatabase_unlock(manager->db);
1485 return ERROR_SUCCESS;
1488 static struct service_entry *find_service_by_group(struct scmdatabase *db, const WCHAR *group)
1490 struct service_entry *service;
1491 LIST_FOR_EACH_ENTRY(service, &db->services, struct service_entry, entry)
1493 if (service->config.lpLoadOrderGroup && !wcsicmp(group, service->config.lpLoadOrderGroup))
1494 return service;
1496 return NULL;
1499 static BOOL match_group(const WCHAR *g1, const WCHAR *g2)
1501 if (!g2) return TRUE;
1502 if (!g2[0] && (!g1 || !g1[0])) return TRUE;
1503 if (g1 && !lstrcmpW(g1, g2)) return TRUE;
1504 return FALSE;
1507 DWORD __cdecl svcctl_EnumServicesStatusExA(
1508 SC_RPC_HANDLE scmanager,
1509 SC_ENUM_TYPE info_level,
1510 DWORD service_type,
1511 DWORD service_state,
1512 BYTE *buffer,
1513 DWORD buf_size,
1514 DWORD *needed_size,
1515 DWORD *services_count,
1516 DWORD *resume_index,
1517 LPCSTR groupname)
1519 WINE_FIXME("\n");
1520 return ERROR_CALL_NOT_IMPLEMENTED;
1523 DWORD __cdecl svcctl_EnumServicesStatusExW(
1524 SC_RPC_HANDLE hmngr,
1525 SC_ENUM_TYPE info_level,
1526 DWORD type,
1527 DWORD state,
1528 BYTE *buffer,
1529 DWORD size,
1530 LPDWORD needed,
1531 LPDWORD returned,
1532 DWORD *resume_handle,
1533 LPCWSTR group)
1535 DWORD err, sz, total_size, num_services;
1536 DWORD_PTR offset;
1537 struct sc_manager_handle *manager;
1538 struct service_entry *service;
1539 struct enum_service_status_process *s;
1541 WINE_TRACE("(%p, 0x%x, 0x%x, %p, %u, %p, %p, %s)\n", hmngr, type, state, buffer, size,
1542 needed, returned, wine_dbgstr_w(group));
1544 if (resume_handle)
1545 FIXME("resume handle not supported\n");
1547 if (!type || !state)
1548 return ERROR_INVALID_PARAMETER;
1550 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1551 return err;
1553 scmdatabase_lock(manager->db);
1555 if (group && !find_service_by_group(manager->db, group))
1557 scmdatabase_unlock(manager->db);
1558 return ERROR_SERVICE_DOES_NOT_EXIST;
1561 total_size = num_services = 0;
1562 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1564 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1565 && match_group(service->config.lpLoadOrderGroup, group))
1567 total_size += sizeof(*s);
1568 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1569 if (service->config.lpDisplayName)
1571 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1573 num_services++;
1576 *returned = 0;
1577 *needed = total_size;
1578 if (total_size > size)
1580 scmdatabase_unlock(manager->db);
1581 return ERROR_MORE_DATA;
1583 s = (struct enum_service_status_process *)buffer;
1584 offset = num_services * sizeof(*s);
1585 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1587 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1588 && match_group(service->config.lpLoadOrderGroup, group))
1590 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1591 memcpy(buffer + offset, service->name, sz);
1592 s->service_name = offset;
1593 offset += sz;
1595 if (!service->config.lpDisplayName) s->display_name = 0;
1596 else
1598 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1599 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1600 s->display_name = offset;
1601 offset += sz;
1603 fill_status_process(&s->service_status_process, service);
1604 s++;
1607 *returned = num_services;
1608 *needed = 0;
1609 scmdatabase_unlock(manager->db);
1610 return ERROR_SUCCESS;
1613 DWORD __cdecl svcctl_unknown43(void)
1615 WINE_FIXME("\n");
1616 return ERROR_CALL_NOT_IMPLEMENTED;
1619 DWORD __cdecl svcctl_CreateServiceWOW64A(
1620 SC_RPC_HANDLE scmanager,
1621 LPCSTR servicename,
1622 LPCSTR displayname,
1623 DWORD accessmask,
1624 DWORD service_type,
1625 DWORD start_type,
1626 DWORD error_control,
1627 LPCSTR imagepath,
1628 LPCSTR loadordergroup,
1629 DWORD *tagid,
1630 const BYTE *dependencies,
1631 DWORD depend_size,
1632 LPCSTR start_name,
1633 const BYTE *password,
1634 DWORD password_size,
1635 SC_RPC_HANDLE *service)
1637 WINE_FIXME("\n");
1638 return ERROR_CALL_NOT_IMPLEMENTED;
1641 DWORD __cdecl svcctl_CreateServiceWOW64W(
1642 SC_RPC_HANDLE scmanager,
1643 LPCWSTR servicename,
1644 LPCWSTR displayname,
1645 DWORD accessmask,
1646 DWORD service_type,
1647 DWORD start_type,
1648 DWORD error_control,
1649 LPCWSTR imagepath,
1650 LPCWSTR loadordergroup,
1651 DWORD *tagid,
1652 const BYTE *dependencies,
1653 DWORD depend_size,
1654 LPCWSTR start_name,
1655 const BYTE *password,
1656 DWORD password_size,
1657 SC_RPC_HANDLE *service)
1659 WINE_TRACE("(%s, %s, 0x%x, %s)\n", wine_dbgstr_w(servicename), wine_dbgstr_w(displayname), accessmask, wine_dbgstr_w(imagepath));
1660 return create_serviceW(scmanager, servicename, displayname, accessmask, service_type, start_type, error_control, imagepath,
1661 loadordergroup, tagid, dependencies, depend_size, start_name, password, password_size, service, TRUE);
1664 DWORD __cdecl svcctl_unknown46(void)
1666 WINE_FIXME("\n");
1667 return ERROR_CALL_NOT_IMPLEMENTED;
1670 DWORD __cdecl svcctl_NotifyServiceStatusChange(
1671 SC_RPC_HANDLE handle,
1672 SC_RPC_NOTIFY_PARAMS params,
1673 GUID *clientprocessguid,
1674 GUID *scmprocessguid,
1675 BOOL *createremotequeue,
1676 SC_NOTIFY_RPC_HANDLE *hNotify)
1678 DWORD err, mask;
1679 struct sc_manager_handle *manager = NULL;
1680 struct sc_service_handle *service = NULL;
1681 struct sc_notify_handle *notify;
1682 struct sc_handle *hdr = handle;
1684 WINE_TRACE("(%p, NotifyMask: 0x%x, %p, %p, %p, %p)\n", handle,
1685 params.u.params->dwNotifyMask, clientprocessguid, scmprocessguid,
1686 createremotequeue, hNotify);
1688 switch (hdr->type)
1690 case SC_HTYPE_SERVICE:
1691 err = validate_service_handle(handle, SERVICE_QUERY_STATUS, &service);
1692 break;
1693 case SC_HTYPE_MANAGER:
1694 err = validate_scm_handle(handle, SC_MANAGER_ENUMERATE_SERVICE, &manager);
1695 break;
1696 default:
1697 err = ERROR_INVALID_HANDLE;
1698 break;
1701 if (err != ERROR_SUCCESS)
1702 return err;
1704 if (manager)
1706 WARN("Need support for service creation/deletion notifications\n");
1707 return ERROR_CALL_NOT_IMPLEMENTED;
1710 notify = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*notify));
1711 if (!notify)
1712 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
1714 notify->hdr.type = SC_HTYPE_NOTIFY;
1715 notify->hdr.access = 0;
1717 notify->event = CreateEventW(NULL, TRUE, FALSE, NULL);
1719 notify->notify_mask = params.u.params->dwNotifyMask;
1721 service_lock(service->service_entry);
1723 if (service->notify)
1725 service_unlock(service->service_entry);
1726 sc_notify_release(notify);
1727 return ERROR_ALREADY_REGISTERED;
1730 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
1731 if (!service->status_notified && (notify->notify_mask & mask))
1733 fill_notify(notify, service->service_entry);
1734 service->status_notified = TRUE;
1736 else
1738 sc_notify_retain(notify);
1739 service->notify = notify;
1742 sc_notify_retain(notify);
1743 *hNotify = &notify->hdr;
1745 service_unlock(service->service_entry);
1747 return ERROR_SUCCESS;
1750 DWORD __cdecl svcctl_GetNotifyResults(
1751 SC_NOTIFY_RPC_HANDLE hNotify,
1752 SC_RPC_NOTIFY_PARAMS_LIST **pList)
1754 DWORD err;
1755 struct sc_notify_handle *notify;
1757 WINE_TRACE("(%p, %p)\n", hNotify, pList);
1759 if (!pList)
1760 return ERROR_INVALID_PARAMETER;
1762 *pList = NULL;
1764 if ((err = validate_notify_handle(hNotify, 0, &notify)) != 0)
1765 return err;
1767 sc_notify_retain(notify);
1768 /* block until there is a result */
1769 err = WaitForSingleObject(notify->event, INFINITE);
1771 if (err != WAIT_OBJECT_0)
1773 sc_notify_release(notify);
1774 return err;
1777 *pList = InterlockedExchangePointer((void**)&notify->params_list, NULL);
1778 if (!*pList)
1780 sc_notify_release(notify);
1781 return ERROR_REQUEST_ABORTED;
1784 sc_notify_release(notify);
1786 return ERROR_SUCCESS;
1789 DWORD __cdecl svcctl_CloseNotifyHandle(
1790 SC_NOTIFY_RPC_HANDLE *hNotify,
1791 BOOL *apc_fired)
1793 struct sc_notify_handle *notify;
1794 DWORD err;
1796 WINE_TRACE("(%p, %p)\n", hNotify, apc_fired);
1798 if ((err = validate_notify_handle(*hNotify, 0, &notify)) != 0)
1799 return err;
1801 sc_notify_release(notify);
1803 return ERROR_SUCCESS;
1806 DWORD __cdecl svcctl_ControlServiceExA(
1807 SC_RPC_HANDLE service,
1808 DWORD control,
1809 DWORD info_level,
1810 SC_RPC_SERVICE_CONTROL_IN_PARAMSA *in_params,
1811 SC_RPC_SERVICE_CONTROL_OUT_PARAMSA *out_params)
1813 WINE_FIXME("\n");
1814 return ERROR_CALL_NOT_IMPLEMENTED;
1817 DWORD __cdecl svcctl_ControlServiceExW(
1818 SC_RPC_HANDLE service,
1819 DWORD control,
1820 DWORD info_level,
1821 SC_RPC_SERVICE_CONTROL_IN_PARAMSW *in_params,
1822 SC_RPC_SERVICE_CONTROL_OUT_PARAMSW *out_params)
1824 WINE_FIXME("\n");
1825 return ERROR_CALL_NOT_IMPLEMENTED;
1828 DWORD __cdecl svcctl_unknown52(void)
1830 WINE_FIXME("\n");
1831 return ERROR_CALL_NOT_IMPLEMENTED;
1834 DWORD __cdecl svcctl_unknown53(void)
1836 WINE_FIXME("\n");
1837 return ERROR_CALL_NOT_IMPLEMENTED;
1840 DWORD __cdecl svcctl_unknown54(void)
1842 WINE_FIXME("\n");
1843 return ERROR_CALL_NOT_IMPLEMENTED;
1846 DWORD __cdecl svcctl_unknown55(void)
1848 WINE_FIXME("\n");
1849 return ERROR_CALL_NOT_IMPLEMENTED;
1852 DWORD __cdecl svcctl_QueryServiceConfigEx(
1853 SC_RPC_HANDLE service,
1854 DWORD info_level,
1855 SC_RPC_CONFIG_INFOW *info)
1857 WINE_FIXME("\n");
1858 return ERROR_CALL_NOT_IMPLEMENTED;
1861 DWORD __cdecl svcctl_QueryServiceObjectSecurity(
1862 SC_RPC_HANDLE service,
1863 SECURITY_INFORMATION info,
1864 BYTE *descriptor,
1865 DWORD buf_size,
1866 DWORD *needed_size)
1868 WINE_FIXME("\n");
1869 return ERROR_CALL_NOT_IMPLEMENTED;
1872 DWORD __cdecl svcctl_SetServiceObjectSecurity(
1873 SC_RPC_HANDLE service,
1874 SECURITY_INFORMATION info,
1875 BYTE *descriptor,
1876 DWORD buf_size)
1878 WINE_FIXME("\n");
1879 return ERROR_CALL_NOT_IMPLEMENTED;
1882 DWORD __cdecl svcctl_QueryServiceStatus(
1883 SC_RPC_HANDLE service,
1884 SERVICE_STATUS *status)
1886 WINE_FIXME("\n");
1887 return ERROR_CALL_NOT_IMPLEMENTED;
1890 DWORD __cdecl svcctl_NotifyBootConfigStatus(
1891 SVCCTL_HANDLEW machinename,
1892 DWORD boot_acceptable)
1894 WINE_FIXME("\n");
1895 return ERROR_CALL_NOT_IMPLEMENTED;
1898 DWORD __cdecl svcctl_SCSetServiceBitsW(void)
1900 WINE_FIXME("\n");
1901 return ERROR_CALL_NOT_IMPLEMENTED;
1904 DWORD __cdecl svcctl_EnumDependentServicesW(
1905 SC_RPC_HANDLE service,
1906 DWORD state,
1907 BYTE *services,
1908 DWORD buf_size,
1909 DWORD *needed_size,
1910 DWORD *services_ret)
1912 WINE_FIXME("\n");
1913 return ERROR_CALL_NOT_IMPLEMENTED;
1916 DWORD __cdecl svcctl_QueryServiceLockStatusW(
1917 SC_RPC_HANDLE scmanager,
1918 QUERY_SERVICE_LOCK_STATUSW *status,
1919 DWORD buf_size,
1920 DWORD *needed_size)
1922 WINE_FIXME("\n");
1923 return ERROR_CALL_NOT_IMPLEMENTED;
1926 DWORD __cdecl svcctl_SCSetServiceBitsA(void)
1928 WINE_FIXME("\n");
1929 return ERROR_CALL_NOT_IMPLEMENTED;
1932 DWORD __cdecl svcctl_ChangeServiceConfigA(
1933 SC_RPC_HANDLE service,
1934 DWORD service_type,
1935 DWORD start_type,
1936 DWORD error_control,
1937 LPSTR binarypath,
1938 LPSTR loadordergroup,
1939 DWORD *tagid,
1940 BYTE *dependencies,
1941 DWORD depend_size,
1942 LPSTR startname,
1943 BYTE *password,
1944 DWORD password_size,
1945 LPSTR displayname)
1947 WINE_FIXME("\n");
1948 return ERROR_CALL_NOT_IMPLEMENTED;
1951 DWORD __cdecl svcctl_CreateServiceA(
1952 SC_RPC_HANDLE scmanager,
1953 LPCSTR servicename,
1954 LPCSTR displayname,
1955 DWORD desiredaccess,
1956 DWORD service_type,
1957 DWORD start_type,
1958 DWORD error_control,
1959 LPCSTR binarypath,
1960 LPCSTR loadordergroup,
1961 DWORD *tagid,
1962 const BYTE *dependencies,
1963 DWORD depend_size,
1964 LPCSTR startname,
1965 const BYTE *password,
1966 DWORD password_size,
1967 SC_RPC_HANDLE *service)
1969 WINE_FIXME("\n");
1970 return ERROR_CALL_NOT_IMPLEMENTED;
1973 DWORD __cdecl svcctl_EnumDependentServicesA(
1974 SC_RPC_HANDLE service,
1975 DWORD state,
1976 BYTE *services,
1977 DWORD buf_size,
1978 DWORD *needed_size,
1979 DWORD *services_ret)
1981 WINE_FIXME("\n");
1982 return ERROR_CALL_NOT_IMPLEMENTED;
1985 DWORD __cdecl svcctl_EnumServicesStatusA(
1986 SC_RPC_HANDLE hmngr,
1987 DWORD type,
1988 DWORD state,
1989 BYTE *buffer,
1990 DWORD size,
1991 DWORD *needed,
1992 DWORD *returned,
1993 DWORD *resume)
1995 WINE_FIXME("\n");
1996 return ERROR_CALL_NOT_IMPLEMENTED;
1999 DWORD __cdecl svcctl_OpenSCManagerA(
2000 MACHINE_HANDLEA MachineName,
2001 LPCSTR DatabaseName,
2002 DWORD dwAccessMask,
2003 SC_RPC_HANDLE *handle)
2005 WINE_FIXME("\n");
2006 return ERROR_CALL_NOT_IMPLEMENTED;
2009 DWORD __cdecl svcctl_OpenServiceA(
2010 SC_RPC_HANDLE hSCManager,
2011 LPCSTR lpServiceName,
2012 DWORD dwDesiredAccess,
2013 SC_RPC_HANDLE *phService)
2015 WINE_FIXME("\n");
2016 return ERROR_CALL_NOT_IMPLEMENTED;
2019 DWORD __cdecl svcctl_QueryServiceConfigA(
2020 SC_RPC_HANDLE hService,
2021 QUERY_SERVICE_CONFIGA *config,
2022 DWORD buf_size,
2023 DWORD *needed_size)
2025 WINE_FIXME("\n");
2026 return ERROR_CALL_NOT_IMPLEMENTED;
2029 DWORD __cdecl svcctl_QueryServiceLockStatusA(
2030 SC_RPC_HANDLE scmanager,
2031 QUERY_SERVICE_LOCK_STATUSA *status,
2032 DWORD buf_size,
2033 DWORD *needed_size)
2035 WINE_FIXME("\n");
2036 return ERROR_CALL_NOT_IMPLEMENTED;
2039 DWORD __cdecl svcctl_StartServiceA(
2040 SC_RPC_HANDLE service,
2041 DWORD argc,
2042 LPCSTR *args)
2044 WINE_FIXME("\n");
2045 return ERROR_CALL_NOT_IMPLEMENTED;
2048 DWORD __cdecl svcctl_GetServiceDisplayNameA(
2049 SC_RPC_HANDLE hSCManager,
2050 LPCSTR servicename,
2051 CHAR buffer[],
2052 DWORD *buf_size)
2054 WINE_FIXME("\n");
2055 return ERROR_CALL_NOT_IMPLEMENTED;
2058 DWORD __cdecl svcctl_GetServiceKeyNameA(
2059 SC_RPC_HANDLE hSCManager,
2060 LPCSTR servicename,
2061 CHAR buffer[],
2062 DWORD *buf_size)
2064 WINE_FIXME("\n");
2065 return ERROR_CALL_NOT_IMPLEMENTED;
2068 DWORD __cdecl svcctl_GetCurrentGroupStateW(void)
2070 WINE_FIXME("\n");
2071 return ERROR_CALL_NOT_IMPLEMENTED;
2074 DWORD __cdecl svcctl_EnumServiceGroupW(
2075 SC_RPC_HANDLE scmanager,
2076 DWORD service_type,
2077 DWORD service_state,
2078 BYTE *buffer,
2079 DWORD buf_size,
2080 DWORD *needed_size,
2081 DWORD *returned_size,
2082 DWORD *resume_index,
2083 LPCWSTR groupname)
2085 WINE_FIXME("\n");
2086 return ERROR_CALL_NOT_IMPLEMENTED;
2089 DWORD __cdecl svcctl_ChangeServiceConfig2A(
2090 SC_RPC_HANDLE service,
2091 SC_RPC_CONFIG_INFOA info)
2093 WINE_FIXME("\n");
2094 return ERROR_CALL_NOT_IMPLEMENTED;
2097 DWORD __cdecl svcctl_QueryServiceConfig2A(
2098 SC_RPC_HANDLE service,
2099 DWORD info_level,
2100 BYTE *buffer,
2101 DWORD buf_size,
2102 DWORD *needed_size)
2104 WINE_FIXME("\n");
2105 return ERROR_CALL_NOT_IMPLEMENTED;
2108 DWORD RPC_Init(void)
2110 WCHAR transport[] = SVCCTL_TRANSPORT;
2111 WCHAR endpoint[] = SVCCTL_ENDPOINT;
2112 DWORD err;
2114 if (!(cleanup_group = CreateThreadpoolCleanupGroup()))
2116 WINE_ERR("CreateThreadpoolCleanupGroup failed with error %u\n", GetLastError());
2117 return GetLastError();
2120 if ((err = RpcServerUseProtseqEpW(transport, 0, endpoint, NULL)) != ERROR_SUCCESS)
2122 WINE_ERR("RpcServerUseProtseq failed with error %u\n", err);
2123 return err;
2126 if ((err = RpcServerRegisterIf(svcctl_v2_0_s_ifspec, 0, 0)) != ERROR_SUCCESS)
2128 WINE_ERR("RpcServerRegisterIf failed with error %u\n", err);
2129 return err;
2132 if ((err = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE)) != ERROR_SUCCESS)
2134 WINE_ERR("RpcServerListen failed with error %u\n", err);
2135 return err;
2138 exit_event = __wine_make_process_system();
2139 return ERROR_SUCCESS;
2142 void RPC_Stop(void)
2144 RpcMgmtStopServerListening(NULL);
2145 RpcServerUnregisterIf(svcctl_v2_0_s_ifspec, NULL, TRUE);
2146 RpcMgmtWaitServerListen();
2148 CloseThreadpoolCleanupGroupMembers(cleanup_group, TRUE, NULL);
2149 CloseThreadpoolCleanupGroup(cleanup_group);
2150 CloseHandle(exit_event);
2153 void __RPC_USER SC_RPC_HANDLE_rundown(SC_RPC_HANDLE handle)
2155 SC_RPC_HANDLE_destroy(handle);
2158 void __RPC_USER SC_NOTIFY_RPC_HANDLE_rundown(SC_NOTIFY_RPC_HANDLE handle)
2162 void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
2164 return HeapAlloc(GetProcessHeap(), 0, len);
2167 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
2169 HeapFree(GetProcessHeap(), 0, ptr);