mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 09:58:54 +00:00
tables: Add default values for POSIX os_version (#3848)
This commit is contained in:
parent
40eaddb088
commit
54a8de8b6d
@ -41,14 +41,13 @@ const std::map<std::string, std::string> kOSReleaseColumns = {
|
||||
{"VERSION_ID", "_id"},
|
||||
};
|
||||
|
||||
QueryData genOSRelease() {
|
||||
QueryData genOSRelease(Row& r) {
|
||||
// This will parse /etc/os-version according to the systemd manual.
|
||||
std::string content;
|
||||
if (!readFile(kOSRelease, content).ok()) {
|
||||
return {};
|
||||
return {r};
|
||||
}
|
||||
|
||||
Row r;
|
||||
for (const auto& line : osquery::split(content, "\n")) {
|
||||
auto fields = osquery::split(line, "=", 1);
|
||||
if (fields.size() != 2) {
|
||||
@ -87,22 +86,32 @@ QueryData genOSRelease() {
|
||||
}
|
||||
|
||||
QueryData genOSVersion(QueryContext& context) {
|
||||
Row r;
|
||||
|
||||
// Set defaults if we cannot determine the version.
|
||||
r["name"] = "Unknown";
|
||||
r["major"] = "0";
|
||||
r["minor"] = "0";
|
||||
r["patch"] = "0";
|
||||
r["platform"] = "posix";
|
||||
|
||||
if (isReadable(kOSRelease)) {
|
||||
boost::system::error_code ec;
|
||||
// Funtoo has an empty os-release file.
|
||||
if (boost::filesystem::file_size(kOSRelease, ec) > 0) {
|
||||
return genOSRelease();
|
||||
return genOSRelease(r);
|
||||
}
|
||||
}
|
||||
|
||||
Row r;
|
||||
std::string content;
|
||||
if (readFile(kRedhatRelease, content).ok()) {
|
||||
r["platform"] = "rhel";
|
||||
r["platform_like"] = "rhel";
|
||||
} else if (readFile(kGentooRelease, content).ok()) {
|
||||
r["platform"] = "gentoo";
|
||||
r["platform_like"] = "gentoo";
|
||||
} else {
|
||||
return {};
|
||||
return {r};
|
||||
}
|
||||
|
||||
boost::algorithm::trim_all(content);
|
||||
|
Loading…
Reference in New Issue
Block a user