2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-11-22 06:21:28 -05:00
|
|
|
|
2014-12-15 10:09:17 -05:00
|
|
|
#ifndef SCRIPTFRAME_H
|
|
|
|
|
#define SCRIPTFRAME_H
|
2014-11-22 06:21:28 -05:00
|
|
|
|
2016-08-18 09:45:14 -04:00
|
|
|
#include "base/i2-base.hpp"
|
2014-11-22 06:21:28 -05:00
|
|
|
#include "base/dictionary.hpp"
|
2025-09-22 06:31:02 -04:00
|
|
|
#include "base/namespace.hpp"
|
2025-09-22 06:25:26 -04:00
|
|
|
#include "base/scriptpermission.hpp"
|
2014-12-11 15:12:34 -05:00
|
|
|
#include <boost/thread/tss.hpp>
|
2015-03-29 16:26:07 -04:00
|
|
|
#include <stack>
|
2014-11-22 06:21:28 -05:00
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
|
{
|
|
|
|
|
|
2025-09-22 06:31:02 -04:00
|
|
|
/**
|
|
|
|
|
* A frame describing the context a section of script code is executed in.
|
|
|
|
|
*
|
|
|
|
|
* This is implemented by each new object that is constructed getting pushed on a thread_local
|
|
|
|
|
* global stack that is accessible from anywhere during script evaluation.
|
|
|
|
|
*
|
|
|
|
|
* Most properties in this frame, like local variables do not carry over to successive frames,
|
|
|
|
|
* except the `PermChecker` and `Sandboxed` members, which get propagated to enforce access
|
|
|
|
|
* control and availability of unsafe functions.
|
|
|
|
|
*/
|
2017-12-31 01:22:16 -05:00
|
|
|
struct ScriptFrame
|
2014-11-22 06:21:28 -05:00
|
|
|
{
|
|
|
|
|
Dictionary::Ptr Locals;
|
2025-09-22 06:25:26 -04:00
|
|
|
ScriptPermissionChecker::Ptr PermChecker; /* inherited by next frame */
|
2014-12-12 09:19:23 -05:00
|
|
|
Value Self;
|
2025-09-22 06:25:26 -04:00
|
|
|
bool Sandboxed; /* inherited by next frame */
|
2016-03-23 03:40:32 -04:00
|
|
|
int Depth;
|
2014-11-22 06:21:28 -05:00
|
|
|
|
2018-01-03 04:19:24 -05:00
|
|
|
ScriptFrame(bool allocLocals);
|
2018-01-04 02:54:18 -05:00
|
|
|
ScriptFrame(bool allocLocals, Value self);
|
2018-01-03 22:25:35 -05:00
|
|
|
~ScriptFrame();
|
2014-11-22 06:21:28 -05:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
void IncreaseStackDepth();
|
|
|
|
|
void DecreaseStackDepth();
|
2016-03-23 03:40:32 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
static ScriptFrame *GetCurrentFrame();
|
2014-12-11 15:12:34 -05:00
|
|
|
|
2025-09-22 06:31:02 -04:00
|
|
|
Namespace::Ptr GetGlobals();
|
|
|
|
|
|
2014-12-11 15:12:34 -05:00
|
|
|
private:
|
2025-09-22 06:31:02 -04:00
|
|
|
/**
|
|
|
|
|
* Caches a sanitized version of the global namespace for the current `ScriptFrame`.
|
|
|
|
|
*
|
|
|
|
|
* This is a value that is dependent on a ScriptFrame's `Sandboxed` and `CheckPerms`
|
|
|
|
|
* members. These are both independent of each other and while they are inherited by
|
|
|
|
|
* subsequent frames themselves, their values can be changed for new frames easily.
|
|
|
|
|
* Therefore Globals can hold a different value for each ScriptFrame and is not
|
|
|
|
|
* inherited.
|
|
|
|
|
*/
|
|
|
|
|
Namespace::Ptr Globals;
|
|
|
|
|
|
2015-03-29 16:26:07 -04:00
|
|
|
static boost::thread_specific_ptr<std::stack<ScriptFrame *> > m_ScriptFrames;
|
2014-12-11 15:12:34 -05:00
|
|
|
|
2017-12-20 07:22:38 -05:00
|
|
|
static void PushFrame(ScriptFrame *frame);
|
2018-01-03 22:25:35 -05:00
|
|
|
static ScriptFrame *PopFrame();
|
2016-08-12 05:42:59 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
void InitializeFrame();
|
2014-11-22 06:21:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-12 09:33:02 -05:00
|
|
|
#endif /* SCRIPTFRAME_H */
|