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.

Security.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. // Security.h
  19. // Wrapper classes for a few Windows NT security structures/functions
  20. // that are used by VNC
  21. #ifndef __RFB_WIN32_SECURITY_H__
  22. #define __RFB_WIN32_SECURITY_H__
  23. #include <stdint.h>
  24. #include <vector>
  25. #include <rfb_win32/LocalMem.h>
  26. #include <rfb_win32/TCharArray.h>
  27. #include <aclapi.h>
  28. namespace rfb {
  29. namespace win32 {
  30. struct Trustee : public TRUSTEE {
  31. Trustee(const TCHAR* name,
  32. TRUSTEE_FORM form=TRUSTEE_IS_NAME,
  33. TRUSTEE_TYPE type=TRUSTEE_IS_UNKNOWN);
  34. };
  35. struct ExplicitAccess : public EXPLICIT_ACCESS {
  36. ExplicitAccess(const TCHAR* name,
  37. TRUSTEE_FORM type,
  38. DWORD perms,
  39. ACCESS_MODE mode,
  40. DWORD inherit=0);
  41. };
  42. // Helper class for building access control lists
  43. struct AccessEntries {
  44. AccessEntries();
  45. ~AccessEntries();
  46. void allocMinEntries(int count);
  47. void addEntry(const TCHAR* trusteeName,
  48. DWORD permissions,
  49. ACCESS_MODE mode);
  50. void addEntry(const PSID sid,
  51. DWORD permissions,
  52. ACCESS_MODE mode);
  53. EXPLICIT_ACCESS* entries;
  54. int entry_count;
  55. };
  56. // Helper class for handling SIDs
  57. struct Sid : std::vector<uint8_t> {
  58. Sid() {}
  59. operator PSID() const {return (PSID)data();}
  60. static PSID copySID(const PSID sid);
  61. void setSID(const PSID sid);
  62. void getUserNameAndDomain(TCHAR** name, TCHAR** domain);
  63. struct Administrators;
  64. struct SYSTEM;
  65. struct FromToken;
  66. private:
  67. Sid(const Sid&);
  68. Sid& operator=(const Sid&);
  69. };
  70. struct Sid::Administrators : public Sid {
  71. Administrators();
  72. };
  73. struct Sid::SYSTEM : public Sid {
  74. SYSTEM();
  75. };
  76. struct Sid::FromToken : public Sid {
  77. FromToken(HANDLE h);
  78. };
  79. // Helper class for handling & freeing ACLs
  80. struct AccessControlList : public LocalMem {
  81. AccessControlList(int size) : LocalMem(size) {}
  82. AccessControlList(PACL acl_=0) : LocalMem(acl_) {}
  83. operator PACL() {return (PACL)ptr;}
  84. };
  85. // Create a new ACL based on supplied entries and, if supplied, existing ACL
  86. PACL CreateACL(const AccessEntries& ae, PACL existing_acl=0);
  87. // Helper class for memory-management of self-relative SecurityDescriptors
  88. struct SecurityDescriptorPtr : LocalMem {
  89. SecurityDescriptorPtr(int size) : LocalMem(size) {}
  90. SecurityDescriptorPtr(PSECURITY_DESCRIPTOR sd_=0) : LocalMem(sd_) {}
  91. PSECURITY_DESCRIPTOR takeSD() {return (PSECURITY_DESCRIPTOR)takePtr();}
  92. };
  93. // Create a new self-relative Security Descriptor, owned by SYSTEM/Administrators,
  94. // with the supplied DACL and no SACL. The returned value can be assigned
  95. // to a SecurityDescriptorPtr to be managed.
  96. PSECURITY_DESCRIPTOR CreateSdWithDacl(const PACL dacl);
  97. }
  98. }
  99. #endif