X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=base%2Fapplications%2Fmscutils%2Fservman%2Fquery.c;h=a06ef58be223a9f975239bea42cbfd25a45adc7d;hp=3c007852f6a2652d590e43635464ef4ab42ea1a0;hb=e4a060ead45b9dc87a64408b6d791ea4a5fef55e;hpb=2597cfe258b768473a744df30227f4067252d9b7 diff --git a/base/applications/mscutils/servman/query.c b/base/applications/mscutils/servman/query.c index 3c007852f6a..a06ef58be22 100644 --- a/base/applications/mscutils/servman/query.c +++ b/base/applications/mscutils/servman/query.c @@ -30,63 +30,54 @@ GetSelectedService(PMAIN_WND_INFO Info) LPQUERY_SERVICE_CONFIG GetServiceConfig(LPTSTR lpServiceName) { - SC_HANDLE hSCManager = NULL; - SC_HANDLE hSc = NULL; - LPQUERY_SERVICE_CONFIG pServiceConfig = NULL; - DWORD BytesNeeded = 0; + LPQUERY_SERVICE_CONFIG lpServiceConfig = NULL; + SC_HANDLE hSCManager; + SC_HANDLE hService; + DWORD dwBytesNeeded; hSCManager = OpenSCManager(NULL, NULL, - SC_MANAGER_ENUMERATE_SERVICE); - if (hSCManager == NULL) - { - GetError(); - return NULL; - } - - hSc = OpenService(hSCManager, - lpServiceName, - SERVICE_QUERY_CONFIG); - if (hSc == NULL) - { - GetError(); - goto cleanup; - } - - if (!QueryServiceConfig(hSc, - pServiceConfig, - 0, - &BytesNeeded)) + SC_MANAGER_ALL_ACCESS); + if (hSCManager) { - if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + hService = OpenService(hSCManager, + lpServiceName, + SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG); + if (hService) { - pServiceConfig = (LPQUERY_SERVICE_CONFIG) HeapAlloc(ProcessHeap, - 0, - BytesNeeded); - if (pServiceConfig == NULL) - goto cleanup; - - if (!QueryServiceConfig(hSc, - pServiceConfig, - BytesNeeded, - &BytesNeeded)) + if (!QueryServiceConfig(hService, + NULL, + 0, + &dwBytesNeeded)) { - HeapFree(ProcessHeap, - 0, - pServiceConfig); - - pServiceConfig = NULL; + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + { + lpServiceConfig = (LPQUERY_SERVICE_CONFIG)HeapAlloc(GetProcessHeap(), + 0, + dwBytesNeeded); + if (lpServiceConfig) + { + if (!QueryServiceConfig(hService, + lpServiceConfig, + dwBytesNeeded, + &dwBytesNeeded)) + { + HeapFree(GetProcessHeap(), + 0, + lpServiceConfig); + lpServiceConfig = NULL; + } + } + } } + + CloseServiceHandle(hService); } - } -cleanup: - if (hSCManager != NULL) CloseServiceHandle(hSCManager); - if (hSc != NULL) - CloseServiceHandle(hSc); + } - return pServiceConfig; + return lpServiceConfig; } @@ -152,6 +143,7 @@ GetServiceDescription(LPTSTR lpServiceName) SERVICE_DESCRIPTION *pServiceDescription = NULL; LPTSTR lpDescription = NULL; DWORD BytesNeeded = 0; + DWORD dwSize; hSCManager = OpenSCManager(NULL, NULL, @@ -189,12 +181,16 @@ GetServiceDescription(LPTSTR lpServiceName) { if (pServiceDescription->lpDescription) { + dwSize = _tcslen(pServiceDescription->lpDescription) + 1; lpDescription = HeapAlloc(ProcessHeap, 0, - (_tcslen(pServiceDescription->lpDescription) + 1) * sizeof(TCHAR)); + dwSize * sizeof(TCHAR)); if (lpDescription) - _tcscpy(lpDescription, - pServiceDescription->lpDescription); + { + _tcscpy_s(lpDescription, + dwSize, + pServiceDescription->lpDescription); + } } } }