Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private enum TRUSTEE_FORM
- {
- TRUSTEE_IS_SID,
- TRUSTEE_IS_NAME,
- TRUSTEE_BAD_FORM,
- TRUSTEE_IS_OBJECTS_AND_SID,
- TRUSTEE_IS_OBJECTS_AND_NAME
- }
- private enum TRUSTEE_TYPE
- {
- TRUSTEE_IS_UNKNOWN,
- TRUSTEE_IS_USER,
- TRUSTEE_IS_GROUP,
- TRUSTEE_IS_DOMAIN,
- TRUSTEE_IS_ALIAS,
- TRUSTEE_IS_WELL_KNOWN_GROUP,
- TRUSTEE_IS_DELETED,
- TRUSTEE_IS_INVALID,
- TRUSTEE_IS_COMPUTER
- }
- private struct TRUSTEE
- {
- public IntPtr pMultipleTrustee;
- public MULTIPLE_TRUSTEE_OPERATION MultipleTrusteeOperation;
- public TRUSTEE_FORM TrusteeForm;
- public TRUSTEE_TYPE TrusteeType;
- public IntPtr ptstrName;
- }
- [DllImport("advapi32.dll", SetLastError = true)]
- private static extern void BuildTrusteeWithSid(
- ref TRUSTEE pTrustee,
- byte[] sid
- );
- [DllImport("advapi32.dll")]
- private static extern uint GetEffectiveRightsFromAcl(byte[] pacl, ref TRUSTEE
- pTrustee, ref uint pAccessRights);
- public bool HasAccess(SecurityIdentifier sid)
- {
- DiscretionaryAcl dacl = <DACL from somewhere>;
- byte[] daclBuffer = new byte[dacl.BinaryLength];
- dacl.GetBinaryForm(daclBuffer, 0);
- byte[] sidBuffer = new byte[sid.BinaryLength];
- sid.GetBinaryForm(sidBuffer, 0);
- TRUSTEE t = new TRUSTEE();
- BuildTrusteeWithSid(ref t, sidBuffer);
- uint access = 0;
- uint hr = GetEffectiveRightsFromAcl(daclBuffer, ref t, ref access);
- int i = Marshal.Release(t.ptstrName);
- return ((access | <Desired Access>) == <Desired Access>) ? true : false;
- }
- }
Add Comment
Please, Sign In to add comment