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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Aug 8, 2022 at 13:27 UTC e883e04b68ba7393029bcbeaa2aacb3dff5d3fbd
1 file changed +24
compat/mingw.c
+24
@@ -1,6 +1,7 @@
1 #include "../git-compat-util.h"
2 #include "win32.h"
3 #include <aclapi.h>
4 +#include <sddl.h>
5 #include <conio.h>
6 #include <wchar.h>
7 #include "../strbuf.h"
@@ -2720,6 +2721,29 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
2721 IsValidSid(current_user_sid) &&
2722 EqualSid(sid, current_user_sid))
2723 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 + }
2747 }
2748
2749 /*