Esempio n. 1
0
 internal SecurityContextRunData(SecurityContext securityContext, ContextCallback cb, Object state)
 {
     this.sc       = securityContext;
     this.callBack = cb;
     this.state    = state;
     this.scsw     = new SecurityContextSwitcher();
 }
Esempio n. 2
0
        public override bool Equals(Object obj)
        {
            if (obj == null || !(obj is SecurityContextSwitcher))
            {
                return(false);
            }
            SecurityContextSwitcher sw = (SecurityContextSwitcher)obj;

            return(this.prevSC == sw.prevSC && this.currSC == sw.currSC && this.currEC == sw.currEC && this.cssw == sw.cssw);
        }
        public override bool Equals(object obj)
        {
            if ((obj == null) || !(obj is SecurityContextSwitcher))
            {
                return(false);
            }
            SecurityContextSwitcher switcher = (SecurityContextSwitcher)obj;

            return((((this.prevSC == switcher.prevSC) && (this.currSC == switcher.currSC)) && ((this.currEC == switcher.currEC) && (this.cssw == switcher.cssw))) && (this.wic == switcher.wic));
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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;
        }
Esempio n. 10
0
 internal SecurityContextRunData(SecurityContext securityContext, ContextCallback cb, Object state)
 {
     this.sc = securityContext;
     this.callBack = cb;
     this.state = state;
     this.scsw = new SecurityContextSwitcher();
 }
Esempio n. 11
0
		public static bool op_Inequality (SecurityContextSwitcher c1, SecurityContextSwitcher c2)
		{
			return false;
		}
Esempio n. 12
0
 public static bool op_Inequality(SecurityContextSwitcher c1, SecurityContextSwitcher c2)
 {
     return(false);
 }
Esempio n. 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;
        }
        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;
        }