From a59bcdc26c9f3d3e1c7c9ad76a6f666d919f0d08 Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Tue, 9 Dec 2014 15:38:23 +0100 Subject: [PATCH] Fix major bugs in windows plugins check_load and check_service fixes #7881 #7992 --- plugins/check_load.cpp | 6 ++---- plugins/check_service.cpp | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/plugins/check_load.cpp b/plugins/check_load.cpp index 4f69872b0..8adaceaab 100644 --- a/plugins/check_load.cpp +++ b/plugins/check_load.cpp @@ -56,8 +56,7 @@ int wmain(int argc, wchar_t **argv) if (ret != -1) return ret; - printOutput(printInfo); - return 1; + return printOutput(printInfo); } int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& printInfo) { @@ -110,8 +109,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& L"and \"67%%\" is the returned value.\n" L"The performance data is found behind the \"|\", in order:\n" L"returned value, warning threshold, critical threshold, minimal value and,\n" - L"if applicable, the maximal value. Performance data will only be displayed when\n" - L"you set at least one threshold\n\n" + L"if applicable, the maximal value.\n\n" L"%s' exit codes denote the following:\n" L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n" L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n" diff --git a/plugins/check_service.cpp b/plugins/check_service.cpp index b55045420..ccfd19677 100644 --- a/plugins/check_service.cpp +++ b/plugins/check_service.cpp @@ -171,32 +171,36 @@ int ServiceStatus(const printInfoStruct& printInfo) LPBYTE lpServices = NULL; DWORD cbBufSize = 0; - DWORD *pcbBytesNeeded = NULL, *lpServicesReturned = NULL, *lpResumeHandle = NULL; + DWORD pcbBytesNeeded = NULL, ServicesReturned = NULL, ResumeHandle = NULL; if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, - lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, NULL) + lpServices, cbBufSize, &pcbBytesNeeded, &ServicesReturned, &ResumeHandle, NULL) && GetLastError() != ERROR_MORE_DATA) goto die; - lpServices = reinterpret_cast(new BYTE[*pcbBytesNeeded]); - cbBufSize = *pcbBytesNeeded; + lpServices = reinterpret_cast(new BYTE[pcbBytesNeeded]); + cbBufSize = pcbBytesNeeded; if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, - lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, NULL)) + lpServices, cbBufSize, &pcbBytesNeeded, &ServicesReturned, &ResumeHandle, NULL)) goto die; LPENUM_SERVICE_STATUS_PROCESS pInfo = (LPENUM_SERVICE_STATUS_PROCESS)lpServices; - for (DWORD i = 0; i< *lpServicesReturned; i++) { + for (DWORD i = 0; i < ServicesReturned; i++) { if (!wcscmp(printInfo.service.c_str(), pInfo[i].lpServiceName)) { + int state = pInfo[i].ServiceStatusProcess.dwCurrentState; delete lpServices; - return pInfo[i].ServiceStatusProcess.dwCurrentState; + return state; } } + wcout << L"Service " << printInfo.service << L" could not be found\n"; + delete[] reinterpret_cast(lpServices); + return -1; die: + die(); if (lpServices) delete[] reinterpret_cast(lpServices); - wcout << L"Service " << printInfo.service << L" could not be found" << endl; return -1; }