Fix major bugs in windows plugins check_load and check_service

fixes #7881 #7992
This commit is contained in:
Jean Flach 2014-12-09 15:38:23 +01:00
parent 4a81dbb6fc
commit a59bcdc26c
2 changed files with 14 additions and 12 deletions

View File

@ -56,8 +56,7 @@ int wmain(int argc, wchar_t **argv)
if (ret != -1) if (ret != -1)
return ret; return ret;
printOutput(printInfo); return printOutput(printInfo);
return 1;
} }
int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& 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"and \"67%%\" is the returned value.\n"
L"The performance data is found behind the \"|\", in order:\n" L"The performance data is found behind the \"|\", in order:\n"
L"returned value, warning threshold, critical threshold, minimal value and,\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"if applicable, the maximal value.\n\n"
L"you set at least one threshold\n\n"
L"%s' exit codes denote the following:\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" 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" L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n"

View File

@ -171,32 +171,36 @@ int ServiceStatus(const printInfoStruct& printInfo)
LPBYTE lpServices = NULL; LPBYTE lpServices = NULL;
DWORD cbBufSize = 0; 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, 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) && GetLastError() != ERROR_MORE_DATA)
goto die; goto die;
lpServices = reinterpret_cast<LPBYTE>(new BYTE[*pcbBytesNeeded]); lpServices = reinterpret_cast<LPBYTE>(new BYTE[pcbBytesNeeded]);
cbBufSize = *pcbBytesNeeded; cbBufSize = pcbBytesNeeded;
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, 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; goto die;
LPENUM_SERVICE_STATUS_PROCESS pInfo = (LPENUM_SERVICE_STATUS_PROCESS)lpServices; 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)) { if (!wcscmp(printInfo.service.c_str(), pInfo[i].lpServiceName)) {
int state = pInfo[i].ServiceStatusProcess.dwCurrentState;
delete lpServices; delete lpServices;
return pInfo[i].ServiceStatusProcess.dwCurrentState; return state;
} }
} }
wcout << L"Service " << printInfo.service << L" could not be found\n";
delete[] reinterpret_cast<LPBYTE>(lpServices);
return -1;
die: die:
die();
if (lpServices) if (lpServices)
delete[] reinterpret_cast<LPBYTE>(lpServices); delete[] reinterpret_cast<LPBYTE>(lpServices);
wcout << L"Service " << printInfo.service << L" could not be found" << endl;
return -1; return -1;
} }