Expand the passive inventory shown in device details
Rust development slice / linux (push) Failing after 9s
Rust development slice / linux (push) Failing after 9s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! Read-only Windows APIs. The kernel's recorded startup time identifies the boot.
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use chrono::Utc;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde_json::{Value, json};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{ffi::c_void, os::windows::ffi::OsStrExt, path::Path, ptr, time::Duration};
|
||||
@@ -261,7 +261,23 @@ pub(crate) fn computer_name(format: COMPUTER_NAME_FORMAT) -> Result<String> {
|
||||
Ok(String::from_utf16(&name[..len as usize])?)
|
||||
}
|
||||
|
||||
fn install_date() -> Option<DateTime<Utc>> {
|
||||
let key = wide(r"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
|
||||
let name = wide("InstallDate");
|
||||
let mut seconds = 0_u32;
|
||||
let mut bytes = size_of::<u32>() as u32;
|
||||
let status = unsafe { RegGetValueW(HKEY_LOCAL_MACHINE,key.as_ptr(),name.as_ptr(),RRF_RT_REG_DWORD,
|
||||
ptr::null_mut(),ptr::from_mut(&mut seconds).cast(),&mut bytes) };
|
||||
(status == 0 && bytes as usize == size_of::<u32>() && seconds > 0)
|
||||
.then(|| DateTime::from_timestamp(i64::from(seconds), 0))
|
||||
.flatten().filter(|time| *time <= Utc::now())
|
||||
}
|
||||
|
||||
pub fn snapshot() -> Result<Value> {
|
||||
snapshot_with_boot(None)
|
||||
}
|
||||
|
||||
pub fn snapshot_with_boot(booted_at: Option<DateTime<Utc>>) -> Result<Value> {
|
||||
let started = Utc::now();
|
||||
let hostname = computer_name(ComputerNameDnsHostname)?;
|
||||
let volume = wide(std::env::var("SystemDrive").context("SYSTEM_DRIVE")? + "\\");
|
||||
@@ -281,7 +297,7 @@ pub fn snapshot() -> Result<Value> {
|
||||
let mut snapshot = json!({"os":os,"hostname":hostname,"architecture":std::env::consts::ARCH,"root_total_bytes":total,"root_available_bytes":available,"root_available_inodes":null,
|
||||
"collection_started_at":started,"collection_completed_at":completed,
|
||||
"observations":[
|
||||
{"scope":"windows.os","source_id":"windows.registry:CurrentVersion;GetComputerNameExW","observed_at":completed,"quality":"valid","completeness":"partial","truncated":false,"error_code":null,"data":{"product_name":product,"display_version":display,"build":build}},
|
||||
{"scope":"windows.os","source_id":"windows.registry:CurrentVersion;GetComputerNameExW;Kernel-General/12","observed_at":completed,"quality":"valid","completeness":"partial","truncated":false,"error_code":null,"data":{"product_name":product,"display_version":display,"build":build,"installed_at":install_date(),"booted_at":booted_at}},
|
||||
{"scope":"windows.volumes","source_id":"windows.win32:GetDiskFreeSpaceExW","observed_at":completed,"quality":"valid","completeness":"partial","truncated":false,"error_code":null,"data":{"system_volume_total_bytes":total,"system_volume_available_bytes":available}},
|
||||
{"scope":"windows.inodes","source_id":"windows.win32","observed_at":completed,"quality":"unsupported","completeness":"unknown","truncated":false,"error_code":"NOT_APPLICABLE","data":null}
|
||||
]});
|
||||
@@ -292,7 +308,7 @@ pub fn snapshot() -> Result<Value> {
|
||||
snapshot["collection_completed_at"] = json!(Utc::now());
|
||||
Ok(snapshot)
|
||||
}
|
||||
pub async fn boot_id() -> Result<String> {
|
||||
pub async fn boot_identity() -> Result<(String, DateTime<Utc>)> {
|
||||
// Fixed passive query only. Never interpolates a job or caller-supplied code.
|
||||
// Avoid Win32_Product: it can cause MSI consistency checks and repairs.
|
||||
let executable = Path::new(&std::env::var("SystemRoot")?)
|
||||
@@ -328,7 +344,14 @@ if ($nodes.Count -ne 1) { throw 'BOOT_START_TIME' }
|
||||
.try_into()?;
|
||||
bytes[6] = (bytes[6] & 15) | 0x80;
|
||||
bytes[8] = (bytes[8] & 63) | 0x80;
|
||||
Ok(uuid::Uuid::from_bytes(bytes).to_string())
|
||||
let ticks = text.parse::<i64>()?.checked_sub(621_355_968_000_000_000).context("BOOT_EPOCH")?;
|
||||
let time = DateTime::from_timestamp(ticks.div_euclid(10_000_000), ticks.rem_euclid(10_000_000) as u32 * 100)
|
||||
.context("BOOT_EPOCH")?;
|
||||
Ok((uuid::Uuid::from_bytes(bytes).to_string(),time))
|
||||
}
|
||||
|
||||
pub async fn boot_id() -> Result<String> {
|
||||
boot_identity().await.map(|(id, _)| id)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user