Skip to content

[Cry for help by gitoxide]: Why can this code not determine that the file it just created is indeed owned by it? #1697

Closed
@Byron

Description

@Byron

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions