Пример #1
0
 /// <summary>
 /// Add an ACE to the DACL, creating the DACL if needed.
 /// </summary>
 /// <param name="ace">The ACE to add to the DACL.</param>
 public void AddAce(Ace ace)
 {
     if (Dacl == null)
     {
         Dacl = new Acl();
     }
     Dacl.NullAcl = false;
     Dacl.Add(ace);
 }
        /// <summary>
        /// Clone this ACE.
        /// </summary>
        /// <returns>The cloned ACE.</returns>
        public Ace Clone()
        {
            Ace ace = (Ace)this.MemberwiseClone();

            if (ace.ApplicationData != null)
            {
                ace.ApplicationData = (byte[])ace.ApplicationData.Clone();
            }
            return(ace);
        }
        internal static Ace CreateAceFromReader(BinaryReader reader)
        {
            long    current_position = reader.BaseStream.Position;
            AceType type             = (AceType)reader.ReadByte();
            Ace     ace;

            switch (type)
            {
            case AceType.MandatoryLabel:
                ace = new MandatoryLabelAce();
                break;

            default:
                ace = new Ace(type);
                break;
            }
            ace.Flags = MapToFlags(type, reader.ReadByte());
            int ace_size = reader.ReadUInt16();

            ace.Mask = reader.ReadUInt32();
            if (ace.IsObjectAce)
            {
                ObjectAceFlags flags = (ObjectAceFlags)reader.ReadUInt32();
                if ((flags & ObjectAceFlags.ObjectTypePresent) != 0)
                {
                    ace.ObjectType = new Guid(reader.ReadAllBytes(16));
                }
                if ((flags & ObjectAceFlags.InheritedObjectTypePresent) != 0)
                {
                    ace.InheritedObjectType = new Guid(reader.ReadAllBytes(16));
                }
            }

            if (type == AceType.AllowedCompound)
            {
                // Read out compound ace type.
                ace.CompoundAceType = (CompoundAceType)reader.ReadUInt16();
                // Reserved.
                reader.ReadInt16();
                ace.ServerSid = new Sid(reader);
            }
            ace.Sid = new Sid(reader);
            int bytes_used = (int)(reader.BaseStream.Position - current_position);

            ace.ApplicationData = reader.ReadAllBytes(ace_size - bytes_used);
            return(ace);
        }
Пример #4
0
        /// <summary>
        /// Compare ACE to another object.
        /// </summary>
        /// <param name="obj">The other object.</param>
        /// <returns>True if the other object equals this ACE</returns>
        public override bool Equals(object obj)
        {
            if (object.ReferenceEquals(obj, this))
            {
                return(true);
            }

            Ace ace = obj as Ace;

            if (ace == null)
            {
                return(false);
            }

            return(ace.Type == Type && ace.Flags == Flags && ace.Sid == Sid && ace.Mask == Mask &&
                   ace.ObjectType == ObjectType && ace.InheritedObjectType == InheritedObjectType);
        }
        /// <summary>
        /// Compare ACE to another object.
        /// </summary>
        /// <param name="obj">The other object.</param>
        /// <returns>True if the other object equals this ACE</returns>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, this))
            {
                return(true);
            }

            Ace ace = obj as Ace;

            if (ace == null)
            {
                return(false);
            }

            return(ace.Type == Type && ace.Flags == Flags && ace.Sid == Sid && ace.Mask == Mask &&
                   ace.ObjectType == ObjectType && ace.InheritedObjectType == InheritedObjectType &&
                   ace.ServerSid == ServerSid && NtObjectUtils.EqualByteArray(ApplicationData, ace.ApplicationData));
        }
Пример #6
0
 /// <summary>
 /// Add mandatory integrity label to SACL
 /// </summary>
 /// <param name="label">The integrity label SID</param>
 /// <param name="flags">The ACE flags.</param>
 /// <param name="policy">The mandatory label policy</param>
 public void AddMandatoryLabel(Sid label, AceFlags flags, MandatoryLabelPolicy policy)
 {
     MandatoryLabel = new Ace(AceType.MandatoryLabel, flags, policy, label);
 }