Leaked source code of windows server 2003
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.
 
 
 
 
 
 

54 lines
1.1 KiB

#include "precomp.h"
#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;
}