diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index f700ce53c3..52e0e85234 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,14 @@ +2008-06-11 Esteban Sanchez + + * pandora_windows_service.cc, modules/pandora_module_list.cc: Deleted + debug output. + + * modules/pandora_module_exec.cc: Reindented the code. Add blank + output to the module if there were nothing to read (like when the + executions return nothing). + + * bin/PandoraAgent.exe: Updated to commit. + 2008-06-11 Esteban Sanchez * bin/libodbc++.dll: Added to repository. Needed to run agent since diff --git a/pandora_agents/win32/bin/PandoraAgent.exe b/pandora_agents/win32/bin/PandoraAgent.exe index 640cda448e..38eb3af221 100755 Binary files a/pandora_agents/win32/bin/PandoraAgent.exe and b/pandora_agents/win32/bin/PandoraAgent.exe differ diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc index 87bbc6a242..29be4a7ca7 100644 --- a/pandora_agents/win32/modules/pandora_module.cc +++ b/pandora_agents/win32/modules/pandora_module.cc @@ -294,7 +294,6 @@ Pandora_Module::getXml () { TiXmlText *text; string item_clean, data_clean, desc_clean; Pandora_Data *data; - pandoraDebug ("%s getXML begin", module_name.c_str ()); @@ -317,7 +316,7 @@ Pandora_Module::getXml () { root->InsertEndChild (*element); delete element; delete text; - + if (this->data_list && this->data_list->size () > 1) { list::iterator iter; diff --git a/pandora_agents/win32/modules/pandora_module_exec.cc b/pandora_agents/win32/modules/pandora_module_exec.cc index bde84b1b10..4283adb104 100644 --- a/pandora_agents/win32/modules/pandora_module_exec.cc +++ b/pandora_agents/win32/modules/pandora_module_exec.cc @@ -36,127 +36,129 @@ using namespace Pandora_Modules; */ Pandora_Module_Exec::Pandora_Module_Exec (string name, string exec) : Pandora_Module (name) { - this->module_exec = "cmd.exe /c \"" + exec + "\""; - - this->setKind (module_exec_str); + this->module_exec = "cmd.exe /c \"" + exec + "\""; + + this->setKind (module_exec_str); } void Pandora_Module_Exec::run () { - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD retval; - SECURITY_ATTRIBUTES attributes; - HANDLE out, new_stdout, out_read, job; - string working_dir; - - try { - Pandora_Module::run (); - } catch (Interval_Not_Fulfilled e) { + STARTUPINFO si; + PROCESS_INFORMATION pi; + DWORD retval; + SECURITY_ATTRIBUTES attributes; + HANDLE out, new_stdout, out_read, job; + string working_dir; + + try { + Pandora_Module::run (); + } catch (Interval_Not_Fulfilled e) { this->has_output = false; - return; - } - - /* Set the bInheritHandle flag so pipe handles are inherited. */ - attributes.nLength = sizeof (SECURITY_ATTRIBUTES); - attributes.bInheritHandle = TRUE; - attributes.lpSecurityDescriptor = NULL; - - /* Create a job to kill the child tree if it become zombie */ - /* CAUTION: In order to work this, WINVER should be defined to 0x0500. - This may need no change, since it was redefined by the - program, but if needed, the macro is defined - in */ - job = CreateJobObject (&attributes, this->module_name.c_str ()); - if (job == NULL) { - pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ()); + return; + } + + /* Set the bInheritHandle flag so pipe handles are inherited. */ + attributes.nLength = sizeof (SECURITY_ATTRIBUTES); + attributes.bInheritHandle = TRUE; + attributes.lpSecurityDescriptor = NULL; + + /* Create a job to kill the child tree if it become zombie */ + /* CAUTION: In order to compile this, WINVER should be defined to 0x0500. + This may need no change, since it was redefined by the + program, but if needed, the macro is defined + in */ + job = CreateJobObject (&attributes, this->module_name.c_str ()); + if (job == NULL) { + pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ()); this->has_output = false; - return; - } - - /* Get the handle to the current STDOUT. */ - out = GetStdHandle (STD_OUTPUT_HANDLE); - - if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) { - pandoraLog ("CreatePipe failed. Err: %d", GetLastError ()); + return; + } + + /* Get the handle to the current STDOUT. */ + out = GetStdHandle (STD_OUTPUT_HANDLE); + + if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) { + pandoraLog ("CreatePipe failed. Err: %d", GetLastError ()); this->has_output = false; - return; - } - - /* Ensure the read handle to the pipe for STDOUT is not inherited */ - SetHandleInformation (out_read, HANDLE_FLAG_INHERIT, 0); - - /* Set up members of the STARTUPINFO structure. */ - ZeroMemory (&si, sizeof (si)); - GetStartupInfo (&si); - - si.cb = sizeof (si); - si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; - si.wShowWindow = SW_HIDE; - si.hStdError = new_stdout; - si.hStdOutput = new_stdout; - - /* Set up members of the PROCESS_INFORMATION structure. */ - ZeroMemory (&pi, sizeof (pi)); - pandoraDebug ("Executing: %s", this->module_exec.c_str ()); - - /* Set the working directory of the process. It's "utils" directory - to find the GNU W32 tools */ - working_dir = getPandoraInstallDir () + "util\\"; - - /* Create the child process. */ - if (! CreateProcess (NULL, (CHAR *) this->module_exec.c_str (), NULL, - NULL, TRUE, CREATE_SUSPENDED, NULL, - working_dir.c_str (), &si, &pi)) { - pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d", - this->module_name.c_str (), GetLastError ()); + return; + } + + /* Ensure the read handle to the pipe for STDOUT is not inherited */ + SetHandleInformation (out_read, HANDLE_FLAG_INHERIT, 0); + + /* Set up members of the STARTUPINFO structure. */ + ZeroMemory (&si, sizeof (si)); + GetStartupInfo (&si); + + si.cb = sizeof (si); + si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; + si.wShowWindow = SW_HIDE; + si.hStdError = new_stdout; + si.hStdOutput = new_stdout; + + /* Set up members of the PROCESS_INFORMATION structure. */ + ZeroMemory (&pi, sizeof (pi)); + pandoraDebug ("Executing: %s", this->module_exec.c_str ()); + + /* Set the working directory of the process. It's "utils" directory + to find the GNU W32 tools */ + working_dir = getPandoraInstallDir () + "util\\"; + + /* Create the child process. */ + if (! CreateProcess (NULL, (CHAR *) this->module_exec.c_str (), NULL, + NULL, TRUE, CREATE_SUSPENDED, NULL, + working_dir.c_str (), &si, &pi)) { + pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d", + this->module_name.c_str (), GetLastError ()); this->has_output = false; - } else { - char buffer[BUFSIZE + 1]; - unsigned long read, avail; - - if (! AssignProcessToJobObject (job, pi.hProcess)) { - pandoraLog ("Could not assigned proccess to job (error %d)", - GetLastError ()); - } - ResumeThread (pi.hThread); - - /* Wait until process exits. */ - /* TODO: The time should be an attribute*/ - WaitForSingleObject (pi.hProcess, 15000); - - GetExitCodeProcess (pi.hProcess, &retval); - if (retval != 0) { - if (! TerminateJobObject (job, 0)) { - pandoraLog ("TerminateJobObject failed. (error %d)", - GetLastError ()); - } - - pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)", - this->module_name.c_str (), retval); + } else { + char buffer[BUFSIZE + 1]; + unsigned long read, avail; + + if (! AssignProcessToJobObject (job, pi.hProcess)) { + pandoraLog ("Could not assigned proccess to job (error %d)", + GetLastError ()); + } + ResumeThread (pi.hThread); + + /* Wait until process exits. */ + /* TODO: The time should be an attribute*/ + WaitForSingleObject (pi.hProcess, 15000); + + GetExitCodeProcess (pi.hProcess, &retval); + if (retval != 0) { + if (! TerminateJobObject (job, 0)) { + pandoraLog ("TerminateJobObject failed. (error %d)", + GetLastError ()); + } + + pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)", + this->module_name.c_str (), retval); this->has_output = false; - } - - PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL); - /* Read from the stdout */ - if (read != 0) { + } + + PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL); + /* Read from the stdout */ + if (read != 0) { string output; - do { - ReadFile (out_read, buffer, BUFSIZE, &read, - NULL); - buffer[read] = '\0'; - output += (char *) buffer; - } while (read >= BUFSIZE); + do { + ReadFile (out_read, buffer, BUFSIZE, &read, + NULL); + buffer[read] = '\0'; + output += (char *) buffer; + } while (read >= BUFSIZE); this->setOutput (output); - } - - /* Close job, process and thread handles. */ - CloseHandle (job); - CloseHandle (pi.hProcess); - CloseHandle (pi.hThread); - } - - CloseHandle (new_stdout); - CloseHandle (out_read); + } else { + this->setOutput (""); + } + + /* Close job, process and thread handles. */ + CloseHandle (job); + CloseHandle (pi.hProcess); + CloseHandle (pi.hThread); + } + + CloseHandle (new_stdout); + CloseHandle (out_read); } diff --git a/pandora_agents/win32/modules/pandora_module_list.cc b/pandora_agents/win32/modules/pandora_module_list.cc index 567a0daa55..5b6ce7d3d3 100644 --- a/pandora_agents/win32/modules/pandora_module_list.cc +++ b/pandora_agents/win32/modules/pandora_module_list.cc @@ -119,7 +119,6 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition) module = Pandora_Module_Factory::getModuleFromDefinition (definition); if (module != NULL) { - cout << module->getModuleKind () << endl; switch (module->getModuleKind ()) { case MODULE_EXEC: module_exec = (Pandora_Module_Exec *) module; diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index da911461bf..b6db308b19 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -135,7 +135,6 @@ Pandora_Windows_Service::pandora_init () { this->transfer_interval = this->interval; } } - cout << "trans: " << this->transfer_interval << endl; srand ((unsigned) time (0)); this->setSleepTime (this->interval); @@ -631,7 +630,7 @@ Pandora_Windows_Service::pandora_run () { } this->elapsed_transfer_time += interval; - cout << "interval time: " << interval << " transfer time:" << this->transfer_interval << " time passed: " << this->elapsed_transfer_time << endl; + if (this->elapsed_transfer_time >= this->transfer_interval) { agent = getXmlHeader ();