MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / pt_policy

Function pt_policy

tests/test_test_impact_tree.c:265–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263}
264
265static 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
299static bool pt_make_writable(const char *path) {
300 wchar_t wide[PT_PATH];

Callers 4

pt_private_parentFunction · 0.85
pt_view_matchesFunction · 0.85
ptr_ancestor_policyFunction · 0.85

Calls 4

pt_wideFunction · 0.85
pt_owner_is_currentFunction · 0.85
lstatFunction · 0.85
pt_acl_absentFunction · 0.85

Tested by

no test coverage detected