From: Ian Jackson Date: Mon, 7 Jun 2021 13:41:31 +0000 (+0100) Subject: ssh keys update: Allow setting up if static is hardlinked to real X-Git-Tag: otter-0.7.0~47 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1136f74fd989381345cd57ad33bf4b835799714a;p=otter.git ssh keys update: Allow setting up if static is hardlinked to real Signed-off-by: Ian Jackson --- diff --git a/src/prelude.rs b/src/prelude.rs index 4d49923c..138447b1 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -33,10 +33,10 @@ pub use std::iter; pub use std::iter::repeat_with; pub use std::marker::PhantomData; pub use std::num::{NonZeroUsize, TryFromIntError, Wrapping}; -pub use std::os::linux::fs::MetadataExt; // todo why linux for st_mode?? +pub use std::os::linux::fs::MetadataExt as _; // todo why linux for st_mode?? pub use std::os::unix; pub use std::os::unix::ffi::OsStrExt; -pub use std::os::unix::fs::OpenOptionsExt; +pub use std::os::unix::fs::{MetadataExt, OpenOptionsExt}; pub use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd}; pub use std::os::unix::net::UnixStream; pub use std::os::unix::process::{CommandExt, ExitStatusExt}; diff --git a/src/sshkeys.rs b/src/sshkeys.rs index 8044b3b0..6f9d6373 100644 --- a/src/sshkeys.rs +++ b/src/sshkeys.rs @@ -481,17 +481,24 @@ impl Global { }; (||{ - let f = match File::open(path) { + let mut f = match File::open(path) { Err(e) if e.kind() == ErrorKind::NotFound => return Ok(()), x => x, }.context("open")?; - let l = BufReader::new(f).lines().next() + let l = BufReader::new(&mut f).lines().next() .ok_or_else(|| anyhow!("no first line!"))? .context("read first line")?; if l == MAGIC_BANNER { return Ok(()); } + if let Some(staticf) = &staticf { + let devino = |f: &File| f.metadata().map(|m| (m.dev(), m.ino())); + if devino(staticf).context("fstat static auth keys")? == + devino(&f).context("fstat existing auth keys")? { + return Ok(()); + } + } Err(anyhow!( "first line is not as expected (manually written/edited?)" ))