Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
1.0 KiB

#include "precomp.h"
#ifdef WINNT32
#include "priv.h"
CSid::CSid ():
m_hToken (NULL)
{
if (!OpenThreadToken(GetCurrentThread(),
TOKEN_IMPERSONATE,
TRUE,
&m_hToken)) {
DBG_MSG (DBG_LEV_CALLTREE, (_T ("OpenThreadToken failed: %d\n"), GetLastError()));
m_bValid = FALSE;
} else
m_bValid = TRUE;
}
CSid::~CSid()
{
if (m_hToken) {
CloseHandle (m_hToken);
}
}
BOOL
CSid::SetCurrentSid ()
{
#ifdef DEBUG
WCHAR UserName[256];
DWORD cbUserName=256;
GetUserName(UserName, &cbUserName);
DBG_MSG (DBG_LEV_CALLTREE, (_T ("SetCurrentSid BEFORE: user name is %ws\n"), UserName));
#endif
NtSetInformationThread(NtCurrentThread(), ThreadImpersonationToken,
&m_hToken, sizeof(m_hToken));
#ifdef DEBUG
cbUserName = 256;
GetUserName(UserName, &cbUserName);
DBG_MSG (DBG_LEV_CALLTREE, (_T ("SetCurrentSid AFTER: user name is %ws\n"), UserName));
#endif
return TRUE;
}
#endif