msgsm32.acm: Use standard dlopen() instead of the libwine wrappers.
[wine/zf.git] / programs / services / rpc.c
blob0f2c1440c23c750a3260f47dc78f4fb2af3761f3
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 static void SC_RPC_LOCK_destroy(SC_RPC_LOCK hLock)
1370 struct sc_lock *lock = hLock;
1371 scmdatabase_unlock_startup(lock->db);
1372 HeapFree(GetProcessHeap(), 0, lock);
1375 void __RPC_USER SC_RPC_LOCK_rundown(SC_RPC_LOCK hLock)
1377 SC_RPC_LOCK_destroy(hLock);
1380 DWORD __cdecl svcctl_LockServiceDatabase(
1381 SC_RPC_HANDLE hSCManager,
1382 SC_RPC_LOCK *phLock)
1384 struct sc_manager_handle *manager;
1385 struct sc_lock *lock;
1386 DWORD err;
1388 WINE_TRACE("(%p, %p)\n", hSCManager, phLock);
1390 if ((err = validate_scm_handle(hSCManager, SC_MANAGER_LOCK, &manager)) != ERROR_SUCCESS)
1391 return err;
1393 if (!scmdatabase_lock_startup(manager->db, 0))
1394 return ERROR_SERVICE_DATABASE_LOCKED;
1396 lock = HeapAlloc(GetProcessHeap(), 0, sizeof(struct sc_lock));
1397 if (!lock)
1399 scmdatabase_unlock_startup(manager->db);
1400 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
1403 lock->db = manager->db;
1404 *phLock = lock;
1406 return ERROR_SUCCESS;
1409 DWORD __cdecl svcctl_UnlockServiceDatabase(
1410 SC_RPC_LOCK *phLock)
1412 WINE_TRACE("(&%p)\n", *phLock);
1414 SC_RPC_LOCK_destroy(*phLock);
1415 *phLock = NULL;
1417 return ERROR_SUCCESS;
1420 static BOOL map_state(DWORD state, DWORD mask)
1422 switch (state)
1424 case SERVICE_START_PENDING:
1425 case SERVICE_STOP_PENDING:
1426 case SERVICE_RUNNING:
1427 case SERVICE_CONTINUE_PENDING:
1428 case SERVICE_PAUSE_PENDING:
1429 case SERVICE_PAUSED:
1430 if (SERVICE_ACTIVE & mask) return TRUE;
1431 break;
1432 case SERVICE_STOPPED:
1433 if (SERVICE_INACTIVE & mask) return TRUE;
1434 break;
1435 default:
1436 WINE_ERR("unknown state %u\n", state);
1437 break;
1439 return FALSE;
1442 DWORD __cdecl svcctl_EnumServicesStatusW(
1443 SC_RPC_HANDLE hmngr,
1444 DWORD type,
1445 DWORD state,
1446 BYTE *buffer,
1447 DWORD size,
1448 LPDWORD needed,
1449 LPDWORD returned,
1450 LPDWORD resume)
1452 DWORD err, sz, total_size, num_services, offset;
1453 struct sc_manager_handle *manager;
1454 struct service_entry *service;
1455 struct enum_service_status *s;
1457 WINE_TRACE("(%p, 0x%x, 0x%x, %p, %u, %p, %p, %p)\n", hmngr, type, state, buffer, size, needed, returned, resume);
1459 if (!type || !state)
1460 return ERROR_INVALID_PARAMETER;
1462 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1463 return err;
1465 if (resume)
1466 WINE_FIXME("resume index not supported\n");
1468 scmdatabase_lock(manager->db);
1470 total_size = num_services = 0;
1471 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1473 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1475 total_size += sizeof(*s);
1476 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1477 if (service->config.lpDisplayName)
1479 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1481 num_services++;
1484 *returned = 0;
1485 *needed = total_size;
1486 if (total_size > size)
1488 scmdatabase_unlock(manager->db);
1489 return ERROR_MORE_DATA;
1491 s = (struct enum_service_status *)buffer;
1492 offset = num_services * sizeof(struct enum_service_status);
1493 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1495 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state))
1497 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1498 memcpy(buffer + offset, service->name, sz);
1499 s->service_name = offset;
1500 offset += sz;
1502 if (!service->config.lpDisplayName) s->display_name = 0;
1503 else
1505 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1506 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1507 s->display_name = offset;
1508 offset += sz;
1510 s->service_status = service->status;
1511 s++;
1514 *returned = num_services;
1515 *needed = 0;
1516 scmdatabase_unlock(manager->db);
1517 return ERROR_SUCCESS;
1520 static struct service_entry *find_service_by_group(struct scmdatabase *db, const WCHAR *group)
1522 struct service_entry *service;
1523 LIST_FOR_EACH_ENTRY(service, &db->services, struct service_entry, entry)
1525 if (service->config.lpLoadOrderGroup && !wcsicmp(group, service->config.lpLoadOrderGroup))
1526 return service;
1528 return NULL;
1531 static BOOL match_group(const WCHAR *g1, const WCHAR *g2)
1533 if (!g2) return TRUE;
1534 if (!g2[0] && (!g1 || !g1[0])) return TRUE;
1535 if (g1 && !lstrcmpW(g1, g2)) return TRUE;
1536 return FALSE;
1539 DWORD __cdecl svcctl_EnumServicesStatusExA(
1540 SC_RPC_HANDLE scmanager,
1541 SC_ENUM_TYPE info_level,
1542 DWORD service_type,
1543 DWORD service_state,
1544 BYTE *buffer,
1545 DWORD buf_size,
1546 DWORD *needed_size,
1547 DWORD *services_count,
1548 DWORD *resume_index,
1549 LPCSTR groupname)
1551 WINE_FIXME("\n");
1552 return ERROR_CALL_NOT_IMPLEMENTED;
1555 DWORD __cdecl svcctl_EnumServicesStatusExW(
1556 SC_RPC_HANDLE hmngr,
1557 SC_ENUM_TYPE info_level,
1558 DWORD type,
1559 DWORD state,
1560 BYTE *buffer,
1561 DWORD size,
1562 LPDWORD needed,
1563 LPDWORD returned,
1564 DWORD *resume_handle,
1565 LPCWSTR group)
1567 DWORD err, sz, total_size, num_services;
1568 DWORD_PTR offset;
1569 struct sc_manager_handle *manager;
1570 struct service_entry *service;
1571 struct enum_service_status_process *s;
1573 WINE_TRACE("(%p, 0x%x, 0x%x, %p, %u, %p, %p, %s)\n", hmngr, type, state, buffer, size,
1574 needed, returned, wine_dbgstr_w(group));
1576 if (resume_handle)
1577 FIXME("resume handle not supported\n");
1579 if (!type || !state)
1580 return ERROR_INVALID_PARAMETER;
1582 if ((err = validate_scm_handle(hmngr, SC_MANAGER_ENUMERATE_SERVICE, &manager)) != ERROR_SUCCESS)
1583 return err;
1585 scmdatabase_lock(manager->db);
1587 if (group && !find_service_by_group(manager->db, group))
1589 scmdatabase_unlock(manager->db);
1590 return ERROR_SERVICE_DOES_NOT_EXIST;
1593 total_size = num_services = 0;
1594 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1596 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1597 && match_group(service->config.lpLoadOrderGroup, group))
1599 total_size += sizeof(*s);
1600 total_size += (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1601 if (service->config.lpDisplayName)
1603 total_size += (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1605 num_services++;
1608 *returned = 0;
1609 *needed = total_size;
1610 if (total_size > size)
1612 scmdatabase_unlock(manager->db);
1613 return ERROR_MORE_DATA;
1615 s = (struct enum_service_status_process *)buffer;
1616 offset = num_services * sizeof(*s);
1617 LIST_FOR_EACH_ENTRY(service, &manager->db->services, struct service_entry, entry)
1619 if ((service->status.dwServiceType & type) && map_state(service->status.dwCurrentState, state)
1620 && match_group(service->config.lpLoadOrderGroup, group))
1622 sz = (lstrlenW(service->name) + 1) * sizeof(WCHAR);
1623 memcpy(buffer + offset, service->name, sz);
1624 s->service_name = offset;
1625 offset += sz;
1627 if (!service->config.lpDisplayName) s->display_name = 0;
1628 else
1630 sz = (lstrlenW(service->config.lpDisplayName) + 1) * sizeof(WCHAR);
1631 memcpy(buffer + offset, service->config.lpDisplayName, sz);
1632 s->display_name = offset;
1633 offset += sz;
1635 fill_status_process(&s->service_status_process, service);
1636 s++;
1639 *returned = num_services;
1640 *needed = 0;
1641 scmdatabase_unlock(manager->db);
1642 return ERROR_SUCCESS;
1645 DWORD __cdecl svcctl_unknown43(void)
1647 WINE_FIXME("\n");
1648 return ERROR_CALL_NOT_IMPLEMENTED;
1651 DWORD __cdecl svcctl_CreateServiceWOW64A(
1652 SC_RPC_HANDLE scmanager,
1653 LPCSTR servicename,
1654 LPCSTR displayname,
1655 DWORD accessmask,
1656 DWORD service_type,
1657 DWORD start_type,
1658 DWORD error_control,
1659 LPCSTR imagepath,
1660 LPCSTR loadordergroup,
1661 DWORD *tagid,
1662 const BYTE *dependencies,
1663 DWORD depend_size,
1664 LPCSTR start_name,
1665 const BYTE *password,
1666 DWORD password_size,
1667 SC_RPC_HANDLE *service)
1669 WINE_FIXME("\n");
1670 return ERROR_CALL_NOT_IMPLEMENTED;
1673 DWORD __cdecl svcctl_CreateServiceWOW64W(
1674 SC_RPC_HANDLE scmanager,
1675 LPCWSTR servicename,
1676 LPCWSTR displayname,
1677 DWORD accessmask,
1678 DWORD service_type,
1679 DWORD start_type,
1680 DWORD error_control,
1681 LPCWSTR imagepath,
1682 LPCWSTR loadordergroup,
1683 DWORD *tagid,
1684 const BYTE *dependencies,
1685 DWORD depend_size,
1686 LPCWSTR start_name,
1687 const BYTE *password,
1688 DWORD password_size,
1689 SC_RPC_HANDLE *service)
1691 WINE_TRACE("(%s, %s, 0x%x, %s)\n", wine_dbgstr_w(servicename), wine_dbgstr_w(displayname), accessmask, wine_dbgstr_w(imagepath));
1692 return create_serviceW(scmanager, servicename, displayname, accessmask, service_type, start_type, error_control, imagepath,
1693 loadordergroup, tagid, dependencies, depend_size, start_name, password, password_size, service, TRUE);
1696 DWORD __cdecl svcctl_unknown46(void)
1698 WINE_FIXME("\n");
1699 return ERROR_CALL_NOT_IMPLEMENTED;
1702 DWORD __cdecl svcctl_NotifyServiceStatusChange(
1703 SC_RPC_HANDLE handle,
1704 SC_RPC_NOTIFY_PARAMS params,
1705 GUID *clientprocessguid,
1706 GUID *scmprocessguid,
1707 BOOL *createremotequeue,
1708 SC_NOTIFY_RPC_HANDLE *hNotify)
1710 DWORD err, mask;
1711 struct sc_manager_handle *manager = NULL;
1712 struct sc_service_handle *service = NULL;
1713 struct sc_notify_handle *notify;
1714 struct sc_handle *hdr = handle;
1716 WINE_TRACE("(%p, NotifyMask: 0x%x, %p, %p, %p, %p)\n", handle,
1717 params.u.params->dwNotifyMask, clientprocessguid, scmprocessguid,
1718 createremotequeue, hNotify);
1720 switch (hdr->type)
1722 case SC_HTYPE_SERVICE:
1723 err = validate_service_handle(handle, SERVICE_QUERY_STATUS, &service);
1724 break;
1725 case SC_HTYPE_MANAGER:
1726 err = validate_scm_handle(handle, SC_MANAGER_ENUMERATE_SERVICE, &manager);
1727 break;
1728 default:
1729 err = ERROR_INVALID_HANDLE;
1730 break;
1733 if (err != ERROR_SUCCESS)
1734 return err;
1736 if (manager)
1738 WARN("Need support for service creation/deletion notifications\n");
1739 return ERROR_CALL_NOT_IMPLEMENTED;
1742 notify = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*notify));
1743 if (!notify)
1744 return ERROR_NOT_ENOUGH_SERVER_MEMORY;
1746 notify->hdr.type = SC_HTYPE_NOTIFY;
1747 notify->hdr.access = 0;
1749 notify->event = CreateEventW(NULL, TRUE, FALSE, NULL);
1751 notify->notify_mask = params.u.params->dwNotifyMask;
1753 service_lock(service->service_entry);
1755 if (service->notify)
1757 service_unlock(service->service_entry);
1758 sc_notify_release(notify);
1759 return ERROR_ALREADY_REGISTERED;
1762 mask = 1 << (service->service_entry->status.dwCurrentState - SERVICE_STOPPED);
1763 if (!service->status_notified && (notify->notify_mask & mask))
1765 fill_notify(notify, service->service_entry);
1766 service->status_notified = TRUE;
1768 else
1770 sc_notify_retain(notify);
1771 service->notify = notify;
1774 sc_notify_retain(notify);
1775 *hNotify = &notify->hdr;
1777 service_unlock(service->service_entry);
1779 return ERROR_SUCCESS;
1782 DWORD __cdecl svcctl_GetNotifyResults(
1783 SC_NOTIFY_RPC_HANDLE hNotify,
1784 SC_RPC_NOTIFY_PARAMS_LIST **pList)
1786 DWORD err;
1787 struct sc_notify_handle *notify;
1789 WINE_TRACE("(%p, %p)\n", hNotify, pList);
1791 if (!pList)
1792 return ERROR_INVALID_PARAMETER;
1794 *pList = NULL;
1796 if ((err = validate_notify_handle(hNotify, 0, &notify)) != 0)
1797 return err;
1799 sc_notify_retain(notify);
1800 /* block until there is a result */
1801 err = WaitForSingleObject(notify->event, INFINITE);
1803 if (err != WAIT_OBJECT_0)
1805 sc_notify_release(notify);
1806 return err;
1809 *pList = InterlockedExchangePointer((void**)&notify->params_list, NULL);
1810 if (!*pList)
1812 sc_notify_release(notify);
1813 return ERROR_REQUEST_ABORTED;
1816 sc_notify_release(notify);
1818 return ERROR_SUCCESS;
1821 DWORD __cdecl svcctl_CloseNotifyHandle(
1822 SC_NOTIFY_RPC_HANDLE *hNotify,
1823 BOOL *apc_fired)
1825 struct sc_notify_handle *notify;
1826 DWORD err;
1828 WINE_TRACE("(%p, %p)\n", hNotify, apc_fired);
1830 if ((err = validate_notify_handle(*hNotify, 0, &notify)) != 0)
1831 return err;
1833 sc_notify_release(notify);
1835 return ERROR_SUCCESS;
1838 DWORD __cdecl svcctl_ControlServiceExA(
1839 SC_RPC_HANDLE service,
1840 DWORD control,
1841 DWORD info_level,
1842 SC_RPC_SERVICE_CONTROL_IN_PARAMSA *in_params,
1843 SC_RPC_SERVICE_CONTROL_OUT_PARAMSA *out_params)
1845 WINE_FIXME("\n");
1846 return ERROR_CALL_NOT_IMPLEMENTED;
1849 DWORD __cdecl svcctl_ControlServiceExW(
1850 SC_RPC_HANDLE service,
1851 DWORD control,
1852 DWORD info_level,
1853 SC_RPC_SERVICE_CONTROL_IN_PARAMSW *in_params,
1854 SC_RPC_SERVICE_CONTROL_OUT_PARAMSW *out_params)
1856 WINE_FIXME("\n");
1857 return ERROR_CALL_NOT_IMPLEMENTED;
1860 DWORD __cdecl svcctl_unknown52(void)
1862 WINE_FIXME("\n");
1863 return ERROR_CALL_NOT_IMPLEMENTED;
1866 DWORD __cdecl svcctl_unknown53(void)
1868 WINE_FIXME("\n");
1869 return ERROR_CALL_NOT_IMPLEMENTED;
1872 DWORD __cdecl svcctl_unknown54(void)
1874 WINE_FIXME("\n");
1875 return ERROR_CALL_NOT_IMPLEMENTED;
1878 DWORD __cdecl svcctl_unknown55(void)
1880 WINE_FIXME("\n");
1881 return ERROR_CALL_NOT_IMPLEMENTED;
1884 DWORD __cdecl svcctl_QueryServiceConfigEx(
1885 SC_RPC_HANDLE service,
1886 DWORD info_level,
1887 SC_RPC_CONFIG_INFOW *info)
1889 WINE_FIXME("\n");
1890 return ERROR_CALL_NOT_IMPLEMENTED;
1893 DWORD __cdecl svcctl_QueryServiceObjectSecurity(
1894 SC_RPC_HANDLE service,
1895 SECURITY_INFORMATION info,
1896 BYTE *descriptor,
1897 DWORD buf_size,
1898 DWORD *needed_size)
1900 WINE_FIXME("\n");
1901 return ERROR_CALL_NOT_IMPLEMENTED;
1904 DWORD __cdecl svcctl_SetServiceObjectSecurity(
1905 SC_RPC_HANDLE service,
1906 SECURITY_INFORMATION info,
1907 BYTE *descriptor,
1908 DWORD buf_size)
1910 WINE_FIXME("\n");
1911 return ERROR_CALL_NOT_IMPLEMENTED;
1914 DWORD __cdecl svcctl_QueryServiceStatus(
1915 SC_RPC_HANDLE service,
1916 SERVICE_STATUS *status)
1918 WINE_FIXME("\n");
1919 return ERROR_CALL_NOT_IMPLEMENTED;
1922 DWORD __cdecl svcctl_NotifyBootConfigStatus(
1923 SVCCTL_HANDLEW machinename,
1924 DWORD boot_acceptable)
1926 WINE_FIXME("\n");
1927 return ERROR_CALL_NOT_IMPLEMENTED;
1930 DWORD __cdecl svcctl_SCSetServiceBitsW(void)
1932 WINE_FIXME("\n");
1933 return ERROR_CALL_NOT_IMPLEMENTED;
1936 DWORD __cdecl svcctl_EnumDependentServicesW(
1937 SC_RPC_HANDLE service,
1938 DWORD state,
1939 BYTE *services,
1940 DWORD buf_size,
1941 DWORD *needed_size,
1942 DWORD *services_ret)
1944 WINE_FIXME("\n");
1945 return ERROR_CALL_NOT_IMPLEMENTED;
1948 DWORD __cdecl svcctl_QueryServiceLockStatusW(
1949 SC_RPC_HANDLE scmanager,
1950 QUERY_SERVICE_LOCK_STATUSW *status,
1951 DWORD buf_size,
1952 DWORD *needed_size)
1954 WINE_FIXME("\n");
1955 return ERROR_CALL_NOT_IMPLEMENTED;
1958 DWORD __cdecl svcctl_SCSetServiceBitsA(void)
1960 WINE_FIXME("\n");
1961 return ERROR_CALL_NOT_IMPLEMENTED;
1964 DWORD __cdecl svcctl_ChangeServiceConfigA(
1965 SC_RPC_HANDLE service,
1966 DWORD service_type,
1967 DWORD start_type,
1968 DWORD error_control,
1969 LPSTR binarypath,
1970 LPSTR loadordergroup,
1971 DWORD *tagid,
1972 BYTE *dependencies,
1973 DWORD depend_size,
1974 LPSTR startname,
1975 BYTE *password,
1976 DWORD password_size,
1977 LPSTR displayname)
1979 WINE_FIXME("\n");
1980 return ERROR_CALL_NOT_IMPLEMENTED;
1983 DWORD __cdecl svcctl_CreateServiceA(
1984 SC_RPC_HANDLE scmanager,
1985 LPCSTR servicename,
1986 LPCSTR displayname,
1987 DWORD desiredaccess,
1988 DWORD service_type,
1989 DWORD start_type,
1990 DWORD error_control,
1991 LPCSTR binarypath,
1992 LPCSTR loadordergroup,
1993 DWORD *tagid,
1994 const BYTE *dependencies,
1995 DWORD depend_size,
1996 LPCSTR startname,
1997 const BYTE *password,
1998 DWORD password_size,
1999 SC_RPC_HANDLE *service)
2001 WINE_FIXME("\n");
2002 return ERROR_CALL_NOT_IMPLEMENTED;
2005 DWORD __cdecl svcctl_EnumDependentServicesA(
2006 SC_RPC_HANDLE service,
2007 DWORD state,
2008 BYTE *services,
2009 DWORD buf_size,
2010 DWORD *needed_size,
2011 DWORD *services_ret)
2013 WINE_FIXME("\n");
2014 return ERROR_CALL_NOT_IMPLEMENTED;
2017 DWORD __cdecl svcctl_EnumServicesStatusA(
2018 SC_RPC_HANDLE hmngr,
2019 DWORD type,
2020 DWORD state,
2021 BYTE *buffer,
2022 DWORD size,
2023 DWORD *needed,
2024 DWORD *returned,
2025 DWORD *resume)
2027 WINE_FIXME("\n");
2028 return ERROR_CALL_NOT_IMPLEMENTED;
2031 DWORD __cdecl svcctl_OpenSCManagerA(
2032 MACHINE_HANDLEA MachineName,
2033 LPCSTR DatabaseName,
2034 DWORD dwAccessMask,
2035 SC_RPC_HANDLE *handle)
2037 WINE_FIXME("\n");
2038 return ERROR_CALL_NOT_IMPLEMENTED;
2041 DWORD __cdecl svcctl_OpenServiceA(
2042 SC_RPC_HANDLE hSCManager,
2043 LPCSTR lpServiceName,
2044 DWORD dwDesiredAccess,
2045 SC_RPC_HANDLE *phService)
2047 WINE_FIXME("\n");
2048 return ERROR_CALL_NOT_IMPLEMENTED;
2051 DWORD __cdecl svcctl_QueryServiceConfigA(
2052 SC_RPC_HANDLE hService,
2053 QUERY_SERVICE_CONFIGA *config,
2054 DWORD buf_size,
2055 DWORD *needed_size)
2057 WINE_FIXME("\n");
2058 return ERROR_CALL_NOT_IMPLEMENTED;
2061 DWORD __cdecl svcctl_QueryServiceLockStatusA(
2062 SC_RPC_HANDLE scmanager,
2063 QUERY_SERVICE_LOCK_STATUSA *status,
2064 DWORD buf_size,
2065 DWORD *needed_size)
2067 WINE_FIXME("\n");
2068 return ERROR_CALL_NOT_IMPLEMENTED;
2071 DWORD __cdecl svcctl_StartServiceA(
2072 SC_RPC_HANDLE service,
2073 DWORD argc,
2074 LPCSTR *args)
2076 WINE_FIXME("\n");
2077 return ERROR_CALL_NOT_IMPLEMENTED;
2080 DWORD __cdecl svcctl_GetServiceDisplayNameA(
2081 SC_RPC_HANDLE hSCManager,
2082 LPCSTR servicename,
2083 CHAR buffer[],
2084 DWORD *buf_size)
2086 WINE_FIXME("\n");
2087 return ERROR_CALL_NOT_IMPLEMENTED;
2090 DWORD __cdecl svcctl_GetServiceKeyNameA(
2091 SC_RPC_HANDLE hSCManager,
2092 LPCSTR servicename,
2093 CHAR buffer[],
2094 DWORD *buf_size)
2096 WINE_FIXME("\n");
2097 return ERROR_CALL_NOT_IMPLEMENTED;
2100 DWORD __cdecl svcctl_GetCurrentGroupStateW(void)
2102 WINE_FIXME("\n");
2103 return ERROR_CALL_NOT_IMPLEMENTED;
2106 DWORD __cdecl svcctl_EnumServiceGroupW(
2107 SC_RPC_HANDLE scmanager,
2108 DWORD service_type,
2109 DWORD service_state,
2110 BYTE *buffer,
2111 DWORD buf_size,
2112 DWORD *needed_size,
2113 DWORD *returned_size,
2114 DWORD *resume_index,
2115 LPCWSTR groupname)
2117 WINE_FIXME("\n");
2118 return ERROR_CALL_NOT_IMPLEMENTED;
2121 DWORD __cdecl svcctl_ChangeServiceConfig2A(
2122 SC_RPC_HANDLE service,
2123 SC_RPC_CONFIG_INFOA info)
2125 WINE_FIXME("\n");
2126 return ERROR_CALL_NOT_IMPLEMENTED;
2129 DWORD __cdecl svcctl_QueryServiceConfig2A(
2130 SC_RPC_HANDLE service,
2131 DWORD info_level,
2132 BYTE *buffer,
2133 DWORD buf_size,
2134 DWORD *needed_size)
2136 WINE_FIXME("\n");
2137 return ERROR_CALL_NOT_IMPLEMENTED;
2140 DWORD RPC_Init(void)
2142 WCHAR transport[] = SVCCTL_TRANSPORT;
2143 WCHAR endpoint[] = SVCCTL_ENDPOINT;
2144 DWORD err;
2146 if (!(cleanup_group = CreateThreadpoolCleanupGroup()))
2148 WINE_ERR("CreateThreadpoolCleanupGroup failed with error %u\n", GetLastError());
2149 return GetLastError();
2152 if ((err = RpcServerUseProtseqEpW(transport, 0, endpoint, NULL)) != ERROR_SUCCESS)
2154 WINE_ERR("RpcServerUseProtseq failed with error %u\n", err);
2155 return err;
2158 if ((err = RpcServerRegisterIf(svcctl_v2_0_s_ifspec, 0, 0)) != ERROR_SUCCESS)
2160 WINE_ERR("RpcServerRegisterIf failed with error %u\n", err);
2161 return err;
2164 if ((err = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE)) != ERROR_SUCCESS)
2166 WINE_ERR("RpcServerListen failed with error %u\n", err);
2167 return err;
2170 exit_event = __wine_make_process_system();
2171 return ERROR_SUCCESS;
2174 void RPC_Stop(void)
2176 RpcMgmtStopServerListening(NULL);
2177 RpcServerUnregisterIf(svcctl_v2_0_s_ifspec, NULL, TRUE);
2178 RpcMgmtWaitServerListen();
2180 CloseThreadpoolCleanupGroupMembers(cleanup_group, TRUE, NULL);
2181 CloseThreadpoolCleanupGroup(cleanup_group);
2182 CloseHandle(exit_event);
2185 void __RPC_USER SC_RPC_HANDLE_rundown(SC_RPC_HANDLE handle)
2187 SC_RPC_HANDLE_destroy(handle);
2190 void __RPC_USER SC_NOTIFY_RPC_HANDLE_rundown(SC_NOTIFY_RPC_HANDLE handle)
2194 void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
2196 return HeapAlloc(GetProcessHeap(), 0, len);
2199 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
2201 HeapFree(GetProcessHeap(), 0, ptr);