2008-11-28 11:51:03 +01:00
|
|
|
/* Pandora Windows agent main file.
|
|
|
|
|
2020-11-27 13:52:35 +01:00
|
|
|
Copyright (c) 2006-2021 Artica ST.
|
2008-11-28 11:51:03 +01:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2011-07-14 10:58:18 +02:00
|
|
|
#include <cstdlib>
|
2010-04-21 Ramon Novoa <rnovoa@artica.es>
* main.cc: Updated headers after tinyxml removal.
* modules/pandora_module_list.cc,
modules/pandora_module_factory.cc: Added support for plugin modules.
* modules/pandora_module_exec.cc, modules/pandora_module.h,
modules/pandora_module.cc: Added the module_timeout configuration
token and replaced tinyxml related code.
* bin/pandora_agent.conf: Added a sample plugin module. Added the
group configuration token (was missing).
* modules/pandora_module_plugin.cc,
modules/pandora_module_plugin.h: Added to repository. Plugin module.
* bin/util/df.vbs, bin/util/ps.vbs: Added to repository. Sample
VBScript plugins.
* pandora_windows_service.cc, pandora_windows_service.h,
modules/pandora_module_inventory.cc, ssh/pandora_ssh_test.cc,
ftp/pandora_ftp_test.cc, modules/pandora_module_inventory.h: Replaced
tinyxml related code.
* tinyxml, tinyxml/tinyxmlerror.cpp, tinyxml/tinystr.h,
tinyxml/tinyxmlparser.cpp, tinyxml/tinyxml.cpp,
tinyxml/tinyxml.h, tinyxml/tinystr.cpp: Removed from repository. No
longer used.
* installer/pandora.mpi, pandora.cc: Updated build to RC1.
* Makefile.am: Updated sources. Removed tinyxml and added the plugin
module.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2584 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-21 22:00:31 +02:00
|
|
|
#include <iostream>
|
2008-11-28 11:51:03 +01:00
|
|
|
#include "pandora.h"
|
|
|
|
#include "pandora_windows_service.h"
|
|
|
|
#include "ssh/pandora_ssh_test.h"
|
|
|
|
#include "ftp/pandora_ftp_test.h"
|
2009-09-22 Ramon Novoa <rnovoa@artica.es>
* debug_new.h, fast_mutex.h,
debug_new.cpp, static_assert.h: Added to repository. Wu Yongwei's
memory leak detection tool (part of Nvwa). Only compiled when
debugging is enabled.
* bin/util/tentacle_client.exe: Added to repository. Tentacle client
needed to build the installer.
* installer/pandora_2.0.mpi: moved to installer/pandora.mpi. Updated.
The installer can now be built directly from the installer
subdirectory.
* configure.in, Makefile.am, autogen.sh: Created a proper
configure.in and Makefile.am. The agent can now be cross-compiled
from Linux :-D
* bin/pandora_agent.conf: Fixed. A local configuration had been
uploaded.
* pandora_windows_service.h,pandora_windows_service.cc,
udp_server/udp_server.cc, udp_server/udp_server.h: Properly shutdown
the UDP server.
* modules/pandora_module_regexp.cc,
modules/pandora_module_inventory.cc,
modules/pandora_module_factory.cc,
modules/pandora_module.cc, pandora_strutils.cc,
pandora.h, pandora.cc: Fixed a couple of memory leaks. Small changes
to avoid compile warnings when cross-compiling from Linux.
* windows_service.cc: Removed the interactive service flag to avoid
'black windows'.
* main.cc: Include the memory leak detection tool if debugging is
enabled.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1966 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-09-22 13:48:25 +02:00
|
|
|
#ifdef __DEBUG__
|
|
|
|
#include "debug_new.h"
|
|
|
|
#endif
|
2008-11-28 11:51:03 +01:00
|
|
|
|
2011-07-14 10:58:18 +02:00
|
|
|
using namespace std;
|
|
|
|
using namespace Pandora;
|
|
|
|
|
2008-11-28 11:51:03 +01:00
|
|
|
#define PATH_SIZE _MAX_PATH+1
|
|
|
|
#define SERVICE_INSTALL_CMDLINE_PARAM "--install"
|
|
|
|
#define SERVICE_UNINSTALL_CMDLINE_PARAM "--uninstall"
|
|
|
|
#define SSH_TEST_CMDLINE_PARAM "--test-ssh"
|
|
|
|
#define FTP_TEST_CMDLINE_PARAM "--test-ftp"
|
|
|
|
#define HELP_CMDLINE_PARAM "--help"
|
2009-02-09 11:26:07 +01:00
|
|
|
#define PROCESS_CMDLINE_PARAM "--process"
|
2008-11-28 11:51:03 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[]) {
|
|
|
|
Pandora_Windows_Service *service;
|
|
|
|
char buffer[PATH_SIZE];
|
|
|
|
string aux;
|
2014-06-20 13:16:42 +02:00
|
|
|
int pos;
|
2009-02-09 11:26:07 +01:00
|
|
|
bool process = false;
|
2011-07-14 10:58:18 +02:00
|
|
|
string home;
|
2013-11-14 16:56:04 +01:00
|
|
|
string binary_path;
|
2008-11-28 11:51:03 +01:00
|
|
|
|
|
|
|
service = Pandora_Windows_Service::getInstance ();
|
|
|
|
service->setValues (Pandora::name, Pandora::display_name,
|
|
|
|
Pandora::description);
|
|
|
|
service->start ();
|
|
|
|
|
|
|
|
GetModuleFileName (NULL, buffer, MAX_PATH);
|
|
|
|
aux = buffer;
|
|
|
|
Pandora::setPandoraInstallPath (aux);
|
|
|
|
pos = aux.rfind ("\\");
|
|
|
|
aux.erase (pos + 1);
|
|
|
|
Pandora::setPandoraInstallDir (aux);
|
|
|
|
|
2011-07-14 10:58:18 +02:00
|
|
|
home = "PANDORA_HOME=";
|
|
|
|
home += Pandora::getPandoraInstallDir ();
|
|
|
|
putenv(home.c_str());
|
|
|
|
|
2008-11-28 11:51:03 +01:00
|
|
|
/* Check the parameters */
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (_stricmp(argv[i], SERVICE_INSTALL_CMDLINE_PARAM) == 0) {
|
|
|
|
/* Install parameter */
|
2013-11-14 16:56:04 +01:00
|
|
|
|
|
|
|
/* Quote the path to the service binary to avoid exploits */
|
|
|
|
binary_path = "\"";
|
|
|
|
binary_path += Pandora::getPandoraInstallPath ().c_str ();
|
|
|
|
binary_path += "\"";
|
|
|
|
|
|
|
|
service->install (binary_path.c_str());
|
2008-11-28 11:51:03 +01:00
|
|
|
|
|
|
|
delete service;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else if (_stricmp(argv[i], SERVICE_UNINSTALL_CMDLINE_PARAM) == 0) {
|
|
|
|
/* Uninstall parameter */
|
|
|
|
service->uninstall ();
|
|
|
|
|
|
|
|
delete service;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else if (_stricmp(argv[i], SSH_TEST_CMDLINE_PARAM) == 0) {
|
|
|
|
/* SSH test parameter */
|
|
|
|
SSH::Pandora_SSH_Test ssh_test;
|
|
|
|
|
|
|
|
delete service;
|
|
|
|
|
|
|
|
try {
|
|
|
|
ssh_test.test ();
|
|
|
|
} catch (Pandora_Exception e) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else if (_stricmp(argv[i], FTP_TEST_CMDLINE_PARAM) == 0) {
|
|
|
|
/* SSH test parameter */
|
|
|
|
FTP::Pandora_FTP_Test ftp_test;
|
|
|
|
|
|
|
|
delete service;
|
|
|
|
|
|
|
|
try {
|
|
|
|
ftp_test.test ();
|
|
|
|
} catch (Pandora_Exception e) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-02-09 11:26:07 +01:00
|
|
|
} else if (_stricmp(argv[i], HELP_CMDLINE_PARAM) == 0) {
|
2008-11-28 11:51:03 +01:00
|
|
|
/* Help parameter */
|
2021-05-10 17:58:17 +02:00
|
|
|
cout << "Pandora agent for Windows ";
|
|
|
|
cout << "v" << getPandoraAgentVersion () << endl << endl;
|
2008-11-28 11:51:03 +01:00
|
|
|
cout << "Usage: " << argv[0] << " [OPTION]" << endl << endl;
|
|
|
|
cout << "Available options are:" << endl;
|
|
|
|
cout << "\t" << SERVICE_INSTALL_CMDLINE_PARAM;
|
2009-02-12 12:08:26 +01:00
|
|
|
cout << ": Install the Pandora Agent service." << endl;
|
2008-11-28 11:51:03 +01:00
|
|
|
cout << "\t" << SERVICE_UNINSTALL_CMDLINE_PARAM;
|
|
|
|
cout << ": Uninstall the Pandora Agent service." << endl;
|
|
|
|
cout << "\t" << SSH_TEST_CMDLINE_PARAM;
|
2009-02-12 12:08:26 +01:00
|
|
|
cout << ": Test the SSH Pandora Agent configuration." << endl;
|
2008-11-28 11:51:03 +01:00
|
|
|
cout << "\t" << FTP_TEST_CMDLINE_PARAM;
|
2009-02-12 12:08:26 +01:00
|
|
|
cout << ": Test the FTP Pandora Agent configuration." << endl;
|
|
|
|
cout << "\t" << PROCESS_CMDLINE_PARAM;
|
|
|
|
cout << ": Run the Pandora Agent as a user process instead of a service." << endl;
|
2008-11-28 11:51:03 +01:00
|
|
|
|
|
|
|
return 0;
|
2009-02-09 11:26:07 +01:00
|
|
|
} else if (_stricmp(argv[i], PROCESS_CMDLINE_PARAM) == 0) {
|
|
|
|
process = true;
|
2008-11-28 11:51:03 +01:00
|
|
|
} else {
|
|
|
|
/* No parameter recognized */
|
|
|
|
cout << "Pandora agent for Windows. ";
|
|
|
|
cout << "Version " << getPandoraAgentVersion () << endl;
|
|
|
|
cout << "Usage: " << argv[0] << " [" << SERVICE_INSTALL_CMDLINE_PARAM;
|
|
|
|
cout << "] [" << SERVICE_UNINSTALL_CMDLINE_PARAM;
|
|
|
|
cout << "] [" << SSH_TEST_CMDLINE_PARAM;
|
2009-02-12 12:08:26 +01:00
|
|
|
cout << "] [" << FTP_TEST_CMDLINE_PARAM;
|
|
|
|
cout << "] [" << PROCESS_CMDLINE_PARAM << "]";
|
2008-11-28 11:51:03 +01:00
|
|
|
cout << endl << endl;
|
|
|
|
cout << "Run " << argv[0] << " with " << HELP_CMDLINE_PARAM;
|
|
|
|
cout << " parameter for more info." << endl;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2009-09-23 09:04:04 +02:00
|
|
|
|
|
|
|
#ifdef __DEBUG__
|
|
|
|
service->pandora_init ();
|
|
|
|
service->pandora_run ();
|
|
|
|
#else
|
2009-02-09 11:26:07 +01:00
|
|
|
if (process) {
|
|
|
|
cout << "Pandora agent is now running" << endl;
|
|
|
|
service->pandora_init ();
|
|
|
|
while (1) {
|
|
|
|
service->pandora_run ();
|
2009-10-06 12:55:59 +02:00
|
|
|
Sleep (service->interval);
|
2009-02-09 11:26:07 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
service->run ();
|
|
|
|
}
|
2009-09-23 09:04:04 +02:00
|
|
|
#endif
|
2009-02-09 11:26:07 +01:00
|
|
|
|
2008-11-28 11:51:03 +01:00
|
|
|
delete service;
|
2009-02-09 11:26:07 +01:00
|
|
|
|
2008-11-28 11:51:03 +01:00
|
|
|
return 0;
|
|
|
|
}
|