Skip to content

Commit e883e04

Browse files
dschogitster
authored andcommitted
mingw: provide details about 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 providing more detailed information. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 17d3883 commit e883e04

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

compat/mingw.c

Lines changed: 24 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,29 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
27202721
IsValidSid(current_user_sid) &&
27212722
EqualSid(sid, current_user_sid))
27222723
result = 1;
2724+
else if (report) {
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+
strbuf_addf(report,
2741+
"'%s' is owned by:\n"
2742+
"\t'%s'\nbut the current user is:\n"
2743+
"\t'%s'\n", path, str1, str2);
2744+
LocalFree(to_free1);
2745+
LocalFree(to_free2);
2746+
}
27232747
}
27242748

27252749
/*

0 commit comments

Comments
 (0)