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.

94 lines
4.4 KiB

  1. #include "Aclapi.h"
  2. #include <buffer.hxx>
  3. // class: CSecurityDescriptor
  4. //
  5. // Class to create and modify a Security Descriptor
  6. //
  7. class CSecurityDescriptor
  8. {
  9. private:
  10. BOOL m_bSDValid : 1; // Is the SD Valid?
  11. BOOL m_bDAclIsInheritted : 1; // Is the DACL inheritted (was it taken from an inheritted dacl?)
  12. PACL m_pDAcl; // Our DAcl
  13. PSID m_pOwner;
  14. PSID m_pGroup;
  15. SECURITY_DESCRIPTOR m_SD; // Our Security Descriptor
  16. SECURITY_ATTRIBUTES m_SA; // Our Security Attributes for the SD
  17. BOOL SetDAcl( PACL pAcl );
  18. BOOL SetOwner( PSID pSid );
  19. BOOL SetGroup( PSID pSid );
  20. PACL GetCurrentDAcl();
  21. BOOL InitializeSD();
  22. PSID CreateWellKnowSid( DWORD dwId );
  23. // PSID CreateSidFromName( LPTSTR szTrustee );
  24. BOOL DuplicateACL( PACL pSourceAcl, PACL *pNewlyCreateAcl );
  25. BOOL UpdateDACLwithNewACE( TRUSTEE_FORM TrusteeForm, LPTSTR szTrusteeName,
  26. DWORD dwAccess, ACCESS_MODE dwAccessMode, DWORD dwInheitance);
  27. BOOL IsInherittedAcl( PACL pSourceAcl );
  28. public:
  29. CSecurityDescriptor();
  30. ~CSecurityDescriptor();
  31. // Add/Remove Functions for DAcl's
  32. BOOL AddAccessAcebyName( LPTSTR szName, DWORD dwAccess, BOOL bAllow = TRUE , BOOL bInherit = FALSE );
  33. BOOL AddAccessAcebyWellKnownID( DWORD dwID, DWORD dwAccess, BOOL bAllow = TRUE , BOOL bInherit = FALSE );
  34. BOOL AddAccessAcebyStringSid( LPTSTR szStringSid, DWORD dwAccess, BOOL bAllow = TRUE , BOOL bInherit = FALSE );
  35. BOOL RemoveAccessAcebyName( LPTSTR szName ,BOOL bInherit = FALSE );
  36. BOOL ResetSD();
  37. // Set Owner/Group Info
  38. BOOL SetOwnerbyWellKnownID( DWORD dwID );
  39. BOOL SetGroupbyWellKnownID( DWORD dwID );
  40. // Set/Retrieve Security Infomation
  41. BOOL SetSecurityInfoOnHandle( HANDLE hHandle, SE_OBJECT_TYPE ObjectType, BOOL bAllowInheritance = FALSE );
  42. BOOL SetSecurityInfoOnFile( LPTSTR szFile, BOOL bAllowInheritance );
  43. BOOL SetSecurityInfoOnFiles( LPTSTR szFile, BOOL bAllowInheritance );
  44. BOOL GetSecurityInfoOnHandle( HANDLE hHandle, SE_OBJECT_TYPE ObjectType );
  45. BOOL GetSecurityInfoOnFile( LPTSTR szFile );
  46. BOOL DuplicateSD( PSECURITY_DESCRIPTOR pSD );
  47. // Query Pointers to SD and SA
  48. PSECURITY_DESCRIPTOR QuerySD();
  49. PSECURITY_ATTRIBUTES QuerySA();
  50. BOOL CreateSelfRelativeSD( BUFFER *pBuff, LPDWORD pdwSize );
  51. BOOL QueryEffectiveRightsForTrustee( DWORD dwTrustee,
  52. PACCESS_MASK pAccessMask );
  53. static BOOL DoesFileSystemSupportACLs( LPTSTR szPath, LPBOOL pbSupportAcls );
  54. // Some shortcut calls
  55. BOOL CreateAdminDAcl( BOOL bInheritable = FALSE );
  56. // Constants to be used
  57. static enum USERANDGROUSIDS {
  58. GROUP_ADMINISTRATORS = 0,
  59. GROUP_USERS,
  60. USER_LOCALSYSTEM,
  61. USER_LOCALSERVICE,
  62. USER_NETWORKSERVICE,
  63. USER_EVERYONE,
  64. };
  65. static const ACCESS_FULL = FILE_ALL_ACCESS;
  66. static const ACCESS_WRITEONLY = ACTRL_FILE_WRITE | // File Specific: Write
  67. ACTRL_FILE_APPEND | // File Specific: Append
  68. ACTRL_FILE_WRITE_PROP | // File Specific: Write File Properties
  69. ACTRL_FILE_WRITE_ATTRIB; // File Specific: Write Attributes
  70. static const ACCESS_FILE_DELETE = DELETE; // Standard: Delete
  71. static const ACCESS_DIR_DELETE = ACCESS_FILE_DELETE |
  72. ACTRL_DIR_DELETE_CHILD; // Dir specific: Delete Child
  73. static const ACCESS_READONLY = SYNCHRONIZE | // Standard: Synchronize
  74. STANDARD_RIGHTS_READ | // Standard: Read
  75. ACTRL_FILE_READ | // File Specific: Read File
  76. ACTRL_FILE_READ_PROP | // File Specific: Read Properties
  77. ACTRL_FILE_READ_ATTRIB; // File Specific: Read Attributes
  78. static const ACCESS_READ_EXECUTE = ACCESS_READONLY | // Read from above
  79. STANDARD_RIGHTS_EXECUTE | // Standard: Execute
  80. ACTRL_FILE_EXECUTE; // File Specific: Execute File */
  81. };
  82. BOOL CreateDirectoryWithSA( LPTSTR szPath, CSecurityDescriptor &pSD, BOOL bAllowInheritance );