Exemple #1
0
        // Copy the nodes of the first list. Note that the
        // list gets new nodes, but the Permissions aren't deep
        // copied. As long as we never directly expose a list,
        // and if the Permissions are treated as read only,
        // then this is OK.
        public PermissionList(PermissionList permList)

            : this()
        {
            if (permList == null || permList.m_head == null)
            {
                return;
            }

            // Assign head to a copy of the first node
            m_head = new PListNode(permList.m_head);

            // Use m_last to traverse list starting from head
            m_last = m_head;

            // While m_last isn't really the last, continue to
            // make copies of the original nodes that m_last.next points to.\
            // When we're done, m_last points to last of the copies.
            while (m_last.next != null)
            {
                m_last.next = new PListNode(m_last.next);
                m_last      = m_last.next;
            }

            // Copy how many elements there are.
            m_cElt = permList.m_cElt;
        }
        internal void GetZoneAndOrigin(ArrayList zoneList, ArrayList originList)
        {
            PermissionList zone = this.FindPermissionList(typeof(ZoneIdentityPermission));
            PermissionList url  = this.FindPermissionList(typeof(UrlIdentityPermission));

            IEnumerator enumerator;

            enumerator = new PermissionListEnumerator(zone);

            while (enumerator.MoveNext())
            {
                PListNode node = (PListNode)enumerator.Current;

                if (node.type == PermissionList.MatchChecked && node.perm != null)
                {
                    zoneList.Add(((ZoneIdentityPermission)node.perm).SecurityZone);
                }
            }

            enumerator = new PermissionListEnumerator(url);

            while (enumerator.MoveNext())
            {
                PListNode node = (PListNode)enumerator.Current;

                if (node.type == PermissionList.MatchChecked && node.perm != null)
                {
                    originList.Add(((UrlIdentityPermission)node.perm).Url);
                }
            }
        }
 internal PListNode(CodeAccessPermission perm, int type, PListNode next, PListNode prev)
 {
     this.perm = perm;
     this.type = type;
     this.next = next;
     this.prev = prev;
 }
Exemple #4
0
        // Appends a PermissionList to the current list.
        // NOTE: Since AppendList does not make a copy of the parameter before
        // appending it, operations on the newly formed list also side-effect
        // the parameter. If this is not desired, make a copy of the parameter
        // before calling AppendList.
        public virtual void AppendList(PermissionList permList)
        {
            // Check for null
            if (permList == null)
            {
                return;
            }

            // If current list is empty, then DO NOT
            // append list, possibly adding Permissions!
            if (m_head == null)
            {
                return;
            }
            // Append list only if the last element of the current list does
            // not guarantee a failed check, thus stopping a walk.
            else if (!(m_last.type == MatchChecked && m_last.perm == null))
            {
                // Make sure there is something in the target
                // list to append.
                if (permList.m_head != null)
                {
                    // Stick the head of the target list to the end of
                    // the current list...
                    m_last.next = permList.m_head;

                    // The new last is the last of the target list...
                    m_last = permList.m_last;

                    // Add up the elements.
                    m_cElt += permList.m_cElt;
                }
            }
        }
Exemple #5
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("[" + System.Environment.NewLine);

            PListNode pNext = m_head;

            while (pNext != null)
            {
                sb.Append("(");
                sb.Append(GetStringForType(pNext.type));
                sb.Append("," + System.Environment.NewLine);

                if (pNext.perm == null)
                {
                    sb.Append("null");
                }
                else
                {
                    sb.Append(pNext.perm.ToString());
                }

                sb.Append(")" + System.Environment.NewLine);

                pNext = pNext.next;
            }

            sb.Append("]");
            return(sb.ToString());
        }
 public void Reset()
 {
     if (m_list == null)
     {
         m_current = null;
     }
     else
     {
         m_current = new PListNode(null, 0, m_list.m_head, null);
     }
 }
        public virtual void AppendPermissionAndCompress(CodeAccessPermission perm, int type)
        {
            if (m_head == null)
            {
                BCLDebug.Assert(false, "You should not try to append and compress until there is atleast one other entry");
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_InvalidState"));
            }

            if (type == MatchChecked)
            {
                PListNode current = m_last;

                while (current != null)
                {
                    if (current.type == MatchChecked)
                    {
                        if (current.perm == null)
                        {
                            return;
                        }

                        if (perm == null)
                        {
                            current.perm = null;
                            return;
                        }

                        try
                        {
                            if (perm.IsSubsetOf(current.perm) &&
                                current.perm.IsSubsetOf(perm))
                            {
                                return;
                            }
                        }
                        catch (Exception)
                        {
                            // It is ok to catch and ignore exceptions here because
                            // it only means that we'll continue to iterate and worst-
                            // case add a new PListNode for the parameter perm instance.
                        }
                    }

                    current = current.prev;
                }
            }

            // If we get here, then add normally.
            m_last.next = new PListNode(perm, type, null, m_last);
            m_last      = m_last.next;
            m_cElt++;
        }
        public virtual bool MoveNext()
        {
            if (m_current == null)
            {
                return(false);
            }

            m_current = m_current.next;

            if (m_current == null)
            {
                return(false);
            }

            return(true);
        }
Exemple #9
0
        // Adds a Permission to the end of the list.
        //
        public virtual void AppendPermission(CodeAccessPermission perm, int type)
        {
            if (type <= MatchNone || type > MatchChecked)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMatchType"));
            }

            if (m_head == null)
            {
                m_head = new PListNode(perm, type, null);
                m_last = m_head;
            }
            else
            {
                m_last.next = new PListNode(perm, type, null);
                m_last      = m_last.next;
            }
            m_cElt++;
        }
Exemple #10
0
        public virtual void AppendPermissionAndCompress(CodeAccessPermission perm, int type)
        {
            if (m_head == null)
            {
                BCLDebug.Assert(false, "You should not try to append and compress until there is atleast one other entry");
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_InvalidState"));
            }

            // If the last type is "normal" then do some special checking
            // to try to reduce the size of the list.
            if (m_last.type == MatchChecked)
            {
                // If the last permission is null, then a check will fail
                // here. Don't bother adding anything past it.
                if (m_last.perm == null)
                {
                    return;
                }

                // If the type we are adding is "normal" then do an intersection
                // to optimize away a check.
                if (type == MatchChecked)
                {
                    if (perm != null)
                    {
                        m_last.perm = (CodeAccessPermission)m_last.perm.Intersect(perm);
                    }
                    else
                    {
                        m_last.perm = null;
                    }

                    // Done with "normal" permission.
                    return;
                }
            }

            // If we get here, then add normally.
            m_last.next = new PListNode(perm, type, null);
            m_last      = m_last.next;
            m_cElt++;
        }
Exemple #11
0
     // Copy the nodes of the first list. Note that the
     // list gets new nodes, but the Permissions aren't deep
     // copied. As long as we never directly expose a list,
     // and if the Permissions are treated as read only,
     // then this is OK.
     public PermissionList(PermissionList permList)
     
         : this() {
         if (permList == null || permList.m_head == null)
             return;
 
         // Assign head to a copy of the first node
         m_head = new PListNode(permList.m_head);
 
         // Use m_last to traverse list starting from head
         m_last = m_head;
 
         // While m_last isn't really the last, continue to
         // make copies of the original nodes that m_last.next points to.\
         // When we're done, m_last points to last of the copies.
         while (m_last.next != null)
         {
             m_last.next = new PListNode(m_last.next);
             m_last = m_last.next;
         }
         
         // Copy how many elements there are.
         m_cElt = permList.m_cElt;
     }
Exemple #12
0
     public virtual void AppendPermissionAndCompress(CodeAccessPermission perm, int type)
     {
         if (m_head == null)
         {
             BCLDebug.Assert( false, "You should not try to append and compress until there is atleast one other entry" );
             throw new InvalidOperationException( Environment.GetResourceString( "InvalidOperation_InvalidState" ) );
         }
         
         // If the last type is "normal" then do some special checking
         // to try to reduce the size of the list.
         if (m_last.type == MatchChecked)
         {
             // If the last permission is null, then a check will fail
             // here. Don't bother adding anything past it.
             if (m_last.perm == null)
                 return;
             
             // If the type we are adding is "normal" then do an intersection
             // to optimize away a check.
             if (type == MatchChecked)
             {
                 if (perm != null)
                 {
                     m_last.perm = (CodeAccessPermission) m_last.perm.Intersect(perm);
                 }
                 else
                 {
                     m_last.perm = null;
                 }
                 
                 // Done with "normal" permission.
                 return;
             }
         }
 
         // If we get here, then add normally.
         m_last.next = new PListNode(perm, type, null);
         m_last = m_last.next;
         m_cElt++;
     }
Exemple #13
0
        internal PListNode(PListNode plnode)

            : this(plnode.perm, plnode.type, plnode.next)
        {
        }
Exemple #14
0
 public virtual void AppendStack(PermissionList permList)
 {
     // Check for null
     if (permList == null)
         return;
     
     // If current list is empty, then DO NOT
     // append list, possibly adding Permissions!
     if (m_head == null)
     {
         return;
     }
     else
     {
         // Make sure there is something in the target
         // list to append.
         if (permList.m_head != null)
         {
             // If the last element of the current list and the first element of the
             // appended list are both of type MatchChecked, then we can merge the
             // entries together using intersect to conserve the number of entries
             // in the final list.
             if (m_last.type == MatchChecked && permList.m_head.type == MatchChecked)
             {
                 // If the entries are non-null, then call Intersect.
                 if (m_last.perm != null && permList.m_head.perm != null)
                 {
                     m_last.perm = (CodeAccessPermission) m_last.perm.Intersect(permList.m_head.perm);
                 }
                 else
                 {
                     m_last.perm = null;
                 }
                 
                 // If the last element is now null, then don't bother appending
                 // anything more. Also,
                 // if the combined element was the only element in the appended list,
                 // then there is nothing further to append. So, only do work to append
                 // if the m_head.next is non-null.
                 if (m_last.perm != null && permList.m_head.next != null)
                 {
                     // Stick the element after the head of the target list
                     // to the end of the current list...
                     m_last.next = permList.m_head.next;
                     
                     // The new last is the last element of the target list...
                     m_last = permList.m_last;
                     
                     // The new count is is the sum minus 1 to account for the
                     // merge performed above.
                     m_cElt += (permList.m_cElt - 1);
                 }
             }
             // Otherwise, append the list only if the last element is not a
             // guaranteed failure during a stack walk: the type is Normal and
             // it is null.
             else if (! (m_last.type == MatchChecked && m_last.perm == null))
             {
                 // Stick the head of the target list to the end of
                 // the current list...
                 m_last.next = permList.m_head;
                 
                 // The new last is the last of the target list...
                 m_last = permList.m_last;
                 
                 // Add up the elements.
                 m_cElt += permList.m_cElt;
             }
         }
     }
 }
Exemple #15
0
        public virtual void AppendStack(PermissionList permList)
        {
            // Check for null
            if (permList == null)
            {
                return;
            }

            // If current list is empty, then DO NOT
            // append list, possibly adding Permissions!
            if (m_head == null)
            {
                return;
            }
            else
            {
                // Make sure there is something in the target
                // list to append.
                if (permList.m_head != null)
                {
                    // If the last element of the current list and the first element of the
                    // appended list are both of type MatchChecked, then we can merge the
                    // entries together using intersect to conserve the number of entries
                    // in the final list.
                    if (m_last.type == MatchChecked && permList.m_head.type == MatchChecked)
                    {
                        // If the entries are non-null, then call Intersect.
                        if (m_last.perm != null && permList.m_head.perm != null)
                        {
                            m_last.perm = (CodeAccessPermission)m_last.perm.Intersect(permList.m_head.perm);
                        }
                        else
                        {
                            m_last.perm = null;
                        }

                        // If the last element is now null, then don't bother appending
                        // anything more. Also,
                        // if the combined element was the only element in the appended list,
                        // then there is nothing further to append. So, only do work to append
                        // if the m_head.next is non-null.
                        if (m_last.perm != null && permList.m_head.next != null)
                        {
                            // Stick the element after the head of the target list
                            // to the end of the current list...
                            m_last.next = permList.m_head.next;

                            // The new last is the last element of the target list...
                            m_last = permList.m_last;

                            // The new count is is the sum minus 1 to account for the
                            // merge performed above.
                            m_cElt += (permList.m_cElt - 1);
                        }
                    }
                    // Otherwise, append the list only if the last element is not a
                    // guaranteed failure during a stack walk: the type is Normal and
                    // it is null.
                    else if (!(m_last.type == MatchChecked && m_last.perm == null))
                    {
                        // Stick the head of the target list to the end of
                        // the current list...
                        m_last.next = permList.m_head;

                        // The new last is the last of the target list...
                        m_last = permList.m_last;

                        // Add up the elements.
                        m_cElt += permList.m_cElt;
                    }
                }
            }
        }
Exemple #16
0
 internal PListNode(PListNode plnode)
 
     : this(plnode.perm, plnode.type, plnode.next) {
 }
Exemple #17
0
        internal bool CheckDemandInternal(CodeAccessPermission demand, out Exception exception)
        {
            BCLDebug.Assert(m_head != null, "m_head != null");
            for (PListNode pnext = m_head; pnext != null; pnext = pnext.next)
            {
                if (pnext.perm == null)
                {
                    // If this is a grant set or a permit only, then we should fail since null indicates the empty permission.
                    if (pnext.type == MatchChecked || pnext.type == MatchPermitOnly)
                    {
                        BCLDebug.Assert(!demand.IsSubsetOf(null), "By the time we get here, demands that are subsets of null should have been terminated");
                        exception = new SecurityException(String.Format(Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName));
                        return(false);
                    }

                    // If this is a deny, then we should fail since null indicates the unrestricted permission.
                    if (pnext.type == MatchDeny)
                    {
                        exception = new SecurityException(String.Format(Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName));
                        return(false);
                    }

                    // If this is an assert, then we should return success and terminate the stack walk since
                    // null indicates the unrestricted permission.
                    if (pnext.type == MatchAssert)
                    {
                        exception = null;
                        return(false);
                    }

                    // If this is anything else, then we should act confused.
                    // This case is unexpected.
                    BCLDebug.Assert(false, "This case should never happen");
                    exception = new InvalidOperationException(Environment.GetResourceString("InvalidOperation_InvalidState"));
                    return(false);
                }

                CodeAccessPermission cap = pnext.perm;
                switch (pnext.type)
                {
                case MatchChecked:
                case MatchPermitOnly:
                    if (!demand.IsSubsetOf(cap))
                    {
                        exception = new SecurityException(String.Format(Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName));
                        return(false);
                    }
                    break;

                case MatchAssert:
                    if (demand.IsSubsetOf(cap))
                    {
                        exception = null;
                        return(false);
                    }
                    break;

                case MatchDeny:
                    if (demand.Intersect(cap) != null)
                    {
                        exception = new SecurityException(String.Format(Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName));
                        return(false);
                    }
                    break;

                default:
                    // Illegal entry
                    exception = new InvalidOperationException(Environment.GetResourceString("InvalidOperation_InvalidState"));
                    return(false);
                }
            }

            exception = null;
            return(true);
        }
Exemple #18
0
     // Appends a PermissionList to the current list.
     // NOTE: Since AppendList does not make a copy of the parameter before
     // appending it, operations on the newly formed list also side-effect
     // the parameter. If this is not desired, make a copy of the parameter
     // before calling AppendList.
     public virtual void AppendList(PermissionList permList)
     {
         // Check for null
         if (permList == null)
             return;
 
         // If current list is empty, then DO NOT
         // append list, possibly adding Permissions!
         if (m_head == null)
         {
             return;
         }
         // Append list only if the last element of the current list does
         // not guarantee a failed check, thus stopping a walk.
         else if (! (m_last.type == MatchChecked && m_last.perm == null))
         {
             // Make sure there is something in the target
             // list to append.
             if (permList.m_head != null)
             {
                 // Stick the head of the target list to the end of
                 // the current list...
                 m_last.next = permList.m_head;
                 
                 // The new last is the last of the target list...
                 m_last = permList.m_last;
                 
                 // Add up the elements.
                 m_cElt += permList.m_cElt;
             }
         }
     }
Exemple #19
0
 // Adds a Permission to the end of the list.
 // 
 public virtual void AppendPermission(CodeAccessPermission perm, int type)
 {
     if (type <= MatchNone || type > MatchChecked)
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMatchType"));
     
     if (m_head == null)
     {
         m_head = new PListNode(perm, type, null);
         m_last = m_head;
     }
     else
     {
         m_last.next = new PListNode(perm, type, null);
         m_last = m_last.next;
     }
     m_cElt++;
 }
Exemple #20
0
 internal PListNode(CodeAccessPermission perm, int type, PListNode next)
 {
     this.perm  = perm;
     this.type  = type;
     this.next  = next;
 }