Skip to content

Commit d9e5c63

Browse files
committed
mingw: be more informative when ownership check fails on FAT32
The FAT file system has no concept of ACLs. Therefore, it cannot store any ownership information anyway, and the `GetNamedSecurityInfoW()` call pretends that everything is owned "by the world". Let's special-case that scenario and tell the user what's going on, at least when they set `GIT_TEST_DEBUG_UNSAFE_DIRECTORIES`. This addresses #3886 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 5a4c120 commit d9e5c63

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

compat/mingw.c

+24-1
Original file line numberDiff line numberDiff line change
@@ -2674,6 +2674,22 @@ static PSID get_current_user_sid(void)
26742674
return result;
26752675
}
26762676

2677+
static int acls_supported(const char *path)
2678+
{
2679+
size_t offset = offset_1st_component(path);
2680+
WCHAR wroot[MAX_PATH];
2681+
DWORD file_system_flags;
2682+
2683+
if (offset &&
2684+
xutftowcs_path_ex(wroot, path, MAX_PATH, offset,
2685+
MAX_PATH, 0) > 0 &&
2686+
GetVolumeInformationW(wroot, NULL, 0, NULL, NULL,
2687+
&file_system_flags, NULL, 0))
2688+
return !!(file_system_flags & FILE_PERSISTENT_ACLS);
2689+
2690+
return 0;
2691+
}
2692+
26772693
int is_path_owned_by_current_sid(const char *path)
26782694
{
26792695
WCHAR wpath[MAX_PATH];
@@ -2731,7 +2747,14 @@ int is_path_owned_by_current_sid(const char *path)
27312747
* okay, too.
27322748
*/
27332749
result = 1;
2734-
else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
2750+
else if (IsWellKnownSid(sid, WinWorldSid) &&
2751+
git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0) &&
2752+
!acls_supported(path)) {
2753+
/*
2754+
* On FAT32 volumes, ownership is not actually recorded.
2755+
*/
2756+
warning("'%s' is on a file system that does not record ownership", path);
2757+
} else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
27352758
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
27362759

27372760
if (ConvertSidToStringSidA(sid, &str1))

0 commit comments

Comments
 (0)