diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index ff0d204ce9..cf3dd0b357 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,13 @@ +2006-12-04 Esteban Sanchez + + * misc/pandora_file.[cc,h]: Added a function to check the existance of + a file. + + * pandora_ssh_tesct.cc: Check if private and public key files exists + when doing the test. + + * bin/PandoraAgent.exe: Updated to new commit. + 2006-12-01 Raul Mateos * installer/Pandora_FMS_Windows_Agent-1.2-Setup.exe: Updated with last diff --git a/pandora_agents/win32/misc/pandora_file.cc b/pandora_agents/win32/misc/pandora_file.cc index c2fca02bb6..5c3987836b 100644 --- a/pandora_agents/win32/misc/pandora_file.cc +++ b/pandora_agents/win32/misc/pandora_file.cc @@ -25,6 +25,26 @@ using namespace std; +/** + * Checks if a file exists. + * + * @param filepath Path of the file to check. + * + * @retval True if the file exists. + **/ +bool +Pandora_File::fileExists (const string filepath) { + string line, result; + ifstream myfile (filepath.c_str ()); + + if (! myfile.is_open ()) { + return false; + } + + myfile.close(); + return true; +} + /** * Reads a file and returns its content. * diff --git a/pandora_agents/win32/misc/pandora_file.h b/pandora_agents/win32/misc/pandora_file.h index a2a6afdb74..528ff1835a 100644 --- a/pandora_agents/win32/misc/pandora_file.h +++ b/pandora_agents/win32/misc/pandora_file.h @@ -50,7 +50,8 @@ namespace Pandora_File { class Delete_Error : Pandora_File::File_Exception { }; - string readFile (const string filename); + bool fileExists (const string filename); + string readFile (const string filename); void removeFile (const string filename); void writeFile (const string filename, const string data); } diff --git a/pandora_agents/win32/ssh/pandora_ssh_test.cc b/pandora_agents/win32/ssh/pandora_ssh_test.cc index 886cced169..a3d3b23dfc 100644 --- a/pandora_agents/win32/ssh/pandora_ssh_test.cc +++ b/pandora_agents/win32/ssh/pandora_ssh_test.cc @@ -75,16 +75,26 @@ Pandora_SSH_Test::test () { TiXmlDeclaration *decl; bool saved; - remote_host = this->conf->getValue ("server_ip"); - pubkey_file = Pandora::getPandoraInstallDir (); pubkey_file += "key\\id_dsa.pub"; + if (! Pandora_File::fileExists (pubkey_file)) { + cout << "Public key file " << pubkey_file << " not found." + << endl; + return; + } + cout << "Public key file " << pubkey_file << " exists." << endl; + privkey_file = Pandora::getPandoraInstallDir (); privkey_file += "key\\id_dsa"; - - cout << "Public key file: " << pubkey_file << endl; - cout << "Private key file: " << privkey_file << endl; - cout << "Connecting with " << remote_host << "..." << endl; + if (! Pandora_File::fileExists (privkey_file)) { + cout << "Private key file " << privkey_file << " not found." + << endl; + return; + } + cout << "Private key file: " << privkey_file << " exists." << endl; + + remote_host = this->conf->getValue ("server_ip"); + cout << "Connecting with " << remote_host << "." << endl; try { this->ssh_client->connectWithPublicKey (remote_host.c_str (), 22,