Skip to content

Commit

Permalink
Flip logic and early return on empty queryset; outdent fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
James Jerger committed May 27, 2020
1 parent 6de917d commit 8a9896a
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions osquery/tables/system/windows/chassis_info.cpp
Expand Up @@ -23,47 +23,46 @@ QueryData genChassisInfo(QueryContext& context) {

WmiRequest wmiSystemReq("select * from Win32_SystemEnclosure");
const auto& wmiResults = wmiSystemReq.results();
if (wmiSystemReq.getStatus().ok()) {
if (!wmiResults.empty()) {
for (const auto& data : wmiResults) {
Row r;
bool boolean = false;
long number;
data.GetBool("AudibleAlarm", boolean);
r["audible_alarm"] = boolean ? "True" : "False";
data.GetString("BreachDescription", r["breach_description"]);
data.GetLong("ChassisTypes", number);
r["chassis_types"] = INTEGER(number);
data.GetString("Description", r["description"]);

//reset boolean to make sure there is no interference from the last call
boolean = false;
//check if the results are empty and return a warning if so
if (wmiResults.empty()) {
LOG(WARNING) << wmiSystemReq.getStatus().getMessage();
}

for (const auto& data : wmiResults) {
Row r;
bool boolean = false;
long number;
data.GetBool("AudibleAlarm", boolean);
r["audible_alarm"] = boolean ? "True" : "False";
data.GetString("BreachDescription", r["breach_description"]);
data.GetLong("ChassisTypes", number);
r["chassis_types"] = INTEGER(number);
data.GetString("Description", r["description"]);

//reset boolean to make sure there is no interference from the last call
boolean = false;

data.GetBool("LockPresent", boolean);
r["lock"] = boolean ? "True" : "False";
data.GetString("Manufacturer", r["manufacturer"]);
data.GetString("Model", r["model"]);
data.GetLong("SecurityBreach", number);
r["security_status"] = INTEGER(number);
data.GetString("SerialNumber", r["serial"]);
data.GetString("SMBIOSAssetTag", r["smbios_tag"]);
data.GetString("SKU", r["sku"]);
data.GetString("Status", r["status"]);
data.GetBool("LockPresent", boolean);
r["lock"] = boolean ? "True" : "False";
data.GetString("Manufacturer", r["manufacturer"]);
data.GetString("Model", r["model"]);
data.GetLong("SecurityBreach", number);
r["security_status"] = INTEGER(number);
data.GetString("SerialNumber", r["serial"]);
data.GetString("SMBIOSAssetTag", r["smbios_tag"]);
data.GetString("SKU", r["sku"]);
data.GetString("Status", r["status"]);

//reset boolean to make sure there is no interference from the last call
boolean = false;
//reset boolean to make sure there is no interference from the last call
boolean = false;

data.GetBool("VisibleAlarm", boolean);
r["visible_alarm"] = boolean ? "True" : "False";
results.push_back(std::move(r));
}
} else {
LOG(WARNING) << "WMI resultset empty.";
}
} else {
VLOG(1) << wmiSystemReq.getStatus().getMessage();
data.GetBool("VisibleAlarm", boolean);
r["visible_alarm"] = boolean ? "True" : "False";
results.push_back(std::move(r));
}
return results;
}

return results;
} // namespace tables
} // namespace osquery
} // namespace osquery

0 comments on commit 8a9896a

Please sign in to comment.