From 74fff68c4635d894482c74d039e6d402d837e791 Mon Sep 17 00:00:00 2001 From: Pavel Isaev Date: Sun, 8 Nov 2026 05:42:39 +0300 Subject: [PATCH] Handle OSTree alias timestamps in strict self-check --- src/self_check.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/self_check.rs b/src/self_check.rs index 188e0ac..6aeefce 100644 --- a/src/self_check.rs +++ b/src/self_check.rs @@ -1,14 +1,38 @@ use std::{fs, os::unix::fs::MetadataExt, process::Command}; +// OSTree does not retain symlink mtimes. Accept only that diagnostic for +// these package-owned aliases, after independently verifying each link. +fn ostree_link_times(stderr: &str) -> bool { + let links = [ + ("/usr/bin/archipelagod", "archipelago"), + ("/usr/lib/systemd/system/archipelago-daemon.service", "archipelagod.service"), + ]; + let lines: Vec<_> = stderr.lines().collect(); + !lines.is_empty() && lines.iter().all(|line| links.iter().any(|(path, target)| { + *line == format!("warning: archipelago: {path} (Modification time mismatch)") + && fs::symlink_metadata(path).is_ok_and(|m| m.is_symlink() + && m.uid() == 0 && m.gid() == 0 && m.mode() & 0o7777 == 0o777) + && fs::read_link(path).is_ok_and(|p| p == std::path::Path::new(target)) + })) +} + pub fn check() -> Result<(), String> { let owner = Command::new("pacman").args(["-Qoq", "/usr/bin/archipelago"]) .output().map_err(|e| e.to_string())?; if !owner.status.success() || owner.stdout != b"archipelago\n" { return Err("binary is not owned by the archipelago package".into()); } - let status = Command::new("pacman").args(["-Qkk", "archipelago"]) - .status().map_err(|e| e.to_string())?; - if !status.success() { return Err("package integrity check failed".into()); } + let result = Command::new("pacman").env("LC_ALL", "C").args(["-Qkk", "archipelago"]) + .output().map_err(|e| e.to_string())?; + print!("{}", String::from_utf8_lossy(&result.stdout)); + eprint!("{}", String::from_utf8_lossy(&result.stderr)); + if !result.status.success() { + if result.status.code() != Some(1) || !std::path::Path::new("/run/ostree-booted").exists() + || !ostree_link_times(&String::from_utf8_lossy(&result.stderr)) { + return Err("package integrity check failed".into()); + } + println!("OSTree symlink timestamps differ; alias targets, types, owners and modes verified"); + } let manifest = fs::read_to_string("/usr/share/archipelago/permissions.tsv") .map_err(|e| e.to_string())?; let mut binary_seen = false;