Skip to content

Commit b5fb623

Browse files
committed
Merge branch 'sk/mingw-owner-check-error-message-improvement'
In addition to (rather cryptic) Security Identifiers, show username and domain in the error message when we barf on mismatch between the Git directory and the current user on Windows. * sk/mingw-owner-check-error-message-improvement: mingw: give more details about unsafe directory's ownership
2 parents 22695a3 + f755e09 commit b5fb623

File tree

1 file changed

+57
-13
lines changed

1 file changed

+57
-13
lines changed

compat/mingw.c

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,6 +2684,30 @@ static PSID get_current_user_sid(void)
26842684
return result;
26852685
}
26862686

2687+
static BOOL user_sid_to_user_name(PSID sid, LPSTR *str)
2688+
{
2689+
SID_NAME_USE pe_use;
2690+
DWORD len_user = 0, len_domain = 0;
2691+
BOOL translate_sid_to_user;
2692+
2693+
/*
2694+
* returns only FALSE, because the string pointers are NULL
2695+
*/
2696+
LookupAccountSidA(NULL, sid, NULL, &len_user, NULL, &len_domain,
2697+
&pe_use);
2698+
/*
2699+
* Alloc needed space of the strings
2700+
*/
2701+
ALLOC_ARRAY((*str), (size_t)len_domain + (size_t)len_user);
2702+
translate_sid_to_user = LookupAccountSidA(NULL, sid,
2703+
(*str) + len_domain, &len_user, *str, &len_domain, &pe_use);
2704+
if (!translate_sid_to_user)
2705+
FREE_AND_NULL(*str);
2706+
else
2707+
(*str)[len_domain] = '/';
2708+
return translate_sid_to_user;
2709+
}
2710+
26872711
static int acls_supported(const char *path)
26882712
{
26892713
size_t offset = offset_1st_component(path);
@@ -2765,27 +2789,47 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
27652789
strbuf_addf(report, "'%s' is on a file system that does "
27662790
"not record ownership\n", path);
27672791
} else if (report) {
2768-
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
2792+
LPSTR str1, str2, str3, str4, to_free1 = NULL,
2793+
to_free3 = NULL, to_local_free2 = NULL,
2794+
to_local_free4 = NULL;
27692795

2770-
if (ConvertSidToStringSidA(sid, &str1))
2796+
if (user_sid_to_user_name(sid, &str1))
27712797
to_free1 = str1;
27722798
else
27732799
str1 = "(inconvertible)";
2774-
2775-
if (!current_user_sid)
2776-
str2 = "(none)";
2777-
else if (!IsValidSid(current_user_sid))
2778-
str2 = "(invalid)";
2779-
else if (ConvertSidToStringSidA(current_user_sid, &str2))
2780-
to_free2 = str2;
2800+
if (ConvertSidToStringSidA(sid, &str2))
2801+
to_local_free2 = str2;
27812802
else
27822803
str2 = "(inconvertible)";
2804+
2805+
if (!current_user_sid) {
2806+
str3 = "(none)";
2807+
str4 = "(none)";
2808+
}
2809+
else if (!IsValidSid(current_user_sid)) {
2810+
str3 = "(invalid)";
2811+
str4 = "(invalid)";
2812+
} else {
2813+
if (user_sid_to_user_name(current_user_sid,
2814+
&str3))
2815+
to_free3 = str3;
2816+
else
2817+
str3 = "(inconvertible)";
2818+
if (ConvertSidToStringSidA(current_user_sid,
2819+
&str4))
2820+
to_local_free4 = str4;
2821+
else
2822+
str4 = "(inconvertible)";
2823+
}
27832824
strbuf_addf(report,
27842825
"'%s' is owned by:\n"
2785-
"\t'%s'\nbut the current user is:\n"
2786-
"\t'%s'\n", path, str1, str2);
2787-
LocalFree(to_free1);
2788-
LocalFree(to_free2);
2826+
"\t%s (%s)\nbut the current user is:\n"
2827+
"\t%s (%s)\n",
2828+
path, str1, str2, str3, str4);
2829+
free(to_free1);
2830+
LocalFree(to_local_free2);
2831+
free(to_free3);
2832+
LocalFree(to_local_free4);
27892833
}
27902834
}
27912835

0 commit comments

Comments
 (0)