Skip to content

Commit 00d566e

Browse files
committed
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 676736f commit 00d566e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Documentation/config/safe.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ is running as 'root' in a non Windows platform that provides sudo,
3333
however, git checks the SUDO_UID environment variable that sudo creates
3434
and will allow access to the uid recorded as its value in addition to
3535
the id from 'root'.
36+
+
3637
This is to make it easy to perform a common sequence during installation
3738
"make && sudo make install". A git process running under 'sudo' runs as
3839
'root' but the 'sudo' command exports the environment variable to record
3940
which id the original user has.
41+
+
4042
If that is not what you would prefer and want git to only trust
4143
repositories that are owned by root instead, then you can remove
4244
the `SUDO_UID` variable from root's environment before invoking git.
45+
+
46+
Due to the permission model on Windows where ACLs are used instead of
47+
Unix' simpler permission model, it can be a bit tricky to figure out why
48+
a directory is considered unsafe. To help with this, Git will provide
49+
more detailed information when the environment variable
50+
`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 "../strbuf.h"
@@ -2720,6 +2721,26 @@ int is_path_owned_by_current_sid(const char *path)
27202721
IsValidSid(current_user_sid) &&
27212722
EqualSid(sid, current_user_sid))
27222723
result = 1;
2724+
else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
2725+
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
2726+
2727+
if (ConvertSidToStringSidA(sid, &str1))
2728+
to_free1 = str1;
2729+
else
2730+
str1 = "(inconvertible)";
2731+
2732+
if (!current_user_sid)
2733+
str2 = "(none)";
2734+
else if (!IsValidSid(current_user_sid))
2735+
str2 = "(invalid)";
2736+
else if (ConvertSidToStringSidA(current_user_sid, &str2))
2737+
to_free2 = str2;
2738+
else
2739+
str2 = "(inconvertible)";
2740+
warning("'%s' is owned by:\n\t'%s'\nbut the current user is:\n\t'%s'", path, str1, str2);
2741+
LocalFree(to_free1);
2742+
LocalFree(to_free2);
2743+
}
27232744
}
27242745

27252746
/*

0 commit comments

Comments
 (0)