diff --git a/pandora_agents/ChangeLog b/pandora_agents/ChangeLog index f045946166..391fa98ef7 100644 --- a/pandora_agents/ChangeLog +++ b/pandora_agents/ChangeLog @@ -1,3 +1,10 @@ +2010-07-20 Dario Rodriguez + + * win32/pandora_agent_conf.cc, pandora_agent_conf.h: Added a variable to + control if the collection is added to the PATH. + * win32/pandora_windows_service.h, pandora_windows_service.cc: Added logic + to check if the collection is added to the PATH or not. + 2010-07-16 Dario Rodriguez * misc/pandora_file.cc: fixed error that caused double free. diff --git a/pandora_agents/unix/pandora_agent_daemon b/pandora_agents/unix/pandora_agent_daemon index 11d7597478..4fe2d0c7da 100755 --- a/pandora_agents/unix/pandora_agent_daemon +++ b/pandora_agents/unix/pandora_agent_daemon @@ -22,7 +22,7 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin PANDORA_PATH=/etc/pandora -PANDORA_USER=root +PANDORA_USER=dario DAEMON=/usr/bin/pandora_agent LOGFILE=/var/log/pandora/pandora_agent.log diff --git a/pandora_agents/win32/pandora_agent_conf.cc b/pandora_agents/win32/pandora_agent_conf.cc index c60346517c..4a6acbe059 100644 --- a/pandora_agents/win32/pandora_agent_conf.cc +++ b/pandora_agents/win32/pandora_agent_conf.cc @@ -69,6 +69,7 @@ Pandora::Pandora_Agent_Conf::setFile (string filename) { ifstream file (filename.c_str ()); string buffer; unsigned int pos; + Collection *aux; if (this->key_values) delete this->key_values; @@ -76,7 +77,7 @@ Pandora::Pandora_Agent_Conf::setFile (string filename) { if (this->collection_list) delete this->collection_list; - this->collection_list = new list (); + this->collection_list = new list (); if (!file.is_open ()) { return; @@ -97,8 +98,13 @@ Pandora::Pandora_Agent_Conf::setFile (string filename) { /*Add collection to collection_list*/ /*The number 15 is the number of character of string file_collection*/ collection_name = buffer.substr(pos+15); - trimmed_str = trim (collection_name); - collection_list->push_back (trimmed_str); + + + aux = new Collection(); + + aux->name = trim (collection_name); + aux->verify = 0; + collection_list->push_back (*aux); continue; } /*Check if is a module*/ @@ -149,12 +155,36 @@ Pandora::Pandora_Agent_Conf::getValue (const string key) * */ string -Pandora::Pandora_Agent_Conf::getCurrentCollection() { +Pandora::Pandora_Agent_Conf::getCurrentCollectionName() { string aux; - aux = *collection_it; + aux = collection_it->name; return aux; } +/** + * Queries for a collection check of added to PATH. + * + * This method returns 1 if the collections is in the PATH + * + * @return 1 if the collections is added to PATH + * + */ +unsigned char +Pandora::Pandora_Agent_Conf::getCurrentCollectionVerify() { + unsigned char aux; + aux = collection_it->verify; + return aux; +} + +/** + * Set check path add field to 1. + * + */ +void +Pandora::Pandora_Agent_Conf::setCurrentCollectionVerify() { + collection_it->verify = 1; +} + /** * Set iterator pointing to the first collection of the list. * diff --git a/pandora_agents/win32/pandora_agent_conf.h b/pandora_agents/win32/pandora_agent_conf.h index 8739e8489c..3161693ad1 100644 --- a/pandora_agents/win32/pandora_agent_conf.h +++ b/pandora_agents/win32/pandora_agent_conf.h @@ -27,6 +27,11 @@ using namespace std; +typedef struct { + string name; + unsigned char verify; +}Collection; + namespace Pandora { /** * Agent main configuration class. @@ -38,8 +43,8 @@ namespace Pandora { class Pandora_Agent_Conf { private: list *key_values; - list *collection_list; - list::iterator collection_it; + list *collection_list; + list::iterator collection_it; Pandora_Agent_Conf (); public: @@ -49,7 +54,9 @@ namespace Pandora { void setFile (string filename); string getValue (const string key); - string getCurrentCollection(); + string getCurrentCollectionName(); + unsigned char getCurrentCollectionVerify(); + void setCurrentCollectionVerify(); void goFirstCollection (); void goNextCollection (); diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index 436c20e98c..d3f79e1b5c 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -123,7 +123,7 @@ Pandora_Windows_Service::pandora_init () { path = getenv ("PATH"); env = "PATH=" + path + ";" + util_dir; putenv (env.c_str ()); - + conf_file = Pandora::getPandoraInstallDir (); conf_file += "pandora_agent.conf"; @@ -654,10 +654,21 @@ Pandora_Windows_Service::checkCollections () { /*Set iterator in the firs collection*/ conf->goFirstCollection(); - + while (! conf->isLastCollection()) { - collection_name = conf->getCurrentCollection(); + collection_name = conf->getCurrentCollectionName(); + + if(! conf->getCurrentCollectionVerify() ) { + /*Add the collection directory to the path*/ + tmp = collections_dir + collection_name; + path = getenv ("PATH"); + env = "PATH=" + path + ";" + tmp; + putenv (env.c_str ()); + conf->setCurrentCollectionVerify(); + + } + collection_zip = collection_name+".zip"; collection_md5 = collection_name + ".md5"; tmp = collections_dir+collection_md5; @@ -665,11 +676,13 @@ Pandora_Windows_Service::checkCollections () { /*Reading local collection md5*/ try { if (Pandora_File::readBinFile (tmp, &coll_md5) < 32) { - pandoraLog ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str()); + pandoraDebug ("Pandora_Windows_Service::checkCollection: Invalid local md5", tmp.c_str()); if (coll_md5 != NULL) { delete[] coll_md5; } - return; + /*Go to next collection*/ + conf->goNextCollection(); + continue; } } catch (...) { /*Getting new md5*/ @@ -681,11 +694,15 @@ Pandora_Windows_Service::checkCollections () { tmp = temp_dir + collection_md5; if (Pandora_File::readBinFile (tmp, &coll_md5) < 32) { - pandoraLog ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str()); + pandoraDebug ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str()); if (coll_md5 != NULL) { delete[] coll_md5; - } - return; + } + + Pandora_File::removeFile (tmp); + /*Go to next collection*/ + conf->goNextCollection(); + continue; } Pandora_File::removeFile (tmp); @@ -695,8 +712,10 @@ Pandora_Windows_Service::checkCollections () { Pandora_File::writeBinFile (tmp, coll_md5, 32); } catch(...) { - pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_md5.c_str()); - return; + pandoraDebug ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_md5.c_str()); + /*Go to next collection*/ + conf->goNextCollection(); + continue; } /*Getting new zipped collection*/ @@ -707,17 +726,23 @@ Pandora_Windows_Service::checkCollections () { /*Uncompress zipped collection*/ tmp = temp_dir + collection_zip; dest_dir = collections_dir + collection_name; - unzipCollection(tmp,dest_dir); - - /*Add the collection directory to the path*/ - tmp = collections_dir + collection_name; - path = getenv ("PATH"); - env = "PATH=" + path + ";" + tmp; - putenv (env.c_str ()); + try { + unzipCollection(tmp,dest_dir); + } catch (...) { + Pandora_File::removeFile (tmp); + /*Go to next collection*/ + conf->goNextCollection(); + continue; + } + + Pandora_File::removeFile (tmp); } catch (...) { - pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str()); - return; + pandoraDebug ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str()); + + /*Go to next collection*/ + conf->goNextCollection(); + continue; } conf->goNextCollection(); @@ -730,17 +755,22 @@ Pandora_Windows_Service::checkCollections () { recvDataFile(collection_md5); tmp = temp_dir+collection_md5; if (Pandora_File::readBinFile (tmp, &server_coll_md5) < 32) { - pandoraLog ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str()); + pandoraDebug ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str()); if (server_coll_md5 != NULL) { delete[] server_coll_md5; } - return; + Pandora_File::removeFile (tmp); + /*Go to next collection*/ + conf->goNextCollection(); + continue; } Pandora_File::removeFile (tmp); } catch (...) { - pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_md5.c_str()); - return; + pandoraDebug ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_md5.c_str()); + /*Go to next collection*/ + conf->goNextCollection(); + continue; } /*Check both md5*/ @@ -754,10 +784,12 @@ Pandora_Windows_Service::checkCollections () { /*If the two md5 are equals, exit*/ if (flag == 0) { - return; + /*Go to next collection*/ + conf->goNextCollection(); + continue; } - pandoraLog("Pandora_Windows_Service::checkCollections: Collection %s has changed", collection_md5.c_str ()); + pandoraDebug ("Pandora_Windows_Service::checkCollections: Collection %s has changed", collection_md5.c_str ()); /*Getting new zipped collection*/ try { @@ -767,18 +799,24 @@ Pandora_Windows_Service::checkCollections () { /*Uncompress zipped collection*/ tmp = temp_dir + collection_zip; dest_dir = collections_dir + collection_name; - unzipCollection(tmp,dest_dir); - - /*Add the collection directory to the path*/ - /*Add the collection directory to the path*/ - tmp = collections_dir + collection_name; - path = getenv ("PATH"); - env = "PATH=" + path + ";" + tmp; - putenv (env.c_str ()); - + + try { + unzipCollection(tmp,dest_dir); + } catch (...) { + Pandora_File::removeFile (tmp); + /*Go to next collection*/ + conf->goNextCollection(); + continue; + } + + Pandora_File::removeFile (tmp); + } catch (...) { - pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str()); - return; + pandoraDebug ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str()); + + /*Go to next collection*/ + conf->goNextCollection(); + continue; } /* Save new md5 file */ @@ -800,151 +838,6 @@ Pandora_Windows_Service::checkCollections () { } } -void -Pandora_Windows_Service::checkCollections () { - - int flag, i; - char *coll_md5 = NULL, *server_coll_md5 = NULL; - string collection_name, collections_dir, tmp; - string collection_zip, install_dir, temp_dir; - - /*Get collections directory*/ - install_dir = Pandora::getPandoraInstallDir (); - collections_dir = install_dir+"collections\\"; - - /* Get temporal directory */ - temp_dir = conf->getValue ("temporal"); - if (temp_dir[temp_dir.length () - 1] != '\\') { - temp_dir += "\\"; - } - - /*Set iterator in the firs collection*/ - conf->goFirstCollection(); - - while (! conf->isLastCollection()) { - - collection_name = conf->getCurrentCollection(); - collection_zip = collection_name+".zip"; - collection_name = collection_name + ".md5"; - tmp = collections_dir+collection_name; - - /*Reading local collection md5*/ - try { - if (Pandora_File::readBinFile (tmp, &coll_md5) < 32) { - pandoraLog ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str()); - if (coll_md5 != NULL) { - delete[] coll_md5; - } - return; - } - } catch (...) { - /*Getting new md5*/ - try { - /*Downloading md5 file*/ - recvDataFile (collection_name); - - /*Reading new md5 file*/ - tmp = temp_dir + collection_name; - - if (Pandora_File::readBinFile (tmp, &coll_md5) < 32) { - cout<<"ERROR"<goNextCollection(); - } -} - void Pandora_Windows_Service::checkConfig () { int i, conf_size; @@ -1216,7 +1109,7 @@ Pandora_Windows_Service::pandora_run () { pandoraDebug ("Run begin"); conf = this->getConf (); - + /* Check for configuration changes */ if (getPandoraDebug () == false) { this->checkConfig (); diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index 777d80360d..4fe7807465 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -71,6 +71,7 @@ namespace Pandora { int unzipCollection(string zip_path, string dest_dir); void checkCollections (); + void addCollectionsPath(); void checkConfig (); Pandora_Windows_Service ();