mirror of
https://github.com/falcosecurity/falco.git
synced 2025-06-30 16:42:14 +00:00
Add a verbose flag.
Add a verbose flag -v which implies printing additional info. This is passed down to lua during load_rules and sets the per-module verbose value for the compiler and parser modules. Later commits will use this to print additional info when loading rules.
This commit is contained in:
parent
e66b3a817e
commit
5955c00f9c
@ -55,6 +55,7 @@ static void usage()
|
|||||||
" -r <rules_file> Rules file (defaults to value set in configuration file, or /etc/falco_rules.yaml).\n"
|
" -r <rules_file> Rules file (defaults to value set in configuration file, or /etc/falco_rules.yaml).\n"
|
||||||
" -L Show the name and description of all rules and exit.\n"
|
" -L Show the name and description of all rules and exit.\n"
|
||||||
" -l <rule> Show the name and description of the rule with name <rule> and exit.\n"
|
" -l <rule> Show the name and description of the rule with name <rule> and exit.\n"
|
||||||
|
" -v Verbose output.\n"
|
||||||
"\n"
|
"\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -253,6 +254,7 @@ int falco_init(int argc, char **argv)
|
|||||||
string pidfilename = "/var/run/falco.pid";
|
string pidfilename = "/var/run/falco.pid";
|
||||||
bool describe_all_rules = false;
|
bool describe_all_rules = false;
|
||||||
string describe_rule = "";
|
string describe_rule = "";
|
||||||
|
bool verbose = false;
|
||||||
|
|
||||||
static struct option long_options[] =
|
static struct option long_options[] =
|
||||||
{
|
{
|
||||||
@ -272,7 +274,7 @@ int falco_init(int argc, char **argv)
|
|||||||
// Parse the args
|
// Parse the args
|
||||||
//
|
//
|
||||||
while((op = getopt_long(argc, argv,
|
while((op = getopt_long(argc, argv,
|
||||||
"c:ho:e:r:dp:Ll:",
|
"c:ho:e:r:dp:Ll:v",
|
||||||
long_options, &long_index)) != -1)
|
long_options, &long_index)) != -1)
|
||||||
{
|
{
|
||||||
switch(op)
|
switch(op)
|
||||||
@ -301,6 +303,9 @@ int falco_init(int argc, char **argv)
|
|||||||
case 'L':
|
case 'L':
|
||||||
describe_all_rules = true;
|
describe_all_rules = true;
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
verbose = true;
|
||||||
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
describe_rule = optarg;
|
describe_rule = optarg;
|
||||||
break;
|
break;
|
||||||
@ -397,7 +402,7 @@ int falco_init(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
inspector->set_drop_event_flags(EF_DROP_FALCO);
|
inspector->set_drop_event_flags(EF_DROP_FALCO);
|
||||||
rules->load_rules(config.m_rules_filename);
|
rules->load_rules(config.m_rules_filename, verbose);
|
||||||
inspector->set_filter(rules->get_filter());
|
inspector->set_filter(rules->get_filter());
|
||||||
falco_logger::log(LOG_INFO, "Parsed rules from file " + config.m_rules_filename + "\n");
|
falco_logger::log(LOG_INFO, "Parsed rules from file " + config.m_rules_filename + "\n");
|
||||||
|
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
local parser = require("parser")
|
local parser = require("parser")
|
||||||
local compiler = {}
|
local compiler = {}
|
||||||
|
|
||||||
|
compiler.verbose = false
|
||||||
|
|
||||||
|
function compiler.set_verbose(verbose)
|
||||||
|
compiler.verbose = verbose
|
||||||
|
parser.set_verbose(verbose)
|
||||||
|
end
|
||||||
|
|
||||||
function map(f, arr)
|
function map(f, arr)
|
||||||
local res = {}
|
local res = {}
|
||||||
for i,v in ipairs(arr) do
|
for i,v in ipairs(arr) do
|
||||||
|
@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
local parser = {}
|
local parser = {}
|
||||||
|
|
||||||
|
parser.verbose = false
|
||||||
|
|
||||||
|
function parser.set_verbose(verbose)
|
||||||
|
parser.verbose = verbose
|
||||||
|
end
|
||||||
|
|
||||||
local lpeg = require "lpeg"
|
local lpeg = require "lpeg"
|
||||||
|
|
||||||
lpeg.locale(lpeg)
|
lpeg.locale(lpeg)
|
||||||
|
@ -117,7 +117,9 @@ end
|
|||||||
-- to a rule.
|
-- to a rule.
|
||||||
local state = {macros={}, lists={}, filter_ast=nil, rules_by_name={}, n_rules=0, rules_by_idx={}}
|
local state = {macros={}, lists={}, filter_ast=nil, rules_by_name={}, n_rules=0, rules_by_idx={}}
|
||||||
|
|
||||||
function load_rules(filename)
|
function load_rules(filename, verbose)
|
||||||
|
|
||||||
|
compiler.set_verbose(verbose)
|
||||||
|
|
||||||
local f = assert(io.open(filename, "r"))
|
local f = assert(io.open(filename, "r"))
|
||||||
local s = f:read("*all")
|
local s = f:read("*all")
|
||||||
|
@ -40,7 +40,7 @@ void falco_rules::load_compiler(string lua_main_filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void falco_rules::load_rules(string rules_filename)
|
void falco_rules::load_rules(string rules_filename, bool verbose)
|
||||||
{
|
{
|
||||||
lua_getglobal(m_ls, m_lua_load_rules.c_str());
|
lua_getglobal(m_ls, m_lua_load_rules.c_str());
|
||||||
if(lua_isfunction(m_ls, -1))
|
if(lua_isfunction(m_ls, -1))
|
||||||
@ -82,7 +82,8 @@ void falco_rules::load_rules(string rules_filename)
|
|||||||
lua_setglobal(m_ls, m_lua_ignored_syscalls.c_str());
|
lua_setglobal(m_ls, m_lua_ignored_syscalls.c_str());
|
||||||
|
|
||||||
lua_pushstring(m_ls, rules_filename.c_str());
|
lua_pushstring(m_ls, rules_filename.c_str());
|
||||||
if(lua_pcall(m_ls, 1, 0, 0) != 0)
|
lua_pushboolean(m_ls, (verbose ? 1 : 0));
|
||||||
|
if(lua_pcall(m_ls, 2, 0, 0) != 0)
|
||||||
{
|
{
|
||||||
const char* lerr = lua_tostring(m_ls, -1);
|
const char* lerr = lua_tostring(m_ls, -1);
|
||||||
string err = "Error loading rules:" + string(lerr);
|
string err = "Error loading rules:" + string(lerr);
|
||||||
|
@ -8,7 +8,7 @@ class falco_rules
|
|||||||
public:
|
public:
|
||||||
falco_rules(sinsp* inspector, lua_State *ls, string lua_main_filename);
|
falco_rules(sinsp* inspector, lua_State *ls, string lua_main_filename);
|
||||||
~falco_rules();
|
~falco_rules();
|
||||||
void load_rules(string rules_filename);
|
void load_rules(string rules_filename, bool verbose);
|
||||||
void describe_rule(string *rule);
|
void describe_rule(string *rule);
|
||||||
sinsp_filter* get_filter();
|
sinsp_filter* get_filter();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user