2010-07-20 Dario Rodriguez <dario.rodriguez@artica.es>

* 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.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3043 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
darode 2010-07-20 16:38:29 +00:00
parent a8a82a4cd8
commit 033040b10f
6 changed files with 129 additions and 191 deletions

View File

@ -1,3 +1,10 @@
2010-07-20 Dario Rodriguez <dario.rodriguez@artica.es>
* 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 <dario.rodriguez@artica.es>
* misc/pandora_file.cc: fixed error that caused double free.

View File

@ -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

View File

@ -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<string> ();
this->collection_list = new list<Collection> ();
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.
*

View File

@ -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_Value> *key_values;
list<string> *collection_list;
list<string>::iterator collection_it;
list<Collection> *collection_list;
list<Collection>::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 ();

View File

@ -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"<<endl;
pandoraLog ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str());
if (coll_md5 != NULL) {
delete[] coll_md5;
}
return;
}
Pandora_File::removeFile (tmp);
/* Save new md5 file */
tmp = collections_dir + collection_name;
Pandora_File::writeBinFile (tmp, coll_md5, 32);
} catch(...) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_name.c_str());
return;
}
/*Getting new zipped collection*/
try {
/*Downloading zipped collection*/
recvDataFile (collection_zip);
/*Uncompress zipped collection*/
/*NOT YET*/
} catch (...) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str());
return;
}
return;
}
/*Reading server collection md5*/
try {
recvDataFile(collection_name);
tmp = temp_dir+collection_name;
if (Pandora_File::readBinFile (tmp, &server_coll_md5) < 32) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str());
if (server_coll_md5 != NULL) {
delete[] server_coll_md5;
}
return;
}
Pandora_File::removeFile (tmp);
} catch (...) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_name.c_str());
return;
}
/*Check both md5*/
flag = 0;
for (i = 0; i < 32; i++) {
if (coll_md5[i] != server_coll_md5[i]) {
flag = 1;
break;
}
}
/*If the two md5 are equals, exit*/
if (flag == 0) {
return;
}
pandoraLog("Pandora_Windows_Service::checkCollections: Collection %s has changed", collection_name.c_str ());
/*Getting new zipped collection*/
try {
/*Downloading zipped collection*/
recvDataFile (collection_zip);
/*Uncompress zipped collection*/
/*NOT YET*/
} catch (...) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str());
return;
}
/* Save new md5 file */
tmp = collections_dir + collection_name;
Pandora_File::writeBinFile (tmp, server_coll_md5, 32);
/*Free coll_md5*/
if (coll_md5 != NULL) {
delete[] coll_md5;
}
/*Free server_coll_md5*/
if (server_coll_md5 != NULL) {
delete[] server_coll_md5;
}
conf->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 ();

View File

@ -71,6 +71,7 @@ namespace Pandora {
int unzipCollection(string zip_path, string dest_dir);
void checkCollections ();
void addCollectionsPath();
void checkConfig ();
Pandora_Windows_Service ();