#include "services.h"
#include <winnls.h>
+#include <strsafe.h>
#define NDEBUG
#include <debug.h>
#define MANAGER_TAG 0x72674D68 /* 'hMgr' */
#define SERVICE_TAG 0x63765368 /* 'hSvc' */
+#define INVALID_TAG 0xAABBCCDD
typedef struct _SCMGR_HANDLE
{
SERVICE_EXECUTE,
SERVICE_ALL_ACCESS};
+DWORD g_dwServiceBits = 0;
/* FUNCTIONS ***************************************************************/
if (!Expanded)
{
DPRINT("Error allocating memory for boot driver name!\n");
+ RtlFreeUnicodeString(&NtPathName);
return ERROR_NOT_ENOUGH_MEMORY;
}
ExpandedLen = NtPathName.Length / sizeof(WCHAR);
wcsncpy(Expanded, NtPathName.Buffer, ExpandedLen);
Expanded[ExpandedLen] = UNICODE_NULL;
+ RtlFreeUnicodeString(&NtPathName);
if (ServiceNameLen > ExpandedLen &&
!_wcsnicmp(Expanded, CanonName, ExpandedLen))
{
+ HeapFree(GetProcessHeap(), 0, Expanded);
+
/* Only \SystemRoot\ is missing */
*RelativeName = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
if (*RelativeName == NULL)
{
DPRINT("Error allocating memory for boot driver name!\n");
- HeapFree(GetProcessHeap(), 0, Expanded);
return ERROR_NOT_ENOUGH_MEMORY;
}
wcscpy(*RelativeName, L"\\SystemRoot\\");
wcscat(*RelativeName, CanonName + ExpandedLen);
- RtlFreeUnicodeString(&NtPathName);
return ERROR_SUCCESS;
}
+ /* No longer need this */
+ HeapFree(GetProcessHeap(), 0, Expanded);
+
/* The most complex case starts here */
RtlInitUnicodeString(&SystemRoot, L"\\SystemRoot");
InitializeObjectAttributes(&ObjectAttributes,
/* Open this symlink */
Status = NtOpenSymbolicLinkObject(&SymbolicLinkHandle, SYMBOLIC_LINK_QUERY, &ObjectAttributes);
-
if (NT_SUCCESS(Status))
{
- LinkTarget.Length = 0;
- LinkTarget.MaximumLength = 0;
-
DPRINT("Opened symbolic link object\n");
+ RtlInitEmptyUnicodeString(&LinkTarget, NULL, 0);
Status = NtQuerySymbolicLinkObject(SymbolicLinkHandle, &LinkTarget, &BufferSize);
if (NT_SUCCESS(Status) || Status == STATUS_BUFFER_TOO_SMALL)
{
/* Check if required buffer size is sane */
- if (BufferSize > 0xFFFD)
+ if (BufferSize > UNICODE_STRING_MAX_BYTES - sizeof(UNICODE_NULL))
{
DPRINT("Too large buffer required\n");
- if (SymbolicLinkHandle) NtClose(SymbolicLinkHandle);
- HeapFree(GetProcessHeap(), 0, Expanded);
+ NtClose(SymbolicLinkHandle);
return ERROR_NOT_ENOUGH_MEMORY;
}
if (!LinkTarget.Buffer)
{
DPRINT("Unable to alloc buffer\n");
- if (SymbolicLinkHandle) NtClose(SymbolicLinkHandle);
- HeapFree(GetProcessHeap(), 0, Expanded);
+ NtClose(SymbolicLinkHandle);
return ERROR_NOT_ENOUGH_MEMORY;
}
/* Do a real query now */
Status = NtQuerySymbolicLinkObject(SymbolicLinkHandle, &LinkTarget, &BufferSize);
+ NtClose(SymbolicLinkHandle);
if (NT_SUCCESS(Status))
{
DPRINT("LinkTarget: %wZ\n", &LinkTarget);
if (*RelativeName == NULL)
{
DPRINT("Unable to alloc buffer\n");
- if (SymbolicLinkHandle) NtClose(SymbolicLinkHandle);
- HeapFree(GetProcessHeap(), 0, Expanded);
- RtlFreeUnicodeString(&NtPathName);
return ERROR_NOT_ENOUGH_MEMORY;
}
wcscpy(*RelativeName, L"\\SystemRoot\\");
wcscat(*RelativeName, CanonName+ExpandedLen+1);
- /* Cleanup */
- if (SymbolicLinkHandle) NtClose(SymbolicLinkHandle);
- HeapFree(GetProcessHeap(), 0, Expanded);
- RtlFreeUnicodeString(&NtPathName);
-
/* Return success */
return ERROR_SUCCESS;
}
else
{
- if (SymbolicLinkHandle) NtClose(SymbolicLinkHandle);
- HeapFree(GetProcessHeap(), 0, Expanded);
- RtlFreeUnicodeString(&NtPathName);
return ERROR_INVALID_PARAMETER;
}
}
else
{
DPRINT("Error, Status = %08X\n", Status);
- if (SymbolicLinkHandle) NtClose(SymbolicLinkHandle);
- HeapFree(GetProcessHeap(), 0, Expanded);
- RtlFreeUnicodeString(&NtPathName);
return ERROR_INVALID_PARAMETER;
}
}
else
{
DPRINT("Error, Status = %08X\n", Status);
- if (SymbolicLinkHandle) NtClose(SymbolicLinkHandle);
- HeapFree(GetProcessHeap(), 0, Expanded);
- RtlFreeUnicodeString(&NtPathName);
+ NtClose(SymbolicLinkHandle);
return ERROR_INVALID_PARAMETER;
}
}
{
/* Failure */
DPRINT("Error, Status = %08X\n", Status);
- HeapFree(GetProcessHeap(), 0, Expanded);
return ERROR_INVALID_PARAMETER;
}
}
if (dwError != ERROR_SUCCESS)
return dwError;
- dwSize = MAX_PATH;
+ dwSize = MAX_PATH * sizeof(WCHAR);
/* Check for the DependOnService Value */
dwError = RegQueryValueExW(hServiceEnumKey,
/* Function 0 */
-DWORD RCloseServiceHandle(
+DWORD
+WINAPI
+RCloseServiceHandle(
LPSC_RPC_HANDLE hSCObject)
{
PMANAGER_HANDLE hManager;
{
DPRINT("Found manager handle\n");
- /* FIXME: add handle cleanup code */
+ /* Make sure we don't access stale memory if someone tries to use this handle again. */
+ hManager->Handle.Tag = INVALID_TAG;
HeapFree(GetProcessHeap(), 0, hManager);
hManager = NULL;
{
DPRINT("Found service handle\n");
- /* Lock the service database exlusively */
+ /* Lock the service database exclusively */
ScmLockDatabaseExclusive();
/* Get the pointer to the service record */
lpService = hService->ServiceEntry;
- /* FIXME: add handle cleanup code */
+ /* Make sure we don't access stale memory if someone tries to use this handle again. */
+ hService->Handle.Tag = INVALID_TAG;
/* Free the handle */
HeapFree(GetProcessHeap(), 0, hService);
if (lpService->dwRefCount == 0)
{
/* If this service has been marked for deletion */
- if (lpService->bDeleted)
+ if (lpService->bDeleted &&
+ lpService->Status.dwCurrentState == SERVICE_STOPPED)
{
/* Open the Services Reg key */
dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
return ERROR_SUCCESS;
}
- /* There are no references and no runnning dependencies,
+ /* There are no references and no running dependencies,
it is now safe to delete the service */
/* Delete the Service Key */
- dwError = RegDeleteKeyW(hServicesKey,
- lpService->lpServiceName);
+ dwError = ScmDeleteRegKey(hServicesKey,
+ lpService->lpServiceName);
RegCloseKey(hServicesKey);
/* Function 1 */
-DWORD RControlService(
+DWORD
+WINAPI
+RControlService(
SC_RPC_HANDLE hService,
DWORD dwControl,
LPSERVICE_STATUS lpServiceStatus)
DWORD dwControlsAccepted;
DWORD dwCurrentState;
HKEY hServicesKey = NULL;
- LPCWSTR lpErrorStrings[2];
+ LPCWSTR lpLogStrings[2];
+ WCHAR szLogBuffer[80];
+ UINT uID;
DPRINT("RControlService() called\n");
case SERVICE_CONTROL_PAUSE:
case SERVICE_CONTROL_CONTINUE:
+ case SERVICE_CONTROL_PARAMCHANGE:
+ case SERVICE_CONTROL_NETBINDADD:
+ case SERVICE_CONTROL_NETBINDREMOVE:
+ case SERVICE_CONTROL_NETBINDENABLE:
+ case SERVICE_CONTROL_NETBINDDISABLE:
DesiredAccess = SERVICE_PAUSE_CONTINUE;
break;
if ((dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) == 0)
return ERROR_INVALID_SERVICE_CONTROL;
break;
+
+ case SERVICE_CONTROL_PARAMCHANGE:
+ if ((dwControlsAccepted & SERVICE_ACCEPT_PARAMCHANGE) == 0)
+ return ERROR_INVALID_SERVICE_CONTROL;
+ break;
+
+ case SERVICE_CONTROL_NETBINDADD:
+ case SERVICE_CONTROL_NETBINDREMOVE:
+ case SERVICE_CONTROL_NETBINDENABLE:
+ case SERVICE_CONTROL_NETBINDDISABLE:
+ if ((dwControlsAccepted & SERVICE_ACCEPT_NETBINDCHANGE) == 0)
+ return ERROR_INVALID_SERVICE_CONTROL;
+ break;
}
/* Send control code to the service */
- dwError = ScmControlService(lpService,
+ dwError = ScmControlService(lpService->lpImage->hControlPipe,
+ lpService->lpServiceName,
+ (SERVICE_STATUS_HANDLE)lpService,
dwControl);
/* Return service status information */
if (dwError == ERROR_SUCCESS)
{
- if (dwControl != SERVICE_CONTROL_INTERROGATE)
- {
- /* Log a sucessful send control */
- lpErrorStrings[0] = lpService->lpDisplayName;
+ if (dwControl == SERVICE_CONTROL_STOP ||
+ dwControl == SERVICE_CONTROL_PAUSE ||
+ dwControl == SERVICE_CONTROL_CONTINUE)
+ {
+ /* Log a successful send control */
- switch(dwControl)
- {
- case SERVICE_CONTROL_STOP:
- lpErrorStrings[1] = L"stop";
- break;
+ switch (dwControl)
+ {
+ case SERVICE_CONTROL_STOP:
+ uID = IDS_SERVICE_STOP;
+ break;
- case SERVICE_CONTROL_PAUSE:
- lpErrorStrings[1] = L"pause";
- break;
+ case SERVICE_CONTROL_PAUSE:
+ uID = IDS_SERVICE_PAUSE;
+ break;
- case SERVICE_CONTROL_CONTINUE:
- lpErrorStrings[1] = L"continue";
- break;
+ case SERVICE_CONTROL_CONTINUE:
+ uID = IDS_SERVICE_RESUME;
+ break;
+ }
+ LoadStringW(GetModuleHandle(NULL), uID, szLogBuffer, ARRAYSIZE(szLogBuffer));
- default:
- lpErrorStrings[1] = L"other";
- break;
- }
+ lpLogStrings[0] = lpService->lpDisplayName;
+ lpLogStrings[1] = szLogBuffer;
- ScmLogEvent(EVENT_SERVICE_CONTROL_SUCCESS,
- EVENTLOG_INFORMATION_TYPE,
- 2,
- lpErrorStrings);
- }
+ ScmLogEvent(EVENT_SERVICE_CONTROL_SUCCESS,
+ EVENTLOG_INFORMATION_TYPE,
+ 2,
+ lpLogStrings);
+ }
}
return dwError;
/* Function 2 */
-DWORD RDeleteService(
+DWORD
+WINAPI
+RDeleteService(
SC_RPC_HANDLE hService)
{
PSERVICE_HANDLE hSvc;
/* Function 3 */
-DWORD RLockServiceDatabase(
+DWORD
+WINAPI
+RLockServiceDatabase(
SC_RPC_HANDLE hSCManager,
LPSC_RPC_LOCK lpLock)
{
/* Function 4 */
-DWORD RQueryServiceObjectSecurity(
+DWORD
+WINAPI
+RQueryServiceObjectSecurity(
SC_RPC_HANDLE hService,
SECURITY_INFORMATION dwSecurityInformation,
LPBYTE lpSecurityDescriptor,
DWORD dwBytesNeeded;
DWORD dwError;
-
- SECURITY_DESCRIPTOR ObjectDescriptor;
-
DPRINT("RQueryServiceObjectSecurity() called\n");
hSvc = ScmGetServiceFromHandle(hService);
/* Lock the service database */
ScmLockDatabaseShared();
-
- /* hack */
- Status = RtlCreateSecurityDescriptor(&ObjectDescriptor, SECURITY_DESCRIPTOR_REVISION);
-
- Status = RtlQuerySecurityObject(&ObjectDescriptor /* lpService->lpSecurityDescriptor */,
+ /* Retrieve the security descriptor */
+ Status = RtlQuerySecurityObject(lpService->pSecurityDescriptor,
dwSecurityInformation,
(PSECURITY_DESCRIPTOR)lpSecurityDescriptor,
cbBufSize,
/* Function 5 */
-DWORD RSetServiceObjectSecurity(
+DWORD
+WINAPI
+RSetServiceObjectSecurity(
SC_RPC_HANDLE hService,
DWORD dwSecurityInformation,
LPBYTE lpSecurityDescriptor,
- DWORD dwSecuityDescriptorSize)
+ DWORD dwSecurityDescriptorSize)
{
PSERVICE_HANDLE hSvc;
PSERVICE lpService;
- ULONG DesiredAccess = 0;
- /* HANDLE hToken = NULL; */
- HKEY hServiceKey;
- /* NTSTATUS Status; */
+ ACCESS_MASK DesiredAccess = 0;
+ HANDLE hToken = NULL;
+ HKEY hServiceKey = NULL;
+ BOOL bDatabaseLocked = FALSE;
+ NTSTATUS Status;
DWORD dwError;
DPRINT("RSetServiceObjectSecurity() called\n");
if (!RtlAreAllAccessesGranted(hSvc->Handle.DesiredAccess,
DesiredAccess))
{
- DPRINT("Insufficient access rights! 0x%lx\n", hSvc->Handle.DesiredAccess);
+ DPRINT1("Insufficient access rights! 0x%lx\n", hSvc->Handle.DesiredAccess);
return ERROR_ACCESS_DENIED;
}
lpService = hSvc->ServiceEntry;
if (lpService == NULL)
{
- DPRINT("lpService == NULL!\n");
+ DPRINT1("lpService == NULL!\n");
return ERROR_INVALID_HANDLE;
}
RpcRevertToSelf();
#endif
- /* Lock the service database exclusive */
- ScmLockDatabaseExclusive();
-
-#if 0
+ /* Build the new security descriptor */
Status = RtlSetSecurityObject(dwSecurityInformation,
(PSECURITY_DESCRIPTOR)lpSecurityDescriptor,
- &lpService->lpSecurityDescriptor,
+ &lpService->pSecurityDescriptor,
&ScmServiceMapping,
hToken);
if (!NT_SUCCESS(Status))
dwError = RtlNtStatusToDosError(Status);
goto Done;
}
-#endif
+ /* Lock the service database exclusive */
+ ScmLockDatabaseExclusive();
+ bDatabaseLocked = TRUE;
+
+ /* Open the service key */
dwError = ScmOpenServiceKey(lpService->lpServiceName,
READ_CONTROL | KEY_CREATE_SUB_KEY | KEY_SET_VALUE,
&hServiceKey);
if (dwError != ERROR_SUCCESS)
goto Done;
- UNIMPLEMENTED;
- dwError = ERROR_SUCCESS;
-// dwError = ScmWriteSecurityDescriptor(hServiceKey,
-// lpService->lpSecurityDescriptor);
+ /* Store the new security descriptor */
+ dwError = ScmWriteSecurityDescriptor(hServiceKey,
+ lpService->pSecurityDescriptor);
RegFlushKey(hServiceKey);
- RegCloseKey(hServiceKey);
Done:
+ if (hServiceKey != NULL)
+ RegCloseKey(hServiceKey);
+
+ /* Unlock service database */
+ if (bDatabaseLocked == TRUE)
+ ScmUnlockDatabase();
-#if 0
if (hToken != NULL)
NtClose(hToken);
-#endif
-
- /* Unlock service database */
- ScmUnlockDatabase();
DPRINT("RSetServiceObjectSecurity() done (Error %lu)\n", dwError);
/* Function 6 */
-DWORD RQueryServiceStatus(
+DWORD
+WINAPI
+RQueryServiceStatus(
SC_RPC_HANDLE hService,
LPSERVICE_STATUS lpServiceStatus)
{
/* Function 7 */
-DWORD RSetServiceStatus(
+DWORD
+WINAPI
+RSetServiceStatus(
RPC_SERVICE_STATUS_HANDLE hServiceStatus,
LPSERVICE_STATUS lpServiceStatus)
{
PSERVICE lpService;
DWORD dwPreviousState;
DWORD dwPreviousType;
- LPCWSTR lpErrorStrings[2];
- WCHAR szErrorBuffer[32];
+ LPCWSTR lpLogStrings[2];
+ WCHAR szLogBuffer[80];
+ UINT uID;
DPRINT("RSetServiceStatus() called\n");
DPRINT("hServiceStatus = %lu\n", hServiceStatus);
/* Restore the previous service type */
lpService->Status.dwServiceType = dwPreviousType;
+ /* Dereference a stopped service */
+ if ((lpServiceStatus->dwServiceType & SERVICE_WIN32) &&
+ (lpServiceStatus->dwCurrentState == SERVICE_STOPPED))
+ {
+ /* Decrement the image run counter */
+ lpService->lpImage->dwImageRunCount--;
+
+ /* If we just stopped the last running service... */
+ if (lpService->lpImage->dwImageRunCount == 0)
+ {
+ /* Stop the dispatcher thread */
+ ScmControlService(lpService->lpImage->hControlPipe,
+ L"",
+ (SERVICE_STATUS_HANDLE)lpService,
+ SERVICE_CONTROL_STOP);
+
+ /* Remove the service image */
+ ScmRemoveServiceImage(lpService->lpImage);
+ lpService->lpImage = NULL;
+ }
+ }
+
/* Unlock the service database */
ScmUnlockDatabase();
(lpServiceStatus->dwWin32ExitCode != ERROR_SUCCESS))
{
/* Log a failed service stop */
- swprintf(szErrorBuffer, L"%lu", lpServiceStatus->dwWin32ExitCode);
- lpErrorStrings[0] = lpService->lpDisplayName;
- lpErrorStrings[1] = szErrorBuffer;
+ StringCchPrintfW(szLogBuffer, ARRAYSIZE(szLogBuffer),
+ L"%lu", lpServiceStatus->dwWin32ExitCode);
+ lpLogStrings[0] = lpService->lpDisplayName;
+ lpLogStrings[1] = szLogBuffer;
ScmLogEvent(EVENT_SERVICE_EXIT_FAILED,
EVENTLOG_ERROR_TYPE,
2,
- lpErrorStrings);
+ lpLogStrings);
}
else if (lpServiceStatus->dwCurrentState != dwPreviousState &&
(lpServiceStatus->dwCurrentState == SERVICE_STOPPED ||
lpServiceStatus->dwCurrentState == SERVICE_PAUSED))
{
/* Log a successful service status change */
- lpErrorStrings[0] = lpService->lpDisplayName;
-
switch(lpServiceStatus->dwCurrentState)
{
case SERVICE_STOPPED:
- lpErrorStrings[1] = L"stopped";
+ uID = IDS_SERVICE_STOPPED;
break;
case SERVICE_RUNNING:
- lpErrorStrings[1] = L"running";
+ uID = IDS_SERVICE_RUNNING;
break;
case SERVICE_PAUSED:
- lpErrorStrings[1] = L"paused";
+ uID = IDS_SERVICE_PAUSED;
break;
}
+ LoadStringW(GetModuleHandle(NULL), uID, szLogBuffer, ARRAYSIZE(szLogBuffer));
+ lpLogStrings[0] = lpService->lpDisplayName;
+ lpLogStrings[1] = szLogBuffer;
+
ScmLogEvent(EVENT_SERVICE_STATUS_SUCCESS,
EVENTLOG_INFORMATION_TYPE,
2,
- lpErrorStrings);
+ lpLogStrings);
}
DPRINT("Set %S to %lu\n", lpService->lpDisplayName, lpService->Status.dwCurrentState);
/* Function 8 */
-DWORD RUnlockServiceDatabase(
+DWORD
+WINAPI
+RUnlockServiceDatabase(
LPSC_RPC_LOCK Lock)
{
DPRINT("RUnlockServiceDatabase(%p)\n", Lock);
/* Function 9 */
-DWORD RNotifyBootConfigStatus(
+DWORD
+WINAPI
+RNotifyBootConfigStatus(
SVCCTL_HANDLEW lpMachineName,
DWORD BootAcceptable)
{
/* Function 10 */
-DWORD RI_ScSetServiceBitsW(
+DWORD
+WINAPI
+RI_ScSetServiceBitsW(
RPC_SERVICE_STATUS_HANDLE hServiceStatus,
DWORD dwServiceBits,
int bSetBitsOn,
int bUpdateImmediately,
wchar_t *lpString)
{
- UNIMPLEMENTED;
- return ERROR_CALL_NOT_IMPLEMENTED;
+ PSERVICE pService;
+
+ DPRINT("RI_ScSetServiceBitsW(%p %lx %d %d %S)\n",
+ hServiceStatus, dwServiceBits, bSetBitsOn,
+ bUpdateImmediately, lpString);
+
+ if (ScmShutdown)
+ return ERROR_SHUTDOWN_IN_PROGRESS;
+
+ if (lpString != NULL)
+ return ERROR_INVALID_PARAMETER;
+
+ if (hServiceStatus == 0)
+ {
+ DPRINT("hServiceStatus == NULL!\n");
+ return ERROR_INVALID_HANDLE;
+ }
+
+ // FIXME: Validate the status handle
+ pService = (PSERVICE)hServiceStatus;
+
+ if (bSetBitsOn)
+ {
+ DPRINT("Old service bits: %08lx\n", pService->dwServiceBits);
+ DPRINT("Old global service bits: %08lx\n", g_dwServiceBits);
+ pService->dwServiceBits |= dwServiceBits;
+ g_dwServiceBits |= dwServiceBits;
+ DPRINT("New service bits: %08lx\n", pService->dwServiceBits);
+ DPRINT("New global service bits: %08lx\n", g_dwServiceBits);
+ }
+ else
+ {
+ DPRINT("Old service bits: %08lx\n", pService->dwServiceBits);
+ DPRINT("Old global service bits: %08lx\n", g_dwServiceBits);
+ pService->dwServiceBits &= ~dwServiceBits;
+ g_dwServiceBits &= ~dwServiceBits;
+ DPRINT("New service bits: %08lx\n", pService->dwServiceBits);
+ DPRINT("New global service bits: %08lx\n", g_dwServiceBits);
+ }
+
+ return ERROR_SUCCESS;
}
/* Function 11 */
-DWORD RChangeServiceConfigW(
+DWORD
+WINAPI
+RChangeServiceConfigW(
SC_RPC_HANDLE hService,
DWORD dwServiceType,
DWORD dwStartType,
return ERROR_ACCESS_DENIED;
}
+ /* Check for invalid service type value */
+ if ((dwServiceType != SERVICE_NO_CHANGE) &&
+ (dwServiceType != SERVICE_KERNEL_DRIVER) &&
+ (dwServiceType != SERVICE_FILE_SYSTEM_DRIVER) &&
+ ((dwServiceType & ~SERVICE_INTERACTIVE_PROCESS) != SERVICE_WIN32_OWN_PROCESS) &&
+ ((dwServiceType & ~SERVICE_INTERACTIVE_PROCESS) != SERVICE_WIN32_SHARE_PROCESS))
+ return ERROR_INVALID_PARAMETER;
+
+ /* Check for invalid start type value */
+ if ((dwStartType != SERVICE_NO_CHANGE) &&
+ (dwStartType != SERVICE_BOOT_START) &&
+ (dwStartType != SERVICE_SYSTEM_START) &&
+ (dwStartType != SERVICE_AUTO_START) &&
+ (dwStartType != SERVICE_DEMAND_START) &&
+ (dwStartType != SERVICE_DISABLED))
+ return ERROR_INVALID_PARAMETER;
+
+ /* Only drivers can be boot start or system start services */
+ if ((dwStartType == SERVICE_BOOT_START) ||
+ (dwStartType == SERVICE_SYSTEM_START))
+ {
+ if ((dwServiceType != SERVICE_KERNEL_DRIVER) &&
+ (dwServiceType != SERVICE_FILE_SYSTEM_DRIVER))
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ /* Check for invalid error control value */
+ if ((dwErrorControl != SERVICE_NO_CHANGE) &&
+ (dwErrorControl != SERVICE_ERROR_IGNORE) &&
+ (dwErrorControl != SERVICE_ERROR_NORMAL) &&
+ (dwErrorControl != SERVICE_ERROR_SEVERE) &&
+ (dwErrorControl != SERVICE_ERROR_CRITICAL))
+ return ERROR_INVALID_PARAMETER;
+
lpService = hSvc->ServiceEntry;
if (lpService == NULL)
{
goto done;
}
+ wcscpy(lpDisplayNameW, lpDisplayName);
if (lpService->lpDisplayName != lpService->lpServiceName)
HeapFree(GetProcessHeap(), 0, lpService->lpDisplayName);
goto done;
}
+ /* Set the tag */
if (lpdwTagId != NULL)
{
dwError = ScmAssignNewTag(lpService);
if (lpPassword != NULL)
{
- /* FIXME: Decrypt and write password */
+ if (wcslen((LPWSTR)lpPassword) != 0)
+ {
+ /* FIXME: Decrypt the password */
+
+ /* Write the password */
+ dwError = ScmSetServicePassword(lpService->szServiceName,
+ (LPCWSTR)lpPassword);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
+ }
+ else
+ {
+ /* Delete the password */
+ dwError = ScmSetServicePassword(lpService->szServiceName,
+ NULL);
+ if (dwError == ERROR_FILE_NOT_FOUND)
+ dwError = ERROR_SUCCESS;
+
+ if (dwError != ERROR_SUCCESS)
+ goto done;
+ }
}
done:
/* Function 12 */
-DWORD RCreateServiceW(
+DWORD
+WINAPI
+RCreateServiceW(
SC_RPC_HANDLE hSCManager,
LPCWSTR lpServiceName,
LPCWSTR lpDisplayName,
if ((dwServiceType == (SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS)) &&
(lpServiceStartName))
{
- return ERROR_INVALID_PARAMETER;
+ /* We allow LocalSystem to run interactive. */
+ if (wcsicmp(lpServiceStartName, L"LocalSystem"))
+ {
+ return ERROR_INVALID_PARAMETER;
+ }
}
if (lpdwTagId && (!lpLoadOrderGroup || !*lpLoadOrderGroup))
/* Allocate a new service entry */
dwError = ScmCreateNewServiceRecord(lpServiceName,
- &lpService);
+ &lpService,
+ dwServiceType,
+ dwStartType);
if (dwError != ERROR_SUCCESS)
goto done;
/* Fill the new service entry */
- lpService->Status.dwServiceType = dwServiceType;
- lpService->dwStartType = dwStartType;
lpService->dwErrorControl = dwErrorControl;
/* Fill the display name */
goto done;
}
+ /* Assign the default security descriptor */
+ if (dwServiceType & SERVICE_WIN32)
+ {
+ dwError = ScmCreateDefaultServiceSD(&lpService->pSecurityDescriptor);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
+ }
+
/* Write service data to the registry */
/* Create the service key */
dwError = ScmCreateServiceKey(lpServiceName,
goto done;
}
+ /* Set the service tag */
if (lpdwTagId != NULL)
{
dwError = RegSetValueExW(hServiceKey,
goto done;
}
- /* Write service start name */
+ /* Start name and password are only used by Win32 services */
if (dwServiceType & SERVICE_WIN32)
{
+ /* Write service start name */
lpObjectName = (lpServiceStartName != NULL) ? (LPWSTR)lpServiceStartName : L"LocalSystem";
dwError = RegSetValueExW(hServiceKey,
L"ObjectName",
(DWORD)((wcslen(lpObjectName) + 1) * sizeof(WCHAR)));
if (dwError != ERROR_SUCCESS)
goto done;
- }
- if (lpPassword != NULL)
- {
- /* FIXME: Decrypt and write password */
+ if (lpPassword != NULL && wcslen((LPWSTR)lpPassword) != 0)
+ {
+ /* FIXME: Decrypt the password */
+
+ /* Write the password */
+ dwError = ScmSetServicePassword(lpServiceName,
+ (LPCWSTR)lpPassword);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
+ }
+
+ /* Write the security descriptor */
+ dwError = ScmWriteSecurityDescriptor(hServiceKey,
+ lpService->pSecurityDescriptor);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
}
dwError = ScmCreateServiceHandle(lpService,
/* Function 13 */
-DWORD REnumDependentServicesW(
+DWORD
+WINAPI
+REnumDependentServicesW(
SC_RPC_HANDLE hService,
DWORD dwServiceState,
LPBYTE lpServices,
/* Function 14 */
-DWORD REnumServicesStatusW(
+DWORD
+WINAPI
+REnumServicesStatusW(
SC_RPC_HANDLE hSCManager,
DWORD dwServiceType,
DWORD dwServiceState,
/* Function 15 */
-DWORD ROpenSCManagerW(
+DWORD
+WINAPI
+ROpenSCManagerW(
LPWSTR lpMachineName,
LPWSTR lpDatabaseName,
DWORD dwDesiredAccess,
/* Function 16 */
-DWORD ROpenServiceW(
+DWORD
+WINAPI
+ROpenServiceW(
SC_RPC_HANDLE hSCManager,
LPWSTR lpServiceName,
DWORD dwDesiredAccess,
/* Function 17 */
-DWORD RQueryServiceConfigW(
+DWORD
+WINAPI
+RQueryServiceConfigW(
SC_RPC_HANDLE hService,
LPBYTE lpBuf, //LPQUERY_SERVICE_CONFIGW lpServiceConfig,
DWORD cbBufSize,
/* Function 18 */
-DWORD RQueryServiceLockStatusW(
+DWORD
+WINAPI
+RQueryServiceLockStatusW(
SC_RPC_HANDLE hSCManager,
LPBYTE lpBuf, // LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus,
DWORD cbBufSize,
/* Function 19 */
-DWORD RStartServiceW(
+DWORD
+WINAPI
+RStartServiceW(
SC_RPC_HANDLE hService,
DWORD argc,
LPSTRING_PTRSW argv)
/* Function 20 */
-DWORD RGetServiceDisplayNameW(
+DWORD
+WINAPI
+RGetServiceDisplayNameW(
SC_RPC_HANDLE hSCManager,
LPCWSTR lpServiceName,
LPWSTR lpDisplayName,
/* Function 21 */
-DWORD RGetServiceKeyNameW(
+DWORD
+WINAPI
+RGetServiceKeyNameW(
SC_RPC_HANDLE hSCManager,
LPCWSTR lpDisplayName,
LPWSTR lpServiceName,
/* Function 22 */
-DWORD RI_ScSetServiceBitsA(
+DWORD
+WINAPI
+RI_ScSetServiceBitsA(
RPC_SERVICE_STATUS_HANDLE hServiceStatus,
DWORD dwServiceBits,
int bSetBitsOn,
int bUpdateImmediately,
char *lpString)
{
- UNIMPLEMENTED;
- return ERROR_CALL_NOT_IMPLEMENTED;
+ if (ScmShutdown)
+ return ERROR_SHUTDOWN_IN_PROGRESS;
+
+ if (lpString != NULL)
+ return ERROR_INVALID_PARAMETER;
+
+ return RI_ScSetServiceBitsW(hServiceStatus,
+ dwServiceBits,
+ bSetBitsOn,
+ bUpdateImmediately,
+ NULL);
}
/* Function 23 */
-DWORD RChangeServiceConfigA(
+DWORD
+WINAPI
+RChangeServiceConfigA(
SC_RPC_HANDLE hService,
DWORD dwServiceType,
DWORD dwStartType,
dwDependSize);
HeapFree(GetProcessHeap(), 0, lpDependenciesW);
+
+ if (dwError != ERROR_SUCCESS)
+ goto done;
}
if (lpPassword != NULL)
{
- /* FIXME: Decrypt and write password */
+ if (wcslen((LPWSTR)lpPassword) != 0)
+ {
+ /* FIXME: Decrypt the password */
+
+ /* Write the password */
+ dwError = ScmSetServicePassword(lpService->szServiceName,
+ (LPCWSTR)lpPassword);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
+ }
+ else
+ {
+ /* Delete the password */
+ dwError = ScmSetServicePassword(lpService->szServiceName,
+ NULL);
+ if (dwError == ERROR_FILE_NOT_FOUND)
+ dwError = ERROR_SUCCESS;
+
+ if (dwError != ERROR_SUCCESS)
+ goto done;
+ }
}
done:
/* Function 24 */
-DWORD RCreateServiceA(
+DWORD
+WINAPI
+RCreateServiceA(
SC_RPC_HANDLE hSCManager,
LPSTR lpServiceName,
LPSTR lpDisplayName,
/* Function 25 */
-DWORD REnumDependentServicesA(
+DWORD
+WINAPI
+REnumDependentServicesA(
SC_RPC_HANDLE hService,
DWORD dwServiceState,
LPBYTE lpServices,
/* Function 26 */
-DWORD REnumServicesStatusA(
+DWORD
+WINAPI
+REnumServicesStatusA(
SC_RPC_HANDLE hSCManager,
DWORD dwServiceType,
DWORD dwServiceState,
/* Function 27 */
-DWORD ROpenSCManagerA(
+DWORD
+WINAPI
+ROpenSCManagerA(
LPSTR lpMachineName,
LPSTR lpDatabaseName,
DWORD dwDesiredAccess,
/* Function 28 */
-DWORD ROpenServiceA(
+DWORD
+WINAPI
+ROpenServiceA(
SC_RPC_HANDLE hSCManager,
LPSTR lpServiceName,
DWORD dwDesiredAccess,
/* Function 29 */
-DWORD RQueryServiceConfigA(
+DWORD
+WINAPI
+RQueryServiceConfigA(
SC_RPC_HANDLE hService,
LPBYTE lpBuf, //LPQUERY_SERVICE_CONFIGA lpServiceConfig,
DWORD cbBufSize,
/* Function 30 */
-DWORD RQueryServiceLockStatusA(
+DWORD
+WINAPI
+RQueryServiceLockStatusA(
SC_RPC_HANDLE hSCManager,
LPBYTE lpBuf, // LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus,
DWORD cbBufSize,
/* Function 31 */
-DWORD RStartServiceA(
+DWORD
+WINAPI
+RStartServiceA(
SC_RPC_HANDLE hService,
DWORD argc,
LPSTRING_PTRSA argv)
/* Function 32 */
-DWORD RGetServiceDisplayNameA(
+DWORD
+WINAPI
+RGetServiceDisplayNameA(
SC_RPC_HANDLE hSCManager,
LPCSTR lpServiceName,
LPSTR lpDisplayName,
/* Function 33 */
-DWORD RGetServiceKeyNameA(
+DWORD
+WINAPI
+RGetServiceKeyNameA(
SC_RPC_HANDLE hSCManager,
LPCSTR lpDisplayName,
LPSTR lpServiceName,
/* Function 34 */
-DWORD RI_ScGetCurrentGroupStateW(
+DWORD
+WINAPI
+RI_ScGetCurrentGroupStateW(
SC_RPC_HANDLE hSCManager,
LPWSTR lpLoadOrderGroup,
LPDWORD lpState)
{
- UNIMPLEMENTED;
- return ERROR_CALL_NOT_IMPLEMENTED;
+ PMANAGER_HANDLE hManager;
+ PSERVICE_GROUP pServiceGroup;
+ DWORD dwError = ERROR_SUCCESS;
+
+ DPRINT("RI_ScGetCurrentGroupStateW() called\n");
+
+ if (ScmShutdown)
+ return ERROR_SHUTDOWN_IN_PROGRESS;
+
+ hManager = ScmGetServiceManagerFromHandle(hSCManager);
+ if (hManager == NULL)
+ {
+ DPRINT1("Invalid service manager handle!\n");
+ return ERROR_INVALID_HANDLE;
+ }
+
+ /* Check for SC_MANAGER_ENUMERATE_SERVICE access right */
+ if (!RtlAreAllAccessesGranted(hManager->Handle.DesiredAccess,
+ SC_MANAGER_ENUMERATE_SERVICE))
+ {
+ DPRINT("Insufficient access rights! 0x%lx\n",
+ hManager->Handle.DesiredAccess);
+ return ERROR_ACCESS_DENIED;
+ }
+
+ /* Lock the service database shared */
+ ScmLockDatabaseShared();
+
+ /* Get the group list entry */
+ pServiceGroup = ScmGetServiceGroupByName(lpLoadOrderGroup);
+ if (pServiceGroup == NULL)
+ {
+ dwError = ERROR_SERVICE_DOES_NOT_EXIST;
+ goto done;
+ }
+
+ /* FIXME: Return the group state */
+ *lpState = 0;
+
+done:
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
+ DPRINT("RI_ScGetCurrentGroupStateW() done (Error %lu)\n", dwError);
+
+ return dwError;
}
/* Function 35 */
-DWORD REnumServiceGroupW(
+DWORD
+WINAPI
+REnumServiceGroupW(
SC_RPC_HANDLE hSCManager,
DWORD dwServiceType,
DWORD dwServiceState,
/* Function 36 */
-DWORD RChangeServiceConfig2A(
+DWORD
+WINAPI
+RChangeServiceConfig2A(
SC_RPC_HANDLE hService,
SC_RPC_CONFIG_INFOA Info)
{
- SC_RPC_CONFIG_INFOW InfoW;
+ SC_RPC_CONFIG_INFOW InfoW = { 0 };
DWORD dwRet, dwLength;
PVOID ptr = NULL;
DPRINT("RChangeServiceConfig2A() called\n");
DPRINT("dwInfoLevel = %lu\n", Info.dwInfoLevel);
+ if ((Info.dwInfoLevel < SERVICE_CONFIG_DESCRIPTION) ||
+ (Info.dwInfoLevel > SERVICE_CONFIG_FAILURE_ACTIONS))
+ return ERROR_INVALID_LEVEL;
+
InfoW.dwInfoLevel = Info.dwInfoLevel;
if (InfoW.dwInfoLevel == SERVICE_CONFIG_DESCRIPTION)
{
LPSERVICE_DESCRIPTIONW lpServiceDescriptionW;
- //LPSERVICE_DESCRIPTIONA lpServiceDescriptionA;
+ LPSERVICE_DESCRIPTIONA lpServiceDescriptionA;
- //lpServiceDescriptionA = Info.psd;
+ lpServiceDescriptionA = Info.psd;
- ///if (lpServiceDescriptionA &&
- ///lpServiceDescriptionA->lpDescription)
- ///{
- dwLength = (DWORD)((strlen(Info.lpDescription) + 1) * sizeof(WCHAR));
+ if (lpServiceDescriptionA &&
+ lpServiceDescriptionA->lpDescription)
+ {
+ dwLength = (DWORD)((strlen(lpServiceDescriptionA->lpDescription) + 1) * sizeof(WCHAR));
lpServiceDescriptionW = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
MultiByteToWideChar(CP_ACP,
0,
- Info.lpDescription,
+ lpServiceDescriptionA->lpDescription,
-1,
lpServiceDescriptionW->lpDescription,
dwLength);
ptr = lpServiceDescriptionW;
InfoW.psd = lpServiceDescriptionW;
- ///}
+ }
}
else if (Info.dwInfoLevel == SERVICE_CONFIG_FAILURE_ACTIONS)
{
static DWORD
-ScmSetFailureActions(PSERVICE_HANDLE hSvc,
- PSERVICE lpService,
- HKEY hServiceKey,
+ScmSetFailureActions(HKEY hServiceKey,
LPSERVICE_FAILURE_ACTIONSW lpFailureActions)
{
LPSERVICE_FAILURE_ACTIONSW lpReadBuffer = NULL;
LPSERVICE_FAILURE_ACTIONSW lpWriteBuffer = NULL;
- BOOL bIsActionRebootSet = FALSE;
- DWORD dwDesiredAccess = SERVICE_CHANGE_CONFIG;
DWORD dwRequiredSize = 0;
DWORD dwType = 0;
- DWORD i = 0;
DWORD dwError;
/* There is nothing to be done if we have no failure actions */
return ERROR_SUCCESS;
/*
- * 1- Check whether or not we can set
- * failure actions for this service.
- */
-
- /* Failure actions can only be set for Win32 services, not for drivers */
- if (lpService->Status.dwServiceType & SERVICE_DRIVER)
- return ERROR_CANNOT_DETECT_DRIVER_FAILURE;
-
- /*
- * If the service controller handles the SC_ACTION_RESTART action,
- * hService must have the SERVICE_START access right.
- *
- * If you specify SC_ACTION_REBOOT, the caller must have the
- * SE_SHUTDOWN_NAME privilege.
- */
- if (lpFailureActions->cActions > 0 &&
- lpFailureActions->lpsaActions != NULL)
- {
- for (i = 0; i < lpFailureActions->cActions; ++i)
- {
- if (lpFailureActions->lpsaActions[i].Type == SC_ACTION_RESTART)
- dwDesiredAccess |= SERVICE_START;
- else if (lpFailureActions->lpsaActions[i].Type == SC_ACTION_REBOOT)
- bIsActionRebootSet = TRUE;
- }
- }
-
- /* Re-check the access rights */
- if (!RtlAreAllAccessesGranted(hSvc->Handle.DesiredAccess,
- dwDesiredAccess))
- {
- DPRINT1("Insufficient access rights! 0x%lx\n", hSvc->Handle.DesiredAccess);
- return ERROR_ACCESS_DENIED;
- }
-
- /* FIXME: Check if the caller has the SE_SHUTDOWN_NAME privilege */
- if (bIsActionRebootSet)
- {
- }
-
- /*
- * 2- Retrieve the original value of FailureActions.
+ * 1- Retrieve the original value of FailureActions.
*/
/* Query value length */
lpReadBuffer->lpCommand = NULL;
/*
- * 3- Initialize the new value to set.
+ * 2- Initialize the new value to set.
*/
dwRequiredSize = sizeof(SERVICE_FAILURE_ACTIONSW);
/* Function 37 */
-DWORD RChangeServiceConfig2W(
+DWORD
+WINAPI
+RChangeServiceConfig2W(
SC_RPC_HANDLE hService,
SC_RPC_CONFIG_INFOW Info)
{
PSERVICE_HANDLE hSvc;
PSERVICE lpService = NULL;
HKEY hServiceKey = NULL;
+ ACCESS_MASK RequiredAccess = SERVICE_CHANGE_CONFIG;
DPRINT("RChangeServiceConfig2W() called\n");
DPRINT("dwInfoLevel = %lu\n", Info.dwInfoLevel);
if (ScmShutdown)
return ERROR_SHUTDOWN_IN_PROGRESS;
+ if ((Info.dwInfoLevel < SERVICE_CONFIG_DESCRIPTION) ||
+ (Info.dwInfoLevel > SERVICE_CONFIG_FAILURE_ACTIONS))
+ return ERROR_INVALID_LEVEL;
+
hSvc = ScmGetServiceFromHandle(hService);
if (hSvc == NULL)
{
- DPRINT1("Invalid service handle!\n");
+ DPRINT("Invalid service handle!\n");
return ERROR_INVALID_HANDLE;
}
+ if (Info.dwInfoLevel == SERVICE_CONFIG_FAILURE_ACTIONS)
+ RequiredAccess |= SERVICE_START;
+
+ /* Check the access rights */
if (!RtlAreAllAccessesGranted(hSvc->Handle.DesiredAccess,
- SERVICE_CHANGE_CONFIG))
+ RequiredAccess))
{
DPRINT("Insufficient access rights! 0x%lx\n", hSvc->Handle.DesiredAccess);
return ERROR_ACCESS_DENIED;
}
+ if (Info.dwInfoLevel == SERVICE_CONFIG_FAILURE_ACTIONS)
+ {
+ /* FIXME: Check if the caller has the SE_SHUTDOWN_NAME privilege */
+
+ }
+
lpService = hSvc->ServiceEntry;
if (lpService == NULL)
{
return ERROR_INVALID_HANDLE;
}
+ /* Failure actions can only be set for Win32 services, not for drivers */
+ if (Info.dwInfoLevel == SERVICE_CONFIG_FAILURE_ACTIONS)
+ {
+ if (lpService->Status.dwServiceType & SERVICE_DRIVER)
+ return ERROR_CANNOT_DETECT_DRIVER_FAILURE;
+ }
+
/* Lock the service database exclusively */
ScmLockDatabaseExclusive();
}
else if (Info.dwInfoLevel == SERVICE_CONFIG_FAILURE_ACTIONS)
{
- dwError = ScmSetFailureActions(hSvc,
- lpService,
- hServiceKey,
+ dwError = ScmSetFailureActions(hServiceKey,
(LPSERVICE_FAILURE_ACTIONSW)Info.psfa);
}
/* Function 38 */
-DWORD RQueryServiceConfig2A(
+DWORD
+WINAPI
+RQueryServiceConfig2A(
SC_RPC_HANDLE hService,
DWORD dwInfoLevel,
LPBYTE lpBuffer,
if (ScmShutdown)
return ERROR_SHUTDOWN_IN_PROGRESS;
+ if ((dwInfoLevel < SERVICE_CONFIG_DESCRIPTION) ||
+ (dwInfoLevel > SERVICE_CONFIG_FAILURE_ACTIONS))
+ return ERROR_INVALID_LEVEL;
+
hSvc = ScmGetServiceFromHandle(hService);
if (hSvc == NULL)
{
/* Function 39 */
-DWORD RQueryServiceConfig2W(
+DWORD
+WINAPI
+RQueryServiceConfig2W(
SC_RPC_HANDLE hService,
DWORD dwInfoLevel,
LPBYTE lpBuffer,
if (ScmShutdown)
return ERROR_SHUTDOWN_IN_PROGRESS;
+ if ((dwInfoLevel < SERVICE_CONFIG_DESCRIPTION) ||
+ (dwInfoLevel > SERVICE_CONFIG_FAILURE_ACTIONS))
+ return ERROR_INVALID_LEVEL;
+
hSvc = ScmGetServiceFromHandle(hService);
if (hSvc == NULL)
{
/* Function 40 */
-DWORD RQueryServiceStatusEx(
+DWORD
+WINAPI
+RQueryServiceStatusEx(
SC_RPC_HANDLE hService,
SC_STATUS_TYPE InfoLevel,
LPBYTE lpBuffer,
&lpService->Status,
sizeof(SERVICE_STATUS));
- lpStatus->dwProcessId = (lpService->lpImage != NULL) ? lpService->lpImage->dwProcessId : 0; /* FIXME */
+ /* Copy the service process ID */
+ if ((lpService->Status.dwCurrentState == SERVICE_STOPPED) || (lpService->lpImage == NULL))
+ lpStatus->dwProcessId = 0;
+ else
+ lpStatus->dwProcessId = lpService->lpImage->dwProcessId;
+
lpStatus->dwServiceFlags = 0; /* FIXME */
/* Unlock the service database */
/* Function 41 */
-DWORD REnumServicesStatusExA(
+DWORD
+WINAPI
+REnumServicesStatusExA(
SC_RPC_HANDLE hSCManager,
SC_ENUM_TYPE InfoLevel,
DWORD dwServiceType,
if (!pszGroupNameW)
{
DPRINT("Failed to allocate buffer!\n");
- return ERROR_NOT_ENOUGH_MEMORY;
+ dwError = ERROR_NOT_ENOUGH_MEMORY;
+ goto Done;
}
MultiByteToWideChar(CP_ACP,
if (!lpStatusPtrW)
{
DPRINT("Failed to allocate buffer!\n");
- return ERROR_NOT_ENOUGH_MEMORY;
+ dwError = ERROR_NOT_ENOUGH_MEMORY;
+ goto Done;
}
}
&lpStatusPtrIncrW->ServiceStatusProcess,
sizeof(SERVICE_STATUS));
- lpStatusPtrA->ServiceStatusProcess.dwProcessId = lpStatusPtrIncrW->ServiceStatusProcess.dwProcessId; /* FIXME */
+ /* Copy the service process ID */
+ lpStatusPtrA->ServiceStatusProcess.dwProcessId = lpStatusPtrIncrW->ServiceStatusProcess.dwProcessId;
+
lpStatusPtrA->ServiceStatusProcess.dwServiceFlags = 0; /* FIXME */
lpStatusPtrIncrW++;
/* Function 42 */
-DWORD REnumServicesStatusExW(
+DWORD
+WINAPI
+REnumServicesStatusExW(
SC_RPC_HANDLE hSCManager,
SC_ENUM_TYPE InfoLevel,
DWORD dwServiceType,
memcpy(&lpStatusPtr->ServiceStatusProcess,
&CurrentService->Status,
sizeof(SERVICE_STATUS));
- lpStatusPtr->ServiceStatusProcess.dwProcessId =
- (CurrentService->lpImage != NULL) ? CurrentService->lpImage->dwProcessId : 0; /* FIXME */
+
+ /* Copy the service process ID */
+ if ((CurrentService->Status.dwCurrentState == SERVICE_STOPPED) || (CurrentService->lpImage == NULL))
+ lpStatusPtr->ServiceStatusProcess.dwProcessId = 0;
+ else
+ lpStatusPtr->ServiceStatusProcess.dwProcessId = CurrentService->lpImage->dwProcessId;
+
lpStatusPtr->ServiceStatusProcess.dwServiceFlags = 0; /* FIXME */
lpStatusPtr++;
/* Function 43 */
-DWORD RSendTSMessage(
+DWORD
+WINAPI
+RSendTSMessage(
handle_t BindingHandle) /* FIXME */
{
UNIMPLEMENTED;
/* Function 44 */
-DWORD RCreateServiceWOW64A(
+DWORD
+WINAPI
+RCreateServiceWOW64A(
handle_t BindingHandle,
LPSTR lpServiceName,
LPSTR lpDisplayName,
/* Function 45 */
-DWORD RCreateServiceWOW64W(
+DWORD
+WINAPI
+RCreateServiceWOW64W(
handle_t BindingHandle,
LPWSTR lpServiceName,
LPWSTR lpDisplayName,
/* Function 46 */
-DWORD RQueryServiceTagInfo(
+DWORD
+WINAPI
+RQueryServiceTagInfo(
handle_t BindingHandle) /* FIXME */
{
UNIMPLEMENTED;
/* Function 47 */
-DWORD RNotifyServiceStatusChange(
+DWORD
+WINAPI
+RNotifyServiceStatusChange(
SC_RPC_HANDLE hService,
SC_RPC_NOTIFY_PARAMS NotifyParams,
GUID *pClientProcessGuid,
/* Function 48 */
-DWORD RGetNotifyResults(
+DWORD
+WINAPI
+RGetNotifyResults(
SC_NOTIFY_RPC_HANDLE hNotify,
PSC_RPC_NOTIFY_PARAMS_LIST *ppNotifyParams)
{
/* Function 49 */
-DWORD RCloseNotifyHandle(
+DWORD
+WINAPI
+RCloseNotifyHandle(
LPSC_NOTIFY_RPC_HANDLE phNotify,
PBOOL pfApcFired)
{
/* Function 50 */
-DWORD RControlServiceExA(
+DWORD
+WINAPI
+RControlServiceExA(
SC_RPC_HANDLE hService,
DWORD dwControl,
DWORD dwInfoLevel)
/* Function 51 */
-DWORD RControlServiceExW(
+DWORD
+WINAPI
+RControlServiceExW(
SC_RPC_HANDLE hService,
DWORD dwControl,
DWORD dwInfoLevel)
/* Function 52 */
-DWORD RSendPnPMessage(
+DWORD
+WINAPI
+RSendPnPMessage(
handle_t BindingHandle) /* FIXME */
{
UNIMPLEMENTED;
/* Function 53 */
-DWORD RValidatePnPService(
+DWORD
+WINAPI
+RValidatePnPService(
handle_t BindingHandle) /* FIXME */
{
UNIMPLEMENTED;
/* Function 54 */
-DWORD ROpenServiceStatusHandle(
+DWORD
+WINAPI
+ROpenServiceStatusHandle(
handle_t BindingHandle) /* FIXME */
{
UNIMPLEMENTED;
/* Function 55 */
-DWORD RFunction55(
+DWORD
+WINAPI
+RFunction55(
handle_t BindingHandle) /* FIXME */
{
UNIMPLEMENTED;