mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-12 21:16:33 +00:00
Convert direct pointer refs to shared_ptr
Some objects used by falco (falco outputs, falco_formats, etc) were using raw pointer references, which isn't great. So convert use of raw pointers (originally passed from falco_init or functions it called) with shared_ptr, as they are now held in application state. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
This commit is contained in:
@@ -20,7 +20,7 @@ limitations under the License.
|
|||||||
#include "falco_engine.h"
|
#include "falco_engine.h"
|
||||||
#include "banned.h" // This raises a compilation error when certain functions are used
|
#include "banned.h" // This raises a compilation error when certain functions are used
|
||||||
|
|
||||||
falco_formats::falco_formats(falco_engine *engine,
|
falco_formats::falco_formats(std::shared_ptr<falco_engine> engine,
|
||||||
bool json_include_output_property,
|
bool json_include_output_property,
|
||||||
bool json_include_tags_property)
|
bool json_include_tags_property)
|
||||||
: m_falco_engine(engine),
|
: m_falco_engine(engine),
|
||||||
|
@@ -24,7 +24,7 @@ limitations under the License.
|
|||||||
class falco_formats
|
class falco_formats
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
falco_formats(falco_engine *engine,
|
falco_formats(std::shared_ptr<falco_engine> engine,
|
||||||
bool json_include_output_property,
|
bool json_include_output_property,
|
||||||
bool json_include_tags_property);
|
bool json_include_tags_property);
|
||||||
virtual ~falco_formats();
|
virtual ~falco_formats();
|
||||||
@@ -36,7 +36,7 @@ public:
|
|||||||
const std::string &format);
|
const std::string &format);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
falco_engine *m_falco_engine;
|
std::shared_ptr<falco_engine> m_falco_engine;
|
||||||
bool m_json_include_output_property;
|
bool m_json_include_output_property;
|
||||||
bool m_json_include_tags_property;
|
bool m_json_include_tags_property;
|
||||||
};
|
};
|
||||||
|
@@ -32,8 +32,8 @@ syscall_evt_drop_mgr::~syscall_evt_drop_mgr()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void syscall_evt_drop_mgr::init(sinsp *inspector,
|
void syscall_evt_drop_mgr::init(std::shared_ptr<sinsp> inspector,
|
||||||
falco_outputs *outputs,
|
std::shared_ptr<falco_outputs> outputs,
|
||||||
syscall_evt_drop_actions &actions,
|
syscall_evt_drop_actions &actions,
|
||||||
double threshold,
|
double threshold,
|
||||||
double rate,
|
double rate,
|
||||||
@@ -55,7 +55,7 @@ void syscall_evt_drop_mgr::init(sinsp *inspector,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syscall_evt_drop_mgr::process_event(sinsp *inspector, sinsp_evt *evt)
|
bool syscall_evt_drop_mgr::process_event(std::shared_ptr<sinsp> inspector, sinsp_evt *evt)
|
||||||
{
|
{
|
||||||
if(m_next_check_ts == 0)
|
if(m_next_check_ts == 0)
|
||||||
{
|
{
|
||||||
|
@@ -15,6 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include <sinsp.h>
|
#include <sinsp.h>
|
||||||
@@ -41,8 +42,8 @@ public:
|
|||||||
syscall_evt_drop_mgr();
|
syscall_evt_drop_mgr();
|
||||||
virtual ~syscall_evt_drop_mgr();
|
virtual ~syscall_evt_drop_mgr();
|
||||||
|
|
||||||
void init(sinsp *inspector,
|
void init(std::shared_ptr<sinsp> inspector,
|
||||||
falco_outputs *outputs,
|
std::shared_ptr<falco_outputs> outputs,
|
||||||
syscall_evt_drop_actions &actions,
|
syscall_evt_drop_actions &actions,
|
||||||
double threshold,
|
double threshold,
|
||||||
double rate,
|
double rate,
|
||||||
@@ -54,7 +55,7 @@ public:
|
|||||||
// event drops, and performing any actions.
|
// event drops, and performing any actions.
|
||||||
//
|
//
|
||||||
// Returns whether event processing should continue or stop (with an error).
|
// Returns whether event processing should continue or stop (with an error).
|
||||||
bool process_event(sinsp *inspector, sinsp_evt *evt);
|
bool process_event(std::shared_ptr<sinsp> inspector, sinsp_evt *evt);
|
||||||
|
|
||||||
void print_stats();
|
void print_stats();
|
||||||
|
|
||||||
@@ -64,8 +65,8 @@ protected:
|
|||||||
|
|
||||||
uint64_t m_num_syscall_evt_drops;
|
uint64_t m_num_syscall_evt_drops;
|
||||||
uint64_t m_num_actions;
|
uint64_t m_num_actions;
|
||||||
sinsp *m_inspector;
|
std::shared_ptr<sinsp> m_inspector;
|
||||||
falco_outputs *m_outputs;
|
std::shared_ptr<falco_outputs> m_outputs;
|
||||||
syscall_evt_drop_actions m_actions;
|
syscall_evt_drop_actions m_actions;
|
||||||
token_bucket m_bucket;
|
token_bucket m_bucket;
|
||||||
uint64_t m_next_check_ts;
|
uint64_t m_next_check_ts;
|
||||||
|
@@ -60,7 +60,7 @@ falco_outputs::~falco_outputs()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void falco_outputs::init(falco_engine *engine,
|
void falco_outputs::init(std::shared_ptr<falco_engine> engine,
|
||||||
bool json_output,
|
bool json_output,
|
||||||
bool json_include_output_property,
|
bool json_include_output_property,
|
||||||
bool json_include_tags_property,
|
bool json_include_tags_property,
|
||||||
|
@@ -39,7 +39,7 @@ public:
|
|||||||
falco_outputs();
|
falco_outputs();
|
||||||
virtual ~falco_outputs();
|
virtual ~falco_outputs();
|
||||||
|
|
||||||
void init(falco_engine *engine,
|
void init(std::shared_ptr<falco_engine> engine,
|
||||||
bool json_output,
|
bool json_output,
|
||||||
bool json_include_output_property,
|
bool json_include_output_property,
|
||||||
bool json_include_tags_property,
|
bool json_include_tags_property,
|
||||||
|
@@ -31,7 +31,7 @@ static void timer_handler (int signum)
|
|||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
StatsFileWriter::StatsFileWriter()
|
StatsFileWriter::StatsFileWriter()
|
||||||
: m_num_stats(0), m_inspector(NULL)
|
: m_num_stats(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ StatsFileWriter::~StatsFileWriter()
|
|||||||
m_output.close();
|
m_output.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StatsFileWriter::init(sinsp *inspector, string &filename, uint32_t interval_msec, string &errstr)
|
bool StatsFileWriter::init(std::shared_ptr<sinsp> inspector, string &filename, uint32_t interval_msec, string &errstr)
|
||||||
{
|
{
|
||||||
struct itimerval timer;
|
struct itimerval timer;
|
||||||
struct sigaction handler;
|
struct sigaction handler;
|
||||||
|
@@ -31,7 +31,7 @@ public:
|
|||||||
virtual ~StatsFileWriter();
|
virtual ~StatsFileWriter();
|
||||||
|
|
||||||
// Returns success as bool. On false fills in errstr.
|
// Returns success as bool. On false fills in errstr.
|
||||||
bool init(sinsp *inspector, std::string &filename,
|
bool init(std::shared_ptr<sinsp> inspector, std::string &filename,
|
||||||
uint32_t interval_msec,
|
uint32_t interval_msec,
|
||||||
string &errstr);
|
string &errstr);
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t m_num_stats;
|
uint32_t m_num_stats;
|
||||||
sinsp *m_inspector;
|
std::shared_ptr<sinsp> m_inspector;
|
||||||
std::ofstream m_output;
|
std::ofstream m_output;
|
||||||
std::string m_extra;
|
std::string m_extra;
|
||||||
scap_stats m_last_stats;
|
scap_stats m_last_stats;
|
||||||
|
@@ -25,7 +25,7 @@ limitations under the License.
|
|||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
k8s_audit_handler::k8s_audit_handler(falco_engine *engine, falco_outputs *outputs, std::size_t k8s_audit_event_source_idx):
|
k8s_audit_handler::k8s_audit_handler(std::shared_ptr<falco_engine> engine, std::shared_ptr<falco_outputs> outputs, std::size_t k8s_audit_event_source_idx):
|
||||||
m_engine(engine), m_outputs(outputs), m_k8s_audit_event_source_idx(k8s_audit_event_source_idx)
|
m_engine(engine), m_outputs(outputs), m_k8s_audit_event_source_idx(k8s_audit_event_source_idx)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -43,8 +43,8 @@ bool k8s_healthz_handler::handleGet(CivetServer *server, struct mg_connection *c
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool k8s_audit_handler::accept_data(falco_engine *engine,
|
bool k8s_audit_handler::accept_data(std::shared_ptr<falco_engine> engine,
|
||||||
falco_outputs *outputs,
|
std::shared_ptr<falco_outputs> outputs,
|
||||||
std::size_t k8s_audit_event_source_idx,
|
std::size_t k8s_audit_event_source_idx,
|
||||||
std::string &data,
|
std::string &data,
|
||||||
std::string &errstr)
|
std::string &errstr)
|
||||||
@@ -186,9 +186,9 @@ falco_webserver::~falco_webserver()
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void falco_webserver::init(falco_configuration *config,
|
void falco_webserver::init(std::shared_ptr<falco_configuration> config,
|
||||||
falco_engine *engine,
|
std::shared_ptr<falco_engine> engine,
|
||||||
falco_outputs *outputs,
|
std::shared_ptr<falco_outputs> outputs,
|
||||||
std::size_t k8s_audit_event_source_idx)
|
std::size_t k8s_audit_event_source_idx)
|
||||||
{
|
{
|
||||||
m_config = config;
|
m_config = config;
|
||||||
|
@@ -27,20 +27,20 @@ limitations under the License.
|
|||||||
class k8s_audit_handler : public CivetHandler
|
class k8s_audit_handler : public CivetHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
k8s_audit_handler(falco_engine *engine, falco_outputs *outputs, std::size_t k8s_audit_event_source_idx);
|
k8s_audit_handler(std::shared_ptr<falco_engine> engine, std::shared_ptr<falco_outputs> outputs, std::size_t k8s_audit_event_source_idx);
|
||||||
virtual ~k8s_audit_handler();
|
virtual ~k8s_audit_handler();
|
||||||
|
|
||||||
bool handleGet(CivetServer *server, struct mg_connection *conn);
|
bool handleGet(CivetServer *server, struct mg_connection *conn);
|
||||||
bool handlePost(CivetServer *server, struct mg_connection *conn);
|
bool handlePost(CivetServer *server, struct mg_connection *conn);
|
||||||
|
|
||||||
static bool accept_data(falco_engine *engine,
|
static bool accept_data(std::shared_ptr<falco_engine> engine,
|
||||||
falco_outputs *outputs,
|
std::shared_ptr<falco_outputs> outputs,
|
||||||
std::size_t k8s_audit_event_source_idx,
|
std::size_t k8s_audit_event_source_idx,
|
||||||
std::string &post_data, std::string &errstr);
|
std::string &post_data, std::string &errstr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
falco_engine *m_engine;
|
std::shared_ptr<falco_engine> m_engine;
|
||||||
falco_outputs *m_outputs;
|
std::shared_ptr<falco_outputs> m_outputs;
|
||||||
std::size_t m_k8s_audit_event_source_idx;
|
std::size_t m_k8s_audit_event_source_idx;
|
||||||
bool accept_uploaded_data(std::string &post_data, std::string &errstr);
|
bool accept_uploaded_data(std::string &post_data, std::string &errstr);
|
||||||
};
|
};
|
||||||
@@ -65,18 +65,18 @@ public:
|
|||||||
falco_webserver();
|
falco_webserver();
|
||||||
virtual ~falco_webserver();
|
virtual ~falco_webserver();
|
||||||
|
|
||||||
void init(falco_configuration *config,
|
void init(std::shared_ptr<falco_configuration> config,
|
||||||
falco_engine *engine,
|
std::shared_ptr<falco_engine> engine,
|
||||||
falco_outputs *outputs,
|
std::shared_ptr<falco_outputs> outputs,
|
||||||
std::size_t k8s_audit_event_source_idx);
|
std::size_t k8s_audit_event_source_idx);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
falco_engine *m_engine;
|
std::shared_ptr<falco_engine> m_engine;
|
||||||
falco_configuration *m_config;
|
std::shared_ptr<falco_configuration> m_config;
|
||||||
falco_outputs *m_outputs;
|
std::shared_ptr<falco_outputs> m_outputs;
|
||||||
std::size_t m_k8s_audit_event_source_idx;
|
std::size_t m_k8s_audit_event_source_idx;
|
||||||
unique_ptr<CivetServer> m_server;
|
unique_ptr<CivetServer> m_server;
|
||||||
unique_ptr<k8s_audit_handler> m_k8s_audit_handler;
|
unique_ptr<k8s_audit_handler> m_k8s_audit_handler;
|
||||||
|
Reference in New Issue
Block a user