private static bool TestRemoveInheritedAces(DiscretionaryAcl discretionaryAcl)
        {

            GenericAce ace = null;
            discretionaryAcl.RemoveInheritedAces();
            for (int i = 0; i < discretionaryAcl.Count; i++)
            {
                ace = discretionaryAcl[i];
                if ((ace.AceFlags & AceFlags.Inherited) != 0)
                    return false;
            }
            return true;
        }
Example #2
0
        private static bool TestRemoveInheritedAces(DiscretionaryAcl discretionaryAcl)
        {
            GenericAce ace = null;

            discretionaryAcl.RemoveInheritedAces();
            for (int i = 0; i < discretionaryAcl.Count; i++)
            {
                ace = discretionaryAcl[i];
                if ((ace.AceFlags & AceFlags.Inherited) != 0)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #3
0
        public void DetectsCanonicalMergesAndRemovesInheritedAces()
        {
            SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);

            RawAcl acl = MakeRawAcl(new GenericAce[] {
                new CommonAce(AceFlags.None, AceQualifier.AccessDenied, 4, sid, false, null),
                new CommonAce(AceFlags.None, AceQualifier.AccessDenied, 8, sid, false, null),
                new CommonAce(AceFlags.None, AceQualifier.AccessAllowed, 1, sid, false, null),
                new CommonAce(AceFlags.None, AceQualifier.AccessAllowed, 2, sid, false, null),
                new CommonAce(AceFlags.Inherited, AceQualifier.AccessAllowed, 4, sid, false, null),
                new CommonAce(AceFlags.Inherited, AceQualifier.AccessAllowed, 4, sid, false, null)
            });

            Assert.AreEqual(6, acl.Count);

            DiscretionaryAcl dacl = new DiscretionaryAcl(false, false, acl);

            Assert.IsTrue(dacl.IsCanonical);
            Assert.AreEqual(4, dacl.Count);

            Assert.AreEqual(AceFlags.None, ((CommonAce)dacl [0]).AceFlags);
            Assert.AreEqual(AceFlags.None, ((CommonAce)dacl [1]).AceFlags);
            Assert.AreEqual(AceFlags.Inherited, ((CommonAce)dacl [2]).AceFlags);
            Assert.AreEqual(AceFlags.Inherited, ((CommonAce)dacl [3]).AceFlags);
            Assert.AreEqual(AceQualifier.AccessDenied, ((CommonAce)dacl [0]).AceQualifier);
            Assert.AreEqual(AceQualifier.AccessAllowed, ((CommonAce)dacl [1]).AceQualifier);
            Assert.AreEqual(AceQualifier.AccessAllowed, ((CommonAce)dacl [2]).AceQualifier);
            Assert.AreEqual(AceQualifier.AccessAllowed, ((CommonAce)dacl [3]).AceQualifier);
            GenericAce ace7 = dacl[0];

            Assert.IsInstanceOfType(typeof(CommonAce), ace7);

            dacl.RemoveInheritedAces();
            Assert.AreEqual(2, dacl.Count);

            dacl.Purge(sid);
            Assert.AreEqual(0, dacl.Count);
        }