From bdc77d1d685be9c10b88abb281a42bc620548595 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 2 Mar 2022 11:06:24 +0100 Subject: Add a function to determine whether a path is owned by the current user This function will be used in the next commit to prevent `setup_git_directory()` from discovering a repository in a directory that is owned by someone other than the current user. Note: We cannot simply use `st.st_uid` on Windows just like we do on Linux and other Unix-like platforms: according to https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions this field is always zero on Windows (because Windows' idea of a user ID does not fit into a single numerical value). Therefore, we have to do something a little involved to replicate the same functionality there. Also note: On Windows, a user's home directory is not actually owned by said user, but by the administrator. For all practical purposes, it is under the user's control, though, therefore we pretend that it is owned by the user. Signed-off-by: Johannes Schindelin --- compat/mingw.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'compat/mingw.h') diff --git a/compat/mingw.h b/compat/mingw.h index af8eddd73e..f6bab548f4 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -452,6 +452,13 @@ char *mingw_query_user_email(void); #include #endif +/** + * Verifies that the specified path is owned by the user running the + * current process. + */ +int is_path_owned_by_current_sid(const char *path); +#define is_path_owned_by_current_user is_path_owned_by_current_sid + /** * Verifies that the given path is a valid one on Windows. * -- cgit 1.2.3-korg