Skip to content

Commit

Permalink
Run all files through clang-format
Browse files Browse the repository at this point in the history
Not all of these were actually related to changes I made, but I believe
this syncs everything.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
  • Loading branch information
mstemm committed Oct 14, 2019
1 parent 5b347e9 commit bae8d1b
Show file tree
Hide file tree
Showing 22 changed files with 524 additions and 510 deletions.
2 changes: 1 addition & 1 deletion tests/falco/test_webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST_CASE("webserver must accept invalid data", "[!hide][webserver][k8s_audit_ha
// falco_engine* engine = new falco_engine();
// falco_outputs* outputs = new falco_outputs(engine);
// std::string errstr;
// std::string input("{\"kind\": 0}");
// std::string input("{\"kind\": 0}");
//k8s_audit_handler::accept_data(engine, outputs, input, errstr);

REQUIRE(1 == 1);
Expand Down
11 changes: 5 additions & 6 deletions userspace/engine/falco_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ void falco_common::init(const char *lua_main_filename, const char *alternate_lua
string lua_main_path = lua_dir + lua_main_filename;

is.open(lua_main_path);
if (!is.is_open())
if(!is.is_open())
{
lua_dir = alternate_lua_dir;
lua_main_path = lua_dir + lua_main_filename;

is.open(lua_main_path);
if (!is.is_open())
if(!is.is_open())
{
throw falco_exception("Could not find Falco Lua entrypoint (tried " +
string(FALCO_ENGINE_LUA_DIR) + lua_main_filename + ", " +
Expand All @@ -83,7 +83,7 @@ void falco_common::init(const char *lua_main_filename, const char *alternate_lua
if(luaL_loadstring(m_ls, scriptstr.c_str()) || lua_pcall(m_ls, 0, 0, 0))
{
throw falco_exception("Failed to load script " +
lua_main_path + ": " + lua_tostring(m_ls, -1));
lua_main_path + ": " + lua_tostring(m_ls, -1));
}
}

Expand All @@ -96,7 +96,7 @@ void falco_common::add_lua_path(string &path)
lua_getglobal(m_ls, "package");

lua_getfield(m_ls, -1, "path");
string cur_path = lua_tostring(m_ls, -1 );
string cur_path = lua_tostring(m_ls, -1);
cur_path += ';';
lua_pop(m_ls, 1);

Expand All @@ -106,7 +106,7 @@ void falco_common::add_lua_path(string &path)
lua_setfield(m_ls, -2, "path");

lua_getfield(m_ls, -1, "cpath");
string cur_cpath = lua_tostring(m_ls, -1 );
string cur_cpath = lua_tostring(m_ls, -1);
cur_cpath += ';';
lua_pop(m_ls, 1);

Expand All @@ -117,4 +117,3 @@ void falco_common::add_lua_path(string &path)

lua_pop(m_ls, 1);
}

7 changes: 4 additions & 3 deletions userspace/engine/falco_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ limitations under the License.
#include <exception>
#include <mutex>

extern "C" {
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
Expand Down Expand Up @@ -49,7 +50,7 @@ struct falco_exception : std::exception
m_error_str = error_str;
}

char const* what() const throw()
char const *what() const throw()
{
return m_error_str.c_str();
}
Expand All @@ -73,7 +74,7 @@ class falco_common

void set_inspector(sinsp *inspector);

// Priority levels, as a vector of strings
// Priority levels, as a vector of strings
static std::vector<std::string> priority_names;

// Same as numbers/indices into the above vector
Expand Down
51 changes: 25 additions & 26 deletions userspace/engine/falco_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ limitations under the License.

#include "formats.h"

extern "C" {
extern "C"
{
#include "lpeg.h"
#include "lyaml.h"
}

#include "utils.h"


string lua_on_event = "on_event";
string lua_print_stats = "print_stats";

using namespace std;

nlohmann::json::json_pointer falco_engine::k8s_audit_time = "/stageTimestamp"_json_pointer;

falco_engine::falco_engine(bool seed_rng, const std::string& alternate_lua_dir)
: m_rules(NULL), m_next_ruleset_id(0),
m_min_priority(falco_common::PRIORITY_DEBUG),
m_sampling_ratio(1), m_sampling_multiplier(0),
m_replace_container_info(false)
falco_engine::falco_engine(bool seed_rng, const std::string &alternate_lua_dir):
m_rules(NULL), m_next_ruleset_id(0),
m_min_priority(falco_common::PRIORITY_DEBUG),
m_sampling_ratio(1), m_sampling_multiplier(0),
m_replace_container_info(false)
{
luaopen_lpeg(m_ls);
luaopen_yaml(m_ls);
Expand All @@ -58,7 +58,7 @@ falco_engine::falco_engine(bool seed_rng, const std::string& alternate_lua_dir)

if(seed_rng)
{
srandom((unsigned) getpid());
srandom((unsigned)getpid());
}

m_default_ruleset_id = find_ruleset_id(m_default_ruleset);
Expand All @@ -69,15 +69,15 @@ falco_engine::falco_engine(bool seed_rng, const std::string& alternate_lua_dir)

falco_engine::~falco_engine()
{
if (m_rules)
if(m_rules)
{
delete m_rules;
}
}

uint32_t falco_engine::engine_version()
{
return (uint32_t) FALCO_ENGINE_VERSION;
return (uint32_t)FALCO_ENGINE_VERSION;
}

#define DESCRIPTION_TEXT_START 16
Expand Down Expand Up @@ -153,7 +153,7 @@ void falco_engine::load_rules(const string &rules_content, bool verbose, bool al
void falco_engine::load_rules(const string &rules_content, bool verbose, bool all_events, uint64_t &required_engine_version)
{
// The engine must have been given an inspector by now.
if(! m_inspector)
if(!m_inspector)
{
throw falco_exception("No inspector provided");
}
Expand Down Expand Up @@ -194,7 +194,7 @@ void falco_engine::load_rules_file(const string &rules_filename, bool verbose, b
ifstream is;

is.open(rules_filename);
if (!is.is_open())
if(!is.is_open())
{
throw falco_exception("Could not open rules filename " +
rules_filename + " " +
Expand Down Expand Up @@ -257,7 +257,7 @@ uint64_t falco_engine::num_rules_for_ruleset(const std::string &ruleset)
uint16_t ruleset_id = find_ruleset_id(ruleset);

return m_sinsp_rules->num_rules_for_ruleset(ruleset_id) +
m_k8s_audit_rules->num_rules_for_ruleset(ruleset_id);
m_k8s_audit_rules->num_rules_for_ruleset(ruleset_id);
}

void falco_engine::evttypes_for_ruleset(std::vector<bool> &evttypes, const std::string &ruleset)
Expand Down Expand Up @@ -296,15 +296,15 @@ unique_ptr<falco_engine::rule_result> falco_engine::process_sinsp_event(sinsp_ev

if(lua_pcall(m_ls, 1, 3, 0) != 0)
{
const char* lerr = lua_tostring(m_ls, -1);
const char *lerr = lua_tostring(m_ls, -1);
string err = "Error invoking function output: " + string(lerr);
throw falco_exception(err);
}
res->evt = ev;
const char *p = lua_tostring(m_ls, -3);
const char *p = lua_tostring(m_ls, -3);
res->rule = p;
res->source = "syscall";
res->priority_num = (falco_common::priority_type) lua_tonumber(m_ls, -2);
res->priority_num = (falco_common::priority_type)lua_tonumber(m_ls, -2);
res->format = lua_tostring(m_ls, -1);
lua_pop(m_ls, 3);
}
Expand All @@ -329,7 +329,7 @@ unique_ptr<falco_engine::rule_result> falco_engine::process_k8s_audit_event(json
}

// All k8s audit events have the single tag "1".
if(!m_k8s_audit_rules->run((gen_event *) ev, 1, ruleset_id))
if(!m_k8s_audit_rules->run((gen_event *)ev, 1, ruleset_id))
{
return unique_ptr<struct rule_result>();
}
Expand All @@ -344,15 +344,15 @@ unique_ptr<falco_engine::rule_result> falco_engine::process_k8s_audit_event(json

if(lua_pcall(m_ls, 1, 3, 0) != 0)
{
const char* lerr = lua_tostring(m_ls, -1);
const char *lerr = lua_tostring(m_ls, -1);
string err = "Error invoking function output: " + string(lerr);
throw falco_exception(err);
}
res->evt = ev;
const char *p = lua_tostring(m_ls, -3);
const char *p = lua_tostring(m_ls, -3);
res->rule = p;
res->source = "k8s_audit";
res->priority_num = (falco_common::priority_type) lua_tonumber(m_ls, -2);
res->priority_num = (falco_common::priority_type)lua_tonumber(m_ls, -2);
res->format = lua_tostring(m_ls, -1);
lua_pop(m_ls, 3);
}
Expand Down Expand Up @@ -435,7 +435,7 @@ void falco_engine::print_stats()
{
if(lua_pcall(m_ls, 0, 0, 0) != 0)
{
const char* lerr = lua_tostring(m_ls, -1);
const char *lerr = lua_tostring(m_ls, -1);
string err = "Error invoking function print_stats: " + string(lerr);
throw falco_exception(err);
}
Expand All @@ -444,21 +444,20 @@ void falco_engine::print_stats()
{
throw falco_exception("No function " + lua_print_stats + " found in lua rule loader module");
}

}

void falco_engine::add_sinsp_filter(string &rule,
set<uint32_t> &evttypes,
set<uint32_t> &syscalls,
set<string> &tags,
sinsp_filter* filter)
sinsp_filter *filter)
{
m_sinsp_rules->add(rule, evttypes, syscalls, tags, filter);
}

void falco_engine::add_k8s_audit_filter(string &rule,
set<string> &tags,
json_event_filter* filter)
json_event_filter *filter)
{
// All k8s audit events have a single tag "1".
std::set<uint32_t> event_tags = {1};
Expand Down Expand Up @@ -500,8 +499,8 @@ inline bool falco_engine::should_drop_evt()
return false;
}

double coin = (random() * (1.0/RAND_MAX));
return (coin >= (1.0/(m_sampling_multiplier * m_sampling_ratio)));
double coin = (random() * (1.0 / RAND_MAX));
return (coin >= (1.0 / (m_sampling_multiplier * m_sampling_ratio)));
}

sinsp_filter_factory &falco_engine::sinsp_factory()
Expand Down
13 changes: 6 additions & 7 deletions userspace/engine/falco_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ limitations under the License.
class falco_engine : public falco_common
{
public:
falco_engine(bool seed_rng=true, const std::string& alternate_lua_dir=FALCO_ENGINE_SOURCE_LUA_DIR);
falco_engine(bool seed_rng = true, const std::string &alternate_lua_dir = FALCO_ENGINE_SOURCE_LUA_DIR);
virtual ~falco_engine();

// A given engine has a version which identifies the fields
Expand All @@ -57,7 +57,7 @@ class falco_engine : public falco_common
static uint32_t engine_version();

// Print to stdout (using printf) a description of each field supported by this engine.
void list_fields(bool names_only=false);
void list_fields(bool names_only = false);

//
// Load rules either directly or from a filename.
Expand Down Expand Up @@ -147,7 +147,8 @@ class falco_engine : public falco_common

// **Methods Related to k8s audit log events, which are
// **represented as json objects.
struct rule_result {
struct rule_result
{
gen_event *evt;
std::string rule;
std::string source;
Expand Down Expand Up @@ -188,7 +189,7 @@ class falco_engine : public falco_common
//
void add_k8s_audit_filter(std::string &rule,
std::set<std::string> &tags,
json_event_filter* filter);
json_event_filter *filter);

// **Methods Related to Sinsp Events e.g system calls
//
Expand Down Expand Up @@ -229,13 +230,12 @@ class falco_engine : public falco_common
std::set<uint32_t> &evttypes,
std::set<uint32_t> &syscalls,
std::set<std::string> &tags,
sinsp_filter* filter);
sinsp_filter *filter);

sinsp_filter_factory &sinsp_factory();
json_event_filter_factory &json_factory();

private:

static nlohmann::json::json_pointer k8s_audit_time;

//
Expand Down Expand Up @@ -285,4 +285,3 @@ class falco_engine : public falco_common
std::string m_extra;
bool m_replace_container_info;
};

Loading

0 comments on commit bae8d1b

Please sign in to comment.