mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-01 09:02:18 +00:00
chore(userspace/falco/app/actions): refactor sysinfo function
Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
This commit is contained in:
parent
29d3173ae3
commit
df4e91476f
@ -18,6 +18,7 @@ limitations under the License.
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "actions.h"
|
#include "actions.h"
|
||||||
#include "../../versions_info.h"
|
#include "../../versions_info.h"
|
||||||
@ -34,20 +35,27 @@ static std::string read_file(const std::string &filename)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
falco::app::run_result falco::app::actions::print_support(falco::app::state& s)
|
|
||||||
{
|
|
||||||
if(s.options.print_support)
|
|
||||||
{
|
|
||||||
nlohmann::json support;
|
|
||||||
std::string cmdline;
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
static int get_unix_sysinfo(nlohmann::json &support)
|
||||||
|
{
|
||||||
struct utsname sysinfo;
|
struct utsname sysinfo;
|
||||||
if(uname(&sysinfo) != 0)
|
if(uname(&sysinfo) != 0)
|
||||||
{
|
{
|
||||||
return run_result::fatal(std::string("Could not uname() to find system info: ") + strerror(errno));
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
support["system_info"]["sysname"] = sysinfo.sysname;
|
||||||
|
support["system_info"]["nodename"] = sysinfo.nodename;
|
||||||
|
support["system_info"]["release"] = sysinfo.release;
|
||||||
|
support["system_info"]["version"] = sysinfo.version;
|
||||||
|
support["system_info"]["machine"] = sysinfo.machine;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
static int get_win32_sysinfo(nlohmann::json &support)
|
||||||
|
{
|
||||||
OSVERSIONINFO osvi;
|
OSVERSIONINFO osvi;
|
||||||
SYSTEM_INFO sysInfo;
|
SYSTEM_INFO sysInfo;
|
||||||
TCHAR computerName[256];
|
TCHAR computerName[256];
|
||||||
@ -57,21 +65,9 @@ falco::app::run_result falco::app::actions::print_support(falco::app::state& s)
|
|||||||
GetSystemInfo(&sysInfo);
|
GetSystemInfo(&sysInfo);
|
||||||
if(!GetVersionEx(&osvi) || !GetComputerName(computerName, &size))
|
if(!GetVersionEx(&osvi) || !GetComputerName(computerName, &size))
|
||||||
{
|
{
|
||||||
return run_result::fatal(std::string("Could not get system info: ") + strerror(errno));
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
const falco::versions_info infos(s.offline_inspector);
|
|
||||||
support["version"] = infos.falco_version;
|
|
||||||
support["engine_info"] = infos.as_json();
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
support["system_info"]["sysname"] = sysinfo.sysname;
|
|
||||||
support["system_info"]["nodename"] = sysinfo.nodename;
|
|
||||||
support["system_info"]["release"] = sysinfo.release;
|
|
||||||
support["system_info"]["version"] = sysinfo.version;
|
|
||||||
support["system_info"]["machine"] = sysinfo.machine;
|
|
||||||
#else
|
|
||||||
support["system_info"]["sysname"] = "Windows";
|
support["system_info"]["sysname"] = "Windows";
|
||||||
support["system_info"]["nodename"] = computerName;
|
support["system_info"]["nodename"] = computerName;
|
||||||
support["system_info"]["release"] = osvi.dwMajorVersion;
|
support["system_info"]["release"] = osvi.dwMajorVersion;
|
||||||
@ -93,7 +89,30 @@ falco::app::run_result falco::app::actions::print_support(falco::app::state& s)
|
|||||||
default:
|
default:
|
||||||
support["system_info"]["machine"] = "unknown";
|
support["system_info"]["machine"] = "unknown";
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
falco::app::run_result falco::app::actions::print_support(falco::app::state& s)
|
||||||
|
{
|
||||||
|
if(s.options.print_support)
|
||||||
|
{
|
||||||
|
nlohmann::json support;
|
||||||
|
std::string cmdline;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
int rc = get_unix_sysinfo(support);
|
||||||
|
#else
|
||||||
|
int rc = get_win32_sysinfo(support);
|
||||||
|
#endif
|
||||||
|
if(rc != 0)
|
||||||
|
{
|
||||||
|
return run_result::fatal(std::string("Could not get system info: ") + strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
const falco::versions_info infos(s.offline_inspector);
|
||||||
|
support["version"] = infos.falco_version;
|
||||||
|
support["engine_info"] = infos.as_json();
|
||||||
support["cmdline"] = s.cmdline;
|
support["cmdline"] = s.cmdline;
|
||||||
support["config"] = read_file(s.options.conf_filename);
|
support["config"] = read_file(s.options.conf_filename);
|
||||||
support["rules_files"] = nlohmann::json::array();
|
support["rules_files"] = nlohmann::json::array();
|
||||||
|
Loading…
Reference in New Issue
Block a user