private Parser(Tokenizer t)
 {
     this._t = t;
     this._doc = null;
     try
     {
         this.ParseContents();
     }
     finally
     {
         this._t.Recycle();
     }
 }
 internal SecurityDocumentElement( SecurityDocument document, int position )
 {
     m_document = document;
     m_position = position;
 }
Пример #3
0
 // Token: 0x06001BFE RID: 7166 RVA: 0x000606A5 File Offset: 0x0005E8A5
 internal SecurityDocumentElement(SecurityDocument document, int position)
 {
     this.m_document = document;
     this.m_position = position;
 }
Пример #4
0
        internal virtual void FromXml( SecurityDocument doc, int position, bool allowInternalOnly )
        {
            if (doc == null)
                throw new ArgumentNullException("doc");
            Contract.EndContractBlock();
            
            if (!doc.GetTagForElement( position ).Equals(s_str_PermissionSet))
                throw new ArgumentException(String.Format( null, Environment.GetResourceString( "Argument_InvalidXMLElement" ), "PermissionSet", this.GetType().FullName) );
            
            Reset();
            m_allPermissionsDecoded = false;
            Exception savedException = null;
            String strUnrestricted = doc.GetAttributeForElement( position, "Unrestricted" );
            if (strUnrestricted != null)
                m_Unrestricted = strUnrestricted.Equals( "True" ) || strUnrestricted.Equals( "true" ) || strUnrestricted.Equals( "TRUE" );
            else
                m_Unrestricted = false;

            ArrayList childrenIndices = doc.GetChildrenPositionForElement( position );
            int childCount = childrenIndices.Count;
            for (int i = 0; i < childCount; ++i)
            {
                int childIndex = (int)childrenIndices[i];
                if (IsPermissionTag( doc.GetTagForElement( childIndex ), allowInternalOnly ))
                {
                    try
                    {
                        String className = doc.GetAttributeForElement( childIndex, "class" );

                        PermissionToken token;
                        Object objectToInsert;
                        
                        if (className != null)
                        {
                            token = PermissionToken.GetToken( className );
                            if (token == null)
                            {
                                objectToInsert = CreatePerm( doc.GetElement( childIndex, true ) );

                                if (objectToInsert != null)
                                {
#if _DEBUG
                                    PermissionToken tokenDebug = PermissionToken.GetToken( (IPermission)objectToInsert );
                                    Contract.Assert((tokenDebug != null), "PermissionToken.GetToken returned null ");
                                    Contract.Assert( (tokenDebug.m_type & PermissionTokenType.BuiltIn) != 0, "This should only be called for built-ins" );
#endif
                                    Contract.Assert( objectToInsert.GetType().Module.Assembly == System.Reflection.Assembly.GetExecutingAssembly(),
                                        "PermissionToken.GetToken returned null for non-mscorlib permission" );
                                    token = PermissionToken.GetToken( (IPermission)objectToInsert );
                                    Contract.Assert((token != null), "PermissionToken.GetToken returned null ");
                                    Contract.Assert( (token.m_type & PermissionTokenType.DontKnow) == 0, "We should always know the permission type when getting a token from an instance" );
                                }
                            }
                            else
                            {
                                objectToInsert = ((ISecurityElementFactory)new SecurityDocumentElement(doc, childIndex)).CreateSecurityElement();
                            }
                        }
                        else
                        {
                            IPermission ip = CreatePerm( doc.GetElement( childIndex, true ) );
                            if (ip == null)
                            {
                                token = null;
                                objectToInsert = null;
                            }
                            else
                            {
                                token = PermissionToken.GetToken( ip );
                                Contract.Assert( PermissionToken.IsTokenProperlyAssigned( ip, token ),
                                                 "PermissionToken was improperly assigned" );
                                objectToInsert = ip;
                            }
                        }

                        if (token != null && objectToInsert != null)
                        {
                            if (m_permSet == null)
                                m_permSet = new TokenBasedSet();

                            IPermission permInSlot = null;
                            if (this.m_permSet.GetItem( token.m_index ) != null)
                            {
                                // If there is already something in that slot, let's union them
                                // together.
                                
                                if (this.m_permSet.GetItem( token.m_index ) is IPermission)
                                    permInSlot = (IPermission)this.m_permSet.GetItem( token.m_index );
                                else
                                    permInSlot = CreatePerm( this.m_permSet.GetItem( token.m_index ) );
                            }

                            if (permInSlot != null)
                            {
                                if (objectToInsert is IPermission)
                                    objectToInsert = permInSlot.Union((IPermission)objectToInsert);
                                else
                                    objectToInsert = permInSlot.Union(CreatePerm( objectToInsert ));
                            }

                            if(m_Unrestricted && objectToInsert is IPermission)
                                objectToInsert = null;

                            this.m_permSet.SetItem( token.m_index, objectToInsert );
                        }
                    }
                    catch (Exception e)
                    {
#if _DEBUG
                        if (debug)
                            DEBUG_WRITE( "error while decoding permission set =\n" + e.ToString() );
#endif
                        if (savedException == null)
                            savedException = e;

                    }
                }
            }

            if (savedException != null)
                throw savedException;
                
        }
 internal void FromXml(SecurityDocument doc, int position, PolicyLevel level, bool allowInternalOnly)
 {
     if (doc == null)
     {
         throw new ArgumentNullException("doc");
     }
     if (!doc.GetTagForElement(position).Equals("PolicyStatement"))
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "PolicyStatement", base.GetType().FullName }));
     }
     this.m_attributes = PolicyStatementAttribute.Nothing;
     string attributeForElement = doc.GetAttributeForElement(position, "Attributes");
     if (attributeForElement != null)
     {
         this.m_attributes = (PolicyStatementAttribute) Enum.Parse(typeof(PolicyStatementAttribute), attributeForElement);
     }
     lock (this)
     {
         this.m_permSet = null;
         if (level != null)
         {
             string name = doc.GetAttributeForElement(position, "PermissionSetName");
             if (name != null)
             {
                 this.m_permSet = level.GetNamedPermissionSetInternal(name);
                 if (this.m_permSet == null)
                 {
                     this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                 }
             }
         }
         if (this.m_permSet == null)
         {
             ArrayList childrenPositionForElement = doc.GetChildrenPositionForElement(position);
             int num = -1;
             for (int i = 0; i < childrenPositionForElement.Count; i++)
             {
                 if (doc.GetTagForElement((int) childrenPositionForElement[i]).Equals("PermissionSet"))
                 {
                     num = (int) childrenPositionForElement[i];
                 }
             }
             if (num == -1)
             {
                 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
             }
             string str3 = doc.GetAttributeForElement(num, "class");
             if ((str3 != null) && (str3.Equals("NamedPermissionSet") || str3.Equals("System.Security.NamedPermissionSet")))
             {
                 this.m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
             }
             else
             {
                 this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
             }
             this.m_permSet.FromXml(doc, num, allowInternalOnly);
         }
         if (this.m_permSet == null)
         {
             this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
         }
     }
 }
Пример #6
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void FromXml( SecurityDocument doc, int position, PolicyLevel level, bool allowInternalOnly )
        {
            if (doc == null)
                throw new ArgumentNullException( "doc" );
            Contract.EndContractBlock();

            if (!doc.GetTagForElement( position ).Equals( "PolicyStatement" ))
                throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidXMLElement" ),  "PolicyStatement", this.GetType().FullName ) );
        
            m_attributes = (PolicyStatementAttribute) 0;

            String strAttributes = doc.GetAttributeForElement( position, "Attributes" );

            if (strAttributes != null)
                m_attributes = (PolicyStatementAttribute)Enum.Parse( typeof( PolicyStatementAttribute ), strAttributes );

            lock (this)
            {
                m_permSet = null;

                if (level != null)
                {
                    String permSetName = doc.GetAttributeForElement( position, "PermissionSetName" );
    
                    if (permSetName != null)
                    {
                        m_permSet = level.GetNamedPermissionSetInternal( permSetName );

                        if (m_permSet == null)
                            m_permSet = new PermissionSet( PermissionState.None );
                    }
                }


                if (m_permSet == null)
                {
                    // There is no provided level, it is not a named permission set, or
                    // the named permission set doesn't exist in the provided level,
                    // so just create the class through reflection and decode normally.
        
                    ArrayList childPositions = doc.GetChildrenPositionForElement( position );
                    int positionPermissionSet = -1;

                    for (int i = 0; i < childPositions.Count; ++i)
                    {
                        if (doc.GetTagForElement( (int)childPositions[i] ).Equals( "PermissionSet" ))
                        {
                            positionPermissionSet = (int)childPositions[i];
                        }
                    }

                    if (positionPermissionSet != -1)
                    {
                        String className = doc.GetAttributeForElement( positionPermissionSet, "class" );

                        if (className != null && (className.Equals( "NamedPermissionSet" ) ||
                                                  className.Equals( "System.Security.NamedPermissionSet" )))
                            m_permSet = new NamedPermissionSet( "DefaultName", PermissionState.None );
                        else
                            m_permSet = new PermissionSet( PermissionState.None );
                
                        m_permSet.FromXml( doc, positionPermissionSet, allowInternalOnly );
                    }
                    else
                    {
                        throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidXML" ) );
                    }
                }

                if (m_permSet == null) 
                    m_permSet = new PermissionSet( PermissionState.None );
            }    
        }
 private PolicyStatement CheckCache(int count, byte[] serializedEvidence)
 {
     byte[] buffer;
     if (this.m_configId == System.Security.Policy.ConfigId.None)
     {
         return null;
     }
     if (!Config.GetCacheEntry(this.m_configId, count, serializedEvidence, out buffer))
     {
         return null;
     }
     PolicyStatement statement = new PolicyStatement();
     SecurityDocument doc = new SecurityDocument(buffer);
     statement.FromXml(doc, 0, null, true);
     return statement;
 }
 private void Cache(int count, byte[] serializedEvidence, PolicyStatement policy)
 {
     if (this.m_configId != System.Security.Policy.ConfigId.None)
     {
         byte[] data = new SecurityDocument(policy.ToXml(null, true)).m_data;
         Config.AddCacheEntry(this.m_configId, count, serializedEvidence, data);
     }
 }
 internal virtual void FromXml(SecurityDocument doc, int position, bool allowInternalOnly)
 {
     if (doc == null)
     {
         throw new ArgumentNullException("doc");
     }
     if (!doc.GetTagForElement(position).Equals("PermissionSet"))
     {
         throw new ArgumentException(string.Format(null, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "PermissionSet", base.GetType().FullName }));
     }
     this.Reset();
     this.m_allPermissionsDecoded = false;
     Exception exception = null;
     string attributeForElement = doc.GetAttributeForElement(position, "Unrestricted");
     if (attributeForElement != null)
     {
         this.m_Unrestricted = (attributeForElement.Equals("True") || attributeForElement.Equals("true")) || attributeForElement.Equals("TRUE");
     }
     else
     {
         this.m_Unrestricted = false;
     }
     ArrayList childrenPositionForElement = doc.GetChildrenPositionForElement(position);
     int count = childrenPositionForElement.Count;
     for (int i = 0; i < count; i++)
     {
         int num3 = (int) childrenPositionForElement[i];
         if (IsPermissionTag(doc.GetTagForElement(num3), allowInternalOnly))
         {
             try
             {
                 PermissionToken token;
                 object obj2;
                 string typeStr = doc.GetAttributeForElement(num3, "class");
                 if (typeStr != null)
                 {
                     token = PermissionToken.GetToken(typeStr);
                     if (token == null)
                     {
                         obj2 = this.CreatePerm(doc.GetElement(num3, true));
                         if (obj2 != null)
                         {
                             token = PermissionToken.GetToken((IPermission) obj2);
                         }
                     }
                     else
                     {
                         obj2 = ((ISecurityElementFactory) new SecurityDocumentElement(doc, num3)).CreateSecurityElement();
                     }
                 }
                 else
                 {
                     IPermission perm = this.CreatePerm(doc.GetElement(num3, true));
                     if (perm == null)
                     {
                         token = null;
                         obj2 = null;
                     }
                     else
                     {
                         token = PermissionToken.GetToken(perm);
                         obj2 = perm;
                     }
                 }
                 if ((token != null) && (obj2 != null))
                 {
                     if (this.m_permSet == null)
                     {
                         this.m_permSet = new TokenBasedSet();
                     }
                     IPermission item = null;
                     if (this.m_permSet.GetItem(token.m_index) != null)
                     {
                         if (this.m_permSet.GetItem(token.m_index) is IPermission)
                         {
                             item = (IPermission) this.m_permSet.GetItem(token.m_index);
                         }
                         else
                         {
                             item = this.CreatePerm(this.m_permSet.GetItem(token.m_index));
                         }
                     }
                     if (item != null)
                     {
                         if (obj2 is IPermission)
                         {
                             obj2 = item.Union((IPermission) obj2);
                         }
                         else
                         {
                             obj2 = item.Union(this.CreatePerm(obj2));
                         }
                     }
                     if (this.m_Unrestricted && (obj2 is IPermission))
                     {
                         obj2 = null;
                     }
                     this.m_permSet.SetItem(token.m_index, obj2);
                 }
             }
             catch (Exception exception2)
             {
                 if (exception == null)
                 {
                     exception = exception2;
                 }
             }
         }
     }
     if (exception != null)
     {
         throw exception;
     }
 }
 private void ParseContents()
 {
     TokenizerStream stream = new TokenizerStream();
     this._t.GetTokens(stream, 2, false);
     stream.Reset();
     int position = this.DetermineFormat(stream);
     stream.GoToPosition(position);
     this._t.GetTokens(stream, -1, false);
     stream.Reset();
     int index = 0;
     this.GetRequiredSizes(stream, ref index);
     this._doc = new SecurityDocument(index);
     int num4 = 0;
     stream.Reset();
     for (short i = stream.GetNextFullToken(); i != -1; i = stream.GetNextFullToken())
     {
         if ((i & 0x4000) == 0x4000)
         {
             switch (((short) (i & 0xff00)))
             {
                 case 0x4400:
                 {
                     this._doc.AddToken(4, ref num4);
                     continue;
                 }
                 case 0x5000:
                 {
                     stream.ThrowAwayNextString();
                     continue;
                 }
                 case 0x6300:
                 {
                     this._doc.AppendString(" ", ref num4);
                     this._doc.AppendString(stream.GetNextString(), ref num4);
                     continue;
                 }
                 case 0x4100:
                 {
                     this._doc.AddToken(1, ref num4);
                     this._doc.AddString(stream.GetNextString(), ref num4);
                     continue;
                 }
                 case 0x4200:
                 {
                     this._doc.AddToken(2, ref num4);
                     this._doc.AddString(stream.GetNextString(), ref num4);
                     this._doc.AddString(stream.GetNextString(), ref num4);
                     continue;
                 }
                 case 0x4300:
                 {
                     this._doc.AddToken(3, ref num4);
                     this._doc.AddString(stream.GetNextString(), ref num4);
                     continue;
                 }
             }
             throw new XmlSyntaxException();
         }
     }
 }