2012-03-02 32 views

回答

2

UPDATE 爲了做到這一點,客戶端應該允許服務器通過配置與CoSetProxyBlanket API代理,以獲取其信息,如下圖所示:

HRESULT hr; 
if(FAILED(hr = ::CoSetProxyBlanket(
      unk // An interface the client uses to access the com server 
      , RPC_C_AUTHN_DEFAULT 
      , RPC_C_AUTHZ_DEFAULT 
      , NULL 
      , RPC_C_AUTHN_LEVEL_DEFAULT 
      , RPC_C_IMP_LEVEL_DELEGATE // This flag should be *_DELEGATE or *_IMPERSONATE or *_IDENTIFY 
      , NULL 
      , EOAC_DYNAMIC_CLOAKING))) 
    throw com_exception(hr, "Failed to set proxy blanket"); 

然後被假冒(CoImpersonateClient)你可能用OpenThreadToken訪問用戶的令牌。

UPDATE

結束處,之後,您可以使用GetTokenInformation API如下:

DWORD tokenSize = 0; 
::GetTokenInformation(token, TokenUser, NULL, 0, &tokenSize); 

.... 
TOKEN_USER *tokenInfo; // should point to a memory location of size tokenSize. 
.... 
if(::GetTokenInformation(token, infoClass, tokenInfo, tokenSize, &tokenSize) == FALSE) 
    throw win32_exception(::GetLastError(), "Failed to obtain token information"); 

tokenInfo將包含類型PSID領域User.Sid。

相關問題