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
2.0 KiB

  1. #ifndef _SECDESC_H
  2. #define _SECDESC_H
  3. #include "openfilesdef.h"
  4. #include "account.h"
  5. //+-------------------------------------------------------------------------
  6. //
  7. // Class: FastAllocator
  8. //
  9. // Synopsis: takes in a buffer, buffer size, and needed size, and either
  10. // uses the buffer, or allocates a new one for the size
  11. // and of course destroys it in the dtor
  12. //
  13. //--------------------------------------------------------------------------
  14. class FastAllocator
  15. {
  16. public:
  17. inline FastAllocator(VOID *buf, LONG bufsize);
  18. inline ~FastAllocator();
  19. inline VOID *GetBuf(LONG neededsize);
  20. private:
  21. VOID *_statbuf;
  22. VOID *_allocatedbuf;
  23. LONG _statbufsize;
  24. BOOL _allocated;
  25. };
  26. FastAllocator::FastAllocator(VOID *buf, LONG bufsize)
  27. :_statbuf(buf),
  28. _statbufsize(bufsize),
  29. _allocated(FALSE)
  30. {
  31. }
  32. FastAllocator::~FastAllocator()
  33. {
  34. if (_allocated)
  35. delete _allocatedbuf;
  36. }
  37. VOID *FastAllocator::GetBuf(LONG neededsize)
  38. {
  39. if (neededsize > _statbufsize)
  40. {
  41. _allocatedbuf = (VOID *)new BYTE[neededsize];
  42. if (_allocatedbuf)
  43. _allocated = TRUE;
  44. } else
  45. {
  46. _allocatedbuf = _statbuf;
  47. }
  48. return(_allocatedbuf);
  49. }
  50. typedef struct _USER_ACESSINFO
  51. {
  52. CAccount *pAcc;
  53. BYTE byAceType;
  54. DWORD dwAccessMask;
  55. } USER_ACESSINFO;
  56. class CSecDesc
  57. {
  58. public:
  59. CSecDesc(BYTE *psd);
  60. HRESULT Init();
  61. HRESULT AddUserAccess(LPWSTR szUser, LPWSTR szDomain, BYTE byAceType, DWORD dwAccessMask);
  62. HRESULT GetSecDescAndSize(BYTE **ppsd);
  63. private:
  64. BYTE *m_psd;
  65. ULONG m_ulNumAces;
  66. USER_ACESSINFO m_UserAcessInfo[MAX_ACES];
  67. HRESULT NewDefaultDescriptor( OUT PSECURITY_DESCRIPTOR *ppsd );
  68. ULONG GetAclSize(ULONG *caclsize);
  69. ULONG BuildAcl(ACL **pnewdacl);
  70. ULONG AllocateNewAcl(ACL **ppnewdacl, ULONG caclsize);
  71. ULONG SetAllowedAce(ACL *dacl, ACCESS_MASK mask, SID *psid);
  72. ULONG SetDeniedAce(ACL *dacl, ACCESS_MASK mask, SID *psid);
  73. ULONG FillNewAcl(ACL *pnewdacl);
  74. };
  75. #endif