这里找到了ImpersonationLevel 这个值的出处
贴上MSDN
PsReferenceImpersonationToken returns a pointer to the impersonation token for the given thread. If the thread is not currently impersonating a client, a NULL pointer is returned.
如果说ImpersonationLevel 这个值小于等于SecurityAnonymous等级的话,就直接返回空。从A线程打开B线程的Token时,就是这个SecurityAnonymous等级,所以每次都返回空...
“Every process has a primary token that describes the security context of the user account associated with the process. By default, the system uses the primary token when a thread of the process interacts with a securable object. Moreover, a thread can impersonate a client account. Impersonation allows the thread to interact with securable objects using the client's security context. A thread that is impersonating a client has both a primary token and an impersonation token.
Use the OpenProcessToken function to retrieve a handle to the primary token of a process. Use the OpenThreadToken function to retrieve a handle to the impersonation token of a thread. For more information, see Impersonation.”
大概意思是说,如果没有impersonation的话,thread在访问安全对象的时候,只能使用process token。
如果impersonation的话,那么thread就有两个token,一个primary token(从process继承来的),一个是impersonation token。
我还是不太理解,觉得即使没有impersonation,那么openThreadToken应该也获得primary token吧。