Ejemplo n.º 1
0
        public void RemoveSpecificUsingDSOverload()
        {
            SecurityIdentifier sid  = new SecurityIdentifier("BA");
            SystemAcl          sacl = new SystemAcl(false, true, 0);

            RemoveSpecificBegin(sid, sacl, InheritanceFlags.None);
            sacl.RemoveAuditSpecific(AuditFlags.Success, sid, 3, InheritanceFlags.None, PropagationFlags.None,
                                     ObjectAceFlags.ObjectAceTypePresent, Guid.Empty, Guid.Empty);
            Assert.AreEqual(1, sacl.Count);
            sacl.RemoveAuditSpecific(AuditFlags.Success, sid, 3, InheritanceFlags.None, PropagationFlags.None,
                                     ObjectAceFlags.None, Guid.Empty, Guid.Empty);
            Assert.AreEqual(0, sacl.Count);
        }
Ejemplo n.º 2
0
        private static bool TestRemoveAuditSpecific(SystemAcl systemAcl, RawAcl rawAcl, AuditFlags auditFlag, SecurityIdentifier sid, int accessMask, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            bool result = true;

            byte[] sAclBinaryForm = null;
            byte[] rAclBinaryForm = null;
            systemAcl.RemoveAuditSpecific(auditFlag, sid, accessMask, inheritanceFlags, propagationFlags);
            if (systemAcl.Count == rawAcl.Count &&
                systemAcl.BinaryLength == rawAcl.BinaryLength)
            {
                sAclBinaryForm = new byte[systemAcl.BinaryLength];
                rAclBinaryForm = new byte[rawAcl.BinaryLength];
                systemAcl.GetBinaryForm(sAclBinaryForm, 0);
                rawAcl.GetBinaryForm(rAclBinaryForm, 0);

                if (!Utils.IsBinaryFormEqual(sAclBinaryForm, rAclBinaryForm))
                {
                    result = false;
                }
                //redundant index check
                for (int i = 0; i < systemAcl.Count; i++)
                {
                    if (!Utils.IsAceEqual(systemAcl[i], rawAcl[i]))
                    {
                        result = false;
                        break;
                    }
                }
            }
            else
            {
                result = false;
            }
            return(result);
        }
        private static bool TestRemoveAuditSpecific(SystemAcl systemAcl, RawAcl rawAcl, AuditFlags auditFlag, SecurityIdentifier sid, int accessMask, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            bool result = true;
            byte[] sAclBinaryForm = null;
            byte[] rAclBinaryForm = null;
            systemAcl.RemoveAuditSpecific(auditFlag, sid, accessMask, inheritanceFlags, propagationFlags);
            if (systemAcl.Count == rawAcl.Count &&
                systemAcl.BinaryLength == rawAcl.BinaryLength)
            {
                sAclBinaryForm = new byte[systemAcl.BinaryLength];
                rAclBinaryForm = new byte[rawAcl.BinaryLength];
                systemAcl.GetBinaryForm(sAclBinaryForm, 0);
                rawAcl.GetBinaryForm(rAclBinaryForm, 0);

                if (!Utils.IsBinaryFormEqual(sAclBinaryForm, rAclBinaryForm))
                    result = false;
                //redundant index check                    
                for (int i = 0; i < systemAcl.Count; i++)
                {
                    if (!Utils.IsAceEqual(systemAcl[i], rawAcl[i]))
                    {
                        result = false;
                        break;
                    }
                }
            }
            else
                result = false;
            return result;
        }
Ejemplo n.º 4
0
        void RemoveSpecificBegin(SecurityIdentifier sid, SystemAcl sacl, InheritanceFlags inheritanceFlags)
        {
            SecurityIdentifier otherSid = new SecurityIdentifier("BU");

            sacl.AddAudit(AuditFlags.Success, sid, 3, inheritanceFlags, PropagationFlags.None);
            Assert.AreEqual(1, sacl.Count);
            sacl.RemoveAuditSpecific(AuditFlags.Failure, sid, 1, inheritanceFlags, PropagationFlags.None);
            Assert.AreEqual(1, sacl.Count);
            sacl.RemoveAuditSpecific(AuditFlags.Success, otherSid, 1, inheritanceFlags, PropagationFlags.None);
            Assert.AreEqual(1, sacl.Count);
            sacl.RemoveAuditSpecific(AuditFlags.Success, sid, 1, inheritanceFlags, PropagationFlags.None);
            Assert.AreEqual(1, sacl.Count);
            Assert.AreEqual(3, ((CommonAce)sacl [0]).AccessMask);
            sacl.RemoveAuditSpecific(AuditFlags.Success, sid, 3,
                                     inheritanceFlags ^ InheritanceFlags.ContainerInherit,
                                     PropagationFlags.None);
            Assert.AreEqual(1, sacl.Count);
        }
Ejemplo n.º 5
0
        public void RemoveSpecific()
        {
            SecurityIdentifier sid  = new SecurityIdentifier("BA");
            SystemAcl          sacl = new SystemAcl(false, false, 0);

            RemoveSpecificBegin(sid, sacl, InheritanceFlags.None);
            sacl.RemoveAuditSpecific(AuditFlags.Success, sid, 3, InheritanceFlags.None, PropagationFlags.None);
            Assert.AreEqual(0, sacl.Count);
        }
Ejemplo n.º 6
0
        public static void AdditionalTestCases()
        {
            RawAcl    rawAcl      = null;
            SystemAcl systemAcl   = null;
            bool      isContainer = false;
            bool      isDS        = false;

            int        auditFlags       = 0;
            string     sid              = null;
            int        accessMask       = 1;
            int        inheritanceFlags = 0;
            int        propagationFlags = 0;
            GenericAce gAce             = null;

            byte[] opaque = null;


            //Case 1, remove one audit ACE from the SystemAcl with no ACE
            isContainer      = true;
            isDS             = false;
            auditFlags       = 1;
            sid              = "BA";
            accessMask       = 1;
            inheritanceFlags = 3;
            propagationFlags = 3;
            rawAcl           = new RawAcl(0, 1);
            systemAcl        = new SystemAcl(isContainer, isDS, rawAcl);
            Assert.True(TestRemoveAuditSpecific(systemAcl, rawAcl, (AuditFlags)auditFlags,
                                                new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags));


            //Case 2, remove the last one audit ACE from the SystemAcl
            isContainer      = true;
            isDS             = false;
            auditFlags       = 1;
            sid              = "BA";
            accessMask       = 1;
            inheritanceFlags = 3;
            propagationFlags = 3;
            rawAcl           = new RawAcl(0, 1);
            //79 = AceFlags.SuccessfulAccess | AceFlags.ObjectInherit |AceFlags.ContainerInherit | AceFlags.NoPropagateInherit | AceFlags.InheritOnly
            gAce = new CommonAce((AceFlags)79, AceQualifier.SystemAudit, accessMask,
                                 new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), false, null);
            rawAcl.InsertAce(rawAcl.Count, gAce);
            systemAcl = new SystemAcl(isContainer, isDS, rawAcl);
            //remove the ace to create the validation rawAcl
            rawAcl.RemoveAce(rawAcl.Count - 1);
            Assert.True(TestRemoveAuditSpecific(systemAcl, rawAcl, (AuditFlags)auditFlags,
                                                new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags));

            //Case 3, accessMask = 0

            AssertExtensions.Throws <ArgumentException>("accessMask", () =>
            {
                isContainer      = true;
                isDS             = false;
                auditFlags       = 1;
                sid              = "BA";
                accessMask       = 0;
                inheritanceFlags = 3;
                propagationFlags = 3;
                rawAcl           = new RawAcl(0, 1);
                systemAcl        = new SystemAcl(isContainer, isDS, rawAcl);
                systemAcl.RemoveAuditSpecific((AuditFlags)auditFlags,
                                              new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags);
            });

            //Case 4, Audit Qualifier None

            AssertExtensions.Throws <ArgumentException>("auditFlags", () =>
            {
                isContainer      = true;
                isDS             = false;
                auditFlags       = 0;
                sid              = "BA";
                accessMask       = 1;
                inheritanceFlags = 3;
                propagationFlags = 3;
                rawAcl           = new RawAcl(0, 1);
                systemAcl        = new SystemAcl(isContainer, isDS, rawAcl);
                systemAcl.RemoveAuditSpecific((AuditFlags)auditFlags,
                                              new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags);
            });
            //Case 5, null sid


            Assert.Throws <ArgumentNullException>(() =>
            {
                isContainer      = true;
                isDS             = false;
                auditFlags       = 1;
                accessMask       = 1;
                sid              = "BA";
                inheritanceFlags = 3;
                propagationFlags = 3;
                rawAcl           = new RawAcl(0, 1);
                systemAcl        = new SystemAcl(isContainer, isDS, rawAcl);
                systemAcl.RemoveAuditSpecific((AuditFlags)auditFlags, null, accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags);
            });
            //Case 6, all the ACEs in the Sacl are non-qualified ACE, no remove

            Assert.Throws <InvalidOperationException>(() =>
            {
                isContainer      = true;
                isDS             = false;
                inheritanceFlags = 1; //InheritanceFlags.ContainerInherit
                propagationFlags = 2; //PropagationFlags.InheritOnly

                auditFlags = 3;
                sid        = "BA";
                accessMask = 1;
                rawAcl     = new RawAcl(0, 1);
                opaque     = new byte[4];
                gAce       = new CustomAce(AceType.MaxDefinedAceType + 1,
                                           AceFlags.InheritanceFlags | AceFlags.AuditFlags, opaque);
                rawAcl.InsertAce(0, gAce);
                systemAcl = new SystemAcl(isContainer, isDS, rawAcl);
                //After Mark changes design to make ACL with any CustomAce, CompoundAce uncanonical and
                //forbid the modification on uncanonical ACL, this case will throw InvalidOperationException
                TestRemoveAuditSpecific(systemAcl,
                                        rawAcl,
                                        (AuditFlags)auditFlags,
                                        new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)),
                                        accessMask,
                                        (InheritanceFlags)inheritanceFlags,
                                        (PropagationFlags)propagationFlags);
            });
        }
        public static void AdditionalTestCases()
        {
            RawAcl rawAcl = null;
            SystemAcl systemAcl = null;
            bool isContainer = false;
            bool isDS = false;

            int auditFlags = 0;
            string sid = null;
            int accessMask = 1;
            int inheritanceFlags = 0;
            int propagationFlags = 0;
            GenericAce gAce = null;
            byte[] opaque = null;


            //Case 1, remove one audit ACE from the SystemAcl with no ACE
            isContainer = true;
            isDS = false;
            auditFlags = 1;
            sid = "BA";
            accessMask = 1;
            inheritanceFlags = 3;
            propagationFlags = 3;
            rawAcl = new RawAcl(0, 1);
            systemAcl = new SystemAcl(isContainer, isDS, rawAcl);
            Assert.True(TestRemoveAuditSpecific(systemAcl, rawAcl, (AuditFlags)auditFlags,
                new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags));


            //Case 2, remove the last one audit ACE from the SystemAcl
            isContainer = true;
            isDS = false;
            auditFlags = 1;
            sid = "BA";
            accessMask = 1;
            inheritanceFlags = 3;
            propagationFlags = 3;
            rawAcl = new RawAcl(0, 1);
            //79 = AceFlags.SuccessfulAccess | AceFlags.ObjectInherit |AceFlags.ContainerInherit | AceFlags.NoPropagateInherit | AceFlags.InheritOnly
            gAce = new CommonAce((AceFlags)79, AceQualifier.SystemAudit, accessMask,
                new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), false, null);
            rawAcl.InsertAce(rawAcl.Count, gAce);
            systemAcl = new SystemAcl(isContainer, isDS, rawAcl);
            //remove the ace to create the validation rawAcl
            rawAcl.RemoveAce(rawAcl.Count - 1);
            Assert.True(TestRemoveAuditSpecific(systemAcl, rawAcl, (AuditFlags)auditFlags,
                new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags));

            //Case 3, accessMask = 0

            Assert.Throws<ArgumentException>(() =>
            {
                isContainer = true;
                isDS = false;
                auditFlags = 1;
                sid = "BA";
                accessMask = 0;
                inheritanceFlags = 3;
                propagationFlags = 3;
                rawAcl = new RawAcl(0, 1);
                systemAcl = new SystemAcl(isContainer, isDS, rawAcl);
                systemAcl.RemoveAuditSpecific((AuditFlags)auditFlags,
                    new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags);

            });

            //Case 4, Audit Qualifier None

            Assert.Throws<ArgumentException>(() =>
            {
                isContainer = true;
                isDS = false;
                auditFlags = 0;
                sid = "BA";
                accessMask = 1;
                inheritanceFlags = 3;
                propagationFlags = 3;
                rawAcl = new RawAcl(0, 1);
                systemAcl = new SystemAcl(isContainer, isDS, rawAcl);
                systemAcl.RemoveAuditSpecific((AuditFlags)auditFlags,
                    new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags);

            });
            //Case 5, null sid


            Assert.Throws<ArgumentNullException>(() =>
            {
                isContainer = true;
                isDS = false;
                auditFlags = 1;
                accessMask = 1;
                sid = "BA";
                inheritanceFlags = 3;
                propagationFlags = 3;
                rawAcl = new RawAcl(0, 1);
                systemAcl = new SystemAcl(isContainer, isDS, rawAcl);
                systemAcl.RemoveAuditSpecific((AuditFlags)auditFlags, null, accessMask, (InheritanceFlags)inheritanceFlags, (PropagationFlags)propagationFlags);

            });
            //Case 6, all the ACEs in the Sacl are non-qualified ACE, no remove

            Assert.Throws<InvalidOperationException>(() =>
            {
                isContainer = true;
                isDS = false;
                inheritanceFlags = 1;//InheritanceFlags.ContainerInherit
                propagationFlags = 2; //PropagationFlags.InheritOnly

                auditFlags = 3;
                sid = "BA";
                accessMask = 1;
                rawAcl = new RawAcl(0, 1);
                opaque = new byte[4];
                gAce = new CustomAce(AceType.MaxDefinedAceType + 1,
                    AceFlags.InheritanceFlags | AceFlags.AuditFlags, opaque); ;
                rawAcl.InsertAce(0, gAce);
                systemAcl = new SystemAcl(isContainer, isDS, rawAcl);
                //After Mark changes design to make ACL with any CustomAce, CompoundAce uncanonical and
                //forbid the modification on uncanonical ACL, this case will throw InvalidOperationException
                TestRemoveAuditSpecific(systemAcl,
    rawAcl,
    (AuditFlags)auditFlags,
    new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)),
    accessMask,
    (InheritanceFlags)inheritanceFlags,
    (PropagationFlags)propagationFlags);
            });
        }