From f90d88aad5a53a582c192cf02435a70f025aede0 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 30 Sep 2013 10:07:49 +0200 Subject: [PATCH] Implement validator for LivestatusListener::socket_type. Fixes #4751 --- components/livestatus/listener.cpp | 13 +++++++++++++ components/livestatus/listener.h | 2 ++ components/livestatus/livestatus-type.conf | 2 ++ 3 files changed, 17 insertions(+) diff --git a/components/livestatus/listener.cpp b/components/livestatus/listener.cpp index f829fa696..88473ad7b 100644 --- a/components/livestatus/listener.cpp +++ b/components/livestatus/listener.cpp @@ -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 #include @@ -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); diff --git a/components/livestatus/listener.h b/components/livestatus/listener.h index 9fd86b3af..a181c4f3e 100644 --- a/components/livestatus/listener.h +++ b/components/livestatus/listener.h @@ -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); diff --git a/components/livestatus/livestatus-type.conf b/components/livestatus/livestatus-type.conf index 6695a70ae..9c7421cbf 100644 --- a/components/livestatus/livestatus-type.conf +++ b/components/livestatus/livestatus-type.conf @@ -18,6 +18,8 @@ ******************************************************************************/ type LivestatusListener { + %validator "ValidateSocketType", + %attribute string "socket_type", %attribute string "socket_path", -- 2.40.0