示例#1
0
        private static bool TestRemoveAudit(SystemAcl systemAcl, RawAcl rawAcl, AuditFlags auditFlag, SecurityIdentifier sid, int accessMask, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, bool removePossible)
        {
            bool result = true;
            bool isRemoved = false;
            byte[] sAclBinaryForm = null;
            byte[] rAclBinaryForm = null;
            isRemoved = systemAcl.RemoveAudit(auditFlag, sid, accessMask, inheritanceFlags, propagationFlags);
            if ((isRemoved == removePossible) &&
                (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;
        }
示例#2
0
        private static bool TestAddAudit(SystemAcl systemAcl, RawAcl rawAcl, AuditFlags auditFlag, SecurityIdentifier sid, int accessMask, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            bool result = true;

            byte[] sAclBinaryForm = null;
            byte[] rAclBinaryForm = null;
            systemAcl.AddAudit(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);
        }
示例#3
0
        public byte[] ToSystemAclBytes()
        {
            var systemAcl = new SystemAcl(false, false, 0);
            var bytes     = new byte[systemAcl.BinaryLength];

            systemAcl.GetBinaryForm(bytes, 0);
            return(bytes);
        }
示例#4
0
        public byte[] ToSaclBytes()
        {
            SystemAcl sacl = new SystemAcl(false, false, 0);

            byte[] bytes = new byte[sacl.BinaryLength];
            sacl.GetBinaryForm(bytes, 0);
            return(bytes);
        }
        internal byte[] ToSaclBytes()
        {
            var sacl  = new SystemAcl(false, false, 0);
            var bytes = new byte[sacl.BinaryLength];

            sacl.GetBinaryForm(bytes, 0);
            return(bytes);
        }
示例#6
0
        public static void TestConstructor(bool isContainer, bool isDS, byte revision, int capacity)
        {
            bool result = true;

            byte[] sAclBinaryForm = null;
            byte[] rAclBinaryForm = null;

            SystemAcl systemAcl = null;
            RawAcl    rawAcl    = null;

            systemAcl = new SystemAcl(isContainer, isDS, revision, capacity);
            rawAcl    = new RawAcl(revision, capacity);

            if (isContainer == systemAcl.IsContainer &&
                isDS == systemAcl.IsDS &&
                revision == systemAcl.Revision &&
                0 == systemAcl.Count &&
                8 == systemAcl.BinaryLength &&
                true == systemAcl.IsCanonical)
            {
                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;
            }
            Assert.True(result);
        }
示例#7
0
        public static void TestConstructor(bool isContainer, bool isDS, byte revision, int capacity)
        {
            bool result = true;
            byte[] sAclBinaryForm = null;
            byte[] rAclBinaryForm = null;

            SystemAcl systemAcl = null;
            RawAcl rawAcl = null;

            systemAcl = new SystemAcl(isContainer, isDS, revision, capacity);
            rawAcl = new RawAcl(revision, capacity);

            if (isContainer == systemAcl.IsContainer &&
                isDS == systemAcl.IsDS &&
                revision == systemAcl.Revision &&
                0 == systemAcl.Count &&
                8 == systemAcl.BinaryLength &&
                true == systemAcl.IsCanonical)
            {
                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;
            }
            Assert.True(result);
        }
        private static bool TestConstructor(SystemAcl systemAcl, bool isContainer, bool isDS, bool wasCanonicalInitially, RawAcl rawAcl)
        {
            bool result = true;

            byte[] sAclBinaryForm = null;
            byte[] rAclBinaryForm = null;
            if (systemAcl.IsContainer == isContainer &&
                systemAcl.IsDS == isDS &&
                systemAcl.Revision == rawAcl.Revision &&
                systemAcl.Count == rawAcl.Count &&
                systemAcl.BinaryLength == rawAcl.BinaryLength &&
                systemAcl.IsCanonical == wasCanonicalInitially)
            {
                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 TestConstructor(SystemAcl systemAcl, bool isContainer, bool isDS, bool wasCanonicalInitially, RawAcl rawAcl)
        {
            bool result = true;
            byte[] sAclBinaryForm = null;
            byte[] rAclBinaryForm = null;
            if (systemAcl.IsContainer == isContainer &&
                systemAcl.IsDS == isDS &&
                systemAcl.Revision == rawAcl.Revision &&
                systemAcl.Count == rawAcl.Count &&
                systemAcl.BinaryLength == rawAcl.BinaryLength &&
                systemAcl.IsCanonical == wasCanonicalInitially)
            {
                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;
        }
        public static void BasicValidationTestCases()
        {
            SystemAcl  sAcl = null;
            RawAcl     rAcl = null;
            GenericAce gAce = null;

            byte[] binaryForm = null;

            //Case 1, array binaryForm is null

            Assert.Throws <ArgumentNullException>(() =>
            {
                rAcl = new RawAcl(GenericAcl.AclRevision, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                                     new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                sAcl = new SystemAcl(false, false, rAcl);
                sAcl.GetBinaryForm(binaryForm, 0);
            });
            //Case 2, offset is negative

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                binaryForm = new byte[100];
                rAcl       = new RawAcl(GenericAcl.AclRevision, 1);
                gAce       = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                                           new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                sAcl = new SystemAcl(false, false, rAcl);
                sAcl.GetBinaryForm(binaryForm, -1);
            });
            //Case 3, offset is equal to binaryForm length

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                binaryForm = new byte[100];
                rAcl       = new RawAcl(GenericAcl.AclRevision, 1);
                gAce       = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                                           new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                sAcl = new SystemAcl(false, false, rAcl);
                sAcl.GetBinaryForm(binaryForm, binaryForm.Length);
            });
            //Case 4, offset is a big possitive number

            rAcl = new RawAcl(GenericAcl.AclRevision, 1);
            gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                                 new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
            rAcl.InsertAce(0, gAce);
            sAcl       = new SystemAcl(false, false, rAcl);
            binaryForm = new byte[sAcl.BinaryLength + 10000];
            sAcl.GetBinaryForm(binaryForm, 10000);
            //get the binaryForm of the original RawAcl
            byte[] verifierBinaryForm = new byte[rAcl.BinaryLength];
            rAcl.GetBinaryForm(verifierBinaryForm, 0);
            Assert.True(Utils.IsBinaryFormEqual(binaryForm, 10000, verifierBinaryForm));

            //Case 5, binaryForm array's size is insufficient

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                binaryForm = new byte[4];
                rAcl       = new RawAcl(GenericAcl.AclRevision, 1);
                gAce       = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                                           new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                sAcl = new SystemAcl(false, false, rAcl);
                sAcl.GetBinaryForm(binaryForm, 0);
            });
        }
        public static void BasicValidationTestCases()
        {
            SystemAcl sAcl = null;
            RawAcl rAcl = null;
            GenericAce gAce = null;
            byte[] binaryForm = null;

            //Case 1, array binaryForm is null

            Assert.Throws<ArgumentNullException>(() =>
            {
                rAcl = new RawAcl(GenericAcl.AclRevision, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                    new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                sAcl = new SystemAcl(false, false, rAcl);
                sAcl.GetBinaryForm(binaryForm, 0);
            });
            //Case 2, offset is negative

            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                binaryForm = new byte[100];
                rAcl = new RawAcl(GenericAcl.AclRevision, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                    new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                sAcl = new SystemAcl(false, false, rAcl);
                sAcl.GetBinaryForm(binaryForm, -1);
            });
            //Case 3, offset is equal to binaryForm length

            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                binaryForm = new byte[100];
                rAcl = new RawAcl(GenericAcl.AclRevision, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                    new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                sAcl = new SystemAcl(false, false, rAcl);
                sAcl.GetBinaryForm(binaryForm, binaryForm.Length);
            });
            //Case 4, offset is a big possitive number

            rAcl = new RawAcl(GenericAcl.AclRevision, 1);
            gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
            rAcl.InsertAce(0, gAce);
            sAcl = new SystemAcl(false, false, rAcl);
            binaryForm = new byte[sAcl.BinaryLength + 10000];
            sAcl.GetBinaryForm(binaryForm, 10000);
            //get the binaryForm of the original RawAcl
            byte[] verifierBinaryForm = new byte[rAcl.BinaryLength];
            rAcl.GetBinaryForm(verifierBinaryForm, 0);
            Assert.True(Utils.IsBinaryFormEqual(binaryForm, 10000, verifierBinaryForm));

            //Case 5, binaryForm array's size is insufficient

            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                binaryForm = new byte[4];
                rAcl = new RawAcl(GenericAcl.AclRevision, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1,
                    new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                sAcl = new SystemAcl(false, false, rAcl);
                sAcl.GetBinaryForm(binaryForm, 0);
            });
        }