Closed
Description
As part of my work on gitoxide
to incorporate the additional git
security protocols I am trying to implement an ownership check for windows to assure that gitoxide will not fully trust repositories that aren't owned by the user executing the process.
This is the idea:
pub fn is_path_owned_by_current_user(path: Cow<'_, Path>) -> std::io::Result<bool> {
fn from_path(path: Cow<'_, Path>) -> std::io::Result<u32> {
use std::os::unix::fs::MetadataExt;
let meta = std::fs::symlink_metadata(path)?;
Ok(meta.uid())
}
fn from_process() -> std::io::Result<u32> {
// SAFETY: there is no documented possibility for failure
#[allow(unsafe_code)]
let uid = unsafe { libc::geteuid() };
Ok(uid)
}
Ok(from_path(path)? == from_process()?)
}
However, when trying to implement the same for windows very much similarly as git
itself the following test does not succeed despite hours of trying.
let dir = tempfile::tempdir()?;
assert!(git_sec::identity::is_path_owned_by_current_user(dir.path().into())?);
I am reaching out in the hopes that someone can point me to the issue with the code causing the failure. It's terrible, but maybe there is a way to get it to work nonetheless.
Thanks for your consideration.