private static void PerformSecurityCheck(Type owner, ref StackCrawlMark stackMark, bool skipVisibility)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            RuntimeType underlyingSystemType = owner as RuntimeType;

            if (underlyingSystemType == null)
            {
                underlyingSystemType = owner.UnderlyingSystemType as RuntimeType;
            }
            if (underlyingSystemType == null)
            {
                throw new ArgumentNullException("owner", Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }
            RuntimeType callerType = RuntimeMethodHandle.GetCallerType(ref stackMark);

            if (skipVisibility)
            {
                new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
            }
            else if (callerType != underlyingSystemType)
            {
                new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
            }
            if (underlyingSystemType.Assembly != callerType.Assembly)
            {
                CodeAccessSecurityEngine.ReflectionTargetDemandHelper(PermissionType.SecurityControlEvidence, owner.Assembly.PermissionSet);
            }
        }
예제 #2
0
        [System.Security.SecurityCritical]  // auto-generated
        private void PerformSecurityCheck(Module m, ref StackCrawlMark stackMark, bool skipVisibility)
        {
            if (m == null)
            {
                throw new ArgumentNullException("m");
            }
            Contract.EndContractBlock();

            RuntimeModule rtModule;
            ModuleBuilder mb = m as ModuleBuilder;

            if (mb != null)
            {
                rtModule = mb.InternalModule;
            }
            else
            {
                rtModule = m as RuntimeModule;
            }

            if (rtModule == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeModule"), "m");
            }

            // The user cannot explicitly use this assembly
            if (rtModule == s_anonymouslyHostedDynamicMethodsModule)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidValue"), "m");
            }

            // ask for member access if skip visibility
            if (skipVisibility)
            {
                new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
            }

#if !FEATURE_CORECLR
            // ask for control evidence if outside of the caller assembly
            RuntimeType callingType = RuntimeMethodHandle.GetCallerType(ref stackMark);
            m_creatorAssembly = callingType.GetRuntimeAssembly();
            if (m.Assembly != m_creatorAssembly)
            {
                // Demand the permissions of the assembly where the DynamicMethod will live
                CodeAccessSecurityEngine.ReflectionTargetDemandHelper(PermissionType.SecurityControlEvidence,
                                                                      m.Assembly.PermissionSet);
            }
#else //FEATURE_CORECLR
#pragma warning disable 618
            new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
#pragma warning restore 618
#endif //FEATURE_CORECLR
        }
예제 #3
0
        [System.Security.SecurityCritical]  // auto-generated
        private void PerformSecurityCheck(Type owner, ref StackCrawlMark stackMark, bool skipVisibility)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            RuntimeType rtOwner = owner as RuntimeType;

            if (rtOwner == null)
            {
                rtOwner = owner.UnderlyingSystemType as RuntimeType;
            }

            if (rtOwner == null)
            {
                throw new ArgumentNullException("owner", Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }

            // get the type the call is coming from
            RuntimeType callingType = RuntimeMethodHandle.GetCallerType(ref stackMark);

            // ask for member access if skip visibility
            if (skipVisibility)
            {
                new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
            }
            else
            {
                // if the call is not coming from the same class ask for member access
                if (callingType != rtOwner)
                {
                    new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
                }
            }
#if !FEATURE_CORECLR
            m_creatorAssembly = callingType.GetRuntimeAssembly();

            // ask for control evidence if outside of the caller module
            if (rtOwner.Assembly != m_creatorAssembly)
            {
                // Demand the permissions of the assembly where the DynamicMethod will live
                CodeAccessSecurityEngine.ReflectionTargetDemandHelper(PermissionType.SecurityControlEvidence,
                                                                      owner.Assembly.PermissionSet);
            }
#else //FEATURE_CORECLR
#pragma warning disable 618
            new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
#pragma warning restore 618
#endif //FEATURE_CORECLR
        }
        private static void PerformSecurityCheck(System.Reflection.Module m, ref StackCrawlMark stackMark, bool skipVisibility)
        {
            RuntimeModule internalModule;

            if (m == null)
            {
                throw new ArgumentNullException("m");
            }
            ModuleBuilder builder = m as ModuleBuilder;

            if (builder != null)
            {
                internalModule = builder.InternalModule;
            }
            else
            {
                internalModule = m as RuntimeModule;
            }
            if (internalModule == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeModule"), "m");
            }
            if (internalModule == s_anonymouslyHostedDynamicMethodsModule)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidValue"), "m");
            }
            if (skipVisibility)
            {
                new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
            }
            RuntimeType callerType = RuntimeMethodHandle.GetCallerType(ref stackMark);

            if (m.Assembly != callerType.Assembly)
            {
                CodeAccessSecurityEngine.ReflectionTargetDemandHelper(PermissionType.SecurityControlEvidence, m.Assembly.PermissionSet);
            }
        }