diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index d31714343d..ded6495250 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,27 @@ +2006-07-11 Esteban Sanchez + + * pandora_windows_service.h: Public methods converted into private. + + * modules/pandora_module_freedisk.[cc,h]: Added to repository. + Implements a module to check the free space in a disk. + + * modules/pandora_module.h, modules/pandora_module_factory.cc, + pandora_module_list.cc: Added support to Pandora_Module_Freedisk + modules. + + * ssh/libssh2/channel.c: Fixed a bug on libssh2_channel_wait_closed + that caused to not copy the file to the remote host. + + * windows/wmi/pandora_wmi.[cc,h]: Added getDiskFreeSpace() to get + support eh Pandora_Module_Freedisk modules. + + * pandora_strutils,[cc,h]: Added longtostr() to convert a long into a + string. + + * PandoraAgent.dev: Added new files to the project. + + * bin/PandoraAgent.exe: Updated to the new commit. + 2006-07-10 Esteban Sanchez * modules/pandora_module_list.cc: Delete modules from the list in the diff --git a/pandora_agents/win32/PandoraAgent.dev b/pandora_agents/win32/PandoraAgent.dev index bf5cb4b00f..f681fc581c 100644 --- a/pandora_agents/win32/PandoraAgent.dev +++ b/pandora_agents/win32/PandoraAgent.dev @@ -1,7 +1,7 @@ [Project] FileName=PandoraAgent.dev Name=PandoraAgent -UnitCount=59 +UnitCount=61 Type=1 Ver=1 ObjFiles= @@ -637,3 +637,23 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit60] +FileName=modules\pandora_module_freedisk.cc +CompileCpp=1 +Folder=Modules +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit61] +FileName=modules\pandora_module_freedisk.h +CompileCpp=1 +Folder=Modules +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/pandora_agents/win32/bin/PandoraAgent.exe b/pandora_agents/win32/bin/PandoraAgent.exe index a2e480a23f..fcd39c3ea5 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.h b/pandora_agents/win32/modules/pandora_module.h index 043ac74095..401bbe16d5 100644 --- a/pandora_agents/win32/modules/pandora_module.h +++ b/pandora_agents/win32/modules/pandora_module.h @@ -45,12 +45,14 @@ namespace Pandora_Modules { MODULE_0, MODULE_EXEC, MODULE_PROC, - MODULE_SERVICE + MODULE_SERVICE, + MODULE_FREEDISK }; const string module_exec_str = "module_exec"; const string module_proc_str = "module_proc"; const string module_service_str = "module_service"; + const string module_freedisk_str = "module_freedisk"; class Output_Error : public Pandora::Pandora_Exception { }; class Interval_Error : public Pandora::Pandora_Exception { }; diff --git a/pandora_agents/win32/modules/pandora_module_factory.cc b/pandora_agents/win32/modules/pandora_module_factory.cc index 0c16ef83d0..2ef56accd7 100644 --- a/pandora_agents/win32/modules/pandora_module_factory.cc +++ b/pandora_agents/win32/modules/pandora_module_factory.cc @@ -23,6 +23,7 @@ #include "pandora_module_exec.h" #include "pandora_module_proc.h" #include "pandora_module_service.h" +#include "pandora_module_freedisk.h" #include "../pandora_strutils.h" #include @@ -36,6 +37,7 @@ using namespace Pandora_Strutils; #define TOKEN_EXEC ("module_exec ") #define TOKEN_PROC ("module_proc ") #define TOKEN_SERVICE ("module_service ") +#define TOKEN_FREEDISK ("module_freedisk ") #define TOKEN_MAX ("module_max ") #define TOKEN_MIN ("module_min ") #define TOKEN_DESCRIPTION ("module_description ") @@ -59,6 +61,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { string module_name, module_type, module_exec; string module_min, module_max, module_description; string module_interval, module_proc, module_service; + string module_freedisk; Pandora_Module *module; bool numeric; @@ -100,6 +103,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { if (module_service == "") { module_service = parseLine (line, TOKEN_SERVICE); } + if (module_freedisk == "") { + module_freedisk = parseLine (line, TOKEN_FREEDISK); + } if (module_max == "") { module_max = parseLine (line, TOKEN_MAX); } @@ -122,6 +128,10 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) { } else if (module_service != "") { module = new Pandora_Module_Service (module_name, module_service); + } else if (module_freedisk != "") { + module = new Pandora_Module_Freedisk (module_name, + module_freedisk); + } else { return NULL; } diff --git a/pandora_agents/win32/modules/pandora_module_freedisk.cc b/pandora_agents/win32/modules/pandora_module_freedisk.cc new file mode 100644 index 0000000000..33dfe37608 --- /dev/null +++ b/pandora_agents/win32/modules/pandora_module_freedisk.cc @@ -0,0 +1,62 @@ +/* Pandora freedisk module. These modules check the free space in a + logical drive. + + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "pandora_module_freedisk.h" +#include "../windows/pandora_wmi.h" +#include "../pandora_strutils.h" +#include +#include + +using namespace Pandora; +using namespace Pandora_Modules; +using namespace Pandora_Strutils; + +Pandora_Module_Freedisk::Pandora_Module_Freedisk (string name, string disk_id) + : Pandora_Module (name) { + + this->disk_id = disk_id; + + transform (disk_id.begin (), disk_id.end (), + this->disk_id.begin (), (int (*) (int)) toupper); + + this->module_kind_str = module_freedisk_str; + this->module_kind = MODULE_FREEDISK; +} + +void +Pandora_Module_Freedisk::run () { + long res; + + try { + Pandora_Module::run (); + } catch (Interval_Not_Fulfilled e) { + return; + } + + try { + res = Pandora_Wmi::getDiskFreeSpace (this->disk_id); + + output = longtostr (res); + pandoraDebug ("%s", output.c_str ()); + } catch (Pandora_Wmi::Pandora_Wmi_Error e) { + this->has_output = false; + } +} diff --git a/pandora_agents/win32/modules/pandora_module_freedisk.h b/pandora_agents/win32/modules/pandora_module_freedisk.h new file mode 100644 index 0000000000..13369eae2b --- /dev/null +++ b/pandora_agents/win32/modules/pandora_module_freedisk.h @@ -0,0 +1,38 @@ +/* Pandora freedisk module. These modules check the free space in a + logical drive. + + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef __PANDORA_MODULE_FREEDISK_H__ +#define __PANDORA_MODULE_FREEDISK_H__ + +#include "pandora_module.h" + +namespace Pandora_Modules { + class Pandora_Module_Freedisk : public Pandora_Module { + private: + string disk_id; + public: + Pandora_Module_Freedisk (string name, string disk_id); + + void run (); + }; +} + +#endif diff --git a/pandora_agents/win32/modules/pandora_module_list.cc b/pandora_agents/win32/modules/pandora_module_list.cc index 66b10bcf20..497f037c4b 100644 --- a/pandora_agents/win32/modules/pandora_module_list.cc +++ b/pandora_agents/win32/modules/pandora_module_list.cc @@ -23,6 +23,7 @@ #include "pandora_module_exec.h" #include "pandora_module_proc.h" #include "pandora_module_service.h" +#include "pandora_module_freedisk.h" #include using namespace std; @@ -91,10 +92,11 @@ Pandora_Module_List::~Pandora_Module_List () { void Pandora_Module_List::parseModuleDefinition (string definition) { - Pandora_Module *module; - Pandora_Module_Exec *module_exec; - Pandora_Module_Proc *module_proc; - Pandora_Module_Service *module_service; + Pandora_Module *module; + Pandora_Module_Exec *module_exec; + Pandora_Module_Proc *module_proc; + Pandora_Module_Service *module_service; + Pandora_Module_Freedisk *module_freedisk; module = Pandora_Module_Factory::getModuleFromDefinition (definition); @@ -115,6 +117,12 @@ Pandora_Module_List::parseModuleDefinition (string definition) { module_service = (Pandora_Module_Service *) module; modules->push_back (module_service); + break; + + case MODULE_FREEDISK: + module_freedisk = (Pandora_Module_Freedisk *) module; + modules->push_back (module_freedisk); + break; default: break; diff --git a/pandora_agents/win32/pandora_strutils.cpp b/pandora_agents/win32/pandora_strutils.cpp index 9906e4520b..df79337d6e 100644 --- a/pandora_agents/win32/pandora_strutils.cpp +++ b/pandora_agents/win32/pandora_strutils.cpp @@ -49,7 +49,12 @@ Pandora_Strutils::trim (const string str) { string Pandora_Strutils::inttostr (const int i) { - std::ostringstream o; + return longtostr (i); +} + +string +Pandora_Strutils::longtostr (const long i) { + std::ostringstream o; o << i; diff --git a/pandora_agents/win32/pandora_strutils.h b/pandora_agents/win32/pandora_strutils.h index 9e6892f52c..10ec226187 100644 --- a/pandora_agents/win32/pandora_strutils.h +++ b/pandora_agents/win32/pandora_strutils.h @@ -35,6 +35,7 @@ namespace Pandora_Strutils { string trim (const string str); string inttostr (const int i); + string longtostr (const long i); string longtohex (const long i); int strtoint (const string str); diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index 7c7805f250..7ac534fd73 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -39,7 +39,7 @@ private: string agent_name; TiXmlElement * getXmlHeader (); -public: + void pandora_run (); void pandora_init (); public: diff --git a/pandora_agents/win32/ssh/libssh2/channel.c b/pandora_agents/win32/ssh/libssh2/channel.c index 0daacd502d..42f5949e6f 100644 --- a/pandora_agents/win32/ssh/libssh2/channel.c +++ b/pandora_agents/win32/ssh/libssh2/channel.c @@ -1126,11 +1126,6 @@ LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel) { LIBSSH2_SESSION* session = channel->session; - if (!libssh2_channel_eof(channel)) { - libssh2_error(session, LIBSSH2_ERROR_INVAL, "libssh2_channel_wait_closed() invoked when channel is not in EOF state", 0); - return -1; - } - #ifdef LIBSSH2_DEBUG_CONNECTION _libssh2_debug(session, LIBSSH2_DBG_CONN, "Awaiting close of channel %lu/%lu", channel->local.id, channel->remote.id); #endif diff --git a/pandora_agents/win32/ssh/libssh2/misc.c b/pandora_agents/win32/ssh/libssh2/misc.c index 8c9ac0cf82..7f8a4f0ca1 100644 --- a/pandora_agents/win32/ssh/libssh2/misc.c +++ b/pandora_agents/win32/ssh/libssh2/misc.c @@ -198,9 +198,9 @@ void _libssh2_debug(LIBSSH2_SESSION *session, int context, const char *format, . va_start(vargs, format); len += vsnprintf(buffer + len, 1535 - len, format, vargs); - buffer[len] = '\n'; + buffer[len] = '\0'; va_end(vargs); - write(2, buffer, len + 1); + fprintf (stderr,"%s\n", buffer); } /* }}} */ #endif diff --git a/pandora_agents/win32/ssh/pandora_ssh_test.cc b/pandora_agents/win32/ssh/pandora_ssh_test.cc index af56f542de..4135af47cd 100644 --- a/pandora_agents/win32/ssh/pandora_ssh_test.cc +++ b/pandora_agents/win32/ssh/pandora_ssh_test.cc @@ -120,7 +120,7 @@ Pandora_SSH_Test::test () { remote_filepath += "/"; } - cout << "Remote copying " << tmp_filepath << "on server " << remote_host + cout << "Remote copying " << tmp_filepath << " on server " << remote_host << " at " << remote_filepath << tmp_filename << endl; try { ssh_client->scpFileFilename (remote_filepath + tmp_filename, diff --git a/pandora_agents/win32/windows/pandora_wmi.cc b/pandora_agents/win32/windows/pandora_wmi.cc index 91e3646727..70d5862117 100644 --- a/pandora_agents/win32/windows/pandora_wmi.cc +++ b/pandora_agents/win32/windows/pandora_wmi.cc @@ -132,6 +132,50 @@ Pandora_Wmi::isServiceRunning (string service_name) { return 0; } +long +Pandora_Wmi::getDiskFreeSpace (string disk_id) { + CDhInitialize init; + CDispPtr wmi_svc, quickfixes; + string id; + + dhToggleExceptions (TRUE); + + struct QFix { + CDhStringA id; + long free_space; + }; + + try { + dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc)); + dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc, + L".ExecQuery(%S)", + L"SELECT * FROM Win32_LogicalDisk ")); + + FOR_EACH (quickfix, quickfixes, NULL) { + QFix fix = { 0 }; + + dhGetValue (L"%s", &fix.id, quickfix, + L".DeviceID"); + + id = fix.id; + + pandoraDebug ("%s %s", disk_id.c_str (), id.c_str ()); + + if (disk_id == id) { + dhGetValue (L"%d", &fix.free_space, quickfix, + L".FreeSpace"); + pandoraDebug ("%d Bytes", fix.free_space); + return fix.free_space; + } + + } NEXT_THROW (quickfix); + } catch (string errstr) { + pandoraLog ("getOSName error. %s", errstr.c_str ()); + } + + throw Pandora_Wmi_Error (); +} + string Pandora_Wmi::getOSName () { CDhInitialize init; diff --git a/pandora_agents/win32/windows/pandora_wmi.h b/pandora_agents/win32/windows/pandora_wmi.h index b3dd7de218..a5a693dbfd 100644 --- a/pandora_agents/win32/windows/pandora_wmi.h +++ b/pandora_agents/win32/windows/pandora_wmi.h @@ -30,12 +30,15 @@ using namespace Pandora; using namespace std; namespace Pandora_Wmi { - int isProcessRunning (string process_name); - int isServiceRunning (string service_name); - string getOSName (); - string getOSVersion (); - string getOSBuild (); - string getSystemName (); + class Pandora_Wmi_Error : public Pandora_Exception { }; + + int isProcessRunning (string process_name); + int isServiceRunning (string service_name); + long getDiskFreeSpace (string disk_id); + string getOSName (); + string getOSVersion (); + string getOSBuild (); + string getSystemName (); }; #endif