From 843b40c7adb903fa27476e70d101e0fd53548630 Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Fri, 6 Jul 2007 13:53:29 +0000 Subject: [PATCH] - ensure SetLastError is called when EnumServicesStatusEx is returning required buffer sizes - servman.exe now lists all ReactOS services svn path=/trunk/; revision=27423 --- reactos/dll/win32/advapi32/service/scm.c | 65 +++++++++++++++--------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/reactos/dll/win32/advapi32/service/scm.c b/reactos/dll/win32/advapi32/service/scm.c index 82fcfc84fb3..48e065fa740 100644 --- a/reactos/dll/win32/advapi32/service/scm.c +++ b/reactos/dll/win32/advapi32/service/scm.c @@ -962,21 +962,29 @@ EnumServicesStatusExA(SC_HANDLE hSCManager, lpResumeHandle, (char *)pszGroupName); - lpStatusPtr = (LPENUM_SERVICE_STATUS_PROCESSA)lpServices; - for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) + if (dwError == ERROR_MORE_DATA) { - 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); - - lpStatusPtr++; + DPRINT("Required buffer size %ul\n", *pcbBytesNeeded); + SetLastError(dwError); + return FALSE; } + else if (dwError == ERROR_SUCCESS) + { + lpStatusPtr = (LPENUM_SERVICE_STATUS_PROCESSA)lpServices; + for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) + { + if (lpStatusPtr->lpServiceName) + lpStatusPtr->lpServiceName = + (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName); - if (dwError != ERROR_SUCCESS) + if (lpStatusPtr->lpDisplayName) + lpStatusPtr->lpDisplayName = + (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName); + + lpStatusPtr++; + } + } + else { DPRINT1("ScmrEnumServicesStatusExA() failed (Error %lu)\n", dwError); SetLastError(dwError); @@ -1026,22 +1034,29 @@ EnumServicesStatusExW(SC_HANDLE hSCManager, lpResumeHandle, (wchar_t *)pszGroupName); - lpStatusPtr = (LPENUM_SERVICE_STATUS_PROCESSW)lpServices; - for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) + if (dwError == ERROR_MORE_DATA) { - 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); - - lpStatusPtr++; + DPRINT("Required buffer size %ul\n", *pcbBytesNeeded); + SetLastError(dwError); + return FALSE; } + else if (dwError == ERROR_SUCCESS) + { + lpStatusPtr = (LPENUM_SERVICE_STATUS_PROCESSW)lpServices; + for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) + { + if (lpStatusPtr->lpServiceName) + lpStatusPtr->lpServiceName = + (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName); - if (dwError != ERROR_SUCCESS && - dwError != ERROR_MORE_DATA) + if (lpStatusPtr->lpDisplayName) + lpStatusPtr->lpDisplayName = + (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName); + + lpStatusPtr++; + } + } + else { DPRINT1("ScmrEnumServicesStatusExW() failed (Error %lu)\n", dwError); SetLastError(dwError);