| 263 | } |
| 264 | |
| 265 | static bool pt_policy(const char *path, bool directory, bool executable) { |
| 266 | wchar_t wide[PT_PATH]; |
| 267 | if (!pt_wide(path, wide)) |
| 268 | return false; |
| 269 | PSECURITY_DESCRIPTOR descriptor = NULL; |
| 270 | PSID owner = NULL; |
| 271 | PACL acl = NULL; |
| 272 | DWORD result = GetNamedSecurityInfoW(wide, SE_FILE_OBJECT, |
| 273 | OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, |
| 274 | &owner, NULL, &acl, NULL, &descriptor); |
| 275 | SECURITY_DESCRIPTOR_CONTROL control = 0; |
| 276 | DWORD revision = 0; |
| 277 | bool ok = result == ERROR_SUCCESS && owner && pt_owner_is_current(owner) && acl && |
| 278 | acl->AceCount == 1 && GetSecurityDescriptorControl(descriptor, &control, &revision) && |
| 279 | (control & SE_DACL_PROTECTED) != 0; |
| 280 | void *raw = NULL; |
| 281 | if (ok) |
| 282 | ok = GetAce(acl, 0, &raw) && raw; |
| 283 | if (ok) { |
| 284 | ACCESS_ALLOWED_ACE *ace = raw; |
| 285 | ok = ace->Header.AceType == ACCESS_ALLOWED_ACE_TYPE && EqualSid(owner, &ace->SidStart) && |
| 286 | (ace->Mask & FILE_ALL_ACCESS) == FILE_ALL_ACCESS; |
| 287 | } |
| 288 | DWORD attributes = GetFileAttributesW(wide); |
| 289 | ok = ok && attributes != INVALID_FILE_ATTRIBUTES && |
| 290 | !(attributes & FILE_ATTRIBUTE_REPARSE_POINT) && |
| 291 | (((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) == directory) && |
| 292 | (directory || (attributes & FILE_ATTRIBUTE_READONLY)); |
| 293 | (void)executable; |
| 294 | if (descriptor) |
| 295 | LocalFree(descriptor); |
| 296 | return ok; |
| 297 | } |
| 298 | |
| 299 | static bool pt_make_writable(const char *path) { |
| 300 | wchar_t wide[PT_PATH]; |
no test coverage detected