]> granicus.if.org Git - icinga2/commitdiff
Use an AST node for the 'library' keyword
authorGunnar Beutner <gunnar@beutner.name>
Thu, 27 Aug 2015 12:47:31 +0000 (14:47 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Thu, 27 Aug 2015 12:50:08 +0000 (14:50 +0200)
fixes #10017

lib/config/config_parser.yy
lib/config/configcompiler.cpp
lib/config/configcompiler.hpp
lib/config/expression.cpp
lib/config/expression.hpp

index f23b377bee60108664c1b3bb16493cdc99b538ac..532a408a12abf23ebb9845a243a416bca9be704f 100644 (file)
@@ -324,13 +324,6 @@ lterm_items_inner: lterm %dprec 2
        }
        ;
 
-library: T_LIBRARY T_STRING
-       {
-               context->HandleLibrary($2);
-               free($2);
-       }
-       ;
-
 identifier: T_IDENTIFIER
        | T_STRING
        ;
@@ -436,9 +429,9 @@ combined_set_op: T_SET
        | T_SET_BINARY_OR
        ;
 
-lterm: library
+lterm: T_LIBRARY rterm
        {
-               $$ = MakeLiteral(); // ASTify this
+               $$ = new LibraryExpression($2, @$);
        }
        | rterm combined_set_op rterm
        {
index 05c4950919f9f6a0820709c151f86284eb256658..3deb93f503ed2d7c2c282f064cfc5a6f686a75dc 100644 (file)
@@ -217,16 +217,6 @@ Expression *ConfigCompiler::HandleIncludeZones(const String& tag, const String&
        return new DictExpression(expressions);
 }
 
-/**
- * Handles the library directive.
- *
- * @param library The name of the library.
- */
-void ConfigCompiler::HandleLibrary(const String& library)
-{
-       Loader::LoadExtensionLibrary(library);
-}
-
 /**
  * Compiles a stream.
  *
index 7df8e395195180a57e3091deb141ca7b0b88f3f7..63f6e0ed8475c82ae5e00851206fd39d1636de36 100644 (file)
@@ -109,7 +109,6 @@ public:
        Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
        Expression *HandleIncludeRecursive(const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo());
        Expression *HandleIncludeZones(const String& tag, const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo());
-       void HandleLibrary(const String& library);
 
        size_t ReadInput(char *buffer, size_t max_bytes);
        void *GetScanner(void) const;
index 58a65de7766e44733a313a5967c562ec4816877b..59db8449660e800c3c86a709f073e957ae25b6eb 100644 (file)
@@ -26,6 +26,7 @@
 #include "base/logger.hpp"
 #include "base/exception.hpp"
 #include "base/scriptglobal.hpp"
+#include "base/loader.hpp"
 #include <boost/foreach.hpp>
 #include <boost/exception_ptr.hpp>
 #include <boost/exception/errinfo_nested_exception.hpp>
@@ -780,3 +781,16 @@ ExpressionResult ForExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint)
        return VMOps::For(frame, m_FKVar, m_FVVar, valueres.GetValue(), m_Expression, m_DebugInfo);
 }
 
+ExpressionResult LibraryExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
+{
+       if (frame.Sandboxed)
+               BOOST_THROW_EXCEPTION(ScriptError("Loading libraries is not allowed in sandbox mode.", m_DebugInfo));
+
+       ExpressionResult libres = m_Operand->Evaluate(frame, dhint);
+       CHECK_RESULT(libres);
+
+       Loader::LoadExtensionLibrary(libres.GetValue());
+
+       return Empty;
+}
+
index 6c75e3cfcef029ed237610b58dd0db9e36ffee14..202c4bf65fda511714502f5b37c130b2ec4d6dd0 100644 (file)
@@ -288,7 +288,6 @@ protected:
        Expression *m_Operand2;
 };
 
-       
 class I2_CONFIG_API VariableExpression : public DebuggableExpression
 {
 public:
@@ -885,6 +884,17 @@ private:
        Expression *m_Expression;
 };
 
+class I2_CONFIG_API LibraryExpression : public UnaryExpression
+{
+public:
+       LibraryExpression(Expression *expression, const DebugInfo& debugInfo = DebugInfo())
+               : UnaryExpression(expression, debugInfo)
+       { }
+
+protected:
+       virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
+};
+
 }
 
 #endif /* EXPRESSION_H */