bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;

            if (evidence == null)
                return false;

            ApplicationDirectory dir = evidence.GetHostEvidence<ApplicationDirectory>();
            Url url = evidence.GetHostEvidence<Url>();

            if (dir != null && url != null)
            {
                // We need to add a wildcard at the end because IsSubsetOf keys off of it.
                String appDir = dir.Directory;
                
                if (appDir != null && appDir.Length > 1)
                {
                    if (appDir[appDir.Length-1] == '/')
                        appDir += "*";
                    else
                        appDir += "/*";
                    
                    URLString appDirString = new URLString(appDir);
                    if (url.GetURLString().IsSubsetOf(appDirString))
                    {
                        usedEvidence = dir;
                        return true;
                    }
                }
            }
            
            return false;
        }
Пример #2
0
 /// <include file='doc\URLMembershipCondition.uex' path='docs/doc[@for="UrlMembershipCondition.UrlMembershipCondition"]/*' />
 public UrlMembershipCondition( String url )
 {
     if (url == null)
         throw new ArgumentNullException( "url" );
 
     m_url = new URLString( url );
 }
Пример #3
0
        /// <include file='doc\URLMembershipCondition.uex' path='docs/doc[@for="UrlMembershipCondition.UrlMembershipCondition"]/*' />
        public UrlMembershipCondition(String url)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            m_url = new URLString(url);
        }
        //------------------------------------------------------
        //
        // IMEMBERSHIPCONDITION IMPLEMENTATION
        //
        //------------------------------------------------------

        /// <include file='doc\ApplicationDirectoryMembershipCondition.uex' path='docs/doc[@for="ApplicationDirectoryMembershipCondition.Check"]/*' />
        public bool Check(Evidence evidence)
        {
            if (evidence == null)
            {
                return(false);
            }

            IEnumerator enumerator = evidence.GetHostEnumerator();

            while (enumerator.MoveNext())
            {
                Object obj = enumerator.Current;

                if (obj is ApplicationDirectory)
                {
                    ApplicationDirectory dir = (ApplicationDirectory)obj;

                    IEnumerator innerEnumerator = evidence.GetHostEnumerator();

                    while (innerEnumerator.MoveNext())
                    {
                        Object innerObj = innerEnumerator.Current;

                        if (innerObj is Url)
                        {
                            // We need to add a wildcard at the end because IsSubsetOf
                            // keys off of it.

                            String appDir = dir.Directory;

                            if (appDir != null && appDir.Length > 1)
                            {
                                if (appDir[appDir.Length - 1] == '/')
                                {
                                    appDir += "*";
                                }
                                else
                                {
                                    appDir += "/*";
                                }

                                URLString appDirString = new URLString(appDir);

                                if (((Url)innerObj).GetURLString().IsSubsetOf(appDirString))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Пример #5
0
        /// <include file='doc\URLMembershipCondition.uex' path='docs/doc[@for="UrlMembershipCondition.FromXml1"]/*' />
        public void FromXml(SecurityElement e, PolicyLevel level)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (!e.Tag.Equals("IMembershipCondition"))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement"));
            }

            lock (this)
            {
                m_element = e;
                m_url     = null;
            }
        }
Пример #6
0
        private void ParseURL()
        {
            lock (this)
            {
                if (m_element == null)
                {
                    return;
                }

                String elurl = m_element.Attribute("Url");
                if (elurl == null)
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_UrlCannotBeNull"));
                }
                else
                {
                    m_url = new URLString(elurl, true);
                }

                m_element = null;
            }
        }
        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;

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

            ApplicationDirectory dir = evidence.GetHostEvidence <ApplicationDirectory>();
            Url url = evidence.GetHostEvidence <Url>();

            if (dir != null && url != null)
            {
                // We need to add a wildcard at the end because IsSubsetOf keys off of it.
                String appDir = dir.Directory;

                if (appDir != null && appDir.Length > 1)
                {
                    if (appDir[appDir.Length - 1] == '/')
                    {
                        appDir += "*";
                    }
                    else
                    {
                        appDir += "/*";
                    }

                    URLString appDirString = new URLString(appDir);
                    if (url.GetURLString().IsSubsetOf(appDirString))
                    {
                        usedEvidence = dir;
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #8
0
 private void VerifyCodeBaseDiscovery(String codeBase)
 {                
     if ((codeBase != null) &&
         (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, true, CultureInfo.InvariantCulture) == 0)) {
         System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase );
         new FileIOPermission( FileIOPermissionAccess.PathDiscovery, urlString.GetFileName() ).Demand();
     }
 }
Пример #9
0
        internal static Assembly InternalLoad(AssemblyName assemblyRef, bool stringized,
                                              Evidence assemblySecurity, ref StackCrawlMark stackMark)
        {
       
            if (assemblyRef == null)
                throw new ArgumentNullException("assemblyRef");

            assemblyRef=(AssemblyName)assemblyRef.Clone();

            if (assemblySecurity != null)
                new SecurityPermission( SecurityPermissionFlag.ControlEvidence ).Demand();

            String codeBase = AppDomain.VerifyCodeBase(assemblyRef.CodeBase);
            if (codeBase != null) {

                if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, true, CultureInfo.InvariantCulture) != 0) {
                    IPermission perm = CreateWebPermission( assemblyRef.EscapedCodeBase );

                    if (perm == null) {
                        BCLDebug.Assert( false, "Unable to create System.Net.WebPermission" );
                        return null;
                    }

                    perm.Demand();
                }
                else {
                    System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true );
                    new FileIOPermission( FileIOPermissionAccess.Read, urlString.GetFileName() ).Demand();
                }   
            }

            return nLoad(assemblyRef, codeBase, stringized, assemblySecurity, true, null, ref stackMark);
        }
     //------------------------------------------------------
     //
     // IMEMBERSHIPCONDITION IMPLEMENTATION
     //
     //------------------------------------------------------
 
     /// <include file='doc\ApplicationDirectoryMembershipCondition.uex' path='docs/doc[@for="ApplicationDirectoryMembershipCondition.Check"]/*' />
     public bool Check( Evidence evidence )
     {
         if (evidence == null)
             return false;
     
         IEnumerator enumerator = evidence.GetHostEnumerator();
         while (enumerator.MoveNext())
         {
             Object obj = enumerator.Current;
         
             if (obj is ApplicationDirectory)
             {
                 ApplicationDirectory dir = (ApplicationDirectory)obj;
             
                 IEnumerator innerEnumerator = evidence.GetHostEnumerator();
                 
                 while (innerEnumerator.MoveNext())
                 {
                     Object innerObj = innerEnumerator.Current;
                     
                     if (innerObj is Url)
                     {
                         // We need to add a wildcard at the end because IsSubsetOf
                         // keys off of it.
                         
                         String appDir = dir.Directory;
                         
                         if (appDir != null && appDir.Length > 1)
                         {
                             if (appDir[appDir.Length-1] == '/')
                                 appDir += "*";
                             else
                                 appDir += "/*";
                             
                             URLString appDirString = new URLString( appDir );
                         
                             if (((Url)innerObj).GetURLString().IsSubsetOf( appDirString ))
                             {
                                 return true;
                             }
                         }
                     }
                 }
             }
         }
         
         return false;
     }
Пример #11
0
 /// <include file='doc\URLMembershipCondition.uex' path='docs/doc[@for="UrlMembershipCondition.FromXml1"]/*' />
 public void FromXml( SecurityElement e, PolicyLevel level )
 {
     if (e == null)
         throw new ArgumentNullException("e");
 
     if (!e.Tag.Equals( "IMembershipCondition" ))
     {
         throw new ArgumentException( Environment.GetResourceString( "Argument_MembershipConditionElement" ) );
     }
     
     lock (this)
     {
         m_element = e;
         m_url = null;
     }
 }
Пример #12
0
        [System.Security.SecurityCritical]  // auto-generated
        private void VerifyCodeBaseDiscovery(String codeBase)
        {
#if FEATURE_CAS_POLICY
            if (CodeAccessSecurityEngine.QuickCheckForAllDemands()) {
                return;
            }
#endif // FEATURE_CAS_POLICY

            if ((codeBase != null) &&
                (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) == 0)) {
                System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true );
                new FileIOPermission( FileIOPermissionAccess.PathDiscovery, urlString.GetFileName() ).Demand();
            }
        }
Пример #13
0
        internal static Assembly InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity,
                                              ref StackCrawlMark stackMark, bool forIntrospection)
        {
       
            if (assemblyRef == null)
                throw new ArgumentNullException("assemblyRef");

            assemblyRef = (AssemblyName)assemblyRef.Clone();
            if (assemblySecurity != null)
                new SecurityPermission( SecurityPermissionFlag.ControlEvidence ).Demand();

            String codeBase = VerifyCodeBase(assemblyRef.CodeBase);
            if (codeBase != null) {
                
                if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) != 0) {
                    IPermission perm = CreateWebPermission( assemblyRef.EscapedCodeBase );
                    perm.Demand();
                }
                else {
                    System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true );
                    new FileIOPermission( FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read , urlString.GetFileName() ).Demand();
                }   
            }

            return nLoad(assemblyRef, codeBase, assemblySecurity, null, ref stackMark, true, forIntrospection);
        }
Пример #14
0
     //------------------------------------------------------
     //
     // PUBLIC CONSTRUCTORS
     //
     //------------------------------------------------------
 
     internal UrlMembershipCondition()
     {
         m_url = null;
     }
Пример #15
0
        private void ParseURL()
        {
            lock (this)
            {
                if (m_element == null)
                    return;

                String elurl = m_element.Attribute( "Url" );
                if (elurl == null)
                    throw new ArgumentException( Environment.GetResourceString( "Argument_UrlCannotBeNull" ) );
                else
                    m_url = new URLString( elurl, true );

                m_element = null;
            }
        }    
Пример #16
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static RuntimeAssembly InternalLoadAssemblyName(
            AssemblyName assemblyRef, 
            Evidence assemblySecurity,
            RuntimeAssembly reqAssembly,
            ref StackCrawlMark stackMark,
#if FEATURE_HOSTED_BINDER
            IntPtr pPrivHostBinder,
#endif
            bool throwOnFileNotFound, 
            bool forIntrospection,
            bool suppressSecurityChecks)
        {
       
            if (assemblyRef == null)
                throw new ArgumentNullException("assemblyRef");
            Contract.EndContractBlock();

            if (assemblyRef.CodeBase != null)
            {
                AppDomain.CheckLoadFromSupported();
            }

            assemblyRef = (AssemblyName)assemblyRef.Clone();
#if FEATURE_VERSIONING
            if (!forIntrospection &&
                (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None)) {
                // PA does not have a semantics for by-name binds for execution
                assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None;
            }
#endif

            if (assemblySecurity != null)
            {
#if FEATURE_CAS_POLICY
                if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
                {
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
                }
#endif // FEATURE_CAS_POLICY

                if (!suppressSecurityChecks)
                {
#pragma warning disable 618
                    new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
#pragma warning restore 618
                }
            }


            String codeBase = VerifyCodeBase(assemblyRef.CodeBase);
            if (codeBase != null && !suppressSecurityChecks) {
                
                if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) != 0) {
#if FEATURE_FUSION   // Of all the binders, Fusion is the only one that understands Web locations                 
                    IPermission perm = CreateWebPermission( assemblyRef.EscapedCodeBase );
                    perm.Demand();
#else
                     throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileName"), "assemblyRef.CodeBase");
#endif
                }
                else {
                    System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true );
                    new FileIOPermission( FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read , urlString.GetFileName() ).Demand();
                }   
            }

            return nLoad(assemblyRef, codeBase, assemblySecurity, reqAssembly, ref stackMark,
#if FEATURE_HOSTED_BINDER
                pPrivHostBinder,
#endif
                throwOnFileNotFound, forIntrospection, suppressSecurityChecks);
        }
Пример #17
0
        //------------------------------------------------------
        //
        // PUBLIC CONSTRUCTORS
        //
        //------------------------------------------------------

        internal UrlMembershipCondition()
        {
            m_url = null;
        }
Пример #18
0
        [System.Security.SecurityCritical]  // auto-generated
        private static void DemandPermission(String codeBase, bool havePath,
                                             int demandFlag)
        {
            FileIOPermissionAccess access = FileIOPermissionAccess.PathDiscovery;
            switch(demandFlag) {

            case 0: // default
                break;
            case 1:
                access = FileIOPermissionAccess.Read;
                break;
            case 2:
                access = FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read;
                break;

            case 3:
                IPermission perm = CreateWebPermission(AssemblyName.EscapeCodeBase(codeBase));
                perm.Demand();
                return;
            }

            if (!havePath) {
                System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true );
                codeBase = urlString.GetFileName();
            }

            codeBase = Path.GetFullPathInternal(codeBase);  // canonicalize

            new FileIOPermission(access, codeBase).Demand();
        }
Пример #19
0
        internal static RuntimeAssembly InternalLoadAssemblyName(
            AssemblyName assemblyRef, 
            Evidence assemblySecurity,
            RuntimeAssembly reqAssembly,
            ref StackCrawlMark stackMark,
            IntPtr pPrivHostBinder,
            bool throwOnFileNotFound, 
            bool forIntrospection,
            bool suppressSecurityChecks,
            IntPtr ptrLoadContextBinder = default(IntPtr))
        {
       
            if (assemblyRef == null)
                throw new ArgumentNullException(nameof(assemblyRef));
            Contract.EndContractBlock();

            if (assemblyRef.CodeBase != null)
            {
                AppDomain.CheckLoadFromSupported();
            }

            assemblyRef = (AssemblyName)assemblyRef.Clone();
#if FEATURE_VERSIONING
            if (!forIntrospection &&
                (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None)) {
                // PA does not have a semantics for by-name binds for execution
                assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None;
            }
#endif

            if (assemblySecurity != null)
            {
                if (!suppressSecurityChecks)
                {
#pragma warning disable 618
                    new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
#pragma warning restore 618
                }
            }

            String codeBase = VerifyCodeBase(assemblyRef.CodeBase);
            if (codeBase != null && !suppressSecurityChecks)
            {
                if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    // Of all the binders, Fusion is the only one that understands Web locations                 
                     throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileName"), "assemblyRef.CodeBase");
                }
                else
                {
                    System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true );
                    new FileIOPermission( FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read , urlString.GetFileName() ).Demand();
                }
            }

            return nLoad(assemblyRef, codeBase, assemblySecurity, reqAssembly, ref stackMark,
                pPrivHostBinder,
                throwOnFileNotFound, forIntrospection, suppressSecurityChecks, ptrLoadContextBinder);
        }