예제 #1
0
 internal void Setup(SecurityContextDisableFlow flags)
 {
     useEC            = false;
     _sc              = Thread.CurrentThread.ExecutionContext.SecurityContext;
     _sc._disableFlow = flags;
     _thread          = Thread.CurrentThread;
 }
예제 #2
0
 internal void Setup(SecurityContextDisableFlow flags)
 {
     this.useEC = false;
     this._sc = Thread.CurrentThread.ExecutionContext.SecurityContext;
     this._sc._disableFlow = flags;
     this._thread = Thread.CurrentThread;
 }
예제 #3
0
        internal static bool IsFlowSuppressed(SecurityContextDisableFlow flags)
        {
#if MOBILE
            return(false);
#else
            return(Thread.CurrentThread.GetExecutionContextReader().SecurityContext.IsFlowSuppressed(flags));
#endif
        }
예제 #4
0
 public bool IsFlowSuppressed(SecurityContextDisableFlow flags)
 {
     if (this.m_sc != null)
     {
         return((this.m_sc._disableFlow & flags) == flags);
     }
     return(false);
 }
        internal void Setup(SecurityContextDisableFlow flags)
        {
            this.useEC = false;
            Thread currentThread = Thread.CurrentThread;

            this._sc = currentThread.GetMutableExecutionContext().SecurityContext;
            this._sc._disableFlow = flags;
            this._thread          = currentThread;
        }
예제 #6
0
        [HandleProcessCorruptedStateExceptions] //
#endif // FEATURE_CORRUPTING_EXCEPTIONS
        internal static SecurityContextSwitcher SetSecurityContext(SecurityContext sc, SecurityContext.Reader prevSecurityContext, bool modifyCurrentExecutionContext, ref StackCrawlMark stackMark)
        {
            // Save the flow state at capture and reset it in the SC.
            SecurityContextDisableFlow _capturedFlowState = sc._disableFlow;

            sc._disableFlow = SecurityContextDisableFlow.Nothing;

            //Set up the switcher object
            SecurityContextSwitcher scsw = new SecurityContextSwitcher();

            scsw.currSC = sc;
            scsw.prevSC = prevSecurityContext;

            if (modifyCurrentExecutionContext)
            {
                // save the current Execution Context
                ExecutionContext currEC = Thread.CurrentThread.GetMutableExecutionContext();
                scsw.currEC            = currEC;
                currEC.SecurityContext = sc;
            }

            if (sc != null)
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
#if !FEATURE_PAL && FEATURE_IMPERSONATION
                    scsw.wic = null;
                    if (!_LegacyImpersonationPolicy)
                    {
                        if (sc.WindowsIdentity != null)
                        {
                            scsw.wic = sc.WindowsIdentity.Impersonate(ref stackMark);
                        }
                        else if (((_capturedFlowState & SecurityContextDisableFlow.WI) == 0) &&
                                 prevSecurityContext.WindowsIdentity != null)
                        {
                            // revert impersonation if there was no WI flow supression at capture and we're currently impersonating
                            scsw.wic = WindowsIdentity.SafeRevertToSelf(ref stackMark);
                        }
                    }
#endif
                    scsw.cssw = CompressedStack.SetCompressedStack(sc.CompressedStack, prevSecurityContext.CompressedStack);
                }
                catch
                {
                    scsw.UndoNoThrow();
                    throw;
                }
            }
            return(scsw);
        }
        internal static AsyncFlowControl SuppressFlow(SecurityContextDisableFlow flags)
        {
            if (IsFlowSuppressed(flags))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotSupressFlowMultipleTimes"));
            }
            if (Thread.CurrentThread.ExecutionContext.SecurityContext == null)
            {
                Thread.CurrentThread.ExecutionContext.SecurityContext = new SecurityContext();
            }
            AsyncFlowControl control = new AsyncFlowControl();

            control.Setup(flags);
            return(control);
        }
예제 #8
0
        internal static AsyncFlowControl SuppressFlow(SecurityContextDisableFlow flags)
        {
            if (SecurityContext.IsFlowSuppressed(flags))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotSupressFlowMultipleTimes"));
            }
            ExecutionContext mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();

            if (mutableExecutionContext.SecurityContext == null)
            {
                mutableExecutionContext.SecurityContext = new SecurityContext();
            }
            AsyncFlowControl result = default(AsyncFlowControl);

            result.Setup(flags);
            return(result);
        }
예제 #9
0
        internal static AsyncFlowControl SuppressFlow(SecurityContextDisableFlow flags)
        {
            if (IsFlowSuppressed(flags))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotSupressFlowMultipleTimes"));
            }

            ExecutionContext ec = Thread.CurrentThread.GetMutableExecutionContext();

            if (ec.SecurityContext == null)
            {
                ec.SecurityContext = new SecurityContext();
            }
            AsyncFlowControl afc = new AsyncFlowControl();

            afc.Setup(flags);
            return(afc);
        }
예제 #10
0
        internal static SecurityContextSwitcher SetSecurityContext(SecurityContext sc, SecurityContext.Reader prevSecurityContext, bool modifyCurrentExecutionContext, ref StackCrawlMark stackMark)
        {
            SecurityContextDisableFlow disableFlow = sc._disableFlow;

            sc._disableFlow = SecurityContextDisableFlow.Nothing;
            SecurityContextSwitcher result = default(SecurityContextSwitcher);

            result.currSC = sc;
            result.prevSC = prevSecurityContext;
            if (modifyCurrentExecutionContext)
            {
                ExecutionContext mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();
                result.currEC = mutableExecutionContext;
                mutableExecutionContext.SecurityContext = sc;
            }
            if (sc != null)
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    result.wic = null;
                    if (!SecurityContext._LegacyImpersonationPolicy)
                    {
                        if (sc.WindowsIdentity != null)
                        {
                            result.wic = sc.WindowsIdentity.Impersonate(ref stackMark);
                        }
                        else if ((disableFlow & SecurityContextDisableFlow.WI) == SecurityContextDisableFlow.Nothing && prevSecurityContext.WindowsIdentity != null)
                        {
                            result.wic = WindowsIdentity.SafeRevertToSelf(ref stackMark);
                        }
                    }
                    result.cssw = CompressedStack.SetCompressedStack(sc.CompressedStack, prevSecurityContext.CompressedStack);
                }
                catch
                {
                    result.UndoNoThrow();
                    throw;
                }
            }
            return(result);
        }
        internal static SecurityContextSwitcher SetSecurityContext(SecurityContext sc, SecurityContext prevSecurityContext, ref StackCrawlMark stackMark)
        {
            SecurityContextDisableFlow flow = sc._disableFlow;

            sc._disableFlow = SecurityContextDisableFlow.Nothing;
            SecurityContextSwitcher switcher = new SecurityContextSwitcher {
                currSC = sc
            };

            System.Threading.ExecutionContext executionContext = Thread.CurrentThread.ExecutionContext;
            switcher.currEC = executionContext;
            switcher.prevSC = prevSecurityContext;
            executionContext.SecurityContext = sc;
            if (sc != null)
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    switcher.wic = null;
                    if (!_LegacyImpersonationPolicy)
                    {
                        if (sc.WindowsIdentity != null)
                        {
                            switcher.wic = sc.WindowsIdentity.Impersonate(ref stackMark);
                        }
                        else if ((((flow & SecurityContextDisableFlow.WI) == SecurityContextDisableFlow.Nothing) && (prevSecurityContext != null)) && (prevSecurityContext.WindowsIdentity != null))
                        {
                            switcher.wic = System.Security.Principal.WindowsIdentity.SafeRevertToSelf(ref stackMark);
                        }
                    }
                    switcher.cssw = System.Threading.CompressedStack.SetCompressedStack(sc.CompressedStack, (prevSecurityContext != null) ? prevSecurityContext.CompressedStack : null);
                }
                catch
                {
                    switcher.UndoNoThrow();
                    throw;
                }
            }
            return(switcher);
        }
예제 #12
0
        internal static SecurityContextSwitcher SetSecurityContext(SecurityContext sc, SecurityContext prevSecurityContext, ref StackCrawlMark stackMark)
        {
            // Save the flow state at capture and reset it in the SC.
            SecurityContextDisableFlow _capturedFlowState = sc._disableFlow;

            sc._disableFlow = SecurityContextDisableFlow.Nothing;

            //Set up the switcher object
            SecurityContextSwitcher scsw = new SecurityContextSwitcher();

            scsw.currSC = sc;
            // save the current Execution Context
            ExecutionContext currEC = Thread.CurrentThread.ExecutionContext;

            scsw.currEC = currEC;
            // save the prev security context
            scsw.prevSC = prevSecurityContext;

            // update the current security context to the new security context
            currEC.SecurityContext = sc;


            if (sc != null)
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    scsw.cssw = CompressedStack.SetCompressedStack(sc.CompressedStack,
                                                                   (prevSecurityContext != null?prevSecurityContext.CompressedStack:null));
                }
                catch
                {
                    scsw.UndoNoThrow();
                    throw;
                }
            }
            return(scsw);
        }
예제 #13
0
        internal static SecurityContextSwitcher SetSecurityContext(SecurityContext sc, SecurityContext.Reader prevSecurityContext, bool modifyCurrentExecutionContext, ref StackCrawlMark stackMark)
        {
            // Save the flow state at capture and reset it in the SC.
            SecurityContextDisableFlow _capturedFlowState = sc._disableFlow;

            sc._disableFlow = SecurityContextDisableFlow.Nothing;

            //Set up the switcher object
            SecurityContextSwitcher scsw = new SecurityContextSwitcher();

            scsw.currSC = sc;
            scsw.prevSC = prevSecurityContext;

            if (modifyCurrentExecutionContext)
            {
                // save the current Execution Context
                ExecutionContext currEC = Thread.CurrentThread.GetMutableExecutionContext();
                scsw.currEC            = currEC;
                currEC.SecurityContext = sc;
            }

            if (sc != null)
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    scsw.cssw = CompressedStack.SetCompressedStack(sc.CompressedStack, prevSecurityContext.CompressedStack);
                }
                catch
                {
                    scsw.UndoNoThrow();
                    throw;
                }
            }
            return(scsw);
        }
예제 #14
0
 public bool IsFlowSuppressed(SecurityContextDisableFlow flags)
 {           
     return (m_sc == null) ? false : ((m_sc._disableFlow & flags) == flags);
 }
예제 #15
0
 internal static bool IsFlowSuppressed(SecurityContextDisableFlow flags)
 {           
     return Thread.CurrentThread.GetExecutionContextReader().SecurityContext.IsFlowSuppressed(flags);
 }
        internal static bool IsFlowSuppressed(SecurityContextDisableFlow flags)
        {
            SecurityContext currentSecurityContextNoCreate = GetCurrentSecurityContextNoCreate();

            return((currentSecurityContextNoCreate != null) && ((currentSecurityContextNoCreate._disableFlow & flags) == flags));
        }
예제 #17
0
 internal void Setup(SecurityContextDisableFlow flags)
 {
     useEC = false;
     Thread currentThread = Thread.CurrentThread;
     _sc = currentThread.GetMutableExecutionContext().SecurityContext;
     _sc._disableFlow = flags;
     _thread = currentThread;
 }
예제 #18
0
 internal static bool IsFlowSuppressed(SecurityContextDisableFlow flags)
 {
     return(Thread.CurrentThread.GetExecutionContextReader().SecurityContext.IsFlowSuppressed(flags));
 }
예제 #19
0
 internal static bool IsFlowSuppressed(SecurityContextDisableFlow flags)
 { 
         SecurityContext sc = GetCurrentSecurityContextNoCreate();
         return (sc == null) ? false : ((sc._disableFlow & flags) == flags); 
 } 
예제 #20
0
        internal static AsyncFlowControl SuppressFlow(SecurityContextDisableFlow flags)
        { 
            if (IsFlowSuppressed(flags)) 
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotSupressFlowMultipleTimes")); 
            }

            if (Thread.CurrentThread.ExecutionContext.SecurityContext == null)
                Thread.CurrentThread.ExecutionContext.SecurityContext = new SecurityContext(); 
            AsyncFlowControl afc = new AsyncFlowControl();
            afc.Setup(flags); 
            return afc; 
        }
예제 #21
0
        internal static AsyncFlowControl SuppressFlow(SecurityContextDisableFlow flags)
        {
#if MOBILE
            throw new NotSupportedException ();
#else
            if (IsFlowSuppressed(flags))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotSupressFlowMultipleTimes"));
            }

            ExecutionContext ec = Thread.CurrentThread.GetMutableExecutionContext();
            if (ec.SecurityContext == null)
                ec.SecurityContext = new SecurityContext();
            AsyncFlowControl afc = new AsyncFlowControl();
            afc.Setup(flags);
            return afc;
#endif
        }
예제 #22
0
 public bool IsFlowSuppressed(SecurityContextDisableFlow flags)
 {
     return((m_sc == null) ? false : ((m_sc._disableFlow & flags) == flags));
 }
예제 #23
0
        internal static bool IsFlowSuppressed(SecurityContextDisableFlow flags)
        {  
#if MOBILE
            return false;
#else
            return Thread.CurrentThread.GetExecutionContextReader().SecurityContext.IsFlowSuppressed(flags);
#endif
        }
예제 #24
0
        internal static bool IsFlowSuppressed(SecurityContextDisableFlow flags)
        {
            SecurityContext sc = GetCurrentSecurityContextNoCreate();

            return((sc == null) ? false : ((sc._disableFlow & flags) == flags));
        }