Skip to content

Commit f755e09

Browse files
soekklegitster
authored andcommitted
mingw: give more details about unsafe directory's ownership
Add domain/username in error message, if owner sid of repository and user sid are not equal on windows systems. Old error message: ''' fatal: detected dubious ownership in repository at 'C:/Users/test/source/repos/git' 'C:/Users/test/source/repos/git' is owned by: 'S-1-5-21-571067702-4104414259-3379520149-500' but the current user is: 'S-1-5-21-571067702-4104414259-3379520149-1001' To add an exception for this directory, call: git config --global --add safe.directory C:/Users/test/source/repos/git ''' New error message: ''' fatal: detected dubious ownership in repository at 'C:/Users/test/source/repos/git' 'C:/Users/test/source/repos/git' is owned by: DESKTOP-L78JVA6/Administrator (S-1-5-21-571067702-4104414259-3379520149-500) but the current user is: DESKTOP-L78JVA6/test (S-1-5-21-571067702-4104414259-3379520149-1001) To add an exception for this directory, call: git config --global --add safe.directory C:/Users/test/source/repos/git ''' Signed-off-by: Sören Krecker <[email protected]> Acked-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec58344 commit f755e09

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
@@ -2671,6 +2671,30 @@ static PSID get_current_user_sid(void)
26712671
return result;
26722672
}
26732673

2674+
static BOOL user_sid_to_user_name(PSID sid, LPSTR *str)
2675+
{
2676+
SID_NAME_USE pe_use;
2677+
DWORD len_user = 0, len_domain = 0;
2678+
BOOL translate_sid_to_user;
2679+
2680+
/*
2681+
* returns only FALSE, because the string pointers are NULL
2682+
*/
2683+
LookupAccountSidA(NULL, sid, NULL, &len_user, NULL, &len_domain,
2684+
&pe_use);
2685+
/*
2686+
* Alloc needed space of the strings
2687+
*/
2688+
ALLOC_ARRAY((*str), (size_t)len_domain + (size_t)len_user);
2689+
translate_sid_to_user = LookupAccountSidA(NULL, sid,
2690+
(*str) + len_domain, &len_user, *str, &len_domain, &pe_use);
2691+
if (!translate_sid_to_user)
2692+
FREE_AND_NULL(*str);
2693+
else
2694+
(*str)[len_domain] = '/';
2695+
return translate_sid_to_user;
2696+
}
2697+
26742698
static int acls_supported(const char *path)
26752699
{
26762700
size_t offset = offset_1st_component(path);
@@ -2752,27 +2776,47 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
27522776
strbuf_addf(report, "'%s' is on a file system that does"
27532777
"not record ownership\n", path);
27542778
} else if (report) {
2755-
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
2779+
LPSTR str1, str2, str3, str4, to_free1 = NULL,
2780+
to_free3 = NULL, to_local_free2 = NULL,
2781+
to_local_free4 = NULL;
27562782

2757-
if (ConvertSidToStringSidA(sid, &str1))
2783+
if (user_sid_to_user_name(sid, &str1))
27582784
to_free1 = str1;
27592785
else
27602786
str1 = "(inconvertible)";
2761-
2762-
if (!current_user_sid)
2763-
str2 = "(none)";
2764-
else if (!IsValidSid(current_user_sid))
2765-
str2 = "(invalid)";
2766-
else if (ConvertSidToStringSidA(current_user_sid, &str2))
2767-
to_free2 = str2;
2787+
if (ConvertSidToStringSidA(sid, &str2))
2788+
to_local_free2 = str2;
27682789
else
27692790
str2 = "(inconvertible)";
2791+
2792+
if (!current_user_sid) {
2793+
str3 = "(none)";
2794+
str4 = "(none)";
2795+
}
2796+
else if (!IsValidSid(current_user_sid)) {
2797+
str3 = "(invalid)";
2798+
str4 = "(invalid)";
2799+
} else {
2800+
if (user_sid_to_user_name(current_user_sid,
2801+
&str3))
2802+
to_free3 = str3;
2803+
else
2804+
str3 = "(inconvertible)";
2805+
if (ConvertSidToStringSidA(current_user_sid,
2806+
&str4))
2807+
to_local_free4 = str4;
2808+
else
2809+
str4 = "(inconvertible)";
2810+
}
27702811
strbuf_addf(report,
27712812
"'%s' is owned by:\n"
2772-
"\t'%s'\nbut the current user is:\n"
2773-
"\t'%s'\n", path, str1, str2);
2774-
LocalFree(to_free1);
2775-
LocalFree(to_free2);
2813+
"\t%s (%s)\nbut the current user is:\n"
2814+
"\t%s (%s)\n",
2815+
path, str1, str2, str3, str4);
2816+
free(to_free1);
2817+
LocalFree(to_local_free2);
2818+
free(to_free3);
2819+
LocalFree(to_local_free4);
27762820
}
27772821
}
27782822

0 commit comments

Comments
 (0)