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.

69 lines
2.7 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: PrivilegeEnable.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 _PrivilegeEnable_
  13. #define _PrivilegeEnable_
  14. // --------------------------------------------------------------------------
  15. // CThreadToken
  16. //
  17. // Purpose: This class gets the current thread's token. If the thread is
  18. // not impersonating it gets the current process' token.
  19. //
  20. // History: 1999-08-18 vtan created
  21. // 2000-02-01 vtan moved from Neptune to Whistler
  22. // --------------------------------------------------------------------------
  23. class CThreadToken
  24. {
  25. private:
  26. CThreadToken (void);
  27. CThreadToken (const CThreadToken& copyObject);
  28. bool operator == (const CThreadToken& compareObject) const;
  29. const CThreadToken& operator = (const CThreadToken& assignObject);
  30. public:
  31. CThreadToken (DWORD dwDesiredAccess);
  32. ~CThreadToken (void);
  33. operator HANDLE (void) const;
  34. private:
  35. HANDLE _hToken;
  36. };
  37. // --------------------------------------------------------------------------
  38. // CPrivilegeEnable
  39. //
  40. // Purpose: This class enables a privilege for the duration of its scope.
  41. // The privilege is restored to its original state on
  42. // destruction.
  43. //
  44. // History: 1999-08-18 vtan created
  45. // 2000-02-01 vtan moved from Neptune to Whistler
  46. // --------------------------------------------------------------------------
  47. class CPrivilegeEnable
  48. {
  49. private:
  50. CPrivilegeEnable (void);
  51. CPrivilegeEnable (const CPrivilegeEnable& copyObject);
  52. const CPrivilegeEnable& operator = (const CPrivilegeEnable& assignObject);
  53. public:
  54. CPrivilegeEnable (const TCHAR *pszName);
  55. ~CPrivilegeEnable (void);
  56. private:
  57. bool _fSet;
  58. CThreadToken _hToken;
  59. TOKEN_PRIVILEGES _oldPrivilege;
  60. };
  61. #endif /* _PrivilegeEnable_ */