services: Associate notify handle with service handle instead of service entry.
[wine.git] / programs / services / rpc.c
blob8299dbf0e086d43f45e6485e76b065a044dee7d8
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 NONAMELESSUNION
24 #include <stdarg.h>
25 #include <windows.h>
26 #include <winternl.h>
27 #include <winsvc.h>
28 #include <ntsecapi.h>
29 #include <rpc.h>
31 #include "wine/list.h"
32 #include "wine/unicode.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 (strcmpW(DatabaseName, SERVICES_FAILED_DATABASEW) == 0)
281 return ERROR_DATABASE_DOES_NOT_EXIST;
282 if (strcmpW(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 = strlenW(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 = strlenW(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 = strlenW(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 = strlenW(ptr) + 1;
508 if (*ptr != '+')
510 strcpyW(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 = strlenW(ptr) + 1;
532 if (ptr[0] == '+' && ptr[1])
534 strcpyW(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 = process ? process->process_id : 0;
836 status->dwServiceFlags = 0;
839 static void fill_notify(struct sc_notify_handle *notify, struct service_entry *service)
841 SC_RPC_NOTIFY_PARAMS_LIST *list;
842 SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2 *cparams;
844 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
845 sizeof(SC_RPC_NOTIFY_PARAMS_LIST) + sizeof(SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2));
846 if (!list)
847 return;
849 cparams = (SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2 *)(list + 1);
851 cparams->dwNotifyMask = notify->notify_mask;
852 fill_status_process(&cparams->ServiceStatus, service);
853 cparams->dwNotificationStatus = ERROR_SUCCESS;
854 cparams->dwNotificationTriggered = 1 << (cparams->ServiceStatus.dwCurrentState - SERVICE_STOPPED);
855 cparams->pszServiceNames = NULL;
857 list->cElements = 1;
859 list->NotifyParamsArray[0].dwInfoLevel = 2;
860 list->NotifyParamsArray[0].u.params = cparams;
862 InterlockedExchangePointer((void**)&notify->params_list, list);
864 SetEvent(notify->event);
867 DWORD __cdecl svcctl_SetServiceStatus(
868 SC_RPC_HANDLE hServiceStatus,
869 LPSERVICE_STATUS lpServiceStatus)
871 struct sc_service_handle *service, *service_handle;
872 struct process_entry *process;
873 DWORD err, mask;
875 WINE_TRACE("(%p, %p)\n", hServiceStatus, lpServiceStatus);
877 if ((err = validate_service_handle(hServiceStatus, 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 = *lpServiceStatus;
885 SetEvent(service->service_entry->status_changed_event);
887 if ((process = service->service_entry->process) &&
888 lpServiceStatus->dwCurrentState == SERVICE_STOPPED)
890 service->service_entry->process = NULL;
891 if (!--process->use_count)
892 terminate_after_timeout(process, service_kill_timeout);
893 if (service->service_entry->shared_process && process->use_count <= 1)
894 shutdown_shared_process(process);
895 release_process(process);
898 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
899 LIST_FOR_EACH_ENTRY(service_handle, &service->service_entry->handles, struct sc_service_handle, entry)
901 struct sc_notify_handle *notify = service_handle->notify;
902 if (notify && (notify->notify_mask & mask))
904 fill_notify(notify, service->service_entry);
905 sc_notify_release(notify);
906 service_handle->notify = NULL;
907 service_handle->status_notified = TRUE;
909 else
910 service_handle->status_notified = FALSE;
913 service_unlock(service->service_entry);
915 return ERROR_SUCCESS;
918 DWORD __cdecl svcctl_ChangeServiceConfig2W( SC_RPC_HANDLE hService, SC_RPC_CONFIG_INFOW config )
920 struct sc_service_handle *service;
921 DWORD err;
923 if ((err = validate_service_handle(hService, SERVICE_CHANGE_CONFIG, &service)) != 0)
924 return err;
926 switch (config.dwInfoLevel)
928 case SERVICE_CONFIG_DESCRIPTION:
930 WCHAR *descr = NULL;
932 if (!config.u.descr->lpDescription)
933 break;
935 if (config.u.descr->lpDescription[0])
937 if (!(descr = strdupW( config.u.descr->lpDescription )))
938 return ERROR_NOT_ENOUGH_MEMORY;
941 WINE_TRACE( "changing service %p descr to %s\n", service, wine_dbgstr_w(descr) );
942 service_lock( service->service_entry );
943 HeapFree( GetProcessHeap(), 0, service->service_entry->description );
944 service->service_entry->description = descr;
945 save_service_config( service->service_entry );
946 service_unlock( service->service_entry );
948 break;
949 case SERVICE_CONFIG_FAILURE_ACTIONS:
950 WINE_FIXME( "SERVICE_CONFIG_FAILURE_ACTIONS not implemented: period %u msg %s cmd %s\n",
951 config.u.actions->dwResetPeriod,
952 wine_dbgstr_w(config.u.actions->lpRebootMsg),
953 wine_dbgstr_w(config.u.actions->lpCommand) );
954 break;
955 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
956 WINE_TRACE( "changing service %p preshutdown timeout to %d\n",
957 service, config.u.preshutdown->dwPreshutdownTimeout );
958 service_lock( service->service_entry );
959 service->service_entry->preshutdown_timeout = config.u.preshutdown->dwPreshutdownTimeout;
960 save_service_config( service->service_entry );
961 service_unlock( service->service_entry );
962 break;
963 default:
964 WINE_FIXME("level %u not implemented\n", config.dwInfoLevel);
965 err = ERROR_INVALID_LEVEL;
966 break;
968 return err;
971 DWORD __cdecl svcctl_QueryServiceConfig2W( SC_RPC_HANDLE hService, DWORD level,
972 BYTE *buffer, DWORD size, LPDWORD needed )
974 struct sc_service_handle *service;
975 DWORD err;
977 memset(buffer, 0, size);
979 if ((err = validate_service_handle(hService, SERVICE_QUERY_STATUS, &service)) != 0)
980 return err;
982 switch (level)
984 case SERVICE_CONFIG_DESCRIPTION:
986 struct service_description *desc = (struct service_description *)buffer;
987 DWORD total_size = sizeof(*desc);
989 service_lock(service->service_entry);
990 if (service->service_entry->description)
991 total_size += strlenW(service->service_entry->description) * sizeof(WCHAR);
993 *needed = total_size;
994 if (size >= total_size)
996 if (service->service_entry->description)
998 strcpyW( desc->description, service->service_entry->description );
999 desc->size = total_size - FIELD_OFFSET(struct service_description, description);
1001 else
1003 desc->description[0] = 0;
1004 desc->size = 0;
1007 else err = ERROR_INSUFFICIENT_BUFFER;
1008 service_unlock(service->service_entry);
1010 break;
1012 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
1013 service_lock(service->service_entry);
1015 *needed = sizeof(SERVICE_PRESHUTDOWN_INFO);
1016 if (size >= *needed)
1017 ((LPSERVICE_PRESHUTDOWN_INFO)buffer)->dwPreshutdownTimeout =
1018 service->service_entry->preshutdown_timeout;
1019 else err = ERROR_INSUFFICIENT_BUFFER;
1021 service_unlock(service->service_entry);
1022 break;
1024 default:
1025 WINE_FIXME("level %u not implemented\n", level);
1026 err = ERROR_INVALID_LEVEL;
1027 break;
1029 return err;
1032 DWORD __cdecl svcctl_QueryServiceStatusEx(
1033 SC_RPC_HANDLE hService,
1034 SC_STATUS_TYPE InfoLevel,
1035 BYTE *lpBuffer,
1036 DWORD cbBufSize,
1037 LPDWORD pcbBytesNeeded)
1039 struct sc_service_handle *service;
1040 DWORD err;
1041 LPSERVICE_STATUS_PROCESS pSvcStatusData;
1043 memset(lpBuffer, 0, cbBufSize);
1045 if ((err = validate_service_handle(hService, SERVICE_QUERY_STATUS, &service)) != 0)
1046 return err;
1048 if (InfoLevel != SC_STATUS_PROCESS_INFO)
1049 return ERROR_INVALID_LEVEL;
1051 pSvcStatusData = (LPSERVICE_STATUS_PROCESS) lpBuffer;
1052 if (pSvcStatusData == NULL)
1053 return ERROR_INVALID_PARAMETER;
1055 if (cbBufSize < sizeof(SERVICE_STATUS_PROCESS))
1057 if( pcbBytesNeeded != NULL)
1058 *pcbBytesNeeded = sizeof(SERVICE_STATUS_PROCESS);
1060 return ERROR_INSUFFICIENT_BUFFER;
1063 service_lock(service->service_entry);
1064 fill_status_process(pSvcStatusData, service->service_entry);
1065 service_unlock(service->service_entry);
1067 return ERROR_SUCCESS;
1070 /******************************************************************************
1071 * service_accepts_control
1073 static BOOL service_accepts_control(const struct service_entry *service, DWORD dwControl)
1075 DWORD a = service->status.dwControlsAccepted;
1077 if (dwControl >= 128 && dwControl <= 255)
1078 return TRUE;
1080 switch (dwControl)
1082 case SERVICE_CONTROL_INTERROGATE:
1083 return TRUE;
1084 case SERVICE_CONTROL_STOP:
1085 if (a&SERVICE_ACCEPT_STOP)
1086 return TRUE;
1087 break;
1088 case SERVICE_CONTROL_SHUTDOWN:
1089 if (a&SERVICE_ACCEPT_SHUTDOWN)
1090 return TRUE;
1091 break;
1092 case SERVICE_CONTROL_PAUSE:
1093 case SERVICE_CONTROL_CONTINUE:
1094 if (a&SERVICE_ACCEPT_PAUSE_CONTINUE)
1095 return TRUE;
1096 break;
1097 case SERVICE_CONTROL_PARAMCHANGE:
1098 if (a&SERVICE_ACCEPT_PARAMCHANGE)
1099 return TRUE;
1100 break;
1101 case SERVICE_CONTROL_NETBINDADD:
1102 case SERVICE_CONTROL_NETBINDREMOVE:
1103 case SERVICE_CONTROL_NETBINDENABLE:
1104 case SERVICE_CONTROL_NETBINDDISABLE:
1105 if (a&SERVICE_ACCEPT_NETBINDCHANGE)
1106 return TRUE;
1107 case SERVICE_CONTROL_HARDWAREPROFILECHANGE:
1108 if (a&SERVICE_ACCEPT_HARDWAREPROFILECHANGE)
1109 return TRUE;
1110 break;
1111 case SERVICE_CONTROL_POWEREVENT:
1112 if (a&SERVICE_ACCEPT_POWEREVENT)
1113 return TRUE;
1114 break;
1115 case SERVICE_CONTROL_SESSIONCHANGE:
1116 if (a&SERVICE_ACCEPT_SESSIONCHANGE)
1117 return TRUE;
1118 break;
1120 return FALSE;
1123 /******************************************************************************
1124 * process_send_command
1126 static BOOL process_send_command(struct process_entry *process, const void *data, DWORD size, DWORD *result)
1128 OVERLAPPED overlapped;
1129 DWORD count, ret;
1130 BOOL r;
1132 overlapped.hEvent = process->overlapped_event;
1133 r = WriteFile(process->control_pipe, data, size, &count, &overlapped);
1134 if (!r && GetLastError() == ERROR_IO_PENDING)
1136 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1137 if (ret == WAIT_TIMEOUT)
1139 WINE_ERR("sending command timed out\n");
1140 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1141 return FALSE;
1143 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1145 if (!r || count != size)
1147 WINE_ERR("service protocol error - failed to write pipe!\n");
1148 *result = (!r ? GetLastError() : ERROR_WRITE_FAULT);
1149 return FALSE;
1151 r = ReadFile(process->control_pipe, result, sizeof *result, &count, &overlapped);
1152 if (!r && GetLastError() == ERROR_IO_PENDING)
1154 ret = WaitForSingleObject(process->overlapped_event, service_pipe_timeout);
1155 if (ret == WAIT_TIMEOUT)
1157 WINE_ERR("receiving command result timed out\n");
1158 *result = ERROR_SERVICE_REQUEST_TIMEOUT;
1159 return FALSE;
1161 r = GetOverlappedResult(process->control_pipe, &overlapped, &count, FALSE);
1163 if (!r || count != sizeof *result)
1165 WINE_ERR("service protocol error - failed to read pipe "
1166 "r = %d count = %d!\n", r, count);
1167 *result = (!r ? GetLastError() : ERROR_READ_FAULT);
1168 return FALSE;
1171 return TRUE;
1174 /******************************************************************************
1175 * process_send_control
1177 BOOL process_send_control(struct process_entry *process, BOOL shared_process, const WCHAR *name,
1178 DWORD control, const BYTE *data, DWORD data_size, DWORD *result)
1180 service_start_info *ssi;
1181 DWORD len;
1182 BOOL r;
1184 if (shared_process)
1186 control |= SERVICE_CONTROL_FORWARD_FLAG;
1187 data = (BYTE *)name;
1188 data_size = (strlenW(name) + 1) * sizeof(WCHAR);
1189 name = emptyW;
1192 /* calculate how much space we need to send the startup info */
1193 len = (strlenW(name) + 1) * sizeof(WCHAR) + data_size;
1195 ssi = HeapAlloc(GetProcessHeap(),0,FIELD_OFFSET(service_start_info, data[len]));
1196 ssi->magic = SERVICE_PROTOCOL_MAGIC;
1197 ssi->control = control;
1198 ssi->total_size = FIELD_OFFSET(service_start_info, data[len]);
1199 ssi->name_size = strlenW(name) + 1;
1200 strcpyW((WCHAR *)ssi->data, name);
1201 if (data_size) memcpy(&ssi->data[ssi->name_size * sizeof(WCHAR)], data, data_size);
1203 r = process_send_command(process, ssi, ssi->total_size, result);
1204 HeapFree( GetProcessHeap(), 0, ssi );
1205 return r;
1208 DWORD __cdecl svcctl_StartServiceW(
1209 SC_RPC_HANDLE hService,
1210 DWORD dwNumServiceArgs,
1211 LPCWSTR *lpServiceArgVectors)
1213 struct sc_service_handle *service;
1214 DWORD err;
1216 WINE_TRACE("(%p, %d, %p)\n", hService, dwNumServiceArgs, lpServiceArgVectors);
1218 if ((err = validate_service_handle(hService, SERVICE_START, &service)) != 0)
1219 return err;
1221 if (service->service_entry->config.dwStartType == SERVICE_DISABLED)
1222 return ERROR_SERVICE_DISABLED;
1224 if (!scmdatabase_lock_startup(service->service_entry->db, 3000))
1225 return ERROR_SERVICE_DATABASE_LOCKED;
1227 err = service_start(service->service_entry, dwNumServiceArgs, lpServiceArgVectors);
1229 scmdatabase_unlock_startup(service->service_entry->db);
1230 return err;
1233 DWORD __cdecl svcctl_ControlService(
1234 SC_RPC_HANDLE hService,
1235 DWORD dwControl,
1236 SERVICE_STATUS *lpServiceStatus)
1238 DWORD access_required;
1239 struct sc_service_handle *service;
1240 struct process_entry *process;
1241 BOOL shared_process;
1242 DWORD result;
1244 WINE_TRACE("(%p, %d, %p)\n", hService, dwControl, lpServiceStatus);
1246 switch (dwControl)
1248 case SERVICE_CONTROL_CONTINUE:
1249 case SERVICE_CONTROL_NETBINDADD:
1250 case SERVICE_CONTROL_NETBINDDISABLE:
1251 case SERVICE_CONTROL_NETBINDENABLE:
1252 case SERVICE_CONTROL_NETBINDREMOVE:
1253 case SERVICE_CONTROL_PARAMCHANGE:
1254 case SERVICE_CONTROL_PAUSE:
1255 access_required = SERVICE_PAUSE_CONTINUE;
1256 break;
1257 case SERVICE_CONTROL_INTERROGATE:
1258 access_required = SERVICE_INTERROGATE;
1259 break;
1260 case SERVICE_CONTROL_STOP:
1261 access_required = SERVICE_STOP;
1262 break;
1263 default:
1264 if (dwControl >= 128 && dwControl <= 255)
1265 access_required = SERVICE_USER_DEFINED_CONTROL;
1266 else
1267 return ERROR_INVALID_PARAMETER;
1270 if ((result = validate_service_handle(hService, access_required, &service)) != 0)
1271 return result;
1273 service_lock(service->service_entry);
1275 result = ERROR_SUCCESS;
1276 switch (service->service_entry->status.dwCurrentState)
1278 case SERVICE_STOPPED:
1279 result = ERROR_SERVICE_NOT_ACTIVE;
1280 break;
1281 case SERVICE_START_PENDING:
1282 if (dwControl==SERVICE_CONTROL_STOP)
1283 break;
1284 /* fall through */
1285 case SERVICE_STOP_PENDING:
1286 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1287 break;
1290 if (result == ERROR_SUCCESS && service->service_entry->force_shutdown)
1292 result = ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1293 if ((process = service->service_entry->process))
1295 service->service_entry->process = NULL;
1296 if (!--process->use_count) process_terminate(process);
1297 release_process(process);
1301 if (result != ERROR_SUCCESS)
1303 if (lpServiceStatus) *lpServiceStatus = service->service_entry->status;
1304 service_unlock(service->service_entry);
1305 return result;
1308 if (!service_accepts_control(service->service_entry, dwControl))
1310 service_unlock(service->service_entry);
1311 return ERROR_INVALID_SERVICE_CONTROL;
1314 /* Remember that we tried to shutdown this service. When the service is
1315 * still running on the second invocation, it will be forcefully killed. */
1316 if (dwControl == SERVICE_CONTROL_STOP)
1317 service->service_entry->force_shutdown = TRUE;
1319 /* Hold a reference to the process while sending the command. */
1320 process = grab_process(service->service_entry->process);
1321 shared_process = service->service_entry->shared_process;
1322 service_unlock(service->service_entry);
1324 if (!process)
1325 return ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
1327 result = WaitForSingleObject(process->control_mutex, 30000);
1328 if (result != WAIT_OBJECT_0)
1330 release_process(process);
1331 return ERROR_SERVICE_REQUEST_TIMEOUT;
1334 if (process_send_control(process, shared_process, service->service_entry->name,
1335 dwControl, NULL, 0, &result))
1336 result = ERROR_SUCCESS;
1338 if (lpServiceStatus)
1340 service_lock(service->service_entry);
1341 *lpServiceStatus = service->service_entry->status;
1342 service_unlock(service->service_entry);
1345 ReleaseMutex(process->control_mutex);
1346 release_process(process);
1347 return result;
1350 DWORD __cdecl svcctl_CloseServiceHandle(
1351 SC_RPC_HANDLE *handle)
1353 WINE_TRACE("(&%p)\n", *handle);
1355 SC_RPC_HANDLE_destroy(*handle);
1356 *handle = NULL;
1358 return ERROR_SUCCESS;
1361 static void SC_RPC_LOCK_destroy(SC_RPC_LOCK hLock)
1363 struct sc_lock *lock = hLock;
1364 scmdatabase_unlock_startup(lock->db);
1365 HeapFree(GetProcessHeap(), 0, lock);
1368 void __RPC_USER SC_RPC_LOCK_rundown(SC_RPC_LOCK hLock)
1370 SC_RPC_LOCK_destroy(hLock);
1373 DWORD __cdecl svcctl_LockServiceDatabase(
1374 SC_RPC_HANDLE hSCManager,
1375 SC_RPC_LOCK *phLock)
1377 struct sc_manager_handle *manager;
1378 struct sc_lock *lock;
1379 DWORD err;
1381 WINE_TRACE("(%p, %p)\n", hSCManager, phLock);
1383 if ((err = validate_scm_handle(hSCManager, SC_MANAGER_LOCK, &manager)) != ERROR_SUCCESS)
1384 return err;
1386 if (!scmdatabase_lock_startup(manager->db, 0))
1387 return ERROR_SERVICE_DATABASE_LOCKED;
1389 lock = HeapAlloc(GetProcessHeap(), 0, sizeof(struct sc_lock));
1390 if (!lock)
1392 scmdatabase_unlock_startup(manager->db);
1393 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
1396 lock->db = manager->db;
1397 *phLock = lock;
1399 return ERROR_SUCCESS;
1402 DWORD __cdecl svcctl_UnlockServiceDatabase(
1403 SC_RPC_LOCK *phLock)
1405 WINE_TRACE("(&%p)\n", *phLock);
1407 SC_RPC_LOCK_destroy(*phLock);
1408 *phLock = NULL;
1410 return ERROR_SUCCESS;
1413 static BOOL map_state(DWORD state, DWORD mask)
1415 switch (state)
1417 case SERVICE_START_PENDING:
1418 case SERVICE_STOP_PENDING:
1419 case SERVICE_RUNNING:
1420 case SERVICE_CONTINUE_PENDING:
1421 case SERVICE_PAUSE_PENDING:
1422 case SERVICE_PAUSED:
1423 if (SERVICE_ACTIVE & mask) return TRUE;
1424 break;
1425 case SERVICE_STOPPED:
1426 if (SERVICE_INACTIVE & mask) return TRUE;
1427 break;
1428 default:
1429 WINE_ERR("unknown state %u\n", state);
1430 break;
1432 return FALSE;
1435 DWORD __cdecl svcctl_EnumServicesStatusW(
1436 SC_RPC_HANDLE hmngr,
1437 DWORD type,
1438 DWORD state,
1439 BYTE *buffer,
1440 DWORD size,
1441 LPDWORD needed,
1442 LPDWORD returned,
1443 LPDWORD resume)
1445 DWORD err, sz, total_size, num_services, offset;
1446 struct sc_manager_handle *manager;
1447 struct service_entry *service;
1448 struct enum_service_status *s;
1450 WINE_TRACE("(%p, 0x%x, 0x%x, %p, %u, %p, %p, %p)\n", hmngr, type, state, buffer, size, needed, returned, resume);
1452 if (!type || !state)
1453 return ERROR_INVALID_PARAMETER;
1455 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1456 return err;
1458 if (resume)
1459 WINE_FIXME("resume index not supported\n");
1461 scmdatabase_lock(manager->db);
1463 total_size = num_services = 0;
1464 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1466 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1468 total_size += sizeof(*s);
1469 total_size += (strlenW(service->name) + 1) * sizeof(WCHAR);
1470 if (service->config.lpDisplayName)
1472 total_size += (strlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1474 num_services++;
1477 *returned = 0;
1478 *needed = total_size;
1479 if (total_size > size)
1481 scmdatabase_unlock(manager->db);
1482 return ERROR_MORE_DATA;
1484 s = (struct enum_service_status *)buffer;
1485 offset = num_services * sizeof(struct enum_service_status);
1486 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1488 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1490 sz = (strlenW(service->name) + 1) * sizeof(WCHAR);
1491 memcpy(buffer + offset, service->name, sz);
1492 s->service_name = offset;
1493 offset += sz;
1495 if (!service->config.lpDisplayName) s->display_name = 0;
1496 else
1498 sz = (strlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1499 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1500 s->display_name = offset;
1501 offset += sz;
1503 s->service_status = service->status;
1504 s++;
1507 *returned = num_services;
1508 *needed = 0;
1509 scmdatabase_unlock(manager->db);
1510 return ERROR_SUCCESS;
1513 static struct service_entry *find_service_by_group(struct scmdatabase *db, const WCHAR *group)
1515 struct service_entry *service;
1516 LIST_FOR_EACH_ENTRY(service, &db->services, struct service_entry, entry)
1518 if (service->config.lpLoadOrderGroup && !strcmpiW(group, service->config.lpLoadOrderGroup))
1519 return service;
1521 return NULL;
1524 static BOOL match_group(const WCHAR *g1, const WCHAR *g2)
1526 if (!g2) return TRUE;
1527 if (!g2[0] && (!g1 || !g1[0])) return TRUE;
1528 if (g1 && !strcmpW(g1, g2)) return TRUE;
1529 return FALSE;
1532 DWORD __cdecl svcctl_EnumServicesStatusExA(
1533 SC_RPC_HANDLE scmanager,
1534 SC_ENUM_TYPE info_level,
1535 DWORD service_type,
1536 DWORD service_state,
1537 BYTE *buffer,
1538 DWORD buf_size,
1539 DWORD *needed_size,
1540 DWORD *services_count,
1541 DWORD *resume_index,
1542 LPCSTR groupname)
1544 WINE_FIXME("\n");
1545 return ERROR_CALL_NOT_IMPLEMENTED;
1548 DWORD __cdecl svcctl_EnumServicesStatusExW(
1549 SC_RPC_HANDLE hmngr,
1550 SC_ENUM_TYPE info_level,
1551 DWORD type,
1552 DWORD state,
1553 BYTE *buffer,
1554 DWORD size,
1555 LPDWORD needed,
1556 LPDWORD returned,
1557 DWORD *resume_handle,
1558 LPCWSTR group)
1560 DWORD err, sz, total_size, num_services;
1561 DWORD_PTR offset;
1562 struct sc_manager_handle *manager;
1563 struct service_entry *service;
1564 struct enum_service_status_process *s;
1566 WINE_TRACE("(%p, 0x%x, 0x%x, %p, %u, %p, %p, %s)\n", hmngr, type, state, buffer, size,
1567 needed, returned, wine_dbgstr_w(group));
1569 if (resume_handle)
1570 FIXME("resume handle not supported\n");
1572 if (!type || !state)
1573 return ERROR_INVALID_PARAMETER;
1575 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1576 return err;
1578 scmdatabase_lock(manager->db);
1580 if (group && !find_service_by_group(manager->db, group))
1582 scmdatabase_unlock(manager->db);
1583 return ERROR_SERVICE_DOES_NOT_EXIST;
1586 total_size = num_services = 0;
1587 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1589 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1590 && match_group(service->config.lpLoadOrderGroup, group))
1592 total_size += sizeof(*s);
1593 total_size += (strlenW(service->name) + 1) * sizeof(WCHAR);
1594 if (service->config.lpDisplayName)
1596 total_size += (strlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1598 num_services++;
1601 *returned = 0;
1602 *needed = total_size;
1603 if (total_size > size)
1605 scmdatabase_unlock(manager->db);
1606 return ERROR_MORE_DATA;
1608 s = (struct enum_service_status_process *)buffer;
1609 offset = num_services * sizeof(*s);
1610 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1612 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1613 && match_group(service->config.lpLoadOrderGroup, group))
1615 sz = (strlenW(service->name) + 1) * sizeof(WCHAR);
1616 memcpy(buffer + offset, service->name, sz);
1617 s->service_name = offset;
1618 offset += sz;
1620 if (!service->config.lpDisplayName) s->display_name = 0;
1621 else
1623 sz = (strlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1624 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1625 s->display_name = offset;
1626 offset += sz;
1628 fill_status_process(&s->service_status_process, service);
1629 s++;
1632 *returned = num_services;
1633 *needed = 0;
1634 scmdatabase_unlock(manager->db);
1635 return ERROR_SUCCESS;
1638 DWORD __cdecl svcctl_unknown43(void)
1640 WINE_FIXME("\n");
1641 return ERROR_CALL_NOT_IMPLEMENTED;
1644 DWORD __cdecl svcctl_CreateServiceWOW64A(
1645 SC_RPC_HANDLE scmanager,
1646 LPCSTR servicename,
1647 LPCSTR displayname,
1648 DWORD accessmask,
1649 DWORD service_type,
1650 DWORD start_type,
1651 DWORD error_control,
1652 LPCSTR imagepath,
1653 LPCSTR loadordergroup,
1654 DWORD *tagid,
1655 const BYTE *dependencies,
1656 DWORD depend_size,
1657 LPCSTR start_name,
1658 const BYTE *password,
1659 DWORD password_size,
1660 SC_RPC_HANDLE *service)
1662 WINE_FIXME("\n");
1663 return ERROR_CALL_NOT_IMPLEMENTED;
1666 DWORD __cdecl svcctl_CreateServiceWOW64W(
1667 SC_RPC_HANDLE scmanager,
1668 LPCWSTR servicename,
1669 LPCWSTR displayname,
1670 DWORD accessmask,
1671 DWORD service_type,
1672 DWORD start_type,
1673 DWORD error_control,
1674 LPCWSTR imagepath,
1675 LPCWSTR loadordergroup,
1676 DWORD *tagid,
1677 const BYTE *dependencies,
1678 DWORD depend_size,
1679 LPCWSTR start_name,
1680 const BYTE *password,
1681 DWORD password_size,
1682 SC_RPC_HANDLE *service)
1684 WINE_TRACE("(%s, %s, 0x%x, %s)\n", wine_dbgstr_w(servicename), wine_dbgstr_w(displayname), accessmask, wine_dbgstr_w(imagepath));
1685 return create_serviceW(scmanager, servicename, displayname, accessmask, service_type, start_type, error_control, imagepath,
1686 loadordergroup, tagid, dependencies, depend_size, start_name, password, password_size, service, TRUE);
1689 DWORD __cdecl svcctl_unknown46(void)
1691 WINE_FIXME("\n");
1692 return ERROR_CALL_NOT_IMPLEMENTED;
1695 DWORD __cdecl svcctl_NotifyServiceStatusChange(
1696 SC_RPC_HANDLE handle,
1697 SC_RPC_NOTIFY_PARAMS params,
1698 GUID *clientprocessguid,
1699 GUID *scmprocessguid,
1700 BOOL *createremotequeue,
1701 SC_NOTIFY_RPC_HANDLE *hNotify)
1703 DWORD err, mask;
1704 struct sc_manager_handle *manager = NULL;
1705 struct sc_service_handle *service = NULL;
1706 struct sc_notify_handle *notify;
1707 struct sc_handle *hdr = handle;
1709 WINE_TRACE("(%p, NotifyMask: 0x%x, %p, %p, %p, %p)\n", handle,
1710 params.u.params->dwNotifyMask, clientprocessguid, scmprocessguid,
1711 createremotequeue, hNotify);
1713 switch (hdr->type)
1715 case SC_HTYPE_SERVICE:
1716 err = validate_service_handle(handle, SERVICE_QUERY_STATUS, &service);
1717 break;
1718 case SC_HTYPE_MANAGER:
1719 err = validate_scm_handle(handle, SC_MANAGER_ENUMERATE_SERVICE, &manager);
1720 break;
1721 default:
1722 err = ERROR_INVALID_HANDLE;
1723 break;
1726 if (err != ERROR_SUCCESS)
1727 return err;
1729 if (manager)
1731 WARN("Need support for service creation/deletion notifications\n");
1732 return ERROR_CALL_NOT_IMPLEMENTED;
1735 notify = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*notify));
1736 if (!notify)
1737 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
1739 notify->hdr.type = SC_HTYPE_NOTIFY;
1740 notify->hdr.access = 0;
1742 notify->event = CreateEventW(NULL, TRUE, FALSE, NULL);
1744 notify->notify_mask = params.u.params->dwNotifyMask;
1746 service_lock(service->service_entry);
1748 if (service->notify)
1750 service_unlock(service->service_entry);
1751 sc_notify_release(notify);
1752 return ERROR_ALREADY_REGISTERED;
1755 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
1756 if (!service->status_notified && (notify->notify_mask & mask))
1758 fill_notify(notify, service->service_entry);
1759 service->status_notified = TRUE;
1761 else
1763 sc_notify_retain(notify);
1764 service->notify = notify;
1767 sc_notify_retain(notify);
1768 *hNotify = &notify->hdr;
1770 service_unlock(service->service_entry);
1772 return ERROR_SUCCESS;
1775 DWORD __cdecl svcctl_GetNotifyResults(
1776 SC_NOTIFY_RPC_HANDLE hNotify,
1777 SC_RPC_NOTIFY_PARAMS_LIST **pList)
1779 DWORD err;
1780 struct sc_notify_handle *notify;
1782 WINE_TRACE("(%p, %p)\n", hNotify, pList);
1784 if (!pList)
1785 return ERROR_INVALID_PARAMETER;
1787 *pList = NULL;
1789 if ((err = validate_notify_handle(hNotify, 0, &notify)) != 0)
1790 return err;
1792 sc_notify_retain(notify);
1793 /* block until there is a result */
1794 err = WaitForSingleObject(notify->event, INFINITE);
1796 if (err != WAIT_OBJECT_0)
1798 sc_notify_release(notify);
1799 return err;
1802 *pList = InterlockedExchangePointer((void**)&notify->params_list, NULL);
1803 if (!*pList)
1805 sc_notify_release(notify);
1806 return ERROR_REQUEST_ABORTED;
1809 sc_notify_release(notify);
1811 return ERROR_SUCCESS;
1814 DWORD __cdecl svcctl_CloseNotifyHandle(
1815 SC_NOTIFY_RPC_HANDLE *hNotify,
1816 BOOL *apc_fired)
1818 struct sc_notify_handle *notify;
1819 DWORD err;
1821 WINE_TRACE("(%p, %p)\n", hNotify, apc_fired);
1823 if ((err = validate_notify_handle(*hNotify, 0, &notify)) != 0)
1824 return err;
1826 sc_notify_release(notify);
1828 return ERROR_SUCCESS;
1831 DWORD __cdecl svcctl_ControlServiceExA(
1832 SC_RPC_HANDLE service,
1833 DWORD control,
1834 DWORD info_level,
1835 SC_RPC_SERVICE_CONTROL_IN_PARAMSA *in_params,
1836 SC_RPC_SERVICE_CONTROL_OUT_PARAMSA *out_params)
1838 WINE_FIXME("\n");
1839 return ERROR_CALL_NOT_IMPLEMENTED;
1842 DWORD __cdecl svcctl_ControlServiceExW(
1843 SC_RPC_HANDLE service,
1844 DWORD control,
1845 DWORD info_level,
1846 SC_RPC_SERVICE_CONTROL_IN_PARAMSW *in_params,
1847 SC_RPC_SERVICE_CONTROL_OUT_PARAMSW *out_params)
1849 WINE_FIXME("\n");
1850 return ERROR_CALL_NOT_IMPLEMENTED;
1853 DWORD __cdecl svcctl_unknown52(void)
1855 WINE_FIXME("\n");
1856 return ERROR_CALL_NOT_IMPLEMENTED;
1859 DWORD __cdecl svcctl_unknown53(void)
1861 WINE_FIXME("\n");
1862 return ERROR_CALL_NOT_IMPLEMENTED;
1865 DWORD __cdecl svcctl_unknown54(void)
1867 WINE_FIXME("\n");
1868 return ERROR_CALL_NOT_IMPLEMENTED;
1871 DWORD __cdecl svcctl_unknown55(void)
1873 WINE_FIXME("\n");
1874 return ERROR_CALL_NOT_IMPLEMENTED;
1877 DWORD __cdecl svcctl_QueryServiceConfigEx(
1878 SC_RPC_HANDLE service,
1879 DWORD info_level,
1880 SC_RPC_CONFIG_INFOW *info)
1882 WINE_FIXME("\n");
1883 return ERROR_CALL_NOT_IMPLEMENTED;
1886 DWORD __cdecl svcctl_QueryServiceObjectSecurity(
1887 SC_RPC_HANDLE service,
1888 SECURITY_INFORMATION info,
1889 BYTE *descriptor,
1890 DWORD buf_size,
1891 DWORD *needed_size)
1893 WINE_FIXME("\n");
1894 return ERROR_CALL_NOT_IMPLEMENTED;
1897 DWORD __cdecl svcctl_SetServiceObjectSecurity(
1898 SC_RPC_HANDLE service,
1899 SECURITY_INFORMATION info,
1900 BYTE *descriptor,
1901 DWORD buf_size)
1903 WINE_FIXME("\n");
1904 return ERROR_CALL_NOT_IMPLEMENTED;
1907 DWORD __cdecl svcctl_QueryServiceStatus(
1908 SC_RPC_HANDLE service,
1909 SERVICE_STATUS *status)
1911 WINE_FIXME("\n");
1912 return ERROR_CALL_NOT_IMPLEMENTED;
1915 DWORD __cdecl svcctl_NotifyBootConfigStatus(
1916 SVCCTL_HANDLEW machinename,
1917 DWORD boot_acceptable)
1919 WINE_FIXME("\n");
1920 return ERROR_CALL_NOT_IMPLEMENTED;
1923 DWORD __cdecl svcctl_SCSetServiceBitsW(void)
1925 WINE_FIXME("\n");
1926 return ERROR_CALL_NOT_IMPLEMENTED;
1929 DWORD __cdecl svcctl_EnumDependentServicesW(
1930 SC_RPC_HANDLE service,
1931 DWORD state,
1932 BYTE *services,
1933 DWORD buf_size,
1934 DWORD *needed_size,
1935 DWORD *services_ret)
1937 WINE_FIXME("\n");
1938 return ERROR_CALL_NOT_IMPLEMENTED;
1941 DWORD __cdecl svcctl_QueryServiceLockStatusW(
1942 SC_RPC_HANDLE scmanager,
1943 QUERY_SERVICE_LOCK_STATUSW *status,
1944 DWORD buf_size,
1945 DWORD *needed_size)
1947 WINE_FIXME("\n");
1948 return ERROR_CALL_NOT_IMPLEMENTED;
1951 DWORD __cdecl svcctl_SCSetServiceBitsA(void)
1953 WINE_FIXME("\n");
1954 return ERROR_CALL_NOT_IMPLEMENTED;
1957 DWORD __cdecl svcctl_ChangeServiceConfigA(
1958 SC_RPC_HANDLE service,
1959 DWORD service_type,
1960 DWORD start_type,
1961 DWORD error_control,
1962 LPSTR binarypath,
1963 LPSTR loadordergroup,
1964 DWORD *tagid,
1965 BYTE *dependencies,
1966 DWORD depend_size,
1967 LPSTR startname,
1968 BYTE *password,
1969 DWORD password_size,
1970 LPSTR displayname)
1972 WINE_FIXME("\n");
1973 return ERROR_CALL_NOT_IMPLEMENTED;
1976 DWORD __cdecl svcctl_CreateServiceA(
1977 SC_RPC_HANDLE scmanager,
1978 LPCSTR servicename,
1979 LPCSTR displayname,
1980 DWORD desiredaccess,
1981 DWORD service_type,
1982 DWORD start_type,
1983 DWORD error_control,
1984 LPCSTR binarypath,
1985 LPCSTR loadordergroup,
1986 DWORD *tagid,
1987 const BYTE *dependencies,
1988 DWORD depend_size,
1989 LPCSTR startname,
1990 const BYTE *password,
1991 DWORD password_size,
1992 SC_RPC_HANDLE *service)
1994 WINE_FIXME("\n");
1995 return ERROR_CALL_NOT_IMPLEMENTED;
1998 DWORD __cdecl svcctl_EnumDependentServicesA(
1999 SC_RPC_HANDLE service,
2000 DWORD state,
2001 BYTE *services,
2002 DWORD buf_size,
2003 DWORD *needed_size,
2004 DWORD *services_ret)
2006 WINE_FIXME("\n");
2007 return ERROR_CALL_NOT_IMPLEMENTED;
2010 DWORD __cdecl svcctl_EnumServicesStatusA(
2011 SC_RPC_HANDLE hmngr,
2012 DWORD type,
2013 DWORD state,
2014 BYTE *buffer,
2015 DWORD size,
2016 DWORD *needed,
2017 DWORD *returned,
2018 DWORD *resume)
2020 WINE_FIXME("\n");
2021 return ERROR_CALL_NOT_IMPLEMENTED;
2024 DWORD __cdecl svcctl_OpenSCManagerA(
2025 MACHINE_HANDLEA MachineName,
2026 LPCSTR DatabaseName,
2027 DWORD dwAccessMask,
2028 SC_RPC_HANDLE *handle)
2030 WINE_FIXME("\n");
2031 return ERROR_CALL_NOT_IMPLEMENTED;
2034 DWORD __cdecl svcctl_OpenServiceA(
2035 SC_RPC_HANDLE hSCManager,
2036 LPCSTR lpServiceName,
2037 DWORD dwDesiredAccess,
2038 SC_RPC_HANDLE *phService)
2040 WINE_FIXME("\n");
2041 return ERROR_CALL_NOT_IMPLEMENTED;
2044 DWORD __cdecl svcctl_QueryServiceConfigA(
2045 SC_RPC_HANDLE hService,
2046 QUERY_SERVICE_CONFIGA *config,
2047 DWORD buf_size,
2048 DWORD *needed_size)
2050 WINE_FIXME("\n");
2051 return ERROR_CALL_NOT_IMPLEMENTED;
2054 DWORD __cdecl svcctl_QueryServiceLockStatusA(
2055 SC_RPC_HANDLE scmanager,
2056 QUERY_SERVICE_LOCK_STATUSA *status,
2057 DWORD buf_size,
2058 DWORD *needed_size)
2060 WINE_FIXME("\n");
2061 return ERROR_CALL_NOT_IMPLEMENTED;
2064 DWORD __cdecl svcctl_StartServiceA(
2065 SC_RPC_HANDLE service,
2066 DWORD argc,
2067 LPCSTR *args)
2069 WINE_FIXME("\n");
2070 return ERROR_CALL_NOT_IMPLEMENTED;
2073 DWORD __cdecl svcctl_GetServiceDisplayNameA(
2074 SC_RPC_HANDLE hSCManager,
2075 LPCSTR servicename,
2076 CHAR buffer[],
2077 DWORD *buf_size)
2079 WINE_FIXME("\n");
2080 return ERROR_CALL_NOT_IMPLEMENTED;
2083 DWORD __cdecl svcctl_GetServiceKeyNameA(
2084 SC_RPC_HANDLE hSCManager,
2085 LPCSTR servicename,
2086 CHAR buffer[],
2087 DWORD *buf_size)
2089 WINE_FIXME("\n");
2090 return ERROR_CALL_NOT_IMPLEMENTED;
2093 DWORD __cdecl svcctl_GetCurrentGroupStateW(void)
2095 WINE_FIXME("\n");
2096 return ERROR_CALL_NOT_IMPLEMENTED;
2099 DWORD __cdecl svcctl_EnumServiceGroupW(
2100 SC_RPC_HANDLE scmanager,
2101 DWORD service_type,
2102 DWORD service_state,
2103 BYTE *buffer,
2104 DWORD buf_size,
2105 DWORD *needed_size,
2106 DWORD *returned_size,
2107 DWORD *resume_index,
2108 LPCWSTR groupname)
2110 WINE_FIXME("\n");
2111 return ERROR_CALL_NOT_IMPLEMENTED;
2114 DWORD __cdecl svcctl_ChangeServiceConfig2A(
2115 SC_RPC_HANDLE service,
2116 SC_RPC_CONFIG_INFOA info)
2118 WINE_FIXME("\n");
2119 return ERROR_CALL_NOT_IMPLEMENTED;
2122 DWORD __cdecl svcctl_QueryServiceConfig2A(
2123 SC_RPC_HANDLE service,
2124 DWORD info_level,
2125 BYTE *buffer,
2126 DWORD buf_size,
2127 DWORD *needed_size)
2129 WINE_FIXME("\n");
2130 return ERROR_CALL_NOT_IMPLEMENTED;
2133 DWORD RPC_Init(void)
2135 WCHAR transport[] = SVCCTL_TRANSPORT;
2136 WCHAR endpoint[] = SVCCTL_ENDPOINT;
2137 DWORD err;
2139 if (!(cleanup_group = CreateThreadpoolCleanupGroup()))
2141 WINE_ERR("CreateThreadpoolCleanupGroup failed with error %u\n", GetLastError());
2142 return GetLastError();
2145 if ((err = RpcServerUseProtseqEpW(transport, 0, endpoint, NULL)) != ERROR_SUCCESS)
2147 WINE_ERR("RpcServerUseProtseq failed with error %u\n", err);
2148 return err;
2151 if ((err = RpcServerRegisterIf(svcctl_v2_0_s_ifspec, 0, 0)) != ERROR_SUCCESS)
2153 WINE_ERR("RpcServerRegisterIf failed with error %u\n", err);
2154 return err;
2157 if ((err = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE)) != ERROR_SUCCESS)
2159 WINE_ERR("RpcServerListen failed with error %u\n", err);
2160 return err;
2163 exit_event = __wine_make_process_system();
2164 return ERROR_SUCCESS;
2167 void RPC_Stop(void)
2169 RpcMgmtStopServerListening(NULL);
2170 RpcServerUnregisterIf(svcctl_v2_0_s_ifspec, NULL, TRUE);
2171 RpcMgmtWaitServerListen();
2173 CloseThreadpoolCleanupGroupMembers(cleanup_group, TRUE, NULL);
2174 CloseThreadpoolCleanupGroup(cleanup_group);
2175 CloseHandle(exit_event);
2178 void __RPC_USER SC_RPC_HANDLE_rundown(SC_RPC_HANDLE handle)
2180 SC_RPC_HANDLE_destroy(handle);
2183 void __RPC_USER SC_NOTIFY_RPC_HANDLE_rundown(SC_NOTIFY_RPC_HANDLE handle)
2187 void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
2189 return HeapAlloc(GetProcessHeap(), 0, len);
2192 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
2194 HeapFree(GetProcessHeap(), 0, ptr);