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

Function win_file_acl_secure

src/daemon/ipc.c:4894–4967  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4892}
4893
4894static bool win_file_acl_secure(win_security_t *security, HANDLE file, DWORD mutation,
4895 bool ancestor) {
4896 PACL dacl = NULL;
4897 PSECURITY_DESCRIPTOR descriptor = NULL;
4898 DWORD status = security->get_security_info(file, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
4899 NULL, NULL, &dacl, NULL, &descriptor);
4900 ACL_SIZE_INFORMATION information;
4901 memset(&information, 0, sizeof(information));
4902 bool secure =
4903 status == ERROR_SUCCESS && descriptor && dacl && security->is_valid_acl(dacl) &&
4904 security->get_acl_information(dacl, &information, sizeof(information), AclSizeInformation);
4905 enum {
4906 WIN_FILE_ACE_ALLOW = 0x00,
4907 WIN_FILE_ACE_DENY = 0x01,
4908 WIN_FILE_ACE_DENY_OBJECT = 0x06,
4909 WIN_FILE_ACE_DENY_CALLBACK = 0x0a,
4910 WIN_FILE_ACE_DENY_CALLBACK_OBJECT = 0x0c,
4911 };
4912 for (DWORD index = 0U; secure && index < information.AceCount; index++) {
4913 void *opaque = NULL;
4914 if (!security->get_ace(dacl, index, &opaque) || !opaque) {
4915 secure = false;
4916 break;
4917 }
4918 ACE_HEADER *header = opaque;
4919 if (header->AceType == WIN_FILE_ACE_DENY || header->AceType == WIN_FILE_ACE_DENY_OBJECT ||
4920 header->AceType == WIN_FILE_ACE_DENY_CALLBACK ||
4921 header->AceType == WIN_FILE_ACE_DENY_CALLBACK_OBJECT) {
4922 continue;
4923 }
4924 size_t sid_offset = offsetof(ACCESS_ALLOWED_ACE, SidStart);
4925 if (header->AceType != WIN_FILE_ACE_ALLOW || (size_t)header->AceSize < sid_offset + 8U) {
4926 secure = false;
4927 break;
4928 }
4929 const ACCESS_ALLOWED_ACE *ace = opaque;
4930 if ((ace->Mask & mutation) == 0U) {
4931 continue;
4932 }
4933 const uint8_t *sid = (const uint8_t *)&ace->SidStart;
4934 size_t sid_capacity = (size_t)header->AceSize - sid_offset;
4935 bool creator_owner_inherit_only = (header->AceFlags & INHERIT_ONLY_ACE) != 0U;
4936 if (!win_bounded_sid_trusted(security, sid, sid_capacity, creator_owner_inherit_only,
4937 ancestor)) {
4938 /* Name the untrusted identity class so a harness/profile ACL leak
4939 * (an inherited Users / Authenticated Users / Everyone ACE) is
4940 * distinguishable from a genuinely hostile grant. */
4941 const char *sid_class =
4942 security->is_well_known_sid((PSID)sid, WinBuiltinUsersSid) ? "BUILTIN\\Users"
4943 : security->is_well_known_sid((PSID)sid, WinAuthenticatedUserSid)
4944 ? "Authenticated Users"
4945 : security->is_well_known_sid((PSID)sid, WinWorldSid) ? "Everyone"
4946 : security->is_well_known_sid((PSID)sid, WinInteractiveSid) ? "INTERACTIVE"
4947 : "other";
4948 /* Print the raw SID too: an "other" class is a specific account,
4949 * and only its string form identifies the harness/profile leak. */
4950 wchar_t *sid_text = NULL;
4951 char sid_utf8[96] = "<unprintable>";

Callers 1

win_file_security_secureFunction · 0.85

Calls 2

win_bounded_sid_trustedFunction · 0.85

Tested by

no test coverage detected