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.

52 lines
1.9 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: Impersonation.h
  3. //
  4. // Copyright (c) 1999-2000, Microsoft Corporation
  5. //
  6. // Classes that handle state preservation, changing and restoration.
  7. //
  8. // History: 1999-08-18 vtan created
  9. // 1999-11-16 vtan separate file
  10. // 2000-02-01 vtan moved from Neptune to Whistler
  11. // --------------------------------------------------------------------------
  12. #ifndef _Impersonation_
  13. #define _Impersonation_
  14. #include "KernelResources.h"
  15. // --------------------------------------------------------------------------
  16. // CImpersonation
  17. //
  18. // Purpose: This class allows a thread to impersonate a user and revert to
  19. // self when the object goes out of scope.
  20. //
  21. // History: 1999-08-18 vtan created
  22. // 1999-10-13 vtan added reference counting
  23. // 2000-02-01 vtan moved from Neptune to Whistler
  24. // --------------------------------------------------------------------------
  25. class CImpersonation
  26. {
  27. private:
  28. CImpersonation (void);
  29. public:
  30. CImpersonation (HANDLE hToken);
  31. ~CImpersonation (void);
  32. bool IsImpersonating (void) const;
  33. static NTSTATUS ImpersonateUser (HANDLE hThread, HANDLE hToken);
  34. static NTSTATUS StaticInitialize (void);
  35. static NTSTATUS StaticTerminate (void);
  36. private:
  37. static CMutex* s_pMutex;
  38. static int s_iReferenceCount;
  39. NTSTATUS _status;
  40. bool _fAlreadyImpersonating;
  41. };
  42. #endif /* _Impersonation_ */