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.

188 lines
6.7 KiB

  1. /*****************************************************************************/
  2. /* Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved /
  3. /*****************************************************************************/
  4. /*
  5. * CSecurityDescriptor.h - header file for CSecurityDescriptor class.
  6. *
  7. * Created: 12-14-1997 by Sanjeev Surati
  8. * (based on classes from Windows NT Security by Nik Okuntseff)
  9. */
  10. #if !defined __CSECURITYDESCRIPTOR_H__
  11. #define __CSECURITYDESCRIPTOR_H__
  12. #define ALL_ACCESS_WITHOUT_GENERIC 0x01FFFFFF // all possible access rights
  13. // without generic
  14. ////////////////////////////////////////////////////////////////
  15. //
  16. // Class: CSecurityDescriptor
  17. //
  18. // This class is intended to provide a wrapper for Windows NT
  19. // Security Dscriptors. The idea here is that a client class
  20. // would inherit from this class, obtain a security descriptor
  21. // from an as yet to be determined object, and pass said
  22. // descriptor into this class via InitSecurity(), at which
  23. // point we will take apart the descriptor and store the
  24. // data internally. A user may then change security as needed
  25. // then call the ApplySecurity() function which will call
  26. // a couple of virtual functions, WriteAcls() and WriteOwner()
  27. // that must be implemented by a derived class, supplying
  28. // said class with an appropriately filled out Win32 Security
  29. // Descriptor. Derived classes should also provide an
  30. // implementation for AllAccessMask() in order to provide
  31. // a mask specific to the object they are securing, that
  32. // indicates Full Control access.
  33. //
  34. ////////////////////////////////////////////////////////////////
  35. /*
  36. * Class CSecurityDescriptor is a helper class. It groups user CSid together with its access mask.
  37. */
  38. class CSecurityDescriptor
  39. {
  40. // Constructors and destructor
  41. public:
  42. CSecurityDescriptor();
  43. CSecurityDescriptor( PSECURITY_DESCRIPTOR psd );
  44. CSecurityDescriptor
  45. (
  46. CSid* a_psidOwner,
  47. bool a_fOwnerDefaulted,
  48. CSid* a_psidGroup,
  49. bool a_fGroupDefaulted,
  50. CDACL* a_pDacl,
  51. bool a_fDaclDefaulted,
  52. bool a_fDaclAutoInherited,
  53. CSACL* a_pSacl,
  54. bool a_fSaclDefaulted,
  55. bool a_fSaclAutoInherited
  56. );
  57. virtual ~CSecurityDescriptor();
  58. // public entry to specify which attributes to set.
  59. DWORD ApplySecurity( SECURITY_INFORMATION securityinfo );
  60. // Allows setting various entries
  61. DWORD SetOwner( CSid& sid );
  62. DWORD SetGroup( CSid& sid );
  63. DWORD SetControl ( PSECURITY_DESCRIPTOR_CONTROL pControl );
  64. bool AddDACLEntry( CSid& sid, DACL_Types DaclType, DWORD dwAccessMask, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid);
  65. bool AddSACLEntry( CSid& sid, SACL_Types SaclType, DWORD dwAccessMask, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid);
  66. bool RemoveDACLEntry( CSid& sid, DACL_Types DaclType, DWORD dwAccessMask, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid );
  67. bool RemoveDACLEntry( CSid& sid, DACL_Types DaclType, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid );
  68. bool RemoveDACLEntry( CSid& sid, DACL_Types DaclType, DWORD dwIndex = 0 );
  69. bool RemoveSACLEntry( CSid& sid, SACL_Types SaclType, DWORD dwAccessMask, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid );
  70. bool RemoveSACLEntry( CSid& sid, SACL_Types SaclType, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid );
  71. bool RemoveSACLEntry( CSid& sid, SACL_Types SaclType, DWORD dwIndex = 0 );
  72. // ACE Location methods
  73. bool FindACE( const CSid& sid, BYTE bACEType, DWORD dwAccessMask, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid, CAccessEntry& ace );
  74. bool FindACE( PSID psid, BYTE bACEType, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid, DWORD dwAccessMask, CAccessEntry& ace );
  75. // Empty the ACLs (creates Empty if NULL).
  76. void EmptyDACL();
  77. void EmptySACL();
  78. // Clear (NULL) the ACLs (for DACL, this means a NULL or empty Denied Access,
  79. // DACL and a single entry of "Everyone", "Full Control" for Allowed Access DACL.
  80. bool MakeDACLNull();
  81. bool MakeSACLNull();
  82. // Checks our DACL objects for a NULL DACL condition
  83. bool IsNULLDACL();
  84. // Get owner and ACLs
  85. void GetOwner( CSid& sid );
  86. void GetGroup( CSid& sid );
  87. bool GetDACL( CDACL& DACL );
  88. bool GetSACL( CSACL& SACL );
  89. void GetControl ( PSECURITY_DESCRIPTOR_CONTROL pControl );
  90. // Derived classes should override, and this is called with the appropriate values set
  91. // Derived classes MUST NOT mess with the values in pAbsoluteSD!
  92. virtual DWORD WriteOwner( PSECURITY_DESCRIPTOR pAbsoluteSD ) { return E_FAIL; }
  93. virtual DWORD WriteAcls( PSECURITY_DESCRIPTOR pAbsoluteSD , SECURITY_INFORMATION securityinfo ) { return E_FAIL; }
  94. void DumpDescriptor(LPCWSTR wstrFilename = NULL);
  95. DWORD GetSelfRelativeSD(
  96. SECURITY_INFORMATION securityinfo,
  97. PSECURITY_DESCRIPTOR psd);
  98. protected:
  99. BOOL InitSecurity( PSECURITY_DESCRIPTOR psd );
  100. private:
  101. CSid* m_pOwnerSid;
  102. CSid* m_pGroupSid;
  103. bool m_fOwnerDefaulted;
  104. bool m_fGroupDefaulted;
  105. bool m_fDACLDefaulted;
  106. bool m_fSACLDefaulted;
  107. bool m_fDaclAutoInherited;
  108. bool m_fSaclAutoInherited;
  109. // As of NT5, it is no longer sufficient to just maintain two lists for the dacls, since
  110. // we now have five, not two, types of ACEs that can go into a DACL. Double that since we
  111. // have inherited and non-inherited...
  112. //CDACL* m_pAccessAllowedDACL;
  113. //CDACL* m_pAccessDeniedDACL;
  114. CDACL* m_pDACL;
  115. CSACL* m_pSACL;
  116. SECURITY_DESCRIPTOR_CONTROL m_SecurityDescriptorControl;
  117. void Clear( void );
  118. DWORD SecureObject( PSECURITY_DESCRIPTOR pAbsoluteSD, SECURITY_INFORMATION securityinfo );
  119. BOOL InitDACL( PSECURITY_DESCRIPTOR psd );
  120. BOOL InitSACL( PSECURITY_DESCRIPTOR psd );
  121. bool InitDACL( CDACL* a_pDACL );
  122. bool InitSACL( CSACL* a_pSACL );
  123. };
  124. inline void CSecurityDescriptor::GetOwner( CSid& sid )
  125. {
  126. if ( NULL != m_pOwnerSid )
  127. {
  128. sid = *m_pOwnerSid;
  129. }
  130. }
  131. inline void CSecurityDescriptor::GetGroup( CSid& sid )
  132. {
  133. if (NULL != m_pGroupSid )
  134. {
  135. sid = *m_pGroupSid;
  136. }
  137. }
  138. inline void CSecurityDescriptor::GetControl ( PSECURITY_DESCRIPTOR_CONTROL pControl )
  139. {
  140. //pControl = &m_SecurityDescriptorControl;
  141. //changed to copy the Sec. Desc. Control properly
  142. if(pControl)
  143. {
  144. *pControl = m_SecurityDescriptorControl;
  145. }
  146. }
  147. inline DWORD CSecurityDescriptor::SetControl (PSECURITY_DESCRIPTOR_CONTROL pControl )
  148. {
  149. m_SecurityDescriptorControl = *pControl;
  150. return (ERROR_SUCCESS);
  151. }
  152. #endif // __CSecurityDescriptor_H__