mirror of
				https://github.com/Icinga/icinga2.git
				synced 2025-11-03 21:25:56 +01:00 
			
		
		
		
	Fix major bugs in windows plugins check_load and check_service
fixes #7881 #7992
This commit is contained in:
		
							parent
							
								
									4a81dbb6fc
								
							
						
					
					
						commit
						a59bcdc26c
					
				@ -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"
 | 
			
		||||
 | 
			
		||||
@ -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<LPBYTE>(new BYTE[*pcbBytesNeeded]);
 | 
			
		||||
	cbBufSize = *pcbBytesNeeded;
 | 
			
		||||
	lpServices = reinterpret_cast<LPBYTE>(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<LPBYTE>(lpServices);
 | 
			
		||||
	return -1;
 | 
			
		||||
 | 
			
		||||
die:
 | 
			
		||||
	die();
 | 
			
		||||
	if (lpServices)
 | 
			
		||||
		delete[] reinterpret_cast<LPBYTE>(lpServices);
 | 
			
		||||
	wcout << L"Service " << printInfo.service << L" could not be found" << endl;
 | 
			
		||||
	return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user