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.

269 lines
6.4 KiB

  1. /*****************************************************************************/
  2. /* Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved /
  3. /*****************************************************************************/
  4. /*
  5. * CAccessEntry.h - header file for CAccessEntry 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 __CACCESSENTRY_H__
  11. #define __CACCESSENTRY_H__
  12. #include "Sid.h" // CSid class
  13. #define ALL_ACCESS_WITHOUT_GENERIC 0x01FFFFFF // all possible access rights
  14. // without generic
  15. // This is an NT 5 flag that we will use to tell us that an ACE although read out, should
  16. // NOT be written back. It was copied from the NT 5 WINNT.H, since we are not building
  17. // using that file.
  18. #define INHERITED_ACE (0x10)
  19. //////////////////////////////////////////////////////////////////
  20. //
  21. // Class: CAccessEntry
  22. //
  23. // Class to encapsulate Windows NT ACE information. It basically
  24. // acts as a repository for a SID, and access information.
  25. //
  26. //////////////////////////////////////////////////////////////////
  27. class CAccessEntry
  28. {
  29. // Constructors and destructor
  30. public:
  31. CAccessEntry();
  32. CAccessEntry( PSID pSid,
  33. BYTE bACEType, BYTE bACEFlags,
  34. GUID *pguidObjType, GUID *pguidInhObjType,
  35. DWORD dwAccessMask = ALL_ACCESS_WITHOUT_GENERIC,
  36. LPCTSTR pszComputerName = NULL );
  37. CAccessEntry( PSID pSid,
  38. BYTE bACEType, BYTE bACEFlags,
  39. GUID *pguidObjType, GUID *pguidInhObjType,
  40. DWORD dwAccessMask,
  41. LPCTSTR pszComputerName,
  42. bool fLookup );
  43. CAccessEntry( const CSid& sid,
  44. BYTE bACEType, BYTE bACEFlags,
  45. GUID *pguidObjType, GUID *pguidInhObjType,
  46. DWORD dwAccessMask = ALL_ACCESS_WITHOUT_GENERIC,
  47. LPCTSTR pszComputerName = NULL );
  48. CAccessEntry( LPCTSTR pszAccountName,
  49. BYTE bACEType, BYTE bACEFlags,
  50. GUID *pguidObjType, GUID *pguidInhObjType,
  51. DWORD dwAccessMask = ALL_ACCESS_WITHOUT_GENERIC,
  52. LPCTSTR pszComputerName = NULL );
  53. CAccessEntry( const CAccessEntry &r_AccessEntry );
  54. ~CAccessEntry( void );
  55. CAccessEntry & operator= ( const CAccessEntry & );
  56. bool operator== ( const CAccessEntry & );
  57. BOOL IsEqualToSID( PSID psid );
  58. void GetSID( CSid& sid );
  59. DWORD GetAccessMask( void );
  60. BYTE GetACEType( void );
  61. BYTE GetACEFlags( void );
  62. bool GetObjType(GUID &guidObjType);
  63. bool GetInhObjType(GUID &guidInhObjType);
  64. void SetAccessMask( DWORD dwAccessMask );
  65. void MergeAccessMask( DWORD dwMergeMask );
  66. void SetACEFlags( BYTE bACEFlags );
  67. void SetSID( CSid& sid );
  68. void SetACEType( BYTE aceType );
  69. void SetObjType(GUID &guidObjType);
  70. void SetInhObjType(GUID &guidInhObjType);
  71. BOOL AllocateACE( ACE_HEADER** ppACEHeader );
  72. void FreeACE( ACE_HEADER* pACEHeader );
  73. bool IsInherited( void );
  74. bool IsAllowed();
  75. bool IsDenied();
  76. void DumpAccessEntry(LPCWSTR wstrFilename = NULL);
  77. private:
  78. CSid m_Sid;
  79. DWORD m_dwAccessMask;
  80. BYTE m_bACEType;
  81. BYTE m_bACEFlags;
  82. GUID *m_pguidObjType;
  83. GUID *m_pguidInhObjType;
  84. };
  85. inline void CAccessEntry::GetSID( CSid& sid )
  86. {
  87. sid = m_Sid;
  88. }
  89. inline void CAccessEntry::SetSID( CSid& sid )
  90. {
  91. m_Sid = sid;
  92. }
  93. inline BOOL CAccessEntry::IsEqualToSID( PSID psid )
  94. {
  95. return EqualSid( psid, m_Sid.GetPSid() );
  96. }
  97. inline DWORD CAccessEntry::GetAccessMask( void )
  98. {
  99. return m_dwAccessMask;
  100. }
  101. inline BYTE CAccessEntry::GetACEType( void )
  102. {
  103. return m_bACEType;
  104. }
  105. inline void CAccessEntry::SetACEType( BYTE aceType )
  106. {
  107. m_bACEType = aceType;
  108. }
  109. inline BYTE CAccessEntry::GetACEFlags( void )
  110. {
  111. return m_bACEFlags;
  112. }
  113. inline void CAccessEntry::SetAccessMask( DWORD dwAccessMask )
  114. {
  115. m_dwAccessMask = dwAccessMask;
  116. }
  117. inline void CAccessEntry::MergeAccessMask( DWORD dwMergeMask )
  118. {
  119. m_dwAccessMask |= dwMergeMask;
  120. }
  121. inline void CAccessEntry::SetACEFlags( BYTE bACEFlags )
  122. {
  123. m_bACEFlags = bACEFlags;
  124. }
  125. inline bool CAccessEntry::GetObjType(GUID &guidObjType)
  126. {
  127. bool fRet = false;
  128. if(m_pguidObjType != NULL)
  129. {
  130. memcpy(&guidObjType, m_pguidObjType, sizeof(GUID));
  131. fRet = true;
  132. }
  133. return fRet;
  134. }
  135. inline void CAccessEntry::SetObjType(GUID &guidObjType)
  136. {
  137. if(m_pguidObjType == NULL)
  138. {
  139. try
  140. {
  141. m_pguidObjType = new GUID;
  142. }
  143. catch(...)
  144. {
  145. if(m_pguidObjType != NULL)
  146. {
  147. delete m_pguidObjType;
  148. m_pguidObjType = NULL;
  149. }
  150. throw;
  151. }
  152. }
  153. if(m_pguidObjType != NULL)
  154. {
  155. memcpy(m_pguidObjType, &guidObjType, sizeof(GUID));
  156. }
  157. }
  158. inline bool CAccessEntry::GetInhObjType(GUID &guidObjType)
  159. {
  160. bool fRet = false;
  161. if(m_pguidInhObjType != NULL)
  162. {
  163. memcpy(&guidObjType, m_pguidInhObjType, sizeof(GUID));
  164. fRet = true;
  165. }
  166. return fRet;
  167. }
  168. inline void CAccessEntry::SetInhObjType(GUID &guidInhObjType)
  169. {
  170. if(m_pguidInhObjType == NULL)
  171. {
  172. try
  173. {
  174. m_pguidInhObjType = new GUID;
  175. }
  176. catch(...)
  177. {
  178. if(m_pguidInhObjType != NULL)
  179. {
  180. delete m_pguidInhObjType;
  181. m_pguidInhObjType = NULL;
  182. }
  183. throw;
  184. }
  185. }
  186. if(m_pguidInhObjType != NULL)
  187. {
  188. memcpy(m_pguidInhObjType, &guidInhObjType, sizeof(GUID));
  189. }
  190. }
  191. inline void CAccessEntry::FreeACE( ACE_HEADER* pACEHeader )
  192. {
  193. free( pACEHeader );
  194. }
  195. inline bool CAccessEntry::IsInherited( void )
  196. {
  197. bool fRet = false;
  198. if(m_bACEFlags & INHERITED_ACE)
  199. {
  200. fRet = true;
  201. }
  202. return fRet;
  203. }
  204. inline bool CAccessEntry::IsAllowed( void )
  205. {
  206. bool fRet = false;
  207. if(( m_bACEType == ACCESS_ALLOWED_ACE_TYPE) ||
  208. ( m_bACEType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE) ||
  209. ( m_bACEType == ACCESS_ALLOWED_OBJECT_ACE_TYPE))
  210. {
  211. fRet = true;
  212. }
  213. return fRet;
  214. }
  215. inline bool CAccessEntry::IsDenied( void )
  216. {
  217. bool fRet = false;
  218. if(( m_bACEType == ACCESS_DENIED_ACE_TYPE) ||
  219. ( m_bACEType == ACCESS_DENIED_OBJECT_ACE_TYPE))
  220. {
  221. fRet = true;
  222. }
  223. return fRet;
  224. }
  225. #endif // __CAccessEntry_H__