/* INCLUDES ******************************************************************/
#include <advapi32.h>
-
-#include "wine/debug.h"
-
WINE_DEFAULT_DEBUG_CHANNEL(advapi);
TRACE("ChangeServiceConfig2A() called\n");
+ if (lpInfo == NULL) return TRUE;
+
/* Fill relevent field of the Info structure */
Info.dwInfoLevel = dwInfoLevel;
switch (dwInfoLevel)
return FALSE;
}
- if (lpInfo == NULL)
- return TRUE;
-
RpcTryExcept
{
dwError = RChangeServiceConfig2A((SC_RPC_HANDLE)hService,
TRACE("ChangeServiceConfig2W() called\n");
+ if (lpInfo == NULL) return TRUE;
+
/* Fill relevent field of the Info structure */
Info.dwInfoLevel = dwInfoLevel;
switch (dwInfoLevel)
{
case SERVICE_CONFIG_DESCRIPTION:
- Info.psd = (LPSERVICE_DESCRIPTIONW)&lpInfo;
+ Info.psd = (LPSERVICE_DESCRIPTIONW)lpInfo;
break;
case SERVICE_CONFIG_FAILURE_ACTIONS:
- Info.psfa = (LPSERVICE_FAILURE_ACTIONSW)&lpInfo;
+ Info.psfa = (LPSERVICE_FAILURE_ACTIONSW)lpInfo;
break;
default:
return FALSE;
}
- if (lpInfo == NULL)
- return TRUE;
-
RpcTryExcept
{
dwError = RChangeServiceConfig2W((SC_RPC_HANDLE)hService,
{
DWORD dwError;
DWORD dwDependenciesLength = 0;
- DWORD dwLength;
- LPSTR lpStr;
+ SIZE_T cchLength;
+ LPCSTR lpStr;
+ DWORD dwPasswordLength = 0;
+ LPBYTE lpEncryptedPassword = NULL;
TRACE("ChangeServiceConfigA() called\n");
/* Calculate the Dependencies length*/
if (lpDependencies != NULL)
{
- lpStr = (LPSTR)lpDependencies;
+ lpStr = lpDependencies;
while (*lpStr)
{
- dwLength = strlen(lpStr) + 1;
- dwDependenciesLength += dwLength;
- lpStr = lpStr + dwLength;
+ cchLength = strlen(lpStr) + 1;
+ dwDependenciesLength += (DWORD)cchLength;
+ lpStr = lpStr + cchLength;
}
dwDependenciesLength++;
}
/* FIXME: Encrypt the password */
+ lpEncryptedPassword = (LPBYTE)lpPassword;
+ dwPasswordLength = (DWORD)(lpPassword ? (strlen(lpPassword) + 1) * sizeof(CHAR) : 0);
RpcTryExcept
{
(LPSTR)lpBinaryPathName,
(LPSTR)lpLoadOrderGroup,
lpdwTagId,
- (LPSTR)lpDependencies,
+ (LPBYTE)lpDependencies,
dwDependenciesLength,
(LPSTR)lpServiceStartName,
- NULL, /* FIXME: lpPassword */
- 0, /* FIXME: dwPasswordLength */
+ lpEncryptedPassword,
+ dwPasswordLength,
(LPSTR)lpDisplayName);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
DWORD dwError;
DWORD dwDependenciesLength = 0;
- DWORD dwLength;
- LPWSTR lpStr;
+ SIZE_T cchLength;
+ LPCWSTR lpStr;
+ DWORD dwPasswordLength = 0;
+ LPBYTE lpEncryptedPassword = NULL;
TRACE("ChangeServiceConfigW() called\n");
/* Calculate the Dependencies length*/
if (lpDependencies != NULL)
{
- lpStr = (LPWSTR)lpDependencies;
+ lpStr = lpDependencies;
while (*lpStr)
{
- dwLength = wcslen(lpStr) + 1;
- dwDependenciesLength += dwLength;
- lpStr = lpStr + dwLength;
+ cchLength = wcslen(lpStr) + 1;
+ dwDependenciesLength += (DWORD)cchLength;
+ lpStr = lpStr + cchLength;
}
dwDependenciesLength++;
+ dwDependenciesLength *= sizeof(WCHAR);
}
/* FIXME: Encrypt the password */
+ lpEncryptedPassword = (LPBYTE)lpPassword;
+ dwPasswordLength = (lpPassword ? (wcslen(lpPassword) + 1) * sizeof(WCHAR) : 0);
RpcTryExcept
{
(LPBYTE)lpDependencies,
dwDependenciesLength,
(LPWSTR)lpServiceStartName,
- NULL, /* FIXME: lpPassword */
- 0, /* FIXME: dwPasswordLength */
+ lpEncryptedPassword,
+ dwPasswordLength,
(LPWSTR)lpDisplayName);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
SC_HANDLE hService = NULL;
DWORD dwDependenciesLength = 0;
DWORD dwError;
- DWORD dwLength;
- LPSTR lpStr;
+ SIZE_T cchLength;
+ LPCSTR lpStr;
+ DWORD dwPasswordLength = 0;
+ LPBYTE lpEncryptedPassword = NULL;
TRACE("CreateServiceA() called\n");
- TRACE("%p %s %s\n", hSCManager,
+ TRACE("%p %s %s\n", hSCManager,
lpServiceName, lpDisplayName);
if (!hSCManager)
return NULL;
}
- /* Calculate the Dependencies length*/
+ /* Calculate the Dependencies length */
if (lpDependencies != NULL)
{
- lpStr = (LPSTR)lpDependencies;
+ lpStr = lpDependencies;
while (*lpStr)
{
- dwLength = strlen(lpStr) + 1;
- dwDependenciesLength += dwLength;
- lpStr = lpStr + dwLength;
+ cchLength = strlen(lpStr) + 1;
+ dwDependenciesLength += (DWORD)cchLength;
+ lpStr = lpStr + cchLength;
}
dwDependenciesLength++;
}
/* FIXME: Encrypt the password */
+ lpEncryptedPassword = (LPBYTE)lpPassword;
+ dwPasswordLength = (DWORD)(lpPassword ? (strlen(lpPassword) + 1) * sizeof(CHAR) : 0);
RpcTryExcept
{
(LPBYTE)lpDependencies,
dwDependenciesLength,
(LPSTR)lpServiceStartName,
- NULL, /* FIXME: lpPassword */
- 0, /* FIXME: dwPasswordLength */
+ lpEncryptedPassword,
+ dwPasswordLength,
(SC_RPC_HANDLE *)&hService);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
SC_HANDLE hService = NULL;
DWORD dwDependenciesLength = 0;
DWORD dwError;
- DWORD dwLength;
- LPWSTR lpStr;
+ SIZE_T cchLength;
+ LPCWSTR lpStr;
+ DWORD dwPasswordLength = 0;
+ LPBYTE lpEncryptedPassword = NULL;
TRACE("CreateServiceW() called\n");
- TRACE("%p %S %S\n", hSCManager,
+ TRACE("%p %S %S\n", hSCManager,
lpServiceName, lpDisplayName);
if (!hSCManager)
return NULL;
}
- /* Calculate the Dependencies length*/
+ /* Calculate the Dependencies length */
if (lpDependencies != NULL)
{
- lpStr = (LPWSTR)lpDependencies;
+ lpStr = lpDependencies;
while (*lpStr)
{
- dwLength = wcslen(lpStr) + 1;
- dwDependenciesLength += dwLength;
- lpStr = lpStr + dwLength;
+ cchLength = wcslen(lpStr) + 1;
+ dwDependenciesLength += (DWORD)cchLength;
+ lpStr = lpStr + cchLength;
}
dwDependenciesLength++;
-
dwDependenciesLength *= sizeof(WCHAR);
}
/* FIXME: Encrypt the password */
+ lpEncryptedPassword = (LPBYTE)lpPassword;
+ dwPasswordLength = (DWORD)(lpPassword ? (wcslen(lpPassword) + 1) * sizeof(WCHAR) : 0);
RpcTryExcept
{
(LPBYTE)lpDependencies,
dwDependenciesLength,
lpServiceStartName,
- NULL, /* FIXME: lpPassword */
- 0, /* FIXME: dwPasswordLength */
+ lpEncryptedPassword,
+ dwPasswordLength,
(SC_RPC_HANDLE *)&hService);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
LPDWORD pcbBytesNeeded,
LPDWORD lpServicesReturned)
{
+ ENUM_SERVICE_STATUSA ServiceStatus;
LPENUM_SERVICE_STATUSA lpStatusPtr;
+ DWORD dwBufferSize;
DWORD dwError;
DWORD dwCount;
- TRACE("EnumServicesStatusA() called\n");
+ TRACE("EnumDependentServicesA() called\n");
+
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSA))
+ {
+ lpStatusPtr = &ServiceStatus;
+ dwBufferSize = sizeof(ENUM_SERVICE_STATUSA);
+ }
+ else
+ {
+ lpStatusPtr = lpServices;
+ dwBufferSize = cbBufSize;
+ }
RpcTryExcept
{
dwError = REnumDependentServicesA((SC_RPC_HANDLE)hService,
dwServiceState,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned);
}
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
- lpStatusPtr = (LPENUM_SERVICE_STATUSA)lpServices;
for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{
if (lpStatusPtr->lpServiceName)
LPDWORD pcbBytesNeeded,
LPDWORD lpServicesReturned)
{
+ ENUM_SERVICE_STATUSW ServiceStatus;
LPENUM_SERVICE_STATUSW lpStatusPtr;
+ DWORD dwBufferSize;
DWORD dwError;
DWORD dwCount;
- TRACE("EnumServicesStatusW() called\n");
+ TRACE("EnumDependentServicesW() called\n");
+
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
+ {
+ lpStatusPtr = &ServiceStatus;
+ dwBufferSize = sizeof(ENUM_SERVICE_STATUSW);
+ }
+ else
+ {
+ lpStatusPtr = lpServices;
+ dwBufferSize = cbBufSize;
+ }
RpcTryExcept
{
dwError = REnumDependentServicesW((SC_RPC_HANDLE)hService,
dwServiceState,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned);
}
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
- lpStatusPtr = (LPENUM_SERVICE_STATUSW)lpServices;
for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{
if (lpStatusPtr->lpServiceName)
return FALSE;
}
+ if (pcbBytesNeeded == NULL || lpServicesReturned == NULL)
+ {
+ SetLastError(ERROR_INVALID_ADDRESS);
+ return FALSE;
+ }
+
if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
{
lpStatusPtr = &ServiceStatus;
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
- if (*lpServicesReturned > 0)
+ for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{
- for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
- {
- if (lpStatusPtr->lpServiceName)
- lpStatusPtr->lpServiceName =
- (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
+ if (lpStatusPtr->lpServiceName)
+ lpStatusPtr->lpServiceName =
+ (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
- if (lpStatusPtr->lpDisplayName)
- lpStatusPtr->lpDisplayName =
- (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
+ if (lpStatusPtr->lpDisplayName)
+ lpStatusPtr->lpDisplayName =
+ (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
- lpStatusPtr++;
- }
+ lpStatusPtr++;
}
}
return FALSE;
}
- if (dwServiceType != SERVICE_DRIVER && dwServiceType != SERVICE_WIN32)
- {
- if (pcbBytesNeeded && lpServicesReturned)
- {
- *pcbBytesNeeded = 0;
- *lpServicesReturned = 0;
- }
-
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
- }
-
- if (dwServiceState != SERVICE_ACTIVE && dwServiceState != SERVICE_INACTIVE && dwServiceState != SERVICE_STATE_ALL)
- {
- if (pcbBytesNeeded)
- *pcbBytesNeeded = 0;
-
- if (lpServicesReturned)
- *lpServicesReturned = 0;
-
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
- }
-
- if (!pcbBytesNeeded || !lpServicesReturned)
- {
- SetLastError(ERROR_INVALID_ADDRESS);
- return FALSE;
- }
-
- if (!lpServices && cbBufSize != 0)
+ if (pcbBytesNeeded == NULL || lpServicesReturned == NULL)
{
SetLastError(ERROR_INVALID_ADDRESS);
return FALSE;
}
- if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSA))
{
lpStatusPtr = &ServiceStatus;
- dwBufferSize = sizeof(ENUM_SERVICE_STATUSW);
+ dwBufferSize = sizeof(ENUM_SERVICE_STATUSA);
}
else
{
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
- if (*lpServicesReturned > 0)
+ for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{
- for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
- {
- if (lpStatusPtr->lpServiceName)
- lpStatusPtr->lpServiceName =
- (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
+ if (lpStatusPtr->lpServiceName)
+ lpStatusPtr->lpServiceName =
+ (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
- if (lpStatusPtr->lpDisplayName)
- lpStatusPtr->lpDisplayName =
- (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
+ if (lpStatusPtr->lpDisplayName)
+ lpStatusPtr->lpDisplayName =
+ (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
- lpStatusPtr++;
- }
+ lpStatusPtr++;
}
}
return FALSE;
}
+ if (pcbBytesNeeded == NULL || lpServicesReturned == NULL)
+ {
+ SetLastError(ERROR_INVALID_ADDRESS);
+ return FALSE;
+ }
+
if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
{
lpStatusPtr = &ServiceStatus;
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
- if (*lpServicesReturned > 0)
+ for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{
- for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
- {
- if (lpStatusPtr->lpServiceName)
- lpStatusPtr->lpServiceName =
- (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
+ if (lpStatusPtr->lpServiceName)
+ lpStatusPtr->lpServiceName =
+ (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
- if (lpStatusPtr->lpDisplayName)
- lpStatusPtr->lpDisplayName =
- (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
+ if (lpStatusPtr->lpDisplayName)
+ lpStatusPtr->lpDisplayName =
+ (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
- lpStatusPtr++;
- }
+ lpStatusPtr++;
}
}
return FALSE;
}
- if (lpServices == NULL ||
- cbBufSize < sizeof(ENUM_SERVICE_STATUS_PROCESSA))
+ if (pcbBytesNeeded == NULL || lpServicesReturned == NULL)
+ {
+ SetLastError(ERROR_INVALID_ADDRESS);
+ return FALSE;
+ }
+
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUS_PROCESSA))
{
lpStatusPtr = &ServiceStatus;
dwBufferSize = sizeof(ENUM_SERVICE_STATUS_PROCESSA);
return FALSE;
}
- if (lpServices == NULL ||
- cbBufSize < sizeof(ENUM_SERVICE_STATUS_PROCESSW))
+ if (!hSCManager)
+ {
+ SetLastError(ERROR_INVALID_HANDLE);
+ return FALSE;
+ }
+
+ if (pcbBytesNeeded == NULL || lpServicesReturned == NULL)
+ {
+ SetLastError(ERROR_INVALID_ADDRESS);
+ return FALSE;
+ }
+
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUS_PROCESSW))
{
lpStatusPtr = &ServiceStatus;
dwBufferSize = sizeof(ENUM_SERVICE_STATUS_PROCESSW);
TRACE("WaitForSCManager() called\n");
/* Try to open the existing event */
- hEvent = OpenEventW(SYNCHRONIZE,
- FALSE,
- L"SvcctrlStartEvent_A3752DX");
+ hEvent = OpenEventW(SYNCHRONIZE, FALSE, SCM_START_EVENT);
if (hEvent == NULL)
{
- if (GetLastError() != ERROR_FILE_NOT_FOUND)
- return;
+ if (GetLastError() != ERROR_FILE_NOT_FOUND) return;
/* Try to create a new event */
- hEvent = CreateEventW(NULL,
- TRUE,
- FALSE,
- L"SvcctrlStartEvent_A3752DX");
- if (hEvent == NULL)
- {
- /* Try to open the existing event again */
- hEvent = OpenEventW(SYNCHRONIZE,
- FALSE,
- L"SvcctrlStartEvent_A3752DX");
- if (hEvent == NULL)
- return;
- }
+ hEvent = CreateEventW(NULL, TRUE, FALSE, SCM_START_EVENT);
+ if (hEvent == NULL) return;
}
/* Wait for 3 minutes */
DWORD cbBufSize,
LPDWORD pcbBytesNeeded)
{
+ SERVICE_DESCRIPTIONA ServiceDescription;
+ SERVICE_FAILURE_ACTIONSA ServiceFailureActions;
+ LPBYTE lpTempBuffer;
+ BOOL bUseTempBuffer = FALSE;
+ DWORD dwBufferSize;
DWORD dwError;
TRACE("QueryServiceConfig2A(hService %p, dwInfoLevel %lu, lpBuffer %p, cbBufSize %lu, pcbBytesNeeded %p)\n",
hService, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
- if (dwInfoLevel != SERVICE_CONFIG_DESCRIPTION &&
- dwInfoLevel != SERVICE_CONFIG_FAILURE_ACTIONS)
- {
- SetLastError(ERROR_INVALID_LEVEL);
- return FALSE;
- }
+ lpTempBuffer = lpBuffer;
+ dwBufferSize = cbBufSize;
- if ((lpBuffer == NULL && cbBufSize != 0) ||
- pcbBytesNeeded == NULL)
+ switch (dwInfoLevel)
{
- SetLastError(ERROR_INVALID_ADDRESS);
- return FALSE;
+ case SERVICE_CONFIG_DESCRIPTION:
+ if ((lpBuffer == NULL) || (cbBufSize < sizeof(SERVICE_DESCRIPTIONA)))
+ {
+ lpTempBuffer = (LPBYTE)&ServiceDescription;
+ dwBufferSize = sizeof(SERVICE_DESCRIPTIONA);
+ bUseTempBuffer = TRUE;
+ }
+ break;
+
+ case SERVICE_CONFIG_FAILURE_ACTIONS:
+ if ((lpBuffer == NULL) || (cbBufSize < sizeof(SERVICE_FAILURE_ACTIONSA)))
+ {
+ lpTempBuffer = (LPBYTE)&ServiceFailureActions;
+ dwBufferSize = sizeof(SERVICE_FAILURE_ACTIONSA);
+ bUseTempBuffer = TRUE;
+ }
+ break;
+
+ default:
+ WARN("Unknown info level 0x%lx\n", dwInfoLevel);
+ SetLastError(ERROR_INVALID_LEVEL);
+ return FALSE;
}
RpcTryExcept
/* Call to services.exe using RPC */
dwError = RQueryServiceConfig2A((SC_RPC_HANDLE)hService,
dwInfoLevel,
- lpBuffer,
- cbBufSize,
+ lpTempBuffer,
+ dwBufferSize,
pcbBytesNeeded);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
return FALSE;
}
+ if (bUseTempBuffer == TRUE)
+ {
+ TRACE("RQueryServiceConfig2A() returns ERROR_INSUFFICIENT_BUFFER\n");
+ *pcbBytesNeeded = dwBufferSize;
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ return FALSE;
+ }
+
switch (dwInfoLevel)
{
case SERVICE_CONFIG_DESCRIPTION:
{
- LPSERVICE_DESCRIPTIONA lpPtr = (LPSERVICE_DESCRIPTIONA)lpBuffer;
+ LPSERVICE_DESCRIPTIONA lpPtr = (LPSERVICE_DESCRIPTIONA)lpTempBuffer;
if (lpPtr->lpDescription != NULL)
lpPtr->lpDescription =
- (LPSTR)((UINT_PTR)lpPtr + (UINT_PTR)lpPtr->lpDescription);
+ (LPSTR)((ULONG_PTR)lpPtr + (ULONG_PTR)lpPtr->lpDescription);
}
break;
case SERVICE_CONFIG_FAILURE_ACTIONS:
{
- LPSERVICE_FAILURE_ACTIONSA lpPtr = (LPSERVICE_FAILURE_ACTIONSA)lpBuffer;
+ LPSERVICE_FAILURE_ACTIONSA lpPtr = (LPSERVICE_FAILURE_ACTIONSA)lpTempBuffer;
if (lpPtr->lpRebootMsg != NULL)
lpPtr->lpRebootMsg =
- (LPSTR)((UINT_PTR)lpPtr + (UINT_PTR)lpPtr->lpRebootMsg);
+ (LPSTR)((ULONG_PTR)lpPtr + (ULONG_PTR)lpPtr->lpRebootMsg);
if (lpPtr->lpCommand != NULL)
lpPtr->lpCommand =
- (LPSTR)((UINT_PTR)lpPtr + (UINT_PTR)lpPtr->lpCommand);
+ (LPSTR)((ULONG_PTR)lpPtr + (ULONG_PTR)lpPtr->lpCommand);
if (lpPtr->lpsaActions != NULL)
lpPtr->lpsaActions =
- (SC_ACTION*)((UINT_PTR)lpPtr + (UINT_PTR)lpPtr->lpsaActions);
+ (LPSC_ACTION)((ULONG_PTR)lpPtr + (ULONG_PTR)lpPtr->lpsaActions);
}
break;
-
- default:
- ERR("Unknown info level 0x%lx\n", dwInfoLevel);
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
}
TRACE("QueryServiceConfig2A() done\n");
DWORD cbBufSize,
LPDWORD pcbBytesNeeded)
{
+ SERVICE_DESCRIPTIONW ServiceDescription;
+ SERVICE_FAILURE_ACTIONSW ServiceFailureActions;
+ LPBYTE lpTempBuffer;
+ BOOL bUseTempBuffer = FALSE;
+ DWORD dwBufferSize;
DWORD dwError;
TRACE("QueryServiceConfig2W(%p, %lu, %p, %lu, %p)\n",
hService, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
- if (dwInfoLevel != SERVICE_CONFIG_DESCRIPTION &&
- dwInfoLevel != SERVICE_CONFIG_FAILURE_ACTIONS)
- {
- SetLastError(ERROR_INVALID_LEVEL);
- return FALSE;
- }
+ lpTempBuffer = lpBuffer;
+ dwBufferSize = cbBufSize;
- if ((lpBuffer == NULL && cbBufSize != 0) ||
- pcbBytesNeeded == NULL)
+ switch (dwInfoLevel)
{
- SetLastError(ERROR_INVALID_ADDRESS);
- return FALSE;
+ case SERVICE_CONFIG_DESCRIPTION:
+ if ((lpBuffer == NULL) || (cbBufSize < sizeof(SERVICE_DESCRIPTIONW)))
+ {
+ lpTempBuffer = (LPBYTE)&ServiceDescription;
+ dwBufferSize = sizeof(SERVICE_DESCRIPTIONW);
+ bUseTempBuffer = TRUE;
+ }
+ break;
+
+ case SERVICE_CONFIG_FAILURE_ACTIONS:
+ if ((lpBuffer == NULL) || (cbBufSize < sizeof(SERVICE_FAILURE_ACTIONSW)))
+ {
+ lpTempBuffer = (LPBYTE)&ServiceFailureActions;
+ dwBufferSize = sizeof(SERVICE_FAILURE_ACTIONSW);
+ bUseTempBuffer = TRUE;
+ }
+ break;
+
+ default:
+ WARN("Unknown info level 0x%lx\n", dwInfoLevel);
+ SetLastError(ERROR_INVALID_LEVEL);
+ return FALSE;
}
RpcTryExcept
/* Call to services.exe using RPC */
dwError = RQueryServiceConfig2W((SC_RPC_HANDLE)hService,
dwInfoLevel,
- lpBuffer,
- cbBufSize,
+ lpTempBuffer,
+ dwBufferSize,
pcbBytesNeeded);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
return FALSE;
}
+ if (bUseTempBuffer == TRUE)
+ {
+ TRACE("RQueryServiceConfig2W() returns ERROR_INSUFFICIENT_BUFFER\n");
+ *pcbBytesNeeded = dwBufferSize;
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ return FALSE;
+ }
+
switch (dwInfoLevel)
{
case SERVICE_CONFIG_DESCRIPTION:
{
- LPSERVICE_DESCRIPTIONW lpPtr = (LPSERVICE_DESCRIPTIONW)lpBuffer;
+ LPSERVICE_DESCRIPTIONW lpPtr = (LPSERVICE_DESCRIPTIONW)lpTempBuffer;
if (lpPtr->lpDescription != NULL)
lpPtr->lpDescription =
- (LPWSTR)((UINT_PTR)lpPtr + (UINT_PTR)lpPtr->lpDescription);
+ (LPWSTR)((ULONG_PTR)lpPtr + (ULONG_PTR)lpPtr->lpDescription);
}
break;
case SERVICE_CONFIG_FAILURE_ACTIONS:
{
- LPSERVICE_FAILURE_ACTIONSW lpPtr = (LPSERVICE_FAILURE_ACTIONSW)lpBuffer;
+ LPSERVICE_FAILURE_ACTIONSW lpPtr = (LPSERVICE_FAILURE_ACTIONSW)lpTempBuffer;
if (lpPtr->lpRebootMsg != NULL)
lpPtr->lpRebootMsg =
- (LPWSTR)((UINT_PTR)lpPtr + (UINT_PTR)lpPtr->lpRebootMsg);
+ (LPWSTR)((ULONG_PTR)lpPtr + (ULONG_PTR)lpPtr->lpRebootMsg);
if (lpPtr->lpCommand != NULL)
lpPtr->lpCommand =
- (LPWSTR)((UINT_PTR)lpPtr + (UINT_PTR)lpPtr->lpCommand);
+ (LPWSTR)((ULONG_PTR)lpPtr + (ULONG_PTR)lpPtr->lpCommand);
if (lpPtr->lpsaActions != NULL)
lpPtr->lpsaActions =
- (SC_ACTION*)((UINT_PTR)lpPtr + (UINT_PTR)lpPtr->lpsaActions);
+ (LPSC_ACTION)((ULONG_PTR)lpPtr + (ULONG_PTR)lpPtr->lpsaActions);
}
break;
-
- default:
- WARN("Unknown info level 0x%lx\n", dwInfoLevel);
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
}
TRACE("QueryServiceConfig2W() done\n");
DWORD cbBufSize,
LPDWORD pcbBytesNeeded)
{
+ QUERY_SERVICE_LOCK_STATUSA LockStatus;
+ LPQUERY_SERVICE_LOCK_STATUSA lpStatusPtr;
+ DWORD dwBufferSize;
DWORD dwError;
TRACE("QueryServiceLockStatusA() called\n");
+ if (lpLockStatus == NULL || cbBufSize < sizeof(QUERY_SERVICE_LOCK_STATUSA))
+ {
+ lpStatusPtr = &LockStatus;
+ dwBufferSize = sizeof(QUERY_SERVICE_LOCK_STATUSA);
+ }
+ else
+ {
+ lpStatusPtr = lpLockStatus;
+ dwBufferSize = cbBufSize;
+ }
+
RpcTryExcept
{
/* Call to services.exe using RPC */
dwError = RQueryServiceLockStatusA((SC_RPC_HANDLE)hSCManager,
- lpLockStatus,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
return FALSE;
}
- if (lpLockStatus->lpLockOwner != NULL)
+ if (lpStatusPtr->lpLockOwner != NULL)
{
- lpLockStatus->lpLockOwner =
- (LPSTR)((UINT_PTR)lpLockStatus + (UINT_PTR)lpLockStatus->lpLockOwner);
+ lpStatusPtr->lpLockOwner =
+ (LPSTR)((ULONG_PTR)lpStatusPtr + (ULONG_PTR)lpStatusPtr->lpLockOwner);
}
TRACE("QueryServiceLockStatusA() done\n");
DWORD cbBufSize,
LPDWORD pcbBytesNeeded)
{
+ QUERY_SERVICE_LOCK_STATUSW LockStatus;
+ LPQUERY_SERVICE_LOCK_STATUSW lpStatusPtr;
+ DWORD dwBufferSize;
DWORD dwError;
TRACE("QueryServiceLockStatusW() called\n");
+ if (lpLockStatus == NULL || cbBufSize < sizeof(QUERY_SERVICE_LOCK_STATUSW))
+ {
+ lpStatusPtr = &LockStatus;
+ dwBufferSize = sizeof(QUERY_SERVICE_LOCK_STATUSW);
+ }
+ else
+ {
+ lpStatusPtr = lpLockStatus;
+ dwBufferSize = cbBufSize;
+ }
+
RpcTryExcept
{
/* Call to services.exe using RPC */
dwError = RQueryServiceLockStatusW((SC_RPC_HANDLE)hSCManager,
- lpLockStatus,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
return FALSE;
}
- if (lpLockStatus->lpLockOwner != NULL)
+ if (lpStatusPtr->lpLockOwner != NULL)
{
- lpLockStatus->lpLockOwner =
- (LPWSTR)((UINT_PTR)lpLockStatus + (UINT_PTR)lpLockStatus->lpLockOwner);
+ lpStatusPtr->lpLockOwner =
+ (LPWSTR)((ULONG_PTR)lpStatusPtr + (ULONG_PTR)lpStatusPtr->lpLockOwner);
}
TRACE("QueryServiceLockStatusW() done\n");
return FALSE;
}
+ if (cbBufSize < sizeof(SERVICE_STATUS_PROCESS))
+ {
+ *pcbBytesNeeded = sizeof(SERVICE_STATUS_PROCESS);
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ return FALSE;
+ }
+
RpcTryExcept
{
/* Call to services.exe using RPC */