Exemplo n.º 1
0
        public static bool IsAceEqual(GenericAce ace1, GenericAce ace2)
        {
            bool result = true;
            byte[] ace1BinaryForm;
            byte[] ace2BinaryForm;


            if (null != ace1 && null != ace2)
            {
                //check the BinaryLength
                if (ace1.BinaryLength != ace2.BinaryLength)
                {
                    result = false;
                }
                else
                {
                    ace1BinaryForm = new byte[ace1.BinaryLength];
                    ace2BinaryForm = new byte[ace2.BinaryLength];
                    ace1.GetBinaryForm(ace1BinaryForm, 0);
                    ace2.GetBinaryForm(ace2BinaryForm, 0);
                    if (!IsBinaryFormEqual(ace1BinaryForm, ace2BinaryForm))
                    {
                        result = false;
                    }
                }
            }
            else if (null == ace1 && null == ace2)
            {
                Console.WriteLine("Both aces are null");
            }
            else
                result = false;
            return result;
        }
Exemplo n.º 2
0
        public static void BasicValidationTestCases()
        {
            GenericAce gAce = null;
            RawAcl rAcl = null;
            GenericAce[] gAces = null;

            // Case 1, when collection is actually empty
            rAcl = new RawAcl(1, 1);
            gAces = new GenericAce[rAcl.Count];
            rAcl.CopyTo(gAces, 0);

            // Case 2, collection has one ACE
            rAcl = new RawAcl(0, 1);
            gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
            rAcl.InsertAce(0, gAce);
            gAces = new GenericAce[rAcl.Count];
            rAcl.CopyTo(gAces, 0);

            //Case 3, index = 3
            rAcl = new RawAcl(0, 1);
            gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BG")), false, null);
            rAcl.InsertAce(0, gAce);
            gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
            rAcl.InsertAce(0, gAce);
            gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BO")), false, null);
            rAcl.InsertAce(0, gAce);
            gAces = new GenericAce[rAcl.Count + 5];
            //initialize to null
            for (int i = 0; i < gAces.Length; i++)
                gAces[i] = null;
            rAcl.CopyTo(gAces, 3);
        }
Exemplo n.º 3
0
 public void GenericAce_VerifyAces(GenericAce expectedAce, GenericAce resultAce)
 {
     Assert.Equal(expectedAce.AceType, resultAce.AceType);
     Assert.Equal(expectedAce.AceFlags, resultAce.AceFlags);
     Assert.Equal(expectedAce.AuditFlags, resultAce.AuditFlags);
     Assert.Equal(expectedAce.BinaryLength, resultAce.BinaryLength);
     Assert.Equal(expectedAce.InheritanceFlags, resultAce.InheritanceFlags);
     Assert.Equal(expectedAce.IsInherited, resultAce.IsInherited);
     Assert.Equal(expectedAce.PropagationFlags, resultAce.PropagationFlags);
 }
Exemplo n.º 4
0
 private static bool TestIndex(GenericAce gAce, GenericAce verifierGAce)
 {
     if (Utils.IsAceEqual(gAce, verifierGAce))
     {//as operator == and != are overridden to by value, can not use != to test these two are not same object any more
         gAce.AceFlags = AceFlags.InheritanceFlags | AceFlags.Inherited | AceFlags.AuditFlags;
         if (gAce != verifierGAce)
             return true;
         else
             return false;
     }
     else
         return false;
 }
 public void InsertAce(int index, GenericAce ace);
 public void CopyTo(GenericAce[] array, int index);
	public static bool op_Equality(GenericAce left, GenericAce right) {}
Exemplo n.º 8
0
 public void ObjectAce_CreateFromBinaryForm(GenericAce expectedAce, byte[] testBinaryForm, int testOffset)
 {
     GenericAce resultAce = ObjectAce.CreateFromBinaryForm(testBinaryForm, testOffset);
     GenericAce_VerifyAces(expectedAce, resultAce);
 }
Exemplo n.º 9
0
 public void ObjectAce_GetBinaryForm(GenericAce testAce, byte[] expectedBinaryForm, int testOffset)
 {
     byte[] resultBinaryForm = new byte[testAce.BinaryLength + testOffset];
     testAce.GetBinaryForm(resultBinaryForm, testOffset);
     GenericAce_VerifyBinaryForms(expectedBinaryForm, resultBinaryForm, testOffset);
 }
        public static void AdditionalTestCases()
        {
            ICollection myCollection = null;
            GenericAce gAce = null;
            RawAcl rAcl = null;
            GenericAce[] gAces = null;


            // Case 1, null array
            Assert.Throws<ArgumentNullException>(() =>
            {
                rAcl = new RawAcl(0, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                myCollection = (ICollection)rAcl;
                myCollection.CopyTo(gAces, 0);
            });

            // Case 2, negative index
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                rAcl = new RawAcl(0, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                gAces = new GenericAce[rAcl.Count];
                myCollection = (ICollection)rAcl;
                myCollection.CopyTo(gAces, -1);
            });

            // Case 3, 0 size array
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                rAcl = new RawAcl(0, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                gAces = new GenericAce[0];
                myCollection = (ICollection)rAcl;
                myCollection.CopyTo(gAces, 0);
            });

            // Case 4, insufficient size array
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                rAcl = new RawAcl(0, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BG")), false, null);
                rAcl.InsertAce(0, gAce);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BO")), false, null);
                rAcl.InsertAce(0, gAce);

                gAces = new GenericAce[rAcl.Count - 1];
                myCollection = (ICollection)rAcl;
                myCollection.CopyTo(gAces, 0);
            });
            
            //Case 5, RawAcl with huge number of Aces
            rAcl = new RawAcl(0, GenericAcl.MaxBinaryLength);
            for (int i = 0; i < 1820; i++)
            {
                //this ace binary length is 36, 1820 * 36 = 65520
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, i + 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
            }
            gAces = new GenericAce[rAcl.Count];
            myCollection = (ICollection)rAcl;
            myCollection.CopyTo(gAces, 0);

            // Case 6, test ICollection.CopyTo, array rank is not one. all the other cases are tested by type-friendly version CopyTo
            //on my machine, a BCL assert as resource Rank_MutiDimNotSupported not found
            Assert.Throws<RankException>(() =>
            {
                rAcl = new RawAcl(0, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BG")), false, null);
                rAcl.InsertAce(0, gAce);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                GenericAce[,] gAces2 = new GenericAce[1, 2];
                myCollection = (ICollection)rAcl;
                myCollection.CopyTo(gAces2, 0);
            });
        }
Exemplo n.º 11
0
        public static void AdditionalTestCases()
        {
            GenericAce gAce = null;
            RawAcl rAcl = null;
            GenericAce[] gAces = null;


            // case 1, null array
            Assert.Throws<ArgumentNullException>(() =>
            {
                rAcl = new RawAcl(0, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                rAcl.CopyTo(gAces, 0);
            });

            // case 2, negative index
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                rAcl = new RawAcl(0, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                gAces = new GenericAce[rAcl.Count];
                rAcl.CopyTo(gAces, -1);
            });

            // case 3, insufficient size array
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                rAcl = new RawAcl(0, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                gAces = new GenericAce[0];
                rAcl.CopyTo(gAces, 0);
            });

            // Case 4, insufficient size array
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                rAcl = new RawAcl(0, 1);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BG")), false, null);
                rAcl.InsertAce(0, gAce);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BO")), false, null);
                rAcl.InsertAce(0, gAce);

                gAces = new GenericAce[rAcl.Count - 1];
                rAcl.CopyTo(gAces, 0);
            });
            
            //case 5, RawAcl with huge number of Aces
            rAcl = new RawAcl(0, GenericAcl.MaxBinaryLength);
            for (int i = 0; i < 1820; i++)
            {
                //this ace binary length is 36, 1820 * 36 = 65520                        
                gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, i + 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
                rAcl.InsertAce(0, gAce);
            }
            gAces = new GenericAce[rAcl.Count];
            rAcl.CopyTo(gAces, 0);
        }