選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Security.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <aclapi.h>
  27. namespace rfb {
  28. namespace win32 {
  29. struct Trustee : public TRUSTEE {
  30. Trustee(const char* 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 char* 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 char* 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 : std::vector<uint8_t> {
  57. Sid() {}
  58. operator PSID() const {return (PSID)data();}
  59. static PSID copySID(const PSID sid);
  60. void setSID(const PSID sid);
  61. void getUserNameAndDomain(char** name, char** domain);
  62. struct Administrators;
  63. struct SYSTEM;
  64. struct FromToken;
  65. private:
  66. Sid(const Sid&);
  67. Sid& operator=(const Sid&);
  68. };
  69. struct Sid::Administrators : public Sid {
  70. Administrators();
  71. };
  72. struct Sid::SYSTEM : public Sid {
  73. SYSTEM();
  74. };
  75. struct Sid::FromToken : public Sid {
  76. FromToken(HANDLE h);
  77. };
  78. // Helper class for handling & freeing ACLs
  79. struct AccessControlList : public LocalMem {
  80. AccessControlList(int size) : LocalMem(size) {}
  81. AccessControlList(PACL acl_=0) : LocalMem(acl_) {}
  82. operator PACL() {return (PACL)ptr;}
  83. };
  84. // Create a new ACL based on supplied entries and, if supplied, existing ACL
  85. PACL CreateACL(const AccessEntries& ae, PACL existing_acl=0);
  86. // Helper class for memory-management of self-relative SecurityDescriptors
  87. struct SecurityDescriptorPtr : LocalMem {
  88. SecurityDescriptorPtr(int size) : LocalMem(size) {}
  89. SecurityDescriptorPtr(PSECURITY_DESCRIPTOR sd_=0) : LocalMem(sd_) {}
  90. PSECURITY_DESCRIPTOR takeSD() {return (PSECURITY_DESCRIPTOR)takePtr();}
  91. };
  92. // Create a new self-relative Security Descriptor, owned by SYSTEM/Administrators,
  93. // with the supplied DACL and no SACL. The returned value can be assigned
  94. // to a SecurityDescriptorPtr to be managed.
  95. PSECURITY_DESCRIPTOR CreateSdWithDacl(const PACL dacl);
  96. }
  97. }
  98. #endif