Skip to content

Commit c690b46

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Allow debugging unsafe directories' ownership
When Git refuses to use an existing repository because it is owned by someone else than the current user, it can be a bit tricky on Windows to figure out what is going on. Let's help with that by offering some more information via the environment variable `GIT_TEST_DEBUG_UNSAFE_DIRECTORIES`. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7d83db7 commit c690b46

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Documentation/config/safe.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ directory was listed in the `safe.directory` list. If `safe.directory=*`
2626
is set in system config and you want to re-enable this protection, then
2727
initialize your list with an empty value before listing the repositories
2828
that you deem safe.
29+
+
30+
Due to the permission model on Windows where ACLs are used instead of
31+
Unix' simpler permission model, it can be a bit tricky to figure out why
32+
a directory is considered unsafe. To help with this, Git will provide
33+
more detailed information when the environment variable
34+
`GIT_TEST_DEBUG_UNSAFE_DIRECTORIES` is set to `true`.

compat/mingw.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "../git-compat-util.h"
22
#include "win32.h"
33
#include <aclapi.h>
4+
#include <sddl.h>
45
#include <conio.h>
56
#include <wchar.h>
67
#include <winioctl.h>
@@ -3521,6 +3522,26 @@ int is_path_owned_by_current_sid(const char *path)
35213522
IsValidSid(current_user_sid) &&
35223523
EqualSid(sid, current_user_sid))
35233524
result = 1;
3525+
else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
3526+
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
3527+
3528+
if (ConvertSidToStringSidA(sid, &str1))
3529+
to_free1 = str1;
3530+
else
3531+
str1 = "(inconvertible)";
3532+
3533+
if (!current_user_sid)
3534+
str2 = "(none)";
3535+
else if (!IsValidSid(current_user_sid))
3536+
str2 = "(invalid)";
3537+
else if (ConvertSidToStringSidA(current_user_sid, &str2))
3538+
to_free2 = str2;
3539+
else
3540+
str2 = "(inconvertible)";
3541+
warning("'%s' is owned by:\n\t'%s'\nbut the current user is:\n\t'%s'", path, str1, str2);
3542+
LocalFree(to_free1);
3543+
LocalFree(to_free2);
3544+
}
35243545
}
35253546

35263547
/*

0 commit comments

Comments
 (0)