1
1
#include "../git-compat-util.h"
2
2
#include "win32.h"
3
3
#include <aclapi.h>
4
+ #include <sddl.h>
4
5
#include <conio.h>
5
6
#include <wchar.h>
6
7
#include "../strbuf.h"
@@ -2989,6 +2990,22 @@ static PSID get_current_user_sid(void)
2989
2990
return result ;
2990
2991
}
2991
2992
2993
+ static int acls_supported (const char * path )
2994
+ {
2995
+ size_t offset = offset_1st_component (path );
2996
+ WCHAR wroot [MAX_PATH ];
2997
+ DWORD file_system_flags ;
2998
+
2999
+ if (offset &&
3000
+ xutftowcs_path_ex (wroot , path , MAX_PATH , offset ,
3001
+ MAX_PATH , 0 ) > 0 &&
3002
+ GetVolumeInformationW (wroot , NULL , 0 , NULL , NULL ,
3003
+ & file_system_flags , NULL , 0 ))
3004
+ return !!(file_system_flags & FILE_PERSISTENT_ACLS );
3005
+
3006
+ return 0 ;
3007
+ }
3008
+
2992
3009
int is_path_owned_by_current_sid (const char * path )
2993
3010
{
2994
3011
WCHAR wpath [MAX_PATH ];
@@ -3028,6 +3045,7 @@ int is_path_owned_by_current_sid(const char *path)
3028
3045
else if (sid && IsValidSid (sid )) {
3029
3046
/* Now, verify that the SID matches the current user's */
3030
3047
static PSID current_user_sid ;
3048
+ BOOL is_member ;
3031
3049
3032
3050
if (!current_user_sid )
3033
3051
current_user_sid = get_current_user_sid ();
@@ -3036,6 +3054,42 @@ int is_path_owned_by_current_sid(const char *path)
3036
3054
IsValidSid (current_user_sid ) &&
3037
3055
EqualSid (sid , current_user_sid ))
3038
3056
result = 1 ;
3057
+ else if (IsWellKnownSid (sid , WinBuiltinAdministratorsSid ) &&
3058
+ CheckTokenMembership (NULL , sid , & is_member ) &&
3059
+ is_member )
3060
+ /*
3061
+ * If owned by the Administrators group, and the
3062
+ * current user is an administrator, we consider that
3063
+ * okay, too.
3064
+ */
3065
+ result = 1 ;
3066
+ else if (IsWellKnownSid (sid , WinWorldSid ) &&
3067
+ git_env_bool ("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES" , 0 ) &&
3068
+ !acls_supported (path )) {
3069
+ /*
3070
+ * On FAT32 volumes, ownership is not actually recorded.
3071
+ */
3072
+ warning ("'%s' is on a file system that does not record ownership" , path );
3073
+ } else if (git_env_bool ("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES" , 0 )) {
3074
+ LPSTR str1 , str2 , to_free1 = NULL , to_free2 = NULL ;
3075
+
3076
+ if (ConvertSidToStringSidA (sid , & str1 ))
3077
+ to_free1 = str1 ;
3078
+ else
3079
+ str1 = "(inconvertible)" ;
3080
+
3081
+ if (!current_user_sid )
3082
+ str2 = "(none)" ;
3083
+ else if (!IsValidSid (current_user_sid ))
3084
+ str2 = "(invalid)" ;
3085
+ else if (ConvertSidToStringSidA (current_user_sid , & str2 ))
3086
+ to_free2 = str2 ;
3087
+ else
3088
+ str2 = "(inconvertible)" ;
3089
+ warning ("'%s' is owned by:\n\t'%s'\nbut the current user is:\n\t'%s'" , path , str1 , str2 );
3090
+ LocalFree (to_free1 );
3091
+ LocalFree (to_free2 );
3092
+ }
3039
3093
}
3040
3094
3041
3095
/*
0 commit comments