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

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