Handle OSTree alias timestamps in strict self-check
This commit is contained in:
parent
8d15e1a08d
commit
74fff68c46
1 changed files with 27 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue