2010-11-12 Ramon Novoa <rnovoa@artica.es>

* windows/pandora_wmi.cc: isServiceRunning returns -1 for module
	  states other than "Running" and "Stopped".

	* modules/pandora_module_logevent.cc,
	  modules/pandora_module_logevent.h: Return a non empty string if
	  the event description can not be read. Save the event id as an
	  unsigned long int to avoid overflows.

	* modules/pandora_module_service.cc,
	  modules/pandora_module_service.h: Aesthetic fix. Removed carriage
	  returns.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3580 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2010-11-12 13:41:24 +00:00
parent 4366580093
commit cafe7ef8e5
6 changed files with 142 additions and 116 deletions

View File

@ -1,3 +1,17 @@
2010-11-12 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc: isServiceRunning returns -1 for module
states other than "Running" and "Stopped".
* modules/pandora_module_logevent.cc,
modules/pandora_module_logevent.h: Return a non empty string if
the event description can not be read. Save the event id as an
unsigned long int to avoid overflows.
* modules/pandora_module_service.cc,
modules/pandora_module_service.h: Aesthetic fix. Removed carriage
returns.
2010-11-08 Ramon Novoa <rnovoa@artica.es> 2010-11-08 Ramon Novoa <rnovoa@artica.es>
* modules/pandora_module_logevent.cc, * modules/pandora_module_logevent.cc,

View File

@ -59,7 +59,7 @@ Pandora_Module_Logevent::Pandora_Module_Logevent (string name, string source, st
this->type = -1; this->type = -1;
} }
this->id = atoi (id.c_str ()); this->id = strtoul (id.c_str (), NULL, 0);
this->source = source; this->source = source;
this->pattern = pattern; this->pattern = pattern;
this->application = application; this->application = application;
@ -224,7 +224,10 @@ Pandora_Module_Logevent::getLogEvents (list<string> &event_list, unsigned char d
// Retrieve the event description // Retrieve the event description
getEventDescription (pevlr, description); getEventDescription (pevlr, description);
if (description == "") {
strcpy (description, "N/A");
}
// Filter the event // Filter the event
if (filterEvent (pevlr, description) == 0) { if (filterEvent (pevlr, description) == 0) {
@ -310,6 +313,7 @@ Pandora_Module_Logevent::getEventDescription (PEVENTLOGRECORD pevlr, char *messa
module = LoadLibraryEx (exe_file_path, 0, DONT_RESOLVE_DLL_REFERENCES); module = LoadLibraryEx (exe_file_path, 0, DONT_RESOLVE_DLL_REFERENCES);
if(module == NULL) { if(module == NULL) {
RegCloseKey(hk); RegCloseKey(hk);
pandoraDebug("LoadLibraryEx error %d. Exe file path %s.", GetLastError(), exe_file_path);
return; return;
} }
@ -331,8 +335,8 @@ Pandora_Module_Logevent::getEventDescription (PEVENTLOGRECORD pevlr, char *messa
} }
} }
} }
strcpy(strings[i], (TCHAR *)pevlr + offset); strcpy(strings[i], (TCHAR *)pevlr + offset);
offset += len + 1; offset += len + 1;
} }
// Get the description // Get the description

View File

@ -39,13 +39,13 @@ namespace Pandora_Modules {
class Pandora_Module_Logevent : public Pandora_Module { class Pandora_Module_Logevent : public Pandora_Module {
private: private:
int id; unsigned long id;
int type; int type;
string source; string source;
string application; string application;
string pattern; string pattern;
HANDLE log_event; HANDLE log_event;
HANDLE messages_dll; HANDLE messages_dll;
HANDLE openLogEvent (); HANDLE openLogEvent ();
void closeLogEvent (); void closeLogEvent ();

View File

@ -1,54 +1,54 @@
/* Pandora service module. These modules check if a service is running in the /* Pandora service module. These modules check if a service is running in the
system. system.
Copyright (C) 2006 Artica ST. Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez. Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option) the Free Software Foundation; either version 2, or (at your option)
any later version. any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "pandora_module_service.h" #include "pandora_module_service.h"
#include "pandora_module_list.h" #include "pandora_module_list.h"
#include "../windows/pandora_wmi.h" #include "../windows/pandora_wmi.h"
#include "../pandora_strutils.h" #include "../pandora_strutils.h"
#include "../pandora_windows_service.h" #include "../pandora_windows_service.h"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
using namespace Pandora; using namespace Pandora;
using namespace Pandora_Modules; using namespace Pandora_Modules;
using namespace Pandora_Strutils; using namespace Pandora_Strutils;
/** /**
* Creates a Pandora_Module_Service object. * Creates a Pandora_Module_Service object.
* *
* @param name Module name. * @param name Module name.
* @param service_name Service internal name to check. * @param service_name Service internal name to check.
*/ */
Pandora_Module_Service::Pandora_Module_Service (string name, string service_name) Pandora_Module_Service::Pandora_Module_Service (string name, string service_name)
: Pandora_Module (name) { : Pandora_Module (name) {
this->service_name = service_name; this->service_name = service_name;
transform (service_name.begin (), service_name.end (), transform (service_name.begin (), service_name.end (),
this->service_name.begin (), (int (*) (int)) tolower); this->service_name.begin (), (int (*) (int)) tolower);
this->setKind (module_service_str); this->setKind (module_service_str);
this->thread = 0; this->thread = 0;
this->watchdog = false; this->watchdog = false;
} }
string string
Pandora_Module_Service::getServiceName () const { Pandora_Module_Service::getServiceName () const {
@ -130,7 +130,7 @@ async_run (Pandora_Module_Service *module) {
if (service_event) { if (service_event) {
res = Pandora_Wmi::isServiceRunning (module->getServiceName ()); res = Pandora_Wmi::isServiceRunning (module->getServiceName ());
str_res = inttostr (res); str_res = inttostr (res);
if (str_res != prev_res) { if (str_res != prev_res) {
module->setOutput (str_res); module->setOutput (str_res);
prev_res = str_res; prev_res = str_res;
Pandora_Windows_Service::getInstance ()->sendXml (modules); Pandora_Windows_Service::getInstance ()->sendXml (modules);
@ -145,18 +145,18 @@ async_run (Pandora_Module_Service *module) {
} }
delete modules; delete modules;
} }
void void
Pandora_Module_Service::run () { Pandora_Module_Service::run () {
int res; int res;
try { try {
Pandora_Module::run (); Pandora_Module::run ();
} catch (Interval_Not_Fulfilled e) { } catch (Interval_Not_Fulfilled e) {
return; return;
} }
res = Pandora_Wmi::isServiceRunning (this->service_name); res = Pandora_Wmi::isServiceRunning (this->service_name);
this->setOutput (inttostr (res)); this->setOutput (inttostr (res));
/* Launch thread if it's asynchronous */ /* Launch thread if it's asynchronous */
@ -165,5 +165,5 @@ Pandora_Module_Service::run () {
(LPTHREAD_START_ROUTINE) async_run, (LPTHREAD_START_ROUTINE) async_run,
this, 0, NULL); this, 0, NULL);
this->async = false; this->async = false;
} }
} }

View File

@ -1,48 +1,48 @@
/* Pandora service module. These modules check if a service is running in the /* Pandora service module. These modules check if a service is running in the
system. system.
Copyright (C) 2006 Artica ST. Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez. Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option) the Free Software Foundation; either version 2, or (at your option)
any later version. any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#ifndef __PANDORA_MODULE_SERVICE_H__ #ifndef __PANDORA_MODULE_SERVICE_H__
#define __PANDORA_MODULE_SERVICE_H__ #define __PANDORA_MODULE_SERVICE_H__
#include "pandora_module.h" #include "pandora_module.h"
namespace Pandora_Modules { namespace Pandora_Modules {
/** /**
* Module to check that a windows service is running on the * Module to check that a windows service is running on the
* system. * system.
*/ */
class Pandora_Module_Service : public Pandora_Module { class Pandora_Module_Service : public Pandora_Module {
private: private:
string service_name; string service_name;
HANDLE thread; HANDLE thread;
bool watchdog; bool watchdog;
public: public:
Pandora_Module_Service (string name, string service_name); Pandora_Module_Service (string name, string service_name);
void run (); void run ();
string getServiceName () const; string getServiceName () const;
bool isWatchdog () const; bool isWatchdog () const;
void setWatchdog (bool watchdog); void setWatchdog (bool watchdog);
}; };
} }
#endif #endif

View File

@ -113,7 +113,15 @@ Pandora_Wmi::isServiceRunning (string service_name) {
dhGetValue (L"%s", &state, quickfix, dhGetValue (L"%s", &state, quickfix,
L".State"); L".State");
str_state = state; str_state = state;
retval = (str_state == "Running") ? 1 : 0; if (str_state == "Running") {
retval = 1;
}
else if (str_state == "Stopped") {
retval = 0;
}
else {
retval = -1;
}
dhFreeString (state); dhFreeString (state);
return retval; return retval;