feat: accept native Windows passive client and tenant-safe inventory migration
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//! Development-only read-only receipt inspection. No network, grants or effects.
|
||||
#[cfg(windows)]
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let root = std::path::Path::new(r"C:\ProgramData\RustDiscovery\state");
|
||||
rmm_agent_windows::native::private_path(root, true)?;
|
||||
let path = root.join("telemetry.sqlite");
|
||||
rmm_agent_windows::native::private_path(&path, false)?;
|
||||
let db =
|
||||
rusqlite::Connection::open_with_flags(path, rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY)?;
|
||||
let count: u64 = db.query_row("SELECT count(*) FROM events", [], |r| r.get(0))?;
|
||||
let sequence: u64 =
|
||||
db.query_row("SELECT value FROM metadata WHERE key='sequence'", [], |r| {
|
||||
r.get(0)
|
||||
})?;
|
||||
let agent: String = db.query_row("SELECT agent FROM identity", [], |r| r.get(0))?;
|
||||
let integrity: String = db.query_row("PRAGMA integrity_check", [], |r| r.get(0))?;
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::json!({"agent_id":agent,"pending_inventory_events":count,"sequence":sequence,"integrity":integrity,"read_only":true})
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
fn main() {
|
||||
eprintln!("Windows-only receipt probe");
|
||||
std::process::exit(1);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#![cfg(windows)]
|
||||
use anyhow::{Result, ensure};
|
||||
use rmm_agent_windows::native::{private_path, service_sid, wide};
|
||||
use std::{path::Path, ptr};
|
||||
use windows_sys::Win32::{
|
||||
Foundation::LocalFree,
|
||||
Security::{
|
||||
Authorization::ConvertStringSecurityDescriptorToSecurityDescriptorW,
|
||||
DACL_SECURITY_INFORMATION, OWNER_SECURITY_INFORMATION, PROTECTED_DACL_SECURITY_INFORMATION,
|
||||
SetFileSecurityW,
|
||||
},
|
||||
};
|
||||
fn apply(path: &Path, sddl: &str) -> Result<()> {
|
||||
let text = wide(sddl);
|
||||
let name = wide(path);
|
||||
let mut descriptor = ptr::null_mut();
|
||||
// SAFETY: Windows parses a test-owned SDDL into one owned descriptor.
|
||||
ensure!(
|
||||
unsafe {
|
||||
ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||
text.as_ptr(),
|
||||
1,
|
||||
&mut descriptor,
|
||||
ptr::null_mut(),
|
||||
)
|
||||
} != 0,
|
||||
"TEST_DESCRIPTOR"
|
||||
);
|
||||
let result = unsafe {
|
||||
SetFileSecurityW(
|
||||
name.as_ptr(),
|
||||
OWNER_SECURITY_INFORMATION
|
||||
| DACL_SECURITY_INFORMATION
|
||||
| PROTECTED_DACL_SECURITY_INFORMATION,
|
||||
descriptor,
|
||||
)
|
||||
};
|
||||
unsafe {
|
||||
LocalFree(descriptor.cast());
|
||||
}
|
||||
ensure!(result != 0, "TEST_ACL_APPLY");
|
||||
Ok(())
|
||||
}
|
||||
#[test]
|
||||
fn actual_windows_acl_rejects_broad_null_and_reparse_paths() {
|
||||
// Explicit development VM test. Only a new empty temporary directory and
|
||||
// its dummy nonsecret file are touched; never the running device identity.
|
||||
let root = std::env::temp_dir().join(format!("rmm-private-acl-{}", uuid::Uuid::new_v4()));
|
||||
std::fs::create_dir(&root).unwrap();
|
||||
let sid = service_sid().unwrap();
|
||||
let strict = format!("O:BAD:P(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;0x1301bf;;;{sid})");
|
||||
apply(&root, &strict).unwrap();
|
||||
private_path(&root, true).unwrap();
|
||||
let file = root.join("dummy.txt");
|
||||
std::fs::write(&file, b"nonsecret fixture").unwrap();
|
||||
private_path(&file, false).unwrap();
|
||||
assert!(private_path(&file, true).is_err());
|
||||
apply(&file, "O:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FR;;;BU)").unwrap();
|
||||
assert!(private_path(&file, false).is_err());
|
||||
apply(&file, "O:BAD:NO_ACCESS_CONTROL").unwrap();
|
||||
assert!(private_path(&file, false).is_err());
|
||||
apply(&file, &strict).unwrap();
|
||||
let link = root.join("dummy-link.txt");
|
||||
std::os::windows::fs::symlink_file(&file, &link).unwrap();
|
||||
assert!(private_path(&link, false).is_err());
|
||||
std::fs::remove_file(link).unwrap();
|
||||
std::fs::remove_file(file).unwrap();
|
||||
std::fs::remove_dir(root).unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user