示例#1
0
        internal void Serialize(BinaryWriter writer)
        {
            byte[] sid_data     = Sid.ToArray();
            int    total_length = 4 + 4 + sid_data.Length;

            if (ApplicationData != null)
            {
                total_length += ApplicationData.Length;
            }

            ObjectAceFlags flags = ObjectAceFlags.None;

            if (IsObjectAce)
            {
                // For Flags
                total_length += 4;
                if (ObjectType.HasValue)
                {
                    total_length += 16;
                    flags        |= ObjectAceFlags.ObjectTypePresent;
                }
                if (InheritedObjectType.HasValue)
                {
                    total_length += 16;
                    flags        |= ObjectAceFlags.InheritedObjectTypePresent;
                }
            }
            if (total_length > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException("Total ACE length greater than maximum");
            }

            writer.Write((byte)Type);
            writer.Write((byte)Flags);
            writer.Write((ushort)total_length);
            writer.Write(Mask.Access);
            if (IsObjectAce)
            {
                writer.Write((uint)flags);
                if (ObjectType.HasValue)
                {
                    writer.Write(ObjectType.Value.ToByteArray());
                }
                if (InheritedObjectType.HasValue)
                {
                    writer.Write(InheritedObjectType.Value.ToByteArray());
                }
            }
            writer.Write(sid_data);
            writer.Write(ApplicationData ?? new byte[0]);
        }
示例#2
0
        internal void Serialize(BinaryWriter writer)
        {
            // Length = sizeof(AceHeader) + sizeof(Mask) + ObjectAceData + Sid
            byte[]         sid_data     = Sid.ToArray();
            int            total_length = 4 + 4 + sid_data.Length;
            ObjectAceFlags flags        = ObjectAceFlags.None;

            if (IsObjectAce())
            {
                // For Flags
                total_length += 4;
                if (ObjectType.HasValue)
                {
                    total_length += 16;
                    flags        |= ObjectAceFlags.ObjectTypePresent;
                }
                if (InheritedObjectType.HasValue)
                {
                    total_length += 16;
                    flags        |= ObjectAceFlags.InheritedObjectTypePresent;
                }
            }
            if (total_length > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException("Total ACE length greater than maximum");
            }

            writer.Write((byte)AceType);
            writer.Write((byte)AceFlags);
            writer.Write((ushort)total_length);
            writer.Write(Mask);
            if (IsObjectAce())
            {
                writer.Write((uint)flags);
                if (ObjectType.HasValue)
                {
                    writer.Write(ObjectType.Value.ToByteArray());
                }
                if (InheritedObjectType.HasValue)
                {
                    writer.Write(InheritedObjectType.Value.ToByteArray());
                }
            }
            writer.Write(sid_data);
        }
 /// <summary>
 /// Does this SID dominate another for trust.
 /// </summary>
 /// <param name="sid">The other SID.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>True if the sid dominates.</returns>
 public NtResult <bool> DominatesForTrust(Sid sid, bool throw_on_error)
 {
     return(NtRtl.RtlSidDominatesForTrust(ToArray(), sid.ToArray(),
                                          out bool result).CreateResult(throw_on_error, () => result));
 }
        internal void Serialize(BinaryWriter writer)
        {
            byte[] sid_data = Sid.ToArray();
            if (Type == AceType.AllowedCompound)
            {
                MemoryStream stm       = new MemoryStream();
                BinaryWriter sidwriter = new BinaryWriter(stm);
                sidwriter.Write((int)CompoundAceType.Impersonation);
                sidwriter.Write(ServerSid.ToArray());
                sidwriter.Write(sid_data);
                sid_data = stm.ToArray();
            }

            int total_length = 4 + 4 + sid_data.Length;

            if (ApplicationData != null)
            {
                total_length += ApplicationData.Length;
            }

            // Add a round up to 4 byte alignment.
            int padding = 4 - (total_length % 4);

            if (padding == 4)
            {
                padding = 0;
            }

            total_length += padding;

            ObjectAceFlags flags = ObjectAceFlags.None;

            if (IsObjectAce)
            {
                // For Flags
                total_length += 4;
                if (ObjectType.HasValue)
                {
                    total_length += 16;
                    flags        |= ObjectAceFlags.ObjectTypePresent;
                }
                if (InheritedObjectType.HasValue)
                {
                    total_length += 16;
                    flags        |= ObjectAceFlags.InheritedObjectTypePresent;
                }
            }
            if (total_length > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException("Total ACE length greater than maximum");
            }

            writer.Write((byte)Type);
            writer.Write(MapFromFlags(Type, Flags));
            writer.Write((ushort)total_length);
            writer.Write(Mask.Access);
            if (IsObjectAce)
            {
                writer.Write((uint)flags);
                if (ObjectType.HasValue)
                {
                    writer.Write(ObjectType.Value.ToByteArray());
                }
                if (InheritedObjectType.HasValue)
                {
                    writer.Write(InheritedObjectType.Value.ToByteArray());
                }
            }
            writer.Write(sid_data);
            writer.Write(ApplicationData ?? new byte[0]);
            if (padding != 0)
            {
                writer.Write(new byte[padding]);
            }
        }