Implement validator for LivestatusListener::socket_type.

Fixes #4751
This commit is contained in:
Gunnar Beutner 2013-09-30 10:07:49 +02:00
parent b70f3e9048
commit f90d88aad5
3 changed files with 17 additions and 0 deletions

View File

@ -18,6 +18,7 @@
******************************************************************************/
#include "livestatus/listener.h"
#include "config/configcompilercontext.h"
#include "base/objectlock.h"
#include "base/dynamictype.h"
#include "base/logger_fwd.h"
@ -26,6 +27,7 @@
#include "base/unixsocket.h"
#include "base/networkstream.h"
#include "base/application.h"
#include "base/scriptfunction.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/exception/diagnostic_information.hpp>
@ -34,6 +36,7 @@ using namespace icinga;
using namespace livestatus;
REGISTER_TYPE(LivestatusListener);
REGISTER_SCRIPTFUNCTION(ValidateSocketType, &LivestatusListener::ValidateSocketType);
static int l_ClientsConnected = 0;
static int l_Connections = 0;
@ -176,6 +179,16 @@ void LivestatusListener::ClientThreadProc(const Socket::Ptr& client)
}
}
void LivestatusListener::ValidateSocketType(const String& location, const Dictionary::Ptr& attrs)
{
Value socket_type = attrs->Get("socket_type");
if (!socket_type.IsEmpty() && socket_type != "unix" && socket_type != "tcp") {
ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
location + ": Socket type '" + socket_type + "' is invalid.");
}
}
void LivestatusListener::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
DynamicObject::InternalSerialize(bag, attributeTypes);

View File

@ -46,6 +46,8 @@ public:
static int GetClientsConnected(void);
static int GetConnections(void);
static void ValidateSocketType(const String& location, const Dictionary::Ptr& attrs);
protected:
virtual void Start(void);

View File

@ -18,6 +18,8 @@
******************************************************************************/
type LivestatusListener {
%validator "ValidateSocketType",
%attribute string "socket_type",
%attribute string "socket_path",