Restores a thread's authentication information.
HRESULT RevertToSelf( )
This method supports the standard return value E_FAIL, as well as the following:
In Windows NT 4, IServerSecurity::RevertToSelf sets the thread token to NULL. In Windows NT 5, RevertToSelf restores the thread's authentication information. This behavior is described as follows.
RevertToSelf restores the authentication information on a thread to the authentication information on the thread before impersonation began. If the server does not call RevertToSelf before the end of the current call, it will be called automatically by COM.
When ImpersonateClient is called on a thread that is not currently impersonating, COM saves the token currently on the thread. A subsequent call to RevertToSelf restores the saved token, and IsImpersonating will then return false. This means that if a series of impersonation calls are made using different IServerSecurity objects, RevertToSelf will restore the token that was on the thread when the first call to ImpersonateClient was made. Also, only one RevertToSelf call is needed to undo any number of ImpersonateClient calls.
This method will only revert impersonation changes made by IServerSecurity::ImpersonateClient. If the thread token is modified by other means (through the SetThreadToken or RpcImpersonateClient Win32 functions) the result of this function is undefined.
RevertToSelf affects only the current method invocation. If there are nested method invocations, each invocation can have its own impersonation token and DCOM will correctly restore the impersonation token before returning to them (regardless of whether or not CoRevertToSelf or IServerSecurity::RevertToSelf was called).
It is important to understand that an instance of IServerSecurity is valid on any thread in the apartment until the call represented by IServerSecurity completes. However, impersonation is local to a particular thread for the duration of the current call on that thread. Therefore, if two threads in the same apartment use the same IServerSecurity instance to call IServerSecurity::ImpersonateClient, one thread can call RevertToSelf without affecting the other.
Windows NT: Use version 4.0 or later.
Windows: Use Windows 95 or later. Available as a redistributable for Windows 95.
Windows CE: Unsupported.
Header: Declared in objidl.h.