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.7KB

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 <rdr/types.h>
  24. #include <rfb_win32/LocalMem.h>
  25. #include <rfb_win32/TCharArray.h>
  26. #include <aclapi.h>
  27. namespace rfb {
  28. namespace win32 {
  29. struct Trustee : public TRUSTEE {
  30. Trustee(const TCHAR* name,
  31. TRUSTEE_FORM form=TRUSTEE_IS_NAME,
  32. TRUSTEE_TYPE type=TRUSTEE_IS_UNKNOWN);
  33. };
  34. struct ExplicitAccess : public EXPLICIT_ACCESS {
  35. ExplicitAccess(const TCHAR* name,
  36. TRUSTEE_FORM type,
  37. DWORD perms,
  38. ACCESS_MODE mode,
  39. DWORD inherit=0);
  40. };
  41. // Helper class for building access control lists
  42. struct AccessEntries {
  43. AccessEntries();
  44. ~AccessEntries();
  45. void allocMinEntries(int count);
  46. void addEntry(const TCHAR* trusteeName,
  47. DWORD permissions,
  48. ACCESS_MODE mode);
  49. void addEntry(const PSID sid,
  50. DWORD permissions,
  51. ACCESS_MODE mode);
  52. EXPLICIT_ACCESS* entries;
  53. int entry_count;
  54. };
  55. // Helper class for handling SIDs
  56. struct Sid : rdr::U8Array {
  57. Sid() {}
  58. operator PSID() const {return (PSID)buf;}
  59. PSID takePSID() {PSID r = (PSID)buf; buf = 0; return r;}
  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