Implement bounded Windows MSI delegation with deny-only cancellation and retained installer ownership
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -17,9 +17,10 @@
|
||||
use anyhow::{Result, ensure};
|
||||
#[cfg(any(windows, test))]
|
||||
use rmm_domain::windows_execution::{ResolvedWindowsMsi, valid_package_code};
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Snapshot {
|
||||
pub product_code: String,
|
||||
pub package_code: Option<String>,
|
||||
@@ -34,7 +35,7 @@ pub struct Snapshot {
|
||||
}
|
||||
impl Snapshot {
|
||||
#[cfg(any(windows, test))]
|
||||
fn desired(&self, r: &ResolvedWindowsMsi) -> bool {
|
||||
pub(crate) fn desired(&self, r: &ResolvedWindowsMsi) -> bool {
|
||||
let p = &r.recipe.postcondition;
|
||||
self.product_code == p.product_code
|
||||
&& self.related_products == [p.product_code.clone()]
|
||||
@@ -854,8 +855,17 @@ mod windows {
|
||||
system_root: PathBuf,
|
||||
}
|
||||
impl Prepared {
|
||||
pub fn prepare(r: &ResolvedWindowsMsi, allowed_recipe_sha256: &str) -> Result<Self> {
|
||||
pub fn prepare(
|
||||
r: &ResolvedWindowsMsi,
|
||||
allowed_recipe_sha256: &str,
|
||||
began: Instant,
|
||||
timeout: Duration,
|
||||
) -> Result<Self> {
|
||||
validate(r, allowed_recipe_sha256)?;
|
||||
ensure!(
|
||||
within_budget(began, timeout),
|
||||
"MSI_PREPARATION_TIMEOUT_NO_INSTALLER_START"
|
||||
);
|
||||
let mut roots = Vec::new();
|
||||
for path in [CACHE, FIXTURES] {
|
||||
let file = OpenOptions::new()
|
||||
@@ -872,9 +882,17 @@ mod windows {
|
||||
false,
|
||||
)?;
|
||||
inspect_archive(&mut archive, r)?;
|
||||
ensure!(
|
||||
within_budget(began, timeout),
|
||||
"MSI_PREPARATION_TIMEOUT_NO_INSTALLER_START"
|
||||
);
|
||||
let system_root = system_root()?;
|
||||
let msiexec = Held::open(&system_root.join("System32").join("msiexec.exe"), true)?;
|
||||
let before = snapshot_for(r)?;
|
||||
ensure!(
|
||||
within_budget(began, timeout),
|
||||
"MSI_PREPARATION_TIMEOUT_NO_INSTALLER_START"
|
||||
);
|
||||
ensure!(
|
||||
before.baseline_allowed(r),
|
||||
"MSI_EXISTING_PRODUCT_OR_PAYLOAD_CONFLICT"
|
||||
@@ -911,6 +929,7 @@ mod windows {
|
||||
/// config, privilege, policy, clock, reboot or foreign process occurs.
|
||||
pub fn start(
|
||||
mut self,
|
||||
began: Instant,
|
||||
timeout: Duration,
|
||||
cancelled: &AtomicBool,
|
||||
check_effect_fence: impl FnOnce() -> Result<()>,
|
||||
@@ -923,7 +942,6 @@ mod windows {
|
||||
);
|
||||
// One original budget includes all synchronous verification and
|
||||
// the eventual installer. A late Noop is not retroactive success.
|
||||
let began = Instant::now();
|
||||
let archive = inspect_archive(&mut self.archive, &self.recipe);
|
||||
if !within_budget(began, timeout) {
|
||||
return Ok(self.verification_timeout(None));
|
||||
@@ -1010,6 +1028,11 @@ mod windows {
|
||||
timeout: Duration,
|
||||
}
|
||||
impl Installer {
|
||||
/// Observe only this retained process handle. Never adopt a PID, kill,
|
||||
/// restart, or revise an already persisted timeout outcome.
|
||||
pub fn process_exited(&mut self) -> Result<bool> {
|
||||
Ok(self.child.try_wait()?.is_some())
|
||||
}
|
||||
pub fn process_id(&self) -> u32 {
|
||||
self.child.id()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user