public void Undo()
        {
            int errorCode = 0;

            if (this.m_safeTokenHandle.IsInvalid)
            {
                errorCode = Win32.RevertToSelf();
                if (errorCode < 0)
                {
                    Environment.FailFast(Win32Native.GetMessage(errorCode));
                }
            }
            else
            {
                errorCode = Win32.RevertToSelf();
                if (errorCode < 0)
                {
                    Environment.FailFast(Win32Native.GetMessage(errorCode));
                }
                errorCode = Win32.ImpersonateLoggedOnUser(this.m_safeTokenHandle);
                if (errorCode < 0)
                {
                    throw new SecurityException(Win32Native.GetMessage(errorCode));
                }
            }
            WindowsIdentity.UpdateThreadWI(this.m_wi);
            if (this.m_fsd != null)
            {
                this.m_fsd.SetTokenHandles(null, null);
            }
        }
コード例 #2
0
        public void Undo()
        {
            int hr = 0;

            if (m_safeTokenHandle.IsInvalid)   // the thread was not initially impersonating
            {
                hr = Win32.RevertToSelf();
                if (hr < 0)
                {
                    Environment.FailFast(Win32Native.GetMessage(hr));
                }
            }
            else
            {
                hr = Win32.RevertToSelf();
                if (hr < 0)
                {
                    Environment.FailFast(Win32Native.GetMessage(hr));
                }
                hr = Win32.ImpersonateLoggedOnUser(m_safeTokenHandle);
                if (hr < 0)
                {
                    throw new SecurityException(Win32Native.GetMessage(hr));
                }
            }
            WindowsIdentity.UpdateThreadWI(m_wi);
            if (m_fsd != null)
            {
                m_fsd.SetTokenHandles(null, null);
            }
        }
コード例 #3
0
        internal bool UndoNoThrow()
        {
            bool bRet = false;

            try
            {
                int hr = 0;
                if (m_safeTokenHandle.IsInvalid)
                { // the thread was not initially impersonating
                    hr = Win32.RevertToSelf();
                    if (hr < 0)
                    {
                        Environment.FailFast(Win32Native.GetMessage(hr));
                    }
                }
                else
                {
                    hr = Win32.RevertToSelf();
                    if (hr >= 0)
                    {
                        hr = Win32.ImpersonateLoggedOnUser(m_safeTokenHandle);
                    }
                    else
                    {
                        Environment.FailFast(Win32Native.GetMessage(hr));
                    }
                }
                bRet = (hr >= 0);
                if (m_fsd != null)
                {
                    m_fsd.SetTokenHandles(null, null);
                }
            }
            catch (Exception ex)
            {
                if (!AppContextSwitches.UseLegacyExecutionContextBehaviorUponUndoFailure)
                {
                    // Fail fast since we can't continue safely
                    Environment.FailFast(Environment.GetResourceString("ExecutionContext_UndoFailed"), ex);
                }
                bRet = false;
            }
            return(bRet);
        }
        internal bool UndoNoThrow()
        {
            bool result = false;

            try
            {
                int num;
                if (this.m_safeTokenHandle.IsInvalid)
                {
                    num = Win32.RevertToSelf();
                    if (num < 0)
                    {
                        Environment.FailFast(Win32Native.GetMessage(num));
                    }
                }
                else
                {
                    num = Win32.RevertToSelf();
                    if (num >= 0)
                    {
                        num = Win32.ImpersonateLoggedOnUser(this.m_safeTokenHandle);
                    }
                    else
                    {
                        Environment.FailFast(Win32Native.GetMessage(num));
                    }
                }
                result = (num >= 0);
                if (this.m_fsd != null)
                {
                    this.m_fsd.SetTokenHandles(null, null);
                }
            }
            catch (Exception exception)
            {
                if (!AppContextSwitches.UseLegacyExecutionContextBehaviorUponUndoFailure)
                {
                    Environment.FailFast(Environment.GetResourceString("ExecutionContext_UndoFailed"), exception);
                }
                result = false;
            }
            return(result);
        }
        internal bool UndoNoThrow()
        {
            bool flag = false;

            try
            {
                int errorCode = 0;
                if (this.m_safeTokenHandle.IsInvalid)
                {
                    errorCode = Win32.RevertToSelf();
                    if (errorCode < 0)
                    {
                        Environment.FailFast(Win32Native.GetMessage(errorCode));
                    }
                }
                else
                {
                    errorCode = Win32.RevertToSelf();
                    if (errorCode >= 0)
                    {
                        errorCode = Win32.ImpersonateLoggedOnUser(this.m_safeTokenHandle);
                    }
                    else
                    {
                        Environment.FailFast(Win32Native.GetMessage(errorCode));
                    }
                }
                flag = errorCode >= 0;
                if (this.m_fsd != null)
                {
                    this.m_fsd.SetTokenHandles(null, null);
                }
            }
            catch
            {
                flag = false;
            }
            return(flag);
        }
コード例 #6
0
        [HandleProcessCorruptedStateExceptions] //
#endif // FEATURE_CORRUPTING_EXCEPTIONS
        internal bool UndoNoThrow()
        {
            bool bRet = false;

            try{
                int hr = 0;
                if (m_safeTokenHandle.IsInvalid)
                { // the thread was not initially impersonating
                    hr = Win32.RevertToSelf();
                    if (hr < 0)
                    {
                        Environment.FailFast(Win32Native.GetMessage(hr));
                    }
                }
                else
                {
                    hr = Win32.RevertToSelf();
                    if (hr >= 0)
                    {
                        hr = Win32.ImpersonateLoggedOnUser(m_safeTokenHandle);
                    }
                    else
                    {
                        Environment.FailFast(Win32Native.GetMessage(hr));
                    }
                }
                bRet = (hr >= 0);
                if (m_fsd != null)
                {
                    m_fsd.SetTokenHandles(null, null);
                }
            }
            catch
            {
                bRet = false;
            }
            return(bRet);
        }