diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index 8f4f0e0d8c..4ef061d4f3 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,22 @@ +2009-10-05 Ramon Novoa + + * ftp/pandora_ftp_client.h: Fixed the path of curl.h to match + that in the Dev-cpp libcurl devpack. + + * modules/pandora_module_tcpcheck.cc: Properly close the connection + socket. + + * modules/pandora_module_regexp.cc: Removed debugging code. + + * modules/pandora_module_perfcounter.cc: Close the query handle even if + no data was returned to avoid memory leaks. + + * windows/pandora_windows_info.h, + windows/pandora_windows_info.cc, + modules/pandora_module_proc.cc: Fixed a process handle leak. + + * configure.in: Improved library detection. + 2009-09-24 Sancho Lerena * modules/pandora_module_tcpcheck.cc: WSAStartup memory management diff --git a/pandora_agents/win32/configure.in b/pandora_agents/win32/configure.in index 53e1267148..7ed4bfd79d 100644 --- a/pandora_agents/win32/configure.in +++ b/pandora_agents/win32/configure.in @@ -22,17 +22,18 @@ AM_CONDITIONAL(DEBUG, test "$debug" = "yes") # Checks for libraries. AC_CHECK_LIB([ws2_32], [main], , AC_MSG_ERROR([MingGW not found. You can get it from http://www.mingw.org/])) -AC_CHECK_LIB([psapi], [main], , ) -AC_CHECK_LIB([ole32], [main], , ) -AC_CHECK_LIB([oleaut32], [main], , ) -AC_CHECK_LIB([uuid], [main], , ) -AC_CHECK_LIB([regex], [main], , AC_MSG_ERROR([Boost.Regex not not found. Get it from http://www.boost.org/ and rename it to libregex.a])) -AC_CHECK_LIB([z], [main], , ) -AC_CHECK_LIB([gdi32], [main], , ) -AC_CHECK_LIB([crypto], [main], , ) -AC_CHECK_LIB([ssl], [main], , ) -AC_CHECK_LIB([curl], [main], , ) -AC_CHECK_LIB([odbc++], [main], , ) +AC_CHECK_LIB([winmm], [main], , AC_MSG_ERROR([libwinmm not found.])) +AC_CHECK_LIB([psapi], [main], , AC_MSG_ERROR([libpsapi not found.])) +AC_CHECK_LIB([ole32], [main], , AC_MSG_ERROR([libole32 not found.])) +AC_CHECK_LIB([oleaut32], [main], , AC_MSG_ERROR([liboleaut not found.])) +AC_CHECK_LIB([uuid], [main], , AC_MSG_ERROR([libuuid not found.])) +AC_CHECK_LIB([boost_regex], [main], , AC_MSG_ERROR([Boost.Regex not not found. Get it from http://www.boost.org/])) +AC_CHECK_LIB([z], [main], , AC_MSG_ERROR([libz not found.])) +AC_CHECK_LIB([gdi32], [main], , AC_MSG_ERROR([libgdi32 not found.])) +AC_CHECK_LIB([crypto], [main], , AC_MSG_ERROR([libcrypto not found.])) +AC_CHECK_LIB([ssl], [main], , AC_MSG_ERROR([libssl not found.])) +AC_CHECK_LIB([curl], [main], , AC_MSG_ERROR([libcurl not found.])) +AC_CHECK_LIB([odbc++], [main], , AC_MSG_ERROR([libodbc++ not found.])) # Checks for header files. AC_CHECK_HEADERS([fcntl.h stddef.h stdlib.h string.h sys/socket.h sys/time.h unistd.h wchar.h]) diff --git a/pandora_agents/win32/ftp/pandora_ftp_client.h b/pandora_agents/win32/ftp/pandora_ftp_client.h index 7ebd89772b..f76cac14ae 100644 --- a/pandora_agents/win32/ftp/pandora_ftp_client.h +++ b/pandora_agents/win32/ftp/pandora_ftp_client.h @@ -23,7 +23,7 @@ #include #include "../pandora.h" -#include +#include using namespace std; diff --git a/pandora_agents/win32/modules/pandora_module_perfcounter.cc b/pandora_agents/win32/modules/pandora_module_perfcounter.cc index 8963aa507c..60a9f05af1 100755 --- a/pandora_agents/win32/modules/pandora_module_perfcounter.cc +++ b/pandora_agents/win32/modules/pandora_module_perfcounter.cc @@ -137,6 +137,7 @@ Pandora_Module_Perfcounter::run () { status = PdhAddCounter (query, this->source.c_str (), 0, &counter); if (status != ERROR_SUCCESS) { pandoraLog ("PdhAddCounter failed with error %d", status); + PdhCloseQuery (query); return; } @@ -144,6 +145,7 @@ Pandora_Module_Perfcounter::run () { status = PdhCollectQueryData (query); if (status != ERROR_SUCCESS) { // No data + PdhCloseQuery (query); return; } diff --git a/pandora_agents/win32/modules/pandora_module_proc.cc b/pandora_agents/win32/modules/pandora_module_proc.cc index 96663278ce..91deab0efb 100644 --- a/pandora_agents/win32/modules/pandora_module_proc.cc +++ b/pandora_agents/win32/modules/pandora_module_proc.cc @@ -128,7 +128,7 @@ async_run (Pandora_Module_Proc *module) { Pandora_Module_List *modules; string str_res; string prev_res; - int i, res, counter = 0; + int i, res, counter = 0, num_proc; prev_res = module->getLatestOutput (); modules = new Pandora_Module_List (); @@ -136,7 +136,7 @@ async_run (Pandora_Module_Proc *module) { Sleep (module->getStartDelay ()); while (1) { - processes = getProcessHandles (module->getProcessName ()); + processes = getProcessHandles (module->getProcessName (), &num_proc); if (processes == NULL) { if (module->isWatchdog ()) { if (counter >= module->getRetries ()) { @@ -173,7 +173,7 @@ async_run (Pandora_Module_Proc *module) { if (result > (WAIT_OBJECT_0 + nprocess - 1)) { /* No event happened */ - for (i = 0; i < nprocess; i++) + for (i = 0; i < num_proc; i++) CloseHandle (processes[i]); pandoraFree (processes); continue; @@ -189,7 +189,7 @@ async_run (Pandora_Module_Proc *module) { } /* Free handles */ - for (i = 0; i < nprocess; i++) + for (i = 0; i < num_proc; i++) CloseHandle (processes[i]); pandoraFree (processes); } diff --git a/pandora_agents/win32/modules/pandora_module_regexp.cc b/pandora_agents/win32/modules/pandora_module_regexp.cc index 0303de32c7..ca9ebdab05 100755 --- a/pandora_agents/win32/modules/pandora_module_regexp.cc +++ b/pandora_agents/win32/modules/pandora_module_regexp.cc @@ -49,7 +49,7 @@ Pandora_Module_Regexp::Pandora_Module_Regexp (string name, string source, string // Open the file and skip to the end this->file.open (source.c_str ()); if (this->file.is_open ()) { - //this->file.seekg (0, ios_base::end); + this->file.seekg (0, ios_base::end); } else { pandoraLog ("Error opening file %s", source.c_str ()); } diff --git a/pandora_agents/win32/modules/pandora_module_tcpcheck.cc b/pandora_agents/win32/modules/pandora_module_tcpcheck.cc index d2382e22af..8b5083e0a5 100755 --- a/pandora_agents/win32/modules/pandora_module_tcpcheck.cc +++ b/pandora_agents/win32/modules/pandora_module_tcpcheck.cc @@ -131,11 +131,13 @@ Pandora_Module_Tcpcheck::run () { rc = select(0, NULL, &socket_set, NULL, &timer); if (rc == 0) { - this->setOutput ("0"); - - WSACleanup (); + closesocket (sock); + WSACleanup (); + this->setOutput ("0"); return; } + + closesocket (sock); WSACleanup (); this->setOutput ("1"); } diff --git a/pandora_agents/win32/windows/pandora_windows_info.cc b/pandora_agents/win32/windows/pandora_windows_info.cc index 477ef9b4e0..aceb2bdb30 100644 --- a/pandora_agents/win32/windows/pandora_windows_info.cc +++ b/pandora_agents/win32/windows/pandora_windows_info.cc @@ -84,7 +84,7 @@ Pandora_Windows_Info::getSystemPath () { } HANDLE * -Pandora_Windows_Info::getProcessHandles (string name) { +Pandora_Windows_Info::getProcessHandles (string name, int *num_proc) { HANDLE handle; HANDLE handles[128]; HANDLE *retval; @@ -95,6 +95,7 @@ Pandora_Windows_Info::getProcessHandles (string name) { bool success; TCHAR process_name[MAX_PATH]; + *num_proc = 0; if (! EnumProcesses (pids, sizeof (pids), &needed)) return NULL; @@ -119,11 +120,15 @@ Pandora_Windows_Info::getProcessHandles (string name) { if (stricmp (process_name, name.c_str ()) == 0) { /* Process found */ handles[count++] = handle; + } else { + CloseHandle (handle); } } if (count == 0) return NULL; + + *num_proc = count; retval = (HANDLE *) malloc (count * sizeof (HANDLE)); for (i = 0; i < count; i++) retval[i] = handles[i]; diff --git a/pandora_agents/win32/windows/pandora_windows_info.h b/pandora_agents/win32/windows/pandora_windows_info.h index dc8ae9cb7c..afa3166c22 100644 --- a/pandora_agents/win32/windows/pandora_windows_info.h +++ b/pandora_agents/win32/windows/pandora_windows_info.h @@ -39,7 +39,7 @@ namespace Pandora_Windows_Info { string getOSBuild (); string getSystemName (); string getSystemPath (); - HANDLE *getProcessHandles (string name); + HANDLE *getProcessHandles (string name, int *num_procs); string getRegistryValue (HKEY root, const string treepath, const string keyname); int getSoftware (list &rows, string separator); }