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.

156 lines
5.3 KiB

  1. /*****************************************************************************/
  2. /* Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved /
  3. /*****************************************************************************/
  4. /*
  5. * CAccessEntryList.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 __CACCESSENTRYLIST_H__
  11. #define __CACCESSENTRYLIST_H__
  12. #include "AccessEntry.h"
  13. #include "list"
  14. //////////////////////////////////////////////////////////////////
  15. //
  16. // Class: CAccessEntryList
  17. //
  18. // Class to encapsulate Windows NT ACL data. It basically
  19. // maintains a list of ACEs using an STL Linked List. It provides
  20. // a series of public and protected functions to allow manipulation
  21. // of the list. By keeping a large group of these functions
  22. // protected, we goofproof the class by not allowing public
  23. // users to manipulate our internal data.
  24. //
  25. //////////////////////////////////////////////////////////////////
  26. // Used for front and end indeces
  27. //#define ACCESSENTRY_LIST_FRONT (-1)
  28. //#define ACCESSENTRY_LIST_END (-2)
  29. // We will hide an ACLIter* as a DWORD
  30. typedef LPVOID ACLPOSITION;
  31. typedef std::list<CAccessEntry*>::iterator ACLIter;
  32. // FOR ACE Filtering when Initializing from a PACL. This value
  33. // means ALL_ACE_TYPES
  34. #define ALL_ACE_TYPES 0xFF
  35. class CAccessEntryList
  36. {
  37. // Constructors and destructor
  38. public:
  39. CAccessEntryList();
  40. CAccessEntryList( PACL pWin32ACL, bool fLookup = true);
  41. ~CAccessEntryList( void );
  42. // The only public functions available allow enumeration
  43. // of entries, and emptying the list.
  44. bool BeginEnum( ACLPOSITION& pos );
  45. bool GetNext( ACLPOSITION& pos, CAccessEntry& ACE );
  46. void EndEnum( ACLPOSITION& pos );
  47. DWORD NumEntries( void );
  48. bool IsEmpty( void );
  49. void Clear( void );
  50. bool GetAt( DWORD nIndex, CAccessEntry& ace );
  51. // ACE Location helpers
  52. virtual bool Find( const CSid& sid, BYTE bACEType, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid, DWORD dwAccessMask, CAccessEntry& ace );
  53. virtual bool Find( PSID psid, BYTE bACEType, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid, DWORD dwAccessMask, CAccessEntry& ace );
  54. // Win32 ACL helpers
  55. BOOL CalculateWin32ACLSize( LPDWORD pdwACLSize );
  56. DWORD FillWin32ACL( PACL pACL );
  57. DWORD InitFromWin32ACL( PACL pWin32ACL, BYTE bACEFilter = ALL_ACE_TYPES, bool fLookup = true);
  58. void DumpAccessEntryList(LPCWSTR wstrFilename = NULL);
  59. // protected:
  60. // Only derived classes have access to modify our actual lists.
  61. void Add( CAccessEntry* pACE );
  62. void Append( CAccessEntry* pACE );
  63. ACLIter Find( CAccessEntry* pACE );
  64. CAccessEntry* Find( PSID psid, BYTE bACEType, BYTE bACEFlags, GUID *pguidObjGuid, GUID *pguidInhObjGuid, DWORD dwAccessMask, bool fLookup = true );
  65. CAccessEntry* Find( const CAccessEntry& ace );
  66. void Remove( CAccessEntry* pACE );
  67. bool SetAt( DWORD dwIndex, const CAccessEntry& ace );
  68. bool RemoveAt( DWORD dwIndex );
  69. // These two functions allow us to Add an entry either overwriting or merging
  70. // the access mask of a preexisting entry.
  71. bool AddNoDup( PSID psid,
  72. BYTE bACEType,
  73. BYTE bACEFlags,
  74. DWORD dwMask,
  75. GUID *pguidObjGuid,
  76. GUID *pguidInhObjGuid,
  77. bool fMerge = false );
  78. bool AppendNoDup( PSID psid,
  79. BYTE bACEType,
  80. BYTE bACEFlags,
  81. DWORD dwMask,
  82. GUID *pguidObjGuid,
  83. GUID *pguidInhObjGuid,
  84. bool fMerge = false );
  85. bool AppendNoDup( PSID psid,
  86. BYTE bACEType,
  87. BYTE bACEFlags,
  88. DWORD dwMask,
  89. GUID *pguidObjGuid,
  90. GUID *pguidInhObjGuid,
  91. bool fMerge,
  92. bool fLookup);
  93. // The copy protection is protected so derived classes can
  94. // implement a typesafe equals operator
  95. bool Copy( CAccessEntryList& ACL );
  96. bool AppendList( CAccessEntryList& ACL );
  97. // For NT 5, we will need to handle ACEs separately, so use these
  98. // functions to copy lists inherited/noninherited ACEs into another list.
  99. bool CopyACEs( CAccessEntryList& ACL, BYTE bACEType );
  100. bool CopyInheritedACEs( CAccessEntryList& ACL, BYTE bACEType );
  101. // and use this one to copy lists allowed/denied into another list.
  102. bool CopyAllowedACEs(CAccessEntryList& ACL);
  103. bool CopyDeniedACEs(CAccessEntryList& ACL);
  104. bool CopyByACEType(CAccessEntryList& ACL, BYTE bACEType, bool fInherited);
  105. // Only let derived classes work with actual pointer values. This way
  106. // public users can't 86 our internal memory.
  107. CAccessEntry* GetNext( ACLPOSITION& pos );
  108. private:
  109. std::list<CAccessEntry*> m_ACL;
  110. };
  111. inline DWORD CAccessEntryList::NumEntries( void )
  112. {
  113. return m_ACL.size();
  114. }
  115. inline bool CAccessEntryList::IsEmpty( void )
  116. {
  117. return (m_ACL.empty() ? true : false);
  118. }
  119. #endif // __CAccessEntry_H__