@@ -2684,6 +2684,30 @@ static PSID get_current_user_sid(void)
2684
2684
return result ;
2685
2685
}
2686
2686
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
+
2687
2711
static int acls_supported (const char * path )
2688
2712
{
2689
2713
size_t offset = offset_1st_component (path );
@@ -2765,27 +2789,47 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
2765
2789
strbuf_addf (report , "'%s' is on a file system that does "
2766
2790
"not record ownership\n" , path );
2767
2791
} 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 ;
2769
2795
2770
- if (ConvertSidToStringSidA (sid , & str1 ))
2796
+ if (user_sid_to_user_name (sid , & str1 ))
2771
2797
to_free1 = str1 ;
2772
2798
else
2773
2799
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 ;
2781
2802
else
2782
2803
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
+ }
2783
2824
strbuf_addf (report ,
2784
2825
"'%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 );
2789
2833
}
2790
2834
}
2791
2835
0 commit comments