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

  1. #include "precomp.h"
  2. #ifdef WINNT32
  3. #include "priv.h"
  4. CSid::CSid ():
  5. m_hToken (NULL)
  6. {
  7. if (!OpenThreadToken(GetCurrentThread(),
  8. TOKEN_IMPERSONATE,
  9. TRUE,
  10. &m_hToken)) {
  11. DBG_MSG (DBG_LEV_CALLTREE, (_T ("OpenThreadToken failed: %d\n"), GetLastError()));
  12. m_bValid = FALSE;
  13. } else
  14. m_bValid = TRUE;
  15. }
  16. CSid::~CSid()
  17. {
  18. if (m_hToken) {
  19. CloseHandle (m_hToken);
  20. }
  21. }
  22. BOOL
  23. CSid::SetCurrentSid ()
  24. {
  25. #ifdef DEBUG
  26. WCHAR UserName[256];
  27. DWORD cbUserName=256;
  28. GetUserName(UserName, &cbUserName);
  29. DBG_MSG (DBG_LEV_CALLTREE, (_T ("SetCurrentSid BEFORE: user name is %ws\n"), UserName));
  30. #endif
  31. NtSetInformationThread(NtCurrentThread(), ThreadImpersonationToken,
  32. &m_hToken, sizeof(m_hToken));
  33. #ifdef DEBUG
  34. cbUserName = 256;
  35. GetUserName(UserName, &cbUserName);
  36. DBG_MSG (DBG_LEV_CALLTREE, (_T ("SetCurrentSid AFTER: user name is %ws\n"), UserName));
  37. #endif
  38. return TRUE;
  39. }
  40. #endif