- RCreateServiceW:

- Add more parameter checks.
  - Set the services "ObjectName" value to "LocalSystem" if it doesn't have a name.
- REnumServicesStatusW: Simplify it a little.

svn path=/trunk/; revision=35755
This commit is contained in:
Eric Kohl 2008-08-29 12:59:27 +00:00
parent d5efa7522b
commit 9bde3fcc59

View file

@ -1599,9 +1599,47 @@ DWORD RCreateServiceW(
return ERROR_ACCESS_DENIED; return ERROR_ACCESS_DENIED;
} }
/* Fail if the service already exists! */ if (wcslen(lpServiceName) == 0)
if (ScmGetServiceEntryByName(lpServiceName) != NULL) {
return ERROR_INVALID_NAME;
}
if (wcslen(lpBinaryPathName) == 0)
{
return ERROR_INVALID_PARAMETER;
}
if ((dwServiceType == (SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS)) &&
(lpServiceStartName))
{
return ERROR_INVALID_PARAMETER;
}
if ((dwServiceType > SERVICE_WIN32_SHARE_PROCESS) &&
(dwServiceType != (SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS)) &&
(dwServiceType != (SERVICE_WIN32_SHARE_PROCESS | SERVICE_INTERACTIVE_PROCESS)))
{
return ERROR_INVALID_PARAMETER;
}
if (dwStartType > SERVICE_DISABLED)
{
return ERROR_INVALID_PARAMETER;
}
lpService = ScmGetServiceEntryByName(lpServiceName);
if (lpService)
{
/* check if it is marked for deletion */
if (lpService->bDeleted)
return ERROR_SERVICE_MARKED_FOR_DELETE;
/* Return Error exist */
return ERROR_SERVICE_EXISTS; return ERROR_SERVICE_EXISTS;
}
if (lpDisplayName != NULL &&
ScmGetServiceEntryByDisplayName(lpDisplayName) != NULL)
return ERROR_DUPLICATE_SERVICE_NAME;
if (dwServiceType & SERVICE_DRIVER) if (dwServiceType & SERVICE_DRIVER)
{ {
@ -1612,6 +1650,14 @@ DWORD RCreateServiceW(
if (dwError != ERROR_SUCCESS) if (dwError != ERROR_SUCCESS)
goto done; goto done;
} }
else
{
if (dwStartType == SERVICE_BOOT_START ||
dwStartType == SERVICE_SYSTEM_START)
{
return ERROR_INVALID_PARAMETER;
}
}
/* Allocate a new service entry */ /* Allocate a new service entry */
dwError = ScmCreateNewServiceRecord(lpServiceName, dwError = ScmCreateNewServiceRecord(lpServiceName,
@ -1764,6 +1810,19 @@ DWORD RCreateServiceW(
goto done; goto done;
} }
/* If a non driver and NULL for lpServiceName, write ObjectName as LocalSystem */
if ((dwServiceType & SERVICE_WIN32) && (!lpServiceName))
{
dwError = RegSetValueExW(hServiceKey,
L"ObjectName",
0,
REG_SZ,
(LPBYTE)L"LocalSystem",
24);
if (dwError != ERROR_SUCCESS)
goto done;
}
if (lpPassword != NULL) if (lpPassword != NULL)
{ {
/* FIXME: Write password */ /* FIXME: Write password */
@ -2033,19 +2092,16 @@ DWORD REnumServicesStatusW(
((wcslen(CurrentService->lpServiceName) + 1) * sizeof(WCHAR)) + ((wcslen(CurrentService->lpServiceName) + 1) * sizeof(WCHAR)) +
((wcslen(CurrentService->lpDisplayName) + 1) * sizeof(WCHAR)); ((wcslen(CurrentService->lpDisplayName) + 1) * sizeof(WCHAR));
if (dwRequiredSize + dwSize <= dwBufSize) if (dwRequiredSize + dwSize > dwBufSize)
{
DPRINT("Service name: %S fit\n", CurrentService->lpServiceName);
dwRequiredSize += dwSize;
dwServiceCount++;
dwLastResumeCount = CurrentService->dwResumeCount;
}
else
{ {
DPRINT("Service name: %S no fit\n", CurrentService->lpServiceName); DPRINT("Service name: %S no fit\n", CurrentService->lpServiceName);
break; break;
} }
DPRINT("Service name: %S fit\n", CurrentService->lpServiceName);
dwRequiredSize += dwSize;
dwServiceCount++;
dwLastResumeCount = CurrentService->dwResumeCount;
} }
DPRINT("dwRequiredSize: %lu\n", dwRequiredSize); DPRINT("dwRequiredSize: %lu\n", dwRequiredSize);
@ -2109,17 +2165,16 @@ DWORD REnumServicesStatusW(
((wcslen(CurrentService->lpServiceName) + 1) * sizeof(WCHAR)) + ((wcslen(CurrentService->lpServiceName) + 1) * sizeof(WCHAR)) +
((wcslen(CurrentService->lpDisplayName) + 1) * sizeof(WCHAR)); ((wcslen(CurrentService->lpDisplayName) + 1) * sizeof(WCHAR));
if (dwRequiredSize + dwSize <= dwBufSize) if (dwRequiredSize + dwSize > dwBufSize)
{ break;
/* Copy the service name */ /* Copy the service name */
wcscpy(lpStringPtr, wcscpy(lpStringPtr, CurrentService->lpServiceName);
CurrentService->lpServiceName);
lpStatusPtr->lpServiceName = (LPWSTR)((ULONG_PTR)lpStringPtr - (ULONG_PTR)lpBuffer); lpStatusPtr->lpServiceName = (LPWSTR)((ULONG_PTR)lpStringPtr - (ULONG_PTR)lpBuffer);
lpStringPtr += (wcslen(CurrentService->lpServiceName) + 1); lpStringPtr += (wcslen(CurrentService->lpServiceName) + 1);
/* Copy the display name */ /* Copy the display name */
wcscpy(lpStringPtr, wcscpy(lpStringPtr, CurrentService->lpDisplayName);
CurrentService->lpDisplayName);
lpStatusPtr->lpDisplayName = (LPWSTR)((ULONG_PTR)lpStringPtr - (ULONG_PTR)lpBuffer); lpStatusPtr->lpDisplayName = (LPWSTR)((ULONG_PTR)lpStringPtr - (ULONG_PTR)lpBuffer);
lpStringPtr += (wcslen(CurrentService->lpDisplayName) + 1); lpStringPtr += (wcslen(CurrentService->lpDisplayName) + 1);
@ -2131,12 +2186,6 @@ DWORD REnumServicesStatusW(
lpStatusPtr++; lpStatusPtr++;
dwRequiredSize += dwSize; dwRequiredSize += dwSize;
} }
else
{
break;
}
}
Done:; Done:;
/* FIXME: Unlock the service list */ /* FIXME: Unlock the service list */