Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d831e486e7 | ||
|
|
941d903f5e |
@@ -4,8 +4,8 @@
|
||||
//! attempt before start(). Cache population is a separate verified RMM artifact
|
||||
//! operation: this module has no network, URL, UNC, transform or free arguments.
|
||||
//!
|
||||
//! Only first install/exact noop of v1.0.0 is implemented. Upgrade and EXE are
|
||||
//! separate deliveries, not guessed modes of this MSI executor.
|
||||
//! Only fixed1.0 first install/noop and fixed1.0→1.1 major-upgrade/noop.
|
||||
//! No fresh1.1, downgrade, repair, arbitrary predecessor, or EXE mode.
|
||||
//! MSI metadata APIs are synchronous. The caller owns the outer observation
|
||||
//! deadline; a poll timeout is not a promise that Windows Installer stopped.
|
||||
//! Do not put this controller in a kill-on-close process-tree executor.
|
||||
@@ -15,33 +15,80 @@
|
||||
//! https://learn.microsoft.com/en-us/windows/win32/msi/error-codes
|
||||
#[cfg(windows)]
|
||||
use anyhow::{Result, ensure};
|
||||
#[cfg(windows)]
|
||||
use rmm_domain::windows_execution::ResolvedWindowsMsi;
|
||||
#[cfg(any(windows, test))]
|
||||
use rmm_domain::windows_execution::{ResolvedWindowsMsi, valid_package_code};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
|
||||
pub struct Snapshot {
|
||||
pub product_code: String,
|
||||
pub package_code: Option<String>,
|
||||
pub related_products: Vec<String>,
|
||||
pub predecessor_state: Option<String>,
|
||||
pub predecessor_version: Option<String>,
|
||||
pub predecessor_package_code: Option<String>,
|
||||
pub product_state: Option<String>,
|
||||
pub product_version: Option<String>,
|
||||
pub payload_sha256: Option<String>,
|
||||
pub payload_bytes: Option<u64>,
|
||||
}
|
||||
impl Snapshot {
|
||||
#[cfg(windows)]
|
||||
#[cfg(any(windows, test))]
|
||||
fn desired(&self, r: &ResolvedWindowsMsi) -> bool {
|
||||
let p = &r.recipe.postcondition;
|
||||
self.product_state.as_deref() == Some("5")
|
||||
self.product_code == p.product_code
|
||||
&& self.related_products == [p.product_code.clone()]
|
||||
&& self.predecessor_state.is_none()
|
||||
&& self.predecessor_version.is_none()
|
||||
&& self.predecessor_package_code.is_none()
|
||||
&& r.recipe
|
||||
.package_code
|
||||
.as_ref()
|
||||
.is_none_or(|code| self.package_code.as_ref() == Some(code))
|
||||
&& self.product_state.as_deref() == Some("5")
|
||||
&& self.product_version.as_deref() == Some(&p.product_version)
|
||||
&& self.payload_sha256.as_deref() == Some(&p.payload_sha256)
|
||||
&& self.payload_bytes == Some(p.payload_bytes)
|
||||
}
|
||||
#[cfg(any(windows, test))]
|
||||
fn absent(&self) -> bool {
|
||||
self.product_state.is_none()
|
||||
self.related_products.is_empty()
|
||||
&& self.package_code.is_none()
|
||||
&& self.predecessor_state.is_none()
|
||||
&& self.predecessor_version.is_none()
|
||||
&& self.predecessor_package_code.is_none()
|
||||
&& self.product_state.is_none()
|
||||
&& self.product_version.is_none()
|
||||
&& self.payload_sha256.is_none()
|
||||
&& self.payload_bytes.is_none()
|
||||
}
|
||||
#[cfg(any(windows, test))]
|
||||
fn predecessor(&self, r: &ResolvedWindowsMsi) -> bool {
|
||||
let Some(old) = &r.recipe.predecessor else {
|
||||
return false;
|
||||
};
|
||||
self.product_code == r.recipe.postcondition.product_code
|
||||
&& self.related_products == [old.product_code.clone()]
|
||||
&& self.product_state.is_none()
|
||||
&& self.product_version.is_none()
|
||||
&& self.package_code.is_none()
|
||||
&& self.predecessor_state.as_deref() == Some("5")
|
||||
&& self.predecessor_version.as_ref() == Some(&old.product_version)
|
||||
&& self.predecessor_package_code.as_ref().is_some_and(|code| {
|
||||
valid_package_code(code) && Some(code) != r.recipe.package_code.as_ref()
|
||||
})
|
||||
&& self.payload_sha256.as_ref() == Some(&old.payload_sha256)
|
||||
&& self.payload_bytes == Some(old.payload_bytes)
|
||||
}
|
||||
#[cfg(any(windows, test))]
|
||||
fn baseline_allowed(&self, r: &ResolvedWindowsMsi) -> bool {
|
||||
self.desired(r)
|
||||
|| if r.recipe.predecessor.is_some() {
|
||||
self.predecessor(r)
|
||||
} else {
|
||||
self.absent()
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Observation {
|
||||
@@ -93,6 +140,94 @@ fn classification(
|
||||
_ => ("unknown", "MSI_FAILURE_EFFECT_UNRESOLVED", None, false),
|
||||
}
|
||||
}
|
||||
#[cfg(any(windows, test))]
|
||||
fn within_budget(began: std::time::Instant, timeout: std::time::Duration) -> bool {
|
||||
began.elapsed() < timeout
|
||||
}
|
||||
/// Classify only evidence actually observed inside the original budget. An
|
||||
/// installer may already have changed the machine when a late poll sees exit0;
|
||||
/// late evidence cannot retroactively turn that timed-out attempt into success.
|
||||
#[cfg(any(windows, test))]
|
||||
fn observed_classification(
|
||||
exit: u32,
|
||||
postconditions: bool,
|
||||
within_deadline: bool,
|
||||
) -> (&'static str, &'static str, Option<bool>, bool) {
|
||||
let result = classification(exit, postconditions);
|
||||
if within_deadline {
|
||||
result
|
||||
} else {
|
||||
(
|
||||
"unknown",
|
||||
"MSI_TIMEOUT_EFFECT_UNRESOLVED",
|
||||
result.2,
|
||||
result.3,
|
||||
)
|
||||
}
|
||||
}
|
||||
#[cfg(any(windows, test))]
|
||||
fn expected_upgrade_rows() -> Vec<Vec<Option<String>>> {
|
||||
use rmm_domain::windows_execution::*;
|
||||
let row = |min: &str, max: Option<&str>, attributes: &str, property: &str| {
|
||||
vec![
|
||||
Some(MSI_UPGRADE_CODE.into()),
|
||||
Some(min.into()),
|
||||
max.map(str::to_owned),
|
||||
None,
|
||||
Some(attributes.into()),
|
||||
Some("ALL".into()),
|
||||
Some(property.into()),
|
||||
]
|
||||
};
|
||||
// Both lists must contain exactly the one approved ProductCode in the
|
||||
// LaunchCondition. OnlyDetect never removes an unexpected family member.
|
||||
vec![
|
||||
row("0.0.0", None, "258", MSI_ALL_PRODUCTS),
|
||||
row(MSI_VERSION, Some(MSI_VERSION), "768", MSI_OLD_PRODUCTS),
|
||||
]
|
||||
}
|
||||
#[cfg(any(windows, test))]
|
||||
fn expected_sequence_rows(upgrade: bool) -> Vec<Vec<Option<String>>> {
|
||||
let mut rows = vec![
|
||||
("LaunchConditions", 100),
|
||||
("CostInitialize", 800),
|
||||
("FileCost", 900),
|
||||
("CostFinalize", 1000),
|
||||
("InstallValidate", 1400),
|
||||
("InstallInitialize", 1500),
|
||||
("ProcessComponents", 1600),
|
||||
("UnpublishFeatures", 1800),
|
||||
("RemoveFiles", 3500),
|
||||
("RemoveFolders", 3600),
|
||||
("CreateFolders", 3700),
|
||||
("InstallFiles", 4000),
|
||||
("RegisterUser", 6000),
|
||||
("RegisterProduct", 6100),
|
||||
("PublishFeatures", 6300),
|
||||
("PublishProduct", 6400),
|
||||
("InstallFinalize", 6600),
|
||||
];
|
||||
if upgrade {
|
||||
rows.extend([
|
||||
("FindRelatedProducts", 25),
|
||||
("RemoveExistingProducts", 1550),
|
||||
]);
|
||||
}
|
||||
rows.sort_by_key(|r| r.1);
|
||||
rows.into_iter()
|
||||
.map(|(action, seq)| {
|
||||
vec![
|
||||
Some(action.into()),
|
||||
if action == "RemoveExistingProducts" {
|
||||
Some("NOT Installed".into())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
Some(seq.to_string()),
|
||||
]
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
/// Contract and locally protected policy must agree, independently of the job.
|
||||
/// The policy hash must come from the helper's protected settings, never a field
|
||||
/// copied back out of the job being checked.
|
||||
@@ -108,7 +243,7 @@ fn validate(r: &ResolvedWindowsMsi, allowed_recipe_sha256: &str) -> Result<()> {
|
||||
#[cfg(windows)]
|
||||
mod windows {
|
||||
use super::*;
|
||||
use rmm_domain::windows_execution::{MSI_PAYLOAD, MSI_PRODUCT_CODE};
|
||||
use rmm_domain::windows_execution::*;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{
|
||||
fs::{File, OpenOptions},
|
||||
@@ -352,6 +487,106 @@ mod windows {
|
||||
ensure!(code == ERROR_NO_MORE_ITEMS, "MSI_DATABASE_NOT_UNIQUE");
|
||||
Ok(String::from_utf16(&text[..len as usize])?)
|
||||
}
|
||||
fn msi_rows(db: u32, query: &str, fields: u32) -> Result<Vec<Vec<Option<String>>>> {
|
||||
let mut view = 0;
|
||||
ensure!(
|
||||
unsafe { MsiDatabaseOpenViewW(db, wide(query).as_ptr(), &mut view) } == 0,
|
||||
"MSI_ROWS_VIEW"
|
||||
);
|
||||
let view = Msi(view);
|
||||
ensure!(
|
||||
unsafe { MsiViewExecute(view.0, 0) } == 0,
|
||||
"MSI_ROWS_EXECUTE"
|
||||
);
|
||||
let mut rows = Vec::new();
|
||||
loop {
|
||||
let mut record = 0;
|
||||
let code = unsafe { MsiViewFetch(view.0, &mut record) };
|
||||
let record = Msi(record);
|
||||
if code == ERROR_NO_MORE_ITEMS {
|
||||
return Ok(rows);
|
||||
}
|
||||
ensure!(
|
||||
code == 0
|
||||
&& rows.len() < 64
|
||||
&& unsafe { MsiRecordGetFieldCount(record.0) } == fields,
|
||||
"MSI_ROWS_BOUND"
|
||||
);
|
||||
let mut row = Vec::new();
|
||||
for field in 1..=fields {
|
||||
if unsafe { MsiRecordIsNull(record.0, field) } != 0 {
|
||||
row.push(None);
|
||||
continue;
|
||||
}
|
||||
let mut text = [0u16; 256];
|
||||
let mut count = 255;
|
||||
ensure!(
|
||||
unsafe { MsiRecordGetStringW(record.0, field, text.as_mut_ptr(), &mut count) }
|
||||
== 0
|
||||
&& count < 256,
|
||||
"MSI_ROW_STRING"
|
||||
);
|
||||
row.push(Some(String::from_utf16(&text[..count as usize])?));
|
||||
}
|
||||
rows.push(row);
|
||||
}
|
||||
}
|
||||
fn inspect_upgrade(db: u32, r: &ResolvedWindowsMsi) -> Result<()> {
|
||||
let upgrade = r.recipe.predecessor.is_some();
|
||||
let tables = msi_rows(db, "SELECT `Name` FROM `_Tables` WHERE `Name`='Upgrade'", 1)?;
|
||||
if upgrade {
|
||||
ensure!(
|
||||
tables == vec![vec![Some("Upgrade".into())]],
|
||||
"MSI_UPGRADE_TABLE_REQUIRED"
|
||||
);
|
||||
ensure!(
|
||||
msi_rows(
|
||||
db,
|
||||
"SELECT `UpgradeCode`,`VersionMin`,`VersionMax`,`Language`,`Attributes`,`Remove`,`ActionProperty` FROM `Upgrade` ORDER BY `ActionProperty`",
|
||||
7
|
||||
)? == expected_upgrade_rows(),
|
||||
"MSI_EXACT_UPGRADE_TABLE_REQUIRED"
|
||||
);
|
||||
ensure!(
|
||||
msi_text(
|
||||
db,
|
||||
"SELECT `Value` FROM `Property` WHERE `Property`='SecureCustomProperties'"
|
||||
)? == format!("{MSI_ALL_PRODUCTS};{MSI_OLD_PRODUCTS}"),
|
||||
"MSI_SECURE_UPGRADE_PROPERTIES"
|
||||
);
|
||||
ensure!(
|
||||
msi_rows(
|
||||
db,
|
||||
"SELECT `Condition`,`Description` FROM `LaunchCondition` ORDER BY `Condition`",
|
||||
2
|
||||
)? == vec![
|
||||
vec![
|
||||
Some(MSI_UPGRADE_CONDITION.into()),
|
||||
Some(
|
||||
"Only the exact approved fixture1.0 predecessor may be upgraded."
|
||||
.into()
|
||||
)
|
||||
],
|
||||
vec![
|
||||
Some("VersionNT64".into()),
|
||||
Some("This fixture requires 64-bit Windows.".into())
|
||||
]
|
||||
],
|
||||
"MSI_EXACT_UPGRADE_LAUNCH_CONDITIONS"
|
||||
);
|
||||
} else {
|
||||
ensure!(tables.is_empty(), "MSI_UNEXPECTED_UPGRADE_TABLE");
|
||||
}
|
||||
ensure!(
|
||||
msi_rows(
|
||||
db,
|
||||
"SELECT `Action`,`Condition`,`Sequence` FROM `InstallExecuteSequence` ORDER BY `Sequence`",
|
||||
3
|
||||
)? == expected_sequence_rows(upgrade),
|
||||
"MSI_EXACT_EXECUTE_SEQUENCE_REQUIRED"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
fn no_custom_actions(db: u32) -> Result<()> {
|
||||
let mut view = 0;
|
||||
ensure!(
|
||||
@@ -409,6 +644,7 @@ mod windows {
|
||||
);
|
||||
let db = Msi(db);
|
||||
no_custom_actions(db.0)?;
|
||||
inspect_upgrade(db.0, r)?;
|
||||
let cabinet = msi_text(db.0, "SELECT `Cabinet` FROM `Media`")?;
|
||||
ensure!(
|
||||
cabinet.starts_with('#')
|
||||
@@ -420,7 +656,7 @@ mod windows {
|
||||
"MSI_EMBEDDED_CABINET_REQUIRED"
|
||||
);
|
||||
for (field, value) in [
|
||||
("ProductCode", MSI_PRODUCT_CODE),
|
||||
("ProductCode", r.recipe.postcondition.product_code.as_str()),
|
||||
(
|
||||
"ProductVersion",
|
||||
r.recipe.postcondition.product_version.as_str(),
|
||||
@@ -467,15 +703,41 @@ mod windows {
|
||||
String::from_utf16(&text[..len as usize])?.starts_with("x64;"),
|
||||
"MSI_NOT_X64"
|
||||
);
|
||||
let mut len = 255;
|
||||
ensure!(
|
||||
unsafe {
|
||||
MsiSummaryInfoGetPropertyW(
|
||||
summary.0,
|
||||
9,
|
||||
&mut kind,
|
||||
&mut value,
|
||||
&mut time,
|
||||
text.as_mut_ptr(),
|
||||
&mut len,
|
||||
)
|
||||
} == 0
|
||||
&& kind == 30
|
||||
&& len < 256,
|
||||
"MSI_PACKAGE_SUMMARY"
|
||||
);
|
||||
let package_code = String::from_utf16(&text[..len as usize])?;
|
||||
ensure!(
|
||||
valid_package_code(&package_code)
|
||||
&& r.recipe
|
||||
.package_code
|
||||
.as_ref()
|
||||
.is_none_or(|code| code == &package_code),
|
||||
"MSI_PACKAGE_CODE_BINDING"
|
||||
);
|
||||
file.check()?;
|
||||
Ok(())
|
||||
}
|
||||
fn property(name: &str) -> Result<Option<String>> {
|
||||
fn property(product: &str, name: &str) -> Result<Option<String>> {
|
||||
let mut value = [0u16; 256];
|
||||
let mut len = 255;
|
||||
let code = unsafe {
|
||||
MsiGetProductInfoExW(
|
||||
wide(MSI_PRODUCT_CODE).as_ptr(),
|
||||
wide(product).as_ptr(),
|
||||
ptr::null(),
|
||||
MSIINSTALLCONTEXT_MACHINE,
|
||||
wide(name).as_ptr(),
|
||||
@@ -489,13 +751,58 @@ mod windows {
|
||||
ensure!(code == 0 && len < 256, "MSI_MACHINE_PRODUCT_QUERY");
|
||||
Ok(Some(String::from_utf16(&value[..len as usize])?))
|
||||
}
|
||||
pub fn snapshot() -> Result<Snapshot> {
|
||||
let product_state = property("State")?;
|
||||
fn snapshot_product(product: &str, predecessor: Option<&str>) -> Result<Snapshot> {
|
||||
let product_state = property(product, "State")?;
|
||||
let product_version = if product_state.as_deref() == Some("5") {
|
||||
property("VersionString")?
|
||||
property(product, "VersionString")?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let package_code = if product_state.as_deref() == Some("5") {
|
||||
property(product, "PackageCode")?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let predecessor_state = predecessor
|
||||
.map(|p| property(p, "State"))
|
||||
.transpose()?
|
||||
.flatten();
|
||||
let predecessor_version = if predecessor_state.as_deref() == Some("5") {
|
||||
property(predecessor.unwrap(), "VersionString")?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let predecessor_package_code = if predecessor_state.as_deref() == Some("5") {
|
||||
property(predecessor.unwrap(), "PackageCode")?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut related_products = Vec::new();
|
||||
for index in 0..=16 {
|
||||
let mut code = [0u16; 39];
|
||||
let status = unsafe {
|
||||
MsiEnumRelatedProductsW(
|
||||
wide(MSI_UPGRADE_CODE).as_ptr(),
|
||||
0,
|
||||
index,
|
||||
code.as_mut_ptr(),
|
||||
)
|
||||
};
|
||||
if status == ERROR_NO_MORE_ITEMS {
|
||||
break;
|
||||
}
|
||||
ensure!(
|
||||
status == ERROR_SUCCESS && index < 16 && code[38] == 0,
|
||||
"MSI_RELATED_PRODUCT_QUERY"
|
||||
);
|
||||
let code = String::from_utf16(&code[..38])?;
|
||||
ensure!(
|
||||
!related_products.contains(&code),
|
||||
"MSI_DUPLICATE_RELATED_PRODUCT"
|
||||
);
|
||||
related_products.push(code);
|
||||
}
|
||||
related_products.sort();
|
||||
let (payload_sha256, payload_bytes) = match std::fs::symlink_metadata(MSI_PAYLOAD) {
|
||||
Ok(_) => {
|
||||
let mut file = Held::open(Path::new(MSI_PAYLOAD), false)?;
|
||||
@@ -506,12 +813,32 @@ mod windows {
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
Ok(Snapshot {
|
||||
product_code: product.into(),
|
||||
package_code,
|
||||
related_products,
|
||||
predecessor_state,
|
||||
predecessor_version,
|
||||
predecessor_package_code,
|
||||
product_state,
|
||||
product_version,
|
||||
payload_sha256,
|
||||
payload_bytes,
|
||||
})
|
||||
}
|
||||
/// Retained1.0 read-only witness. No implicit choice of upgrade recipe.
|
||||
pub fn snapshot() -> Result<Snapshot> {
|
||||
snapshot_product(MSI_PRODUCT_CODE, None)
|
||||
}
|
||||
pub fn snapshot_for(r: &ResolvedWindowsMsi) -> Result<Snapshot> {
|
||||
ensure!(r.validate(), "MSI_RECIPE_INVALID");
|
||||
snapshot_product(
|
||||
&r.recipe.postcondition.product_code,
|
||||
r.recipe
|
||||
.predecessor
|
||||
.as_ref()
|
||||
.map(|old| old.product_code.as_str()),
|
||||
)
|
||||
}
|
||||
fn system_root() -> Result<PathBuf> {
|
||||
let mut value = [0u16; 32768];
|
||||
let len = unsafe { GetSystemWindowsDirectoryW(value.as_mut_ptr(), value.len() as u32) };
|
||||
@@ -547,9 +874,9 @@ mod windows {
|
||||
inspect_archive(&mut archive, r)?;
|
||||
let system_root = system_root()?;
|
||||
let msiexec = Held::open(&system_root.join("System32").join("msiexec.exe"), true)?;
|
||||
let before = snapshot()?;
|
||||
let before = snapshot_for(r)?;
|
||||
ensure!(
|
||||
before.absent() || before.desired(r),
|
||||
before.baseline_allowed(r),
|
||||
"MSI_EXISTING_PRODUCT_OR_PAYLOAD_CONFLICT"
|
||||
);
|
||||
Ok(Self {
|
||||
@@ -561,6 +888,25 @@ mod windows {
|
||||
system_root,
|
||||
})
|
||||
}
|
||||
fn verification_timeout(&self, after: Option<Snapshot>) -> Run {
|
||||
Run::Noop(Box::new(Observation {
|
||||
recipe_sha256: self.recipe.recipe_sha256.clone(),
|
||||
artifact_sha256: self.recipe.recipe.artifact.sha256.clone(),
|
||||
process_id: None,
|
||||
state: "unknown",
|
||||
code: "MSI_VERIFICATION_TIMEOUT_NO_INSTALLER_START",
|
||||
exit_code: None,
|
||||
postconditions_passed: false,
|
||||
already_desired: false,
|
||||
installer_process_started: false,
|
||||
transaction_started: Some(false),
|
||||
installer_reboot_required: None,
|
||||
reboot_initiated: false,
|
||||
before: self.before.clone(),
|
||||
after,
|
||||
automatic_retry: false,
|
||||
}))
|
||||
}
|
||||
/// Called only after durable original-grant consumption. No change of
|
||||
/// config, privilege, policy, clock, reboot or foreign process occurs.
|
||||
pub fn start(
|
||||
@@ -575,10 +921,35 @@ mod windows {
|
||||
&& !cancelled.load(Ordering::SeqCst),
|
||||
"MSI_START_LIMIT_OR_CANCELLED"
|
||||
);
|
||||
inspect_archive(&mut self.archive, &self.recipe)?;
|
||||
self.msiexec.check()?;
|
||||
let before = snapshot()?;
|
||||
// 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));
|
||||
}
|
||||
archive?;
|
||||
let executable = self.msiexec.check();
|
||||
if !within_budget(began, timeout) {
|
||||
return Ok(self.verification_timeout(None));
|
||||
}
|
||||
executable?;
|
||||
let observation = snapshot_for(&self.recipe);
|
||||
if !within_budget(began, timeout) {
|
||||
return Ok(self.verification_timeout(observation.ok()));
|
||||
}
|
||||
let before = observation?;
|
||||
ensure!(before == self.before, "MSI_BASELINE_CHANGED");
|
||||
// Both a Noop and an installer decision require a fresh caller
|
||||
// authorization fence; no bypass for the already-desired branch.
|
||||
check_effect_fence()?;
|
||||
if !within_budget(began, timeout) {
|
||||
return Ok(self.verification_timeout(Some(before)));
|
||||
}
|
||||
ensure!(
|
||||
!cancelled.load(Ordering::SeqCst),
|
||||
"MSI_CANCELLED_BEFORE_START"
|
||||
);
|
||||
if before.desired(&self.recipe) {
|
||||
return Ok(Run::Noop(Box::new(Observation {
|
||||
recipe_sha256: self.recipe.recipe_sha256.clone(),
|
||||
@@ -598,14 +969,11 @@ mod windows {
|
||||
automatic_retry: false,
|
||||
})));
|
||||
}
|
||||
ensure!(before.absent(), "MSI_INSTALL_BASELINE_CONFLICT");
|
||||
use std::os::windows::process::CommandExt;
|
||||
check_effect_fence()?;
|
||||
ensure!(
|
||||
!cancelled.load(Ordering::SeqCst),
|
||||
"MSI_CANCELLED_BEFORE_START"
|
||||
before.baseline_allowed(&self.recipe),
|
||||
"MSI_INSTALL_BASELINE_CONFLICT"
|
||||
);
|
||||
let began = Instant::now();
|
||||
use std::os::windows::process::CommandExt;
|
||||
let child = Command::new(&self.msiexec.path)
|
||||
.args([
|
||||
std::ffi::OsStr::new("/i"),
|
||||
@@ -657,14 +1025,21 @@ mod windows {
|
||||
};
|
||||
if exit.is_none()
|
||||
&& !cancelled.load(Ordering::SeqCst)
|
||||
&& self.began.elapsed() < self.timeout
|
||||
&& within_budget(self.began, self.timeout)
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
let mut after = None;
|
||||
let (state, error, reboot, initiated) = if let Some(code) = code {
|
||||
after = snapshot().ok();
|
||||
if after.is_none() && matches!(code, 0 | 3010) {
|
||||
// No extra synchronous MSI query once the original budget has
|
||||
// expired. try_wait and snapshot can themselves return late.
|
||||
if within_budget(self.began, self.timeout) {
|
||||
after = snapshot_for(&self.prepared.recipe).ok();
|
||||
}
|
||||
let within_deadline = within_budget(self.began, self.timeout);
|
||||
if !within_deadline {
|
||||
observed_classification(code, false, false)
|
||||
} else if after.is_none() && matches!(code, 0 | 3010) {
|
||||
(
|
||||
"unknown",
|
||||
"MSI_POSTCONDITION_QUERY_FAILED",
|
||||
@@ -672,11 +1047,12 @@ mod windows {
|
||||
false,
|
||||
)
|
||||
} else {
|
||||
classification(
|
||||
observed_classification(
|
||||
code,
|
||||
after
|
||||
.as_ref()
|
||||
.is_some_and(|s| s.desired(&self.prepared.recipe)),
|
||||
within_deadline,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -716,11 +1092,124 @@ mod windows {
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
pub use windows::{Installer, Prepared, Run, snapshot};
|
||||
pub use windows::{Installer, Prepared, Run, snapshot, snapshot_for};
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn upgrade_and_noop_need_independent_exact_products_family_and_payload() {
|
||||
use rmm_domain::windows_execution::*;
|
||||
let recipe = WindowsMsiRecipe {
|
||||
schema_version: 1,
|
||||
recipe_id: MSI_UPGRADE_RECIPE_ID.into(),
|
||||
recipe_version: "1".into(),
|
||||
platform: "windows".into(),
|
||||
upgrade_code: MSI_UPGRADE_CODE.into(),
|
||||
architecture: Architecture::X64,
|
||||
context: InstallContext::Machine,
|
||||
command_profile: MsiCommandProfile::FixtureQuietNoRebootV1,
|
||||
artifact: MsiArtifact {
|
||||
artifact_id: uuid::Uuid::new_v4(),
|
||||
sha256: "ab".repeat(32),
|
||||
bytes: 20480,
|
||||
},
|
||||
postcondition: MsiPostcondition {
|
||||
product_code: MSI_UPGRADE_PRODUCT_CODE.into(),
|
||||
product_version: MSI_UPGRADE_VERSION.into(),
|
||||
payload_path: MSI_PAYLOAD.into(),
|
||||
payload_sha256: MSI_PAYLOAD_11_SHA256.into(),
|
||||
payload_bytes: MSI_PAYLOAD_BYTES,
|
||||
},
|
||||
no_reboot: true,
|
||||
package_code: Some("{8475C4D1-6EE2-4C3A-B41D-D834A20F4135}".into()),
|
||||
predecessor: Some(MsiPostcondition {
|
||||
product_code: MSI_PRODUCT_CODE.into(),
|
||||
product_version: MSI_VERSION.into(),
|
||||
payload_path: MSI_PAYLOAD.into(),
|
||||
payload_sha256: MSI_PAYLOAD_10_SHA256.into(),
|
||||
payload_bytes: MSI_PAYLOAD_BYTES,
|
||||
}),
|
||||
};
|
||||
let r = ResolvedWindowsMsi {
|
||||
recipe_sha256: recipe.sha256().unwrap(),
|
||||
recipe,
|
||||
};
|
||||
assert!(r.validate());
|
||||
let mut before = Snapshot {
|
||||
product_code: MSI_UPGRADE_PRODUCT_CODE.into(),
|
||||
related_products: vec![MSI_PRODUCT_CODE.into()],
|
||||
predecessor_state: Some("5".into()),
|
||||
predecessor_version: Some(MSI_VERSION.into()),
|
||||
predecessor_package_code: Some("{D1C4ECE2-7025-4E16-A842-A20F320CE783}".into()),
|
||||
payload_sha256: Some(MSI_PAYLOAD_10_SHA256.into()),
|
||||
payload_bytes: Some(MSI_PAYLOAD_BYTES),
|
||||
..Snapshot::default()
|
||||
};
|
||||
assert!(before.predecessor(&r));
|
||||
assert!(before.baseline_allowed(&r));
|
||||
assert!(!before.desired(&r));
|
||||
assert!(!Snapshot::default().baseline_allowed(&r)); // no fresh1.1 fallback
|
||||
before
|
||||
.related_products
|
||||
.push("{11111111-1111-4111-8111-111111111111}".into());
|
||||
assert!(!before.baseline_allowed(&r));
|
||||
let mut after = Snapshot {
|
||||
product_code: MSI_UPGRADE_PRODUCT_CODE.into(),
|
||||
package_code: r.recipe.package_code.clone(),
|
||||
related_products: vec![MSI_UPGRADE_PRODUCT_CODE.into()],
|
||||
product_state: Some("5".into()),
|
||||
product_version: Some(MSI_UPGRADE_VERSION.into()),
|
||||
payload_sha256: Some(MSI_PAYLOAD_11_SHA256.into()),
|
||||
payload_bytes: Some(MSI_PAYLOAD_BYTES),
|
||||
..Snapshot::default()
|
||||
};
|
||||
assert!(after.desired(&r));
|
||||
after.predecessor_state = Some("5".into());
|
||||
assert!(!after.desired(&r));
|
||||
after.predecessor_state = None;
|
||||
after.payload_sha256 = Some(MSI_PAYLOAD_10_SHA256.into());
|
||||
assert!(!after.desired(&r));
|
||||
let table = expected_upgrade_rows();
|
||||
assert_eq!(table.len(), 2);
|
||||
assert_eq!(table[0][4].as_deref(), Some("258"));
|
||||
assert_eq!(table[1][4].as_deref(), Some("768"));
|
||||
let sequence = expected_sequence_rows(true);
|
||||
let position = |name: &str| {
|
||||
sequence
|
||||
.iter()
|
||||
.position(|r| r[0].as_deref() == Some(name))
|
||||
.unwrap()
|
||||
};
|
||||
assert!(position("FindRelatedProducts") < position("LaunchConditions"));
|
||||
assert!(position("InstallInitialize") < position("RemoveExistingProducts"));
|
||||
assert!(position("RemoveExistingProducts") < position("ProcessComponents"));
|
||||
}
|
||||
#[test]
|
||||
fn late_exit_or_postcondition_cannot_retroactively_succeed_or_retry() {
|
||||
use std::time::{Duration, Instant};
|
||||
let original = Instant::now().checked_sub(Duration::from_secs(2)).unwrap();
|
||||
let timely = within_budget(Instant::now(), Duration::from_secs(60));
|
||||
let late = within_budget(original, Duration::from_secs(1));
|
||||
assert!(timely);
|
||||
assert!(!late);
|
||||
// This same budget gates the Noop decision and the installer poll;
|
||||
// metadata returning late does not receive a fresh timer.
|
||||
assert_eq!(observed_classification(0, true, late).0, "unknown");
|
||||
for exit in [0, 3010, 1618, 1603, 1641] {
|
||||
let late = observed_classification(exit, true, false);
|
||||
assert_eq!(
|
||||
(late.0, late.1),
|
||||
("unknown", "MSI_TIMEOUT_EFFECT_UNRESOLVED")
|
||||
);
|
||||
assert_eq!(
|
||||
(late.2, late.3),
|
||||
(classification(exit, true).2, classification(exit, true).3)
|
||||
);
|
||||
}
|
||||
assert_eq!(observed_classification(0, true, true).0, "succeeded");
|
||||
assert_eq!(observed_classification(0, false, true).0, "failed");
|
||||
}
|
||||
#[test]
|
||||
fn exit_code_never_substitutes_for_independent_postconditions_or_reboot_authority() {
|
||||
assert_eq!(
|
||||
classification(0, true),
|
||||
@@ -752,6 +1241,7 @@ mod tests {
|
||||
product_version: None,
|
||||
payload_sha256: None,
|
||||
payload_bytes: None,
|
||||
..Snapshot::default()
|
||||
};
|
||||
assert!(!advertised.absent());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! Unexported Windows MSI fixture contract. No legacy Linux codec is changed.
|
||||
//! This version supports first installation or independently proven exact noop;
|
||||
//! an upgrade requires a separate reviewed recipe with explicit predecessor
|
||||
//! products/UpgradeCode semantics. No implicit REINSTALL flags are inferred.
|
||||
//! Fixed1.0 first installation/noop and separate1.0→1.1 major-upgrade/noop
|
||||
//! recipes only. No implicit REINSTALL, repair, downgrade or fresh1.1 mode.
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
use uuid::Uuid;
|
||||
@@ -11,6 +10,17 @@ pub const MSI_PRODUCT_CODE: &str = "{3F070B4B-9C08-4D65-BD41-13D81B884AEC}";
|
||||
pub const MSI_UPGRADE_CODE: &str = "{C9BF1FB8-E31D-4BD7-BA0D-AB46539BBBAA}";
|
||||
pub const MSI_VERSION: &str = "1.0.0";
|
||||
pub const MSI_PAYLOAD: &str = r"C:\Program Files\RustDiscoveryFixtures\msi-payload.txt";
|
||||
pub const MSI_UPGRADE_RECIPE_ID: &str = "rmm-windows-msi-fixture-upgrade-1.1";
|
||||
pub const MSI_UPGRADE_PRODUCT_CODE: &str = "{D42BD387-079B-4BBF-A134-0DA7B7A97011}";
|
||||
pub const MSI_UPGRADE_VERSION: &str = "1.1.0";
|
||||
pub const MSI_PAYLOAD_BYTES: u64 = 33;
|
||||
pub const MSI_PAYLOAD_10_SHA256: &str =
|
||||
"0c90c4fc7233017cc88c0e925095d6662ac57abdb303c7527ef59d02b454fca0";
|
||||
pub const MSI_PAYLOAD_11_SHA256: &str =
|
||||
"ba0c83deff9eed014009bcd45369b2a356ae909ebf0c1434dc836b0e6d759c49";
|
||||
pub const MSI_OLD_PRODUCTS: &str = "RMM_OLD_PRODUCTS";
|
||||
pub const MSI_ALL_PRODUCTS: &str = "RMM_ALL_PRODUCTS";
|
||||
pub const MSI_UPGRADE_CONDITION: &str = "Installed OR (RMM_OLD_PRODUCTS = \"{3F070B4B-9C08-4D65-BD41-13D81B884AEC}\" AND RMM_ALL_PRODUCTS = \"{3F070B4B-9C08-4D65-BD41-13D81B884AEC}\")";
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Architecture {
|
||||
@@ -56,6 +66,11 @@ pub struct WindowsMsiRecipe {
|
||||
pub artifact: MsiArtifact,
|
||||
pub postcondition: MsiPostcondition,
|
||||
pub no_reboot: bool,
|
||||
// Appended opt-in metadata: old1.0 recipes retain exactly their old bytes.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub package_code: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub predecessor: Option<MsiPostcondition>,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
@@ -70,10 +85,16 @@ pub fn digest(value: &str) -> bool {
|
||||
.bytes()
|
||||
.all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))
|
||||
}
|
||||
pub fn valid_package_code(value: &str) -> bool {
|
||||
Uuid::parse_str(value).is_ok_and(|id| {
|
||||
!id.is_nil()
|
||||
&& value == format!("{{{}}}", id.to_string().to_uppercase())
|
||||
&& ![MSI_PRODUCT_CODE, MSI_UPGRADE_PRODUCT_CODE, MSI_UPGRADE_CODE].contains(&value)
|
||||
})
|
||||
}
|
||||
impl WindowsMsiRecipe {
|
||||
pub fn validate(&self) -> bool {
|
||||
self.schema_version == 1
|
||||
&& self.recipe_id == MSI_RECIPE_ID
|
||||
&& self.recipe_version == "1"
|
||||
&& self.platform == "windows"
|
||||
&& self.upgrade_code == MSI_UPGRADE_CODE
|
||||
@@ -81,11 +102,32 @@ impl WindowsMsiRecipe {
|
||||
&& !self.artifact.artifact_id.is_nil()
|
||||
&& digest(&self.artifact.sha256)
|
||||
&& (1..=262144).contains(&self.artifact.bytes)
|
||||
&& self.postcondition.product_code == MSI_PRODUCT_CODE
|
||||
&& self.postcondition.product_version == MSI_VERSION
|
||||
&& self.postcondition.payload_path == MSI_PAYLOAD
|
||||
&& digest(&self.postcondition.payload_sha256)
|
||||
&& (1..=65536).contains(&self.postcondition.payload_bytes)
|
||||
&& match self.recipe_id.as_str() {
|
||||
MSI_RECIPE_ID => {
|
||||
self.postcondition.product_code == MSI_PRODUCT_CODE
|
||||
&& self.postcondition.product_version == MSI_VERSION
|
||||
&& self.package_code.is_none()
|
||||
&& self.predecessor.is_none()
|
||||
}
|
||||
MSI_UPGRADE_RECIPE_ID => {
|
||||
self.postcondition.product_code == MSI_UPGRADE_PRODUCT_CODE
|
||||
&& self.postcondition.product_version == MSI_UPGRADE_VERSION
|
||||
&& self.postcondition.payload_sha256 == MSI_PAYLOAD_11_SHA256
|
||||
&& self.postcondition.payload_bytes == MSI_PAYLOAD_BYTES
|
||||
&& self.package_code.as_deref().is_some_and(valid_package_code)
|
||||
&& self.predecessor.as_ref().is_some_and(|old| {
|
||||
old.product_code == MSI_PRODUCT_CODE
|
||||
&& old.product_version == MSI_VERSION
|
||||
&& old.payload_path == MSI_PAYLOAD
|
||||
&& old.payload_sha256 == MSI_PAYLOAD_10_SHA256
|
||||
&& old.payload_bytes == MSI_PAYLOAD_BYTES
|
||||
})
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
pub fn sha256(&self) -> Result<String, serde_json::Error> {
|
||||
Ok(format!("{:x}", Sha256::digest(serde_json::to_vec(self)?)))
|
||||
@@ -127,6 +169,55 @@ mod tests {
|
||||
payload_bytes: 20,
|
||||
},
|
||||
no_reboot: true,
|
||||
package_code: None,
|
||||
predecessor: None,
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn major_upgrade_requires_explicit_exact_predecessor_new_package_and_same_family() {
|
||||
let old = recipe();
|
||||
let old_bytes = serde_json::to_vec(&old).unwrap();
|
||||
assert!(
|
||||
!String::from_utf8(old_bytes.clone())
|
||||
.unwrap()
|
||||
.contains("predecessor")
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_vec(&serde_json::from_slice::<WindowsMsiRecipe>(&old_bytes).unwrap())
|
||||
.unwrap(),
|
||||
old_bytes
|
||||
);
|
||||
let mut r = old.clone();
|
||||
r.recipe_id = MSI_UPGRADE_RECIPE_ID.into();
|
||||
r.package_code = Some("{8475C4D1-6EE2-4C3A-B41D-D834A20F4135}".into());
|
||||
r.postcondition.product_code = MSI_UPGRADE_PRODUCT_CODE.into();
|
||||
r.postcondition.product_version = MSI_UPGRADE_VERSION.into();
|
||||
r.postcondition.payload_sha256 = MSI_PAYLOAD_11_SHA256.into();
|
||||
r.postcondition.payload_bytes = MSI_PAYLOAD_BYTES;
|
||||
r.predecessor = Some(MsiPostcondition {
|
||||
product_code: MSI_PRODUCT_CODE.into(),
|
||||
product_version: MSI_VERSION.into(),
|
||||
payload_path: MSI_PAYLOAD.into(),
|
||||
payload_sha256: MSI_PAYLOAD_10_SHA256.into(),
|
||||
payload_bytes: MSI_PAYLOAD_BYTES,
|
||||
});
|
||||
assert!(r.validate());
|
||||
assert_ne!(r.sha256().unwrap(), old.sha256().unwrap());
|
||||
for case in 0..8 {
|
||||
let mut bad = r.clone();
|
||||
match case {
|
||||
0 => bad.predecessor = None,
|
||||
1 => bad.package_code = None,
|
||||
2 => bad.package_code = Some(MSI_PRODUCT_CODE.into()),
|
||||
3 => bad.upgrade_code = Uuid::new_v4().to_string(),
|
||||
4 => {
|
||||
bad.predecessor.as_mut().unwrap().product_code = MSI_UPGRADE_PRODUCT_CODE.into()
|
||||
}
|
||||
5 => bad.predecessor.as_mut().unwrap().payload_sha256 = "aa".repeat(32),
|
||||
6 => bad.postcondition.product_version = "1.2.0".into(),
|
||||
_ => bad.postcondition.payload_sha256 = MSI_PAYLOAD_10_SHA256.into(),
|
||||
};
|
||||
assert!(!bad.validate());
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#requires -Version 5.1
|
||||
<#
|
||||
Build-only, fixed MSI 1.0.0 fixture. Writes only a NEW private child directory.
|
||||
Build-only, fixed MSI1.0.0 or1.1.0 major-upgrade fixture. Writes only a NEW private child directory.
|
||||
Never calls InstallProduct/OpenPackage/msiexec, modifies installed products,
|
||||
services, execution policy, certificate trust or reboot state. No downloads.
|
||||
No upgrade/EXE package is authored by this version.
|
||||
1.1 removes only the exact known1.0 predecessor; no EXE/repair mode.
|
||||
|
||||
Primary API/format contracts:
|
||||
https://learn.microsoft.com/en-us/windows/win32/msi/installer-opendatabase
|
||||
@@ -17,7 +17,8 @@ https://learn.microsoft.com/en-us/windows/win32/msi/package-codes
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$OutputParent,
|
||||
[Guid]$CaseId=([Guid]::NewGuid())
|
||||
[Guid]$CaseId=([Guid]::NewGuid()),
|
||||
[ValidateSet('1.0.0','1.1.0')][string]$FixtureVersion='1.0.0'
|
||||
)
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference='Stop'
|
||||
@@ -25,14 +26,18 @@ $case=$null;$created=$false;$installer=$null;$database=$null;$summary=$null;$mak
|
||||
$product='{3F070B4B-9C08-4D65-BD41-13D81B884AEC}'
|
||||
$upgrade='{C9BF1FB8-E31D-4BD7-BA0D-AB46539BBBAA}'
|
||||
$component='{4D1CA80F-9AF8-4F54-B426-450AFBAFF92E}'
|
||||
$version='1.0.0'
|
||||
$version=$FixtureVersion
|
||||
$isUpgrade=$version -ceq '1.1.0'
|
||||
$oldProduct=$product
|
||||
if($isUpgrade){$product='{D42BD387-079B-4BBF-A134-0DA7B7A97011}'}
|
||||
$upgradeCondition='Installed OR (RMM_OLD_PRODUCTS = "{3F070B4B-9C08-4D65-BD41-13D81B884AEC}" AND RMM_ALL_PRODUCTS = "{3F070B4B-9C08-4D65-BD41-13D81B884AEC}")'
|
||||
# Product/family/component identities are fixed. Nonidentical MSI bytes must
|
||||
# have distinct PackageCodes, so each new authoring case gets its own code.
|
||||
$package='{'+([Guid]::NewGuid().ToString().ToUpperInvariant())+'}'
|
||||
$artifact=[Guid]::NewGuid().ToString()
|
||||
$report=[ordered]@{schema_version=1;case_id=$CaseId.ToString();completed=$false;stage='preflight';
|
||||
build_only=$true;native_installation_tested=$false;product_changes=$false;services_changed=$false;
|
||||
reboot_requested=$false;trust_changed=$false;downloads=$false;upgrade_authored=$false;
|
||||
reboot_requested=$false;trust_changed=$false;downloads=$false;upgrade_authored=$isUpgrade;
|
||||
product_code=$product;upgrade_code=$upgrade;component_code=$component;package_code=$package;version=$version}
|
||||
|
||||
function Require([bool]$Value,[string]$Code) {if (!$Value) {throw $Code}}
|
||||
@@ -169,7 +174,7 @@ try {
|
||||
$report.tools=$tools
|
||||
$report.stage='payload_and_cabinet'
|
||||
$payload=Join-Path $case 'msi-payload.txt'
|
||||
$payloadBytes=[Text.Encoding]::ASCII.GetBytes("RustDiscovery MSI fixture 1.0.0`r`n")
|
||||
$payloadBytes=[Text.Encoding]::ASCII.GetBytes("RustDiscovery MSI fixture $version`r`n")
|
||||
Write-New $payload $payloadBytes
|
||||
$ddf=Join-Path $case 'fixture.ddf'
|
||||
$ddfText=@"
|
||||
@@ -190,7 +195,7 @@ try {
|
||||
$cab=Join-Path $case 'fixture.cab';No-Reparse $cab
|
||||
Require ((Get-Item -LiteralPath $cab).Length -gt 0 -and (Get-Item -LiteralPath $cab).Length -le 65536) 'MSI_CABINET_LIMIT'
|
||||
$report.stage='database_authoring:com_activation'
|
||||
$msi=Join-Path $case 'RustDiscoveryFixture-1.0.0-x64.msi';Require (!(Test-Path -LiteralPath $msi)) 'MSI_OUTPUT_EXISTS'
|
||||
$msi=Join-Path $case ('RustDiscoveryFixture-'+$version+'-x64.msi');Require (!(Test-Path -LiteralPath $msi)) 'MSI_OUTPUT_EXISTS'
|
||||
$installer=New-Object -ComObject WindowsInstaller.Installer
|
||||
$report.stage='database_authoring:open_create'
|
||||
$database=Com-Method $installer 'OpenDatabase' @($msi,[int]3)
|
||||
@@ -205,9 +210,11 @@ try {
|
||||
InstallExecuteSequence='`Action` CHAR(72) NOT NULL, `Condition` CHAR(255), `Sequence` SHORT PRIMARY KEY `Action`'
|
||||
LaunchCondition='`Condition` CHAR(255) NOT NULL, `Description` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `Condition`'
|
||||
}
|
||||
if($isUpgrade){$tables.Upgrade='`UpgradeCode` CHAR(38) NOT NULL, `VersionMin` CHAR(20), `VersionMax` CHAR(20), `Language` CHAR(255), `Attributes` SHORT NOT NULL, `Remove` CHAR(255), `ActionProperty` CHAR(72) NOT NULL PRIMARY KEY `UpgradeCode`, `VersionMin`, `VersionMax`, `Language`, `Attributes`'}
|
||||
foreach ($table in $tables.Keys) {$report.stage='database_authoring:create_table:'+$table;Sql ('CREATE TABLE `'+$table+'` ('+$tables[$table]+')')}
|
||||
$report.stage='database_authoring:insert_rows'
|
||||
$properties=[ordered]@{ProductCode=$product;UpgradeCode=$upgrade;ProductVersion=$version;ProductLanguage='1033';ProductName='RustDiscovery MSI Fixture';Manufacturer='Ease Technologies';ALLUSERS='1';INSTALLLEVEL='1';REBOOT='ReallySuppress'}
|
||||
if($isUpgrade){$properties.SecureCustomProperties='RMM_ALL_PRODUCTS;RMM_OLD_PRODUCTS'}
|
||||
foreach ($key in $properties.Keys) {Sql ("INSERT INTO ``Property`` (``Property``,``Value``) VALUES ('$key','$($properties[$key])')")}
|
||||
Sql 'INSERT INTO `Directory` (`Directory`,`DefaultDir`) VALUES (''TARGETDIR'',''SourceDir'')'
|
||||
Sql 'INSERT INTO `Directory` (`Directory`,`Directory_Parent`,`DefaultDir`) VALUES (''ProgramFiles64Folder'',''TARGETDIR'',''.'')'
|
||||
@@ -218,8 +225,17 @@ try {
|
||||
Sql ("INSERT INTO ``File`` (``File``,``Component_``,``FileName``,``FileSize``,``Attributes``,``Sequence``) VALUES ('PayloadFile','PayloadComponent','MSIPAY~1.TXT|msi-payload.txt',$($payloadBytes.Length),16896,1)")
|
||||
Sql 'INSERT INTO `Media` (`DiskId`,`LastSequence`,`Cabinet`) VALUES (1,1,''#fixture.cab'')'
|
||||
Sql 'INSERT INTO `LaunchCondition` (`Condition`,`Description`) VALUES (''VersionNT64'',''This fixture requires 64-bit Windows.'')'
|
||||
if($isUpgrade){
|
||||
Sql ("INSERT INTO ``Upgrade`` (``UpgradeCode``,``VersionMin``,``VersionMax``,``Attributes``,``Remove``,``ActionProperty``) VALUES ('$upgrade','1.0.0','1.0.0',768,'ALL','RMM_OLD_PRODUCTS')")
|
||||
Sql ("INSERT INTO ``Upgrade`` (``UpgradeCode``,``VersionMin``,``Attributes``,``Remove``,``ActionProperty``) VALUES ('$upgrade','0.0.0',258,'ALL','RMM_ALL_PRODUCTS')")
|
||||
Sql ("INSERT INTO ``LaunchCondition`` (``Condition``,``Description``) VALUES ('$upgradeCondition','Only the exact approved fixture1.0 predecessor may be upgraded.')")
|
||||
}
|
||||
$sequence=[ordered]@{LaunchConditions=100;CostInitialize=800;FileCost=900;CostFinalize=1000;InstallValidate=1400;InstallInitialize=1500;ProcessComponents=1600;UnpublishFeatures=1800;RemoveFiles=3500;RemoveFolders=3600;CreateFolders=3700;InstallFiles=4000;RegisterUser=6000;RegisterProduct=6100;PublishFeatures=6300;PublishProduct=6400;InstallFinalize=6600}
|
||||
foreach ($action in $sequence.Keys) {Sql ("INSERT INTO ``InstallExecuteSequence`` (``Action``,``Sequence``) VALUES ('$action',$($sequence[$action]))")}
|
||||
if($isUpgrade){$sequence.FindRelatedProducts=25;$sequence.RemoveExistingProducts=1550}
|
||||
foreach ($action in $sequence.Keys) {
|
||||
if($action -ceq 'RemoveExistingProducts'){Sql ("INSERT INTO ``InstallExecuteSequence`` (``Action``,``Condition``,``Sequence``) VALUES ('$action','NOT Installed',$($sequence[$action]))")}
|
||||
else {Sql ("INSERT INTO ``InstallExecuteSequence`` (``Action``,``Sequence``) VALUES ('$action',$($sequence[$action]))")}
|
||||
}
|
||||
$view=Com-Method $database 'OpenView' @('INSERT INTO `_Streams` (`Name`,`Data`) VALUES (?,?)');$record=$null
|
||||
try {$record=Com-Method $installer 'CreateRecord' @([int]2);Com-Set $record 'StringData' @([int]1,'fixture.cab');[void](Com-Method $record 'SetStream' @([int]2,$cab));[void](Com-Method $view 'Execute' @($record));[void](Com-Method $view 'Close')}
|
||||
finally {Release-Com $record;Release-Com $view}
|
||||
@@ -236,7 +252,23 @@ try {
|
||||
foreach ($key in $properties.Keys) {$row=Rows ("SELECT ``Value`` FROM ``Property`` WHERE ``Property``='$key'");Require ($row.Count -eq 1 -and $row[0][0] -ceq $properties[$key]) 'MSI_PROPERTY_READBACK'}
|
||||
$allTables=Rows 'SELECT `Name` FROM `_Tables`';$names=@($allTables|ForEach-Object {$_[0]})
|
||||
Require ($names.Count -eq $tables.Count -and @($names|Where-Object {$_ -notin $tables.Keys}).Count -eq 0) 'MSI_UNEXPECTED_TABLE'
|
||||
Require ('CustomAction' -notin $names -and 'Upgrade' -notin $names -and 'Registry' -notin $names -and 'ServiceInstall' -notin $names) 'MSI_FORBIDDEN_TABLE'
|
||||
Require ('CustomAction' -notin $names -and 'Registry' -notin $names -and 'ServiceInstall' -notin $names -and ($isUpgrade -or 'Upgrade' -notin $names)) 'MSI_FORBIDDEN_TABLE'
|
||||
# Independently read committed upgrade/sequence metadata; no install APIs.
|
||||
foreach($action in $sequence.Keys){
|
||||
$row=Rows ("SELECT ``Condition``,``Sequence`` FROM ``InstallExecuteSequence`` WHERE ``Action``='$action'")
|
||||
$condition=if($action -ceq 'RemoveExistingProducts'){'NOT Installed'}else{''}
|
||||
Require ($row.Count -eq 1 -and $row[0][0] -ceq $condition -and $row[0][1] -ceq [string]$sequence[$action]) 'MSI_SEQUENCE_READBACK'
|
||||
}
|
||||
if($isUpgrade){
|
||||
$rows=Rows 'SELECT `UpgradeCode`,`VersionMin`,`VersionMax`,`Attributes`,`Remove`,`ActionProperty` FROM `Upgrade` WHERE `Language` IS NULL ORDER BY `ActionProperty`'
|
||||
Require ($rows.Count -eq 2) 'MSI_UPGRADE_ROW_COUNT'
|
||||
$expected=@(@($upgrade,'0.0.0','','258','ALL','RMM_ALL_PRODUCTS'),@($upgrade,'1.0.0','1.0.0','768','ALL','RMM_OLD_PRODUCTS'))
|
||||
for($i=0;$i -lt 2;$i++){for($j=0;$j -lt 6;$j++){Require ($rows[$i][$j] -ceq $expected[$i][$j]) 'MSI_UPGRADE_ROW_READBACK'}}
|
||||
$nullMax=Rows 'SELECT `ActionProperty` FROM `Upgrade` WHERE `VersionMax` IS NULL'
|
||||
Require ($nullMax.Count -eq 1 -and $nullMax[0][0] -ceq 'RMM_ALL_PRODUCTS') 'MSI_UPGRADE_NULL_MAX_READBACK'
|
||||
$launch=Rows ("SELECT ``Description`` FROM ``LaunchCondition`` WHERE ``Condition``='$upgradeCondition'")
|
||||
Require ($launch.Count -eq 1 -and $launch[0][0] -ceq 'Only the exact approved fixture1.0 predecessor may be upgraded.' -and $readback.LaunchCondition.Count -eq 2) 'MSI_UPGRADE_LAUNCH_READBACK'
|
||||
}
|
||||
$summary=Com-Get $database 'SummaryInformation' @([int]0)
|
||||
Require ((Com-Get $summary 'Property' @([int]7)) -ceq 'x64;1033' -and (Com-Get $summary 'Property' @([int]9)) -ceq $package -and [int](Com-Get $summary 'Property' @([int]15)) -eq 2) 'MSI_SUMMARY_READBACK'
|
||||
Release-Com $summary;$summary=$null
|
||||
@@ -253,12 +285,17 @@ try {
|
||||
$extra=Com-Method $view 'Fetch';Require ($null -eq $extra) 'MSI_DUPLICATE_CAB_STREAM';[void](Com-Method $view 'Close')
|
||||
} finally {Release-Com $record;Release-Com $view}
|
||||
Release-Com $database;$database=$null
|
||||
$recipe=[ordered]@{schema_version=1;recipe_id='rmm-windows-msi-fixture-install-1.0';recipe_version='1';platform='windows';upgrade_code=$upgrade;architecture='x64';context='machine';command_profile='fixture_quiet_no_reboot_v1';artifact=[ordered]@{artifact_id=$artifact;sha256=(Hash $msi);bytes=$length};postcondition=[ordered]@{product_code=$product;product_version=$version;payload_path='C:\Program Files\RustDiscoveryFixtures\msi-payload.txt';payload_sha256=(Hash $payload);payload_bytes=$payloadBytes.Length};no_reboot=$true}
|
||||
$recipe=[ordered]@{schema_version=1;recipe_id=$(if($isUpgrade){'rmm-windows-msi-fixture-upgrade-1.1'}else{'rmm-windows-msi-fixture-install-1.0'});recipe_version='1';platform='windows';upgrade_code=$upgrade;architecture='x64';context='machine';command_profile='fixture_quiet_no_reboot_v1';artifact=[ordered]@{artifact_id=$artifact;sha256=(Hash $msi);bytes=$length};postcondition=[ordered]@{product_code=$product;product_version=$version;payload_path='C:\Program Files\RustDiscoveryFixtures\msi-payload.txt';payload_sha256=(Hash $payload);payload_bytes=$payloadBytes.Length};no_reboot=$true}
|
||||
if($isUpgrade){
|
||||
$recipe.package_code=$package
|
||||
$oldBytes=[Text.Encoding]::ASCII.GetBytes("RustDiscovery MSI fixture 1.0.0`r`n")
|
||||
$recipe.predecessor=[ordered]@{product_code=$oldProduct;product_version='1.0.0';payload_path=$recipe.postcondition.payload_path;payload_sha256=(Hash-Bytes $oldBytes);payload_bytes=$oldBytes.Length}
|
||||
}
|
||||
$recipeJson=$recipe|ConvertTo-Json -Depth 12 -Compress
|
||||
Write-New (Join-Path $case 'recipe.json') ([Text.Encoding]::UTF8.GetBytes($recipeJson))
|
||||
Write-Json (Join-Path $case 'tables.json') $readback
|
||||
$report.artifact=[ordered]@{path=$msi;sha256=(Hash $msi);bytes=$length;artifact_id_proposal=$artifact}
|
||||
$report.payload=[ordered]@{sha256=(Hash $payload);bytes=$payloadBytes.Length;content_ascii="RustDiscovery MSI fixture 1.0.0`r`n";installed_path=$recipe.postcondition.payload_path}
|
||||
$report.payload=[ordered]@{sha256=(Hash $payload);bytes=$payloadBytes.Length;content_ascii="RustDiscovery MSI fixture $version`r`n";installed_path=$recipe.postcondition.payload_path}
|
||||
$report.cabinet=[ordered]@{sha256=(Hash $cab);bytes=(Get-Item -LiteralPath $cab).Length;embedded_hash_verified=$true;stream='fixture.cab'}
|
||||
$report.tables_sha256=Hash (Join-Path $case 'tables.json');$report.table_names=$names
|
||||
$report.resolved_recipe=[ordered]@{recipe=$recipe;recipe_sha256=(Hash (Join-Path $case 'recipe.json'))}
|
||||
@@ -267,7 +304,7 @@ try {
|
||||
Require ((Hash $PSCommandPath) -ceq $report.builder_sha256) 'MSI_BUILDER_CHANGED'
|
||||
$report.completed=$true;$report.stage='authored_and_read_back_not_installed'
|
||||
Write-Json (Join-Path $case 'result.json') $report
|
||||
[ordered]@{completed=$true;build_only=$true;report_path=(Join-Path $case 'result.json');artifact=$report.artifact;native_installation_tested=$false;upgrade_authored=$false}|ConvertTo-Json -Depth 5
|
||||
[ordered]@{completed=$true;build_only=$true;report_path=(Join-Path $case 'result.json');artifact=$report.artifact;native_installation_tested=$false;upgrade_authored=$isUpgrade}|ConvertTo-Json -Depth 5
|
||||
} catch {
|
||||
$report.completed=$false;$report.error_type=$_.Exception.GetType().FullName;$report.error_hresult=$_.Exception.HResult
|
||||
$report.error_line=$_.InvocationInfo.ScriptLineNumber
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# Eigene MSI-Fixture1.1: Quellenstand
|
||||
|
||||
Stand2026-11-14: drei unexportierte Quellen im isolierten Branch
|
||||
`codex/windows-msi-provider` erweitert und unabhängig geprüft. Keine Änderung
|
||||
an produktiven Cargo-/Action-/Helper-/Serverpfaden und keine Capability oder
|
||||
Paketfreigabe. MSI1.1 wurde noch nicht gebaut, registriert oder installiert.
|
||||
Der tatsächliche alte MSI1.0-Artefaktbeleg bleibt unverändert erhalten.
|
||||
|
||||
Neues festes Rezept `rmm-windows-msi-fixture-upgrade-1.1`, ProductCode
|
||||
`{D42BD387-079B-4BBF-A134-0DA7B7A97011}`, gleicher UpgradeCode wie1.0.
|
||||
Das vollständige Rezept bindet zusätzlich den konkreten neuen PackageCode und
|
||||
genau den bekannten1.0-Vorgänger samt Version/33-Byte-Nutzdateihash. Alte1.0-
|
||||
Rezeptbytes bleiben durch am Ende angefügte, bei None ausgelassene Felder gleich.
|
||||
Kein Fresh1.1, Repair, Downgrade oder beliebiger Vorgänger.
|
||||
|
||||
Provider und Builder verlangen feste Upgrade-Tabelle, LaunchCondition und
|
||||
Ausführungssequenz, keine CustomActions. Vorheriger Machine-Produktzustand,
|
||||
Familie und Nutzdatei müssen passen. Nachher1.1 exakt installiert und1.0 entfernt;
|
||||
ein eigener Noop verlangt denselben konkreten1.1-PackageCode. Ein anderes neu
|
||||
gebautes1.1-MSI erhält keine implizite Neuinstallationserlaubnis.
|
||||
|
||||
Zwei Quellenfehler wurden korrigiert: spät beobachteter Installerexit oder
|
||||
Nachzustand wird nicht rückwirkend erfolgreich; zusätzlich beginnt das eine
|
||||
Verifikations-/Installationsbudget vor allen synchronen Prüfungen und umfasst
|
||||
auch Noop samt frischem Fence und erneuter Abbruchprüfung. Timeout bleibt
|
||||
Unknown, kein globales Installerkillen oder Retry. `Run::Noop` kann dadurch
|
||||
auch eine Unknown-Observation enthalten; spätere Aufrufer müssen deren State
|
||||
auswerten und dürfen die Enumvariante nicht pauschal als Erfolg behandeln.
|
||||
|
||||
Tatsächlich lokal bestanden: fünf gezielte Harness-Tests ohne Skips,
|
||||
Linux-/WindowsGNU-Harness-Clippy mit Warnungen als Fehler und PowerShell-AST.
|
||||
Der Harness bindet explizit diesen Worktree und exportiert keine Produktmodule.
|
||||
Originaler Quellenbeleg `devstate/windows-package-msi11/local-source-qualification.json`
|
||||
(`0b562dc2…`) bleibt historisch; enger Folgebeleg
|
||||
`noop-deadline-qualification.json` (`23ed1175…`) bindet den korrigierten Stand.
|
||||
Finale Packagequelle `617b2a73…`, Domain `070a8dfa…`, Builder `6365ac16…`.
|
||||
Im Builder wurde anschließend nur ein überflüssiges Leerzeichen entfernt:
|
||||
PowerShell-Parse erfolgreich und vollständige Tokenliste vorher/nachher
|
||||
identisch; vorheriger Builderquellenbeleg `2d63eaba…` bleibt historisch.
|
||||
|
||||
Offen sind Linux-first-Vertragsintegration, Tenantkatalog, geschützter
|
||||
Artefakttransport/Cache, typisierte SYSTEM-Paketerlaubnis und tatsächliche
|
||||
WebUI-genehmigte Installation/Upgrade/Noops auf der Windows-VM. Lokale Tests
|
||||
und Crossbuilds sind keine native Installerabnahme.
|
||||
Reference in New Issue
Block a user