tables: Add default values for POSIX os_version (#3848)

This commit is contained in:
Teddy Reed 2017-10-16 23:31:03 -07:00 committed by GitHub
parent 40eaddb088
commit 54a8de8b6d

View File

@ -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);