mirror of
https://github.com/git-for-windows/git.git
synced 2026-03-30 09:37:41 -05:00
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 <johannes.schindelin@gmx.de>
This commit is contained in:
@@ -40,3 +40,9 @@ which id the original user has.
|
||||
If that is not what you would prefer and want git to only trust
|
||||
repositories that are owned by root instead, then you can remove
|
||||
the `SUDO_UID` variable from root's environment before invoking git.
|
||||
+
|
||||
Due to the permission model on Windows where ACLs are used instead of
|
||||
Unix' simpler permission model, it can be a bit tricky to figure out why
|
||||
a directory is considered unsafe. To help with this, Git will provide
|
||||
more detailed information when the environment variable
|
||||
`GIT_TEST_DEBUG_UNSAFE_DIRECTORIES` is set to `true`.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "../git-compat-util.h"
|
||||
#include "win32.h"
|
||||
#include <aclapi.h>
|
||||
#include <sddl.h>
|
||||
#include <conio.h>
|
||||
#include <wchar.h>
|
||||
#include "../strbuf.h"
|
||||
@@ -2720,6 +2721,26 @@ int is_path_owned_by_current_sid(const char *path)
|
||||
IsValidSid(current_user_sid) &&
|
||||
EqualSid(sid, current_user_sid))
|
||||
result = 1;
|
||||
else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
|
||||
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
|
||||
|
||||
if (ConvertSidToStringSidA(sid, &str1))
|
||||
to_free1 = str1;
|
||||
else
|
||||
str1 = "(inconvertible)";
|
||||
|
||||
if (!current_user_sid)
|
||||
str2 = "(none)";
|
||||
else if (!IsValidSid(current_user_sid))
|
||||
str2 = "(invalid)";
|
||||
else if (ConvertSidToStringSidA(current_user_sid, &str2))
|
||||
to_free2 = str2;
|
||||
else
|
||||
str2 = "(inconvertible)";
|
||||
warning("'%s' is owned by:\n\t'%s'\nbut the current user is:\n\t'%s'", path, str1, str2);
|
||||
LocalFree(to_free1);
|
||||
LocalFree(to_free2);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user