コード例 #1
0
        private AuthorizationRuleCollection GetRules(bool access, bool includeExplicit, bool includeInherited, System.Type targetType)
        {
            ReadLock();

            try
            {
                AuthorizationRuleCollection result = new AuthorizationRuleCollection();

                if (!SecurityIdentifier.IsValidTargetTypeStatic(targetType))
                {
                    throw new ArgumentException(
                              Environment.GetResourceString("Arg_MustBeIdentityReferenceType"),
                              "targetType");
                }

                CommonAcl acl = null;

                if (access)
                {
                    if ((_securityDescriptor.ControlFlags & ControlFlags.DiscretionaryAclPresent) != 0)
                    {
                        acl = _securityDescriptor.DiscretionaryAcl;
                    }
                }
                else // !access == audit
                {
                    if ((_securityDescriptor.ControlFlags & ControlFlags.SystemAclPresent) != 0)
                    {
                        acl = _securityDescriptor.SystemAcl;
                    }
                }

                if (acl == null)
                {
                    //
                    // The required ACL was not present; return an empty collection.
                    //
                    return(result);
                }

                IdentityReferenceCollection irTarget = null;

                if (targetType != typeof(SecurityIdentifier))
                {
                    IdentityReferenceCollection irSource = new IdentityReferenceCollection(acl.Count);

                    for (int i = 0; i < acl.Count; i++)
                    {
                        //
                        // Calling the indexer on a common ACL results in cloning,
                        // (which would not be the case if we were to use the internal RawAcl property)
                        // but also ensures that the resulting order of ACEs is proper
                        // However, this is a big price to pay - cloning all the ACEs just so that
                        // the canonical order could be ascertained just once.
                        // A better way would be to have an internal method that would canonicalize the ACL
                        // and call it once, then use the RawAcl.
                        //
                        CommonAce ace = acl[i] as CommonAce;
                        if (AceNeedsTranslation(ace, access, includeExplicit, includeInherited))
                        {
                            irSource.Add(ace.SecurityIdentifier);
                        }
                    }

                    irTarget = irSource.Translate(targetType);
                }

                int targetIndex = 0;
                for (int i = 0; i < acl.Count; i++)
                {
                    //
                    // Calling the indexer on a common ACL results in cloning,
                    // (which would not be the case if we were to use the internal RawAcl property)
                    // but also ensures that the resulting order of ACEs is proper
                    // However, this is a big price to pay - cloning all the ACEs just so that
                    // the canonical order could be ascertained just once.
                    // A better way would be to have an internal method that would canonicalize the ACL
                    // and call it once, then use the RawAcl.
                    //

                    CommonAce ace = acl[i] as CommonAce;
                    if (AceNeedsTranslation(ace, access, includeExplicit, includeInherited))
                    {
                        IdentityReference iref = (targetType == typeof(SecurityIdentifier)) ? ace.SecurityIdentifier : irTarget[targetIndex++];

                        if (access)
                        {
                            AccessControlType type;

                            if (ace.AceQualifier == AceQualifier.AccessAllowed)
                            {
                                type = AccessControlType.Allow;
                            }
                            else
                            {
                                type = AccessControlType.Deny;
                            }

                            result.AddRule(
                                AccessRuleFactory(
                                    iref,
                                    ace.AccessMask,
                                    ace.IsInherited,
                                    ace.InheritanceFlags,
                                    ace.PropagationFlags,
                                    type));
                        }
                        else
                        {
                            result.AddRule(
                                AuditRuleFactory(
                                    iref,
                                    ace.AccessMask,
                                    ace.IsInherited,
                                    ace.InheritanceFlags,
                                    ace.PropagationFlags,
                                    ace.AuditFlags));
                        }
                    }
                }

                return(result);
            }
            finally
            {
                ReadUnlock();
            }
        }
コード例 #2
0
        private AuthorizationRuleCollection GetRules(bool access, bool includeExplicit, bool includeInherited, Type targetType)
        {
            AuthorizationRuleCollection rules2;

            base.ReadLock();
            try
            {
                AuthorizationRuleCollection rules = new AuthorizationRuleCollection();
                if (!SecurityIdentifier.IsValidTargetTypeStatic(targetType))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_MustBeIdentityReferenceType"), "targetType");
                }
                CommonAcl discretionaryAcl = null;
                if (access)
                {
                    if ((base._securityDescriptor.ControlFlags & ControlFlags.DiscretionaryAclPresent) != ControlFlags.None)
                    {
                        discretionaryAcl = base._securityDescriptor.DiscretionaryAcl;
                    }
                }
                else if ((base._securityDescriptor.ControlFlags & ControlFlags.SystemAclPresent) != ControlFlags.None)
                {
                    discretionaryAcl = base._securityDescriptor.SystemAcl;
                }
                if (discretionaryAcl == null)
                {
                    return(rules);
                }
                IdentityReferenceCollection references = null;
                if (targetType != typeof(SecurityIdentifier))
                {
                    IdentityReferenceCollection references2 = new IdentityReferenceCollection(discretionaryAcl.Count);
                    for (int j = 0; j < discretionaryAcl.Count; j++)
                    {
                        CommonAce ace = discretionaryAcl[j] as CommonAce;
                        if (this.AceNeedsTranslation(ace, access, includeExplicit, includeInherited))
                        {
                            references2.Add(ace.SecurityIdentifier);
                        }
                    }
                    references = references2.Translate(targetType);
                }
                int num2 = 0;
                for (int i = 0; i < discretionaryAcl.Count; i++)
                {
                    CommonAce ace2 = discretionaryAcl[i] as CommonAce;
                    if (this.AceNeedsTranslation(ace2, access, includeExplicit, includeInherited))
                    {
                        IdentityReference identityReference = (targetType == typeof(SecurityIdentifier)) ? ace2.SecurityIdentifier : references[num2++];
                        if (access)
                        {
                            AccessControlType allow;
                            if (ace2.AceQualifier == AceQualifier.AccessAllowed)
                            {
                                allow = AccessControlType.Allow;
                            }
                            else
                            {
                                allow = AccessControlType.Deny;
                            }
                            rules.AddRule(this.AccessRuleFactory(identityReference, ace2.AccessMask, ace2.IsInherited, ace2.InheritanceFlags, ace2.PropagationFlags, allow));
                        }
                        else
                        {
                            rules.AddRule(this.AuditRuleFactory(identityReference, ace2.AccessMask, ace2.IsInherited, ace2.InheritanceFlags, ace2.PropagationFlags, ace2.AuditFlags));
                        }
                    }
                }
                rules2 = rules;
            }
            finally
            {
                base.ReadUnlock();
            }
            return(rules2);
        }
コード例 #3
0
 private AuthorizationRuleCollection GetRules(bool access, bool includeExplicit, bool includeInherited, Type targetType)
 {
     this.ReadLock();
     try
     {
         AuthorizationRuleCollection authorizationRuleCollection = new AuthorizationRuleCollection();
         if (!SecurityIdentifier.IsValidTargetTypeStatic(targetType))
         {
             throw new ArgumentException(Environment.GetResourceString("Arg_MustBeIdentityReferenceType"), "targetType");
         }
         CommonAcl commonAcl = (CommonAcl)null;
         if (access)
         {
             if ((this._securityDescriptor.ControlFlags & ControlFlags.DiscretionaryAclPresent) != ControlFlags.None)
             {
                 commonAcl = (CommonAcl)this._securityDescriptor.DiscretionaryAcl;
             }
         }
         else if ((this._securityDescriptor.ControlFlags & ControlFlags.SystemAclPresent) != ControlFlags.None)
         {
             commonAcl = (CommonAcl)this._securityDescriptor.SystemAcl;
         }
         if (commonAcl == null)
         {
             return(authorizationRuleCollection);
         }
         IdentityReferenceCollection referenceCollection1 = (IdentityReferenceCollection)null;
         if (targetType != typeof(SecurityIdentifier))
         {
             IdentityReferenceCollection referenceCollection2 = new IdentityReferenceCollection(commonAcl.Count);
             for (int index = 0; index < commonAcl.Count; ++index)
             {
                 QualifiedAce qualifiedAce = commonAcl[index] as QualifiedAce;
                 if (!((GenericAce)qualifiedAce == (GenericAce)null) && !qualifiedAce.IsCallback)
                 {
                     if (access)
                     {
                         if (qualifiedAce.AceQualifier != AceQualifier.AccessAllowed && qualifiedAce.AceQualifier != AceQualifier.AccessDenied)
                         {
                             continue;
                         }
                     }
                     else if (qualifiedAce.AceQualifier != AceQualifier.SystemAudit)
                     {
                         continue;
                     }
                     referenceCollection2.Add((IdentityReference)qualifiedAce.SecurityIdentifier);
                 }
             }
             referenceCollection1 = referenceCollection2.Translate(targetType);
         }
         for (int index = 0; index < commonAcl.Count; ++index)
         {
             QualifiedAce qualifiedAce = (QualifiedAce)(commonAcl[index] as CommonAce);
             if ((GenericAce)qualifiedAce == (GenericAce)null)
             {
                 qualifiedAce = (QualifiedAce)(commonAcl[index] as ObjectAce);
                 if ((GenericAce)qualifiedAce == (GenericAce)null)
                 {
                     continue;
                 }
             }
             if (!qualifiedAce.IsCallback)
             {
                 if (access)
                 {
                     if (qualifiedAce.AceQualifier != AceQualifier.AccessAllowed && qualifiedAce.AceQualifier != AceQualifier.AccessDenied)
                     {
                         continue;
                     }
                 }
                 else if (qualifiedAce.AceQualifier != AceQualifier.SystemAudit)
                 {
                     continue;
                 }
                 if (includeExplicit && (qualifiedAce.AceFlags & AceFlags.Inherited) == AceFlags.None || includeInherited && (qualifiedAce.AceFlags & AceFlags.Inherited) != AceFlags.None)
                 {
                     IdentityReference identityReference = targetType == typeof(SecurityIdentifier) ? (IdentityReference)qualifiedAce.SecurityIdentifier : referenceCollection1[index];
                     if (access)
                     {
                         AccessControlType type = qualifiedAce.AceQualifier != AceQualifier.AccessAllowed ? AccessControlType.Deny : AccessControlType.Allow;
                         if (qualifiedAce is ObjectAce)
                         {
                             ObjectAce objectAce = qualifiedAce as ObjectAce;
                             authorizationRuleCollection.AddRule((AuthorizationRule)this.AccessRuleFactory(identityReference, objectAce.AccessMask, objectAce.IsInherited, objectAce.InheritanceFlags, objectAce.PropagationFlags, type, objectAce.ObjectAceType, objectAce.InheritedObjectAceType));
                         }
                         else
                         {
                             CommonAce commonAce = qualifiedAce as CommonAce;
                             if (!((GenericAce)commonAce == (GenericAce)null))
                             {
                                 authorizationRuleCollection.AddRule((AuthorizationRule)this.AccessRuleFactory(identityReference, commonAce.AccessMask, commonAce.IsInherited, commonAce.InheritanceFlags, commonAce.PropagationFlags, type));
                             }
                         }
                     }
                     else if (qualifiedAce is ObjectAce)
                     {
                         ObjectAce objectAce = qualifiedAce as ObjectAce;
                         authorizationRuleCollection.AddRule((AuthorizationRule)this.AuditRuleFactory(identityReference, objectAce.AccessMask, objectAce.IsInherited, objectAce.InheritanceFlags, objectAce.PropagationFlags, objectAce.AuditFlags, objectAce.ObjectAceType, objectAce.InheritedObjectAceType));
                     }
                     else
                     {
                         CommonAce commonAce = qualifiedAce as CommonAce;
                         if (!((GenericAce)commonAce == (GenericAce)null))
                         {
                             authorizationRuleCollection.AddRule((AuthorizationRule)this.AuditRuleFactory(identityReference, commonAce.AccessMask, commonAce.IsInherited, commonAce.InheritanceFlags, commonAce.PropagationFlags, commonAce.AuditFlags));
                         }
                     }
                 }
             }
         }
         return(authorizationRuleCollection);
     }
     finally
     {
         this.ReadUnlock();
     }
 }
コード例 #4
0
        private AuthorizationRuleCollection GetRules(bool access, bool includeExplicit, bool includeInherited, Type targetType)
        {
            AuthorizationRuleCollection rules2;

            base.ReadLock();
            try
            {
                AuthorizationRuleCollection rules = new AuthorizationRuleCollection();
                if (!SecurityIdentifier.IsValidTargetTypeStatic(targetType))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_MustBeIdentityReferenceType"), "targetType");
                }
                CommonAcl discretionaryAcl = null;
                if (access)
                {
                    if ((base._securityDescriptor.ControlFlags & ControlFlags.DiscretionaryAclPresent) != ControlFlags.None)
                    {
                        discretionaryAcl = base._securityDescriptor.DiscretionaryAcl;
                    }
                }
                else if ((base._securityDescriptor.ControlFlags & ControlFlags.SystemAclPresent) != ControlFlags.None)
                {
                    discretionaryAcl = base._securityDescriptor.SystemAcl;
                }
                if (discretionaryAcl == null)
                {
                    return(rules);
                }
                IdentityReferenceCollection references = null;
                if (targetType != typeof(SecurityIdentifier))
                {
                    IdentityReferenceCollection references2 = new IdentityReferenceCollection(discretionaryAcl.Count);
                    for (int j = 0; j < discretionaryAcl.Count; j++)
                    {
                        QualifiedAce ace = discretionaryAcl[j] as QualifiedAce;
                        if ((ace == null) || ace.IsCallback)
                        {
                            continue;
                        }
                        if (access)
                        {
                            if ((ace.AceQualifier == AceQualifier.AccessAllowed) || (ace.AceQualifier == AceQualifier.AccessDenied))
                            {
                                goto Label_00DD;
                            }
                            continue;
                        }
                        if (ace.AceQualifier != AceQualifier.SystemAudit)
                        {
                            continue;
                        }
Label_00DD:
                        references2.Add(ace.SecurityIdentifier);
                    }
                    references = references2.Translate(targetType);
                }
                for (int i = 0; i < discretionaryAcl.Count; i++)
                {
                    QualifiedAce ace2 = discretionaryAcl[i] as CommonAce;
                    if (ace2 == null)
                    {
                        ace2 = discretionaryAcl[i] as ObjectAce;
                        if (ace2 == null)
                        {
                            continue;
                        }
                    }
                    if (ace2.IsCallback)
                    {
                        continue;
                    }
                    if (access)
                    {
                        if ((ace2.AceQualifier == AceQualifier.AccessAllowed) || (ace2.AceQualifier == AceQualifier.AccessDenied))
                        {
                            goto Label_0174;
                        }
                        continue;
                    }
                    if (ace2.AceQualifier != AceQualifier.SystemAudit)
                    {
                        continue;
                    }
Label_0174:
                    if ((includeExplicit && (((byte)(ace2.AceFlags & AceFlags.Inherited)) == 0)) || (includeInherited && (((byte)(ace2.AceFlags & AceFlags.Inherited)) != 0)))
                    {
                        IdentityReference identityReference = (targetType == typeof(SecurityIdentifier)) ? ace2.SecurityIdentifier : references[i];
                        if (access)
                        {
                            AccessControlType allow;
                            if (ace2.AceQualifier == AceQualifier.AccessAllowed)
                            {
                                allow = AccessControlType.Allow;
                            }
                            else
                            {
                                allow = AccessControlType.Deny;
                            }
                            if (ace2 is ObjectAce)
                            {
                                ObjectAce ace3 = ace2 as ObjectAce;
                                rules.AddRule(this.AccessRuleFactory(identityReference, ace3.AccessMask, ace3.IsInherited, ace3.InheritanceFlags, ace3.PropagationFlags, allow, ace3.ObjectAceType, ace3.InheritedObjectAceType));
                            }
                            else
                            {
                                CommonAce ace4 = ace2 as CommonAce;
                                if (ace4 != null)
                                {
                                    rules.AddRule(this.AccessRuleFactory(identityReference, ace4.AccessMask, ace4.IsInherited, ace4.InheritanceFlags, ace4.PropagationFlags, allow));
                                }
                            }
                        }
                        else if (ace2 is ObjectAce)
                        {
                            ObjectAce ace5 = ace2 as ObjectAce;
                            rules.AddRule(this.AuditRuleFactory(identityReference, ace5.AccessMask, ace5.IsInherited, ace5.InheritanceFlags, ace5.PropagationFlags, ace5.AuditFlags, ace5.ObjectAceType, ace5.InheritedObjectAceType));
                        }
                        else
                        {
                            CommonAce ace6 = ace2 as CommonAce;
                            if (ace6 != null)
                            {
                                rules.AddRule(this.AuditRuleFactory(identityReference, ace6.AccessMask, ace6.IsInherited, ace6.InheritanceFlags, ace6.PropagationFlags, ace6.AuditFlags));
                            }
                        }
                    }
                }
                rules2 = rules;
            }
            finally
            {
                base.ReadUnlock();
            }
            return(rules2);
        }
コード例 #5
0
        // Token: 0x06001FE3 RID: 8163 RVA: 0x0006EFBC File Offset: 0x0006D1BC
        private AuthorizationRuleCollection GetRules(bool access, bool includeExplicit, bool includeInherited, Type targetType)
        {
            base.ReadLock();
            AuthorizationRuleCollection result;

            try
            {
                AuthorizationRuleCollection authorizationRuleCollection = new AuthorizationRuleCollection();
                if (!SecurityIdentifier.IsValidTargetTypeStatic(targetType))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_MustBeIdentityReferenceType"), "targetType");
                }
                CommonAcl commonAcl = null;
                if (access)
                {
                    if ((this._securityDescriptor.ControlFlags & ControlFlags.DiscretionaryAclPresent) != ControlFlags.None)
                    {
                        commonAcl = this._securityDescriptor.DiscretionaryAcl;
                    }
                }
                else if ((this._securityDescriptor.ControlFlags & ControlFlags.SystemAclPresent) != ControlFlags.None)
                {
                    commonAcl = this._securityDescriptor.SystemAcl;
                }
                if (commonAcl == null)
                {
                    result = authorizationRuleCollection;
                }
                else
                {
                    IdentityReferenceCollection identityReferenceCollection = null;
                    if (targetType != typeof(SecurityIdentifier))
                    {
                        IdentityReferenceCollection identityReferenceCollection2 = new IdentityReferenceCollection(commonAcl.Count);
                        for (int i = 0; i < commonAcl.Count; i++)
                        {
                            CommonAce commonAce = commonAcl[i] as CommonAce;
                            if (this.AceNeedsTranslation(commonAce, access, includeExplicit, includeInherited))
                            {
                                identityReferenceCollection2.Add(commonAce.SecurityIdentifier);
                            }
                        }
                        identityReferenceCollection = identityReferenceCollection2.Translate(targetType);
                    }
                    int num = 0;
                    for (int j = 0; j < commonAcl.Count; j++)
                    {
                        CommonAce commonAce2 = commonAcl[j] as CommonAce;
                        if (this.AceNeedsTranslation(commonAce2, access, includeExplicit, includeInherited))
                        {
                            IdentityReference identityReference = (targetType == typeof(SecurityIdentifier)) ? commonAce2.SecurityIdentifier : identityReferenceCollection[num++];
                            if (access)
                            {
                                AccessControlType type;
                                if (commonAce2.AceQualifier == AceQualifier.AccessAllowed)
                                {
                                    type = AccessControlType.Allow;
                                }
                                else
                                {
                                    type = AccessControlType.Deny;
                                }
                                authorizationRuleCollection.AddRule(this.AccessRuleFactory(identityReference, commonAce2.AccessMask, commonAce2.IsInherited, commonAce2.InheritanceFlags, commonAce2.PropagationFlags, type));
                            }
                            else
                            {
                                authorizationRuleCollection.AddRule(this.AuditRuleFactory(identityReference, commonAce2.AccessMask, commonAce2.IsInherited, commonAce2.InheritanceFlags, commonAce2.PropagationFlags, commonAce2.AuditFlags));
                            }
                        }
                    }
                    result = authorizationRuleCollection;
                }
            }
            finally
            {
                base.ReadUnlock();
            }
            return(result);
        }
コード例 #6
0
        // Token: 0x06001FF6 RID: 8182 RVA: 0x0006FAEC File Offset: 0x0006DCEC
        private AuthorizationRuleCollection GetRules(bool access, bool includeExplicit, bool includeInherited, Type targetType)
        {
            base.ReadLock();
            AuthorizationRuleCollection result;

            try
            {
                AuthorizationRuleCollection authorizationRuleCollection = new AuthorizationRuleCollection();
                if (!SecurityIdentifier.IsValidTargetTypeStatic(targetType))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_MustBeIdentityReferenceType"), "targetType");
                }
                CommonAcl commonAcl = null;
                if (access)
                {
                    if ((this._securityDescriptor.ControlFlags & ControlFlags.DiscretionaryAclPresent) != ControlFlags.None)
                    {
                        commonAcl = this._securityDescriptor.DiscretionaryAcl;
                    }
                }
                else if ((this._securityDescriptor.ControlFlags & ControlFlags.SystemAclPresent) != ControlFlags.None)
                {
                    commonAcl = this._securityDescriptor.SystemAcl;
                }
                if (commonAcl == null)
                {
                    result = authorizationRuleCollection;
                }
                else
                {
                    IdentityReferenceCollection identityReferenceCollection = null;
                    if (targetType != typeof(SecurityIdentifier))
                    {
                        IdentityReferenceCollection identityReferenceCollection2 = new IdentityReferenceCollection(commonAcl.Count);
                        for (int i = 0; i < commonAcl.Count; i++)
                        {
                            QualifiedAce qualifiedAce = commonAcl[i] as QualifiedAce;
                            if (!(qualifiedAce == null) && !qualifiedAce.IsCallback)
                            {
                                if (access)
                                {
                                    if (qualifiedAce.AceQualifier != AceQualifier.AccessAllowed && qualifiedAce.AceQualifier != AceQualifier.AccessDenied)
                                    {
                                        goto IL_EB;
                                    }
                                }
                                else if (qualifiedAce.AceQualifier != AceQualifier.SystemAudit)
                                {
                                    goto IL_EB;
                                }
                                identityReferenceCollection2.Add(qualifiedAce.SecurityIdentifier);
                            }
                            IL_EB :;
                        }
                        identityReferenceCollection = identityReferenceCollection2.Translate(targetType);
                    }
                    int j = 0;
                    while (j < commonAcl.Count)
                    {
                        QualifiedAce qualifiedAce2 = commonAcl[j] as CommonAce;
                        if (!(qualifiedAce2 == null))
                        {
                            goto IL_142;
                        }
                        qualifiedAce2 = (commonAcl[j] as ObjectAce);
                        if (!(qualifiedAce2 == null))
                        {
                            goto IL_142;
                        }
IL_306:
                        j++;
                        continue;
IL_142:
                        if (qualifiedAce2.IsCallback)
                        {
                            goto IL_306;
                        }
                        if (access)
                        {
                            if (qualifiedAce2.AceQualifier != AceQualifier.AccessAllowed && qualifiedAce2.AceQualifier != AceQualifier.AccessDenied)
                            {
                                goto IL_306;
                            }
                        }
                        else if (qualifiedAce2.AceQualifier != AceQualifier.SystemAudit)
                        {
                            goto IL_306;
                        }
                        if ((!includeExplicit || (qualifiedAce2.AceFlags & AceFlags.Inherited) != AceFlags.None) && (!includeInherited || (qualifiedAce2.AceFlags & AceFlags.Inherited) == AceFlags.None))
                        {
                            goto IL_306;
                        }
                        IdentityReference identityReference = (targetType == typeof(SecurityIdentifier)) ? qualifiedAce2.SecurityIdentifier : identityReferenceCollection[j];
                        if (access)
                        {
                            AccessControlType type;
                            if (qualifiedAce2.AceQualifier == AceQualifier.AccessAllowed)
                            {
                                type = AccessControlType.Allow;
                            }
                            else
                            {
                                type = AccessControlType.Deny;
                            }
                            if (qualifiedAce2 is ObjectAce)
                            {
                                ObjectAce objectAce = qualifiedAce2 as ObjectAce;
                                authorizationRuleCollection.AddRule(this.AccessRuleFactory(identityReference, objectAce.AccessMask, objectAce.IsInherited, objectAce.InheritanceFlags, objectAce.PropagationFlags, type, objectAce.ObjectAceType, objectAce.InheritedObjectAceType));
                                goto IL_306;
                            }
                            CommonAce commonAce = qualifiedAce2 as CommonAce;
                            if (!(commonAce == null))
                            {
                                authorizationRuleCollection.AddRule(this.AccessRuleFactory(identityReference, commonAce.AccessMask, commonAce.IsInherited, commonAce.InheritanceFlags, commonAce.PropagationFlags, type));
                                goto IL_306;
                            }
                            goto IL_306;
                        }
                        else
                        {
                            if (qualifiedAce2 is ObjectAce)
                            {
                                ObjectAce objectAce2 = qualifiedAce2 as ObjectAce;
                                authorizationRuleCollection.AddRule(this.AuditRuleFactory(identityReference, objectAce2.AccessMask, objectAce2.IsInherited, objectAce2.InheritanceFlags, objectAce2.PropagationFlags, objectAce2.AuditFlags, objectAce2.ObjectAceType, objectAce2.InheritedObjectAceType));
                                goto IL_306;
                            }
                            CommonAce commonAce2 = qualifiedAce2 as CommonAce;
                            if (!(commonAce2 == null))
                            {
                                authorizationRuleCollection.AddRule(this.AuditRuleFactory(identityReference, commonAce2.AccessMask, commonAce2.IsInherited, commonAce2.InheritanceFlags, commonAce2.PropagationFlags, commonAce2.AuditFlags));
                                goto IL_306;
                            }
                            goto IL_306;
                        }
                    }
                    result = authorizationRuleCollection;
                }
            }
            finally
            {
                base.ReadUnlock();
            }
            return(result);
        }
コード例 #7
0
 private AuthorizationRuleCollection GetRules(bool access, bool includeExplicit, bool includeInherited, Type targetType)
 {
     this.ReadLock();
     try
     {
         AuthorizationRuleCollection authorizationRuleCollection = new AuthorizationRuleCollection();
         if (!SecurityIdentifier.IsValidTargetTypeStatic(targetType))
         {
             throw new ArgumentException(Environment.GetResourceString("Arg_MustBeIdentityReferenceType"), "targetType");
         }
         CommonAcl commonAcl = (CommonAcl)null;
         if (access)
         {
             if ((this._securityDescriptor.ControlFlags & ControlFlags.DiscretionaryAclPresent) != ControlFlags.None)
             {
                 commonAcl = (CommonAcl)this._securityDescriptor.DiscretionaryAcl;
             }
         }
         else if ((this._securityDescriptor.ControlFlags & ControlFlags.SystemAclPresent) != ControlFlags.None)
         {
             commonAcl = (CommonAcl)this._securityDescriptor.SystemAcl;
         }
         if (commonAcl == null)
         {
             return(authorizationRuleCollection);
         }
         IdentityReferenceCollection referenceCollection1 = (IdentityReferenceCollection)null;
         if (targetType != typeof(SecurityIdentifier))
         {
             IdentityReferenceCollection referenceCollection2 = new IdentityReferenceCollection(commonAcl.Count);
             for (int index = 0; index < commonAcl.Count; ++index)
             {
                 CommonAce ace = commonAcl[index] as CommonAce;
                 if (this.AceNeedsTranslation(ace, access, includeExplicit, includeInherited))
                 {
                     referenceCollection2.Add((IdentityReference)ace.SecurityIdentifier);
                 }
             }
             referenceCollection1 = referenceCollection2.Translate(targetType);
         }
         int num = 0;
         for (int index = 0; index < commonAcl.Count; ++index)
         {
             CommonAce ace = commonAcl[index] as CommonAce;
             if (this.AceNeedsTranslation(ace, access, includeExplicit, includeInherited))
             {
                 IdentityReference identityReference = targetType == typeof(SecurityIdentifier) ? (IdentityReference)ace.SecurityIdentifier : referenceCollection1[num++];
                 if (access)
                 {
                     AccessControlType type = ace.AceQualifier != AceQualifier.AccessAllowed ? AccessControlType.Deny : AccessControlType.Allow;
                     authorizationRuleCollection.AddRule((AuthorizationRule)this.AccessRuleFactory(identityReference, ace.AccessMask, ace.IsInherited, ace.InheritanceFlags, ace.PropagationFlags, type));
                 }
                 else
                 {
                     authorizationRuleCollection.AddRule((AuthorizationRule)this.AuditRuleFactory(identityReference, ace.AccessMask, ace.IsInherited, ace.InheritanceFlags, ace.PropagationFlags, ace.AuditFlags));
                 }
             }
         }
         return(authorizationRuleCollection);
     }
     finally
     {
         this.ReadUnlock();
     }
 }