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.

219 lines
5.9 KiB

  1. #pragma once
  2. #include <set>
  3. #include <vector>
  4. #include "DomainAccount.h"
  5. #include "VarSetBase.h"
  6. #include <IsAdmin.hpp>
  7. #ifndef StringSet
  8. typedef std::set<_bstr_t> StringSet;
  9. #endif
  10. //---------------------------------------------------------------------------
  11. // Container Class
  12. //
  13. // This class encapsulates the properties of a domain container and the
  14. // operations that may be performed on a domain container.
  15. //---------------------------------------------------------------------------
  16. class CContainer
  17. {
  18. public:
  19. CContainer();
  20. CContainer(_bstr_t strPath);
  21. CContainer(IDispatchPtr sp);
  22. CContainer(const CContainer& r);
  23. virtual ~CContainer();
  24. // assignment operator
  25. CContainer& operator =(_bstr_t strPath);
  26. CContainer& operator =(const CContainer& r);
  27. // boolean operator
  28. // returns true if dispatch interface is not null
  29. operator bool()
  30. {
  31. return m_sp;
  32. }
  33. IDispatchPtr GetInterface() const
  34. {
  35. return m_sp;
  36. }
  37. _bstr_t GetPath();
  38. _bstr_t GetDomain();
  39. _bstr_t GetName();
  40. _bstr_t GetRDN();
  41. // duplicates container hierarchy given a source container
  42. void CreateContainerHierarchy(CContainer& rSource);
  43. // create a child container given a relative distinguished name
  44. virtual CContainer CreateContainer(_bstr_t strRDN);
  45. // retrieve a child container given a relative distinguished name
  46. virtual CContainer GetContainer(_bstr_t strRDN);
  47. virtual void QueryContainers(std::vector<CContainer>& rContainers);
  48. virtual void QueryUsers(bool bRecurse, StringSet& setExcludeNames, CDomainAccounts& rUsers);
  49. virtual void QueryGroups(bool bRecurse, StringSet& setExcludeNames, CDomainAccounts& rGroups);
  50. virtual void QueryComputers(bool bIncludeDCs, bool bRecurse, StringSet& setExcludeNames, CDomainAccounts& rComputers);
  51. protected:
  52. // duplicates container hierarchy given a source container
  53. void CreateContainerHierarchy(CContainer& rSource, bool bParentCreated);
  54. // create a child container given a relative distinguished name
  55. virtual CContainer CreateContainer(_bstr_t strRDN, bool& bCreated);
  56. // recursively delete this container
  57. virtual void DeleteContainersRecursively();
  58. protected:
  59. IDispatchPtr m_sp;
  60. };
  61. typedef std::vector<CContainer> ContainerVector;
  62. //---------------------------------------------------------------------------
  63. // Domain Class
  64. //---------------------------------------------------------------------------
  65. class CDomain : public CContainer
  66. {
  67. public:
  68. CDomain();
  69. ~CDomain();
  70. bool Initialized() const
  71. {
  72. return m_bInitialized;
  73. }
  74. bool UpLevel() const
  75. {
  76. return m_bUpLevel;
  77. }
  78. bool NativeMode() const
  79. {
  80. return m_bNativeMode;
  81. }
  82. _bstr_t Name() const
  83. {
  84. _bstr_t strName = m_strDomainNameDns;
  85. if (!strName)
  86. {
  87. strName = m_strDomainNameFlat;
  88. }
  89. return strName;
  90. }
  91. _bstr_t NameDns() const
  92. {
  93. return m_strDomainNameDns;
  94. }
  95. _bstr_t NameFlat() const
  96. {
  97. return m_strDomainNameFlat;
  98. }
  99. _bstr_t ForestName() const
  100. {
  101. return m_strForestName;
  102. }
  103. _bstr_t Sid() const
  104. {
  105. return m_strDomainSid;
  106. }
  107. _bstr_t DomainControllerName() const
  108. {
  109. return m_strDcNameDns.length() ? (LPCTSTR)m_strDcNameDns : (LPCTSTR)m_strDcNameFlat;
  110. }
  111. _bstr_t DomainControllerNameDns() const
  112. {
  113. return m_strDcNameDns;
  114. }
  115. _bstr_t DomainControllerNameFlat() const
  116. {
  117. return m_strDcNameFlat;
  118. }
  119. void Initialize(_bstr_t strDomainName);
  120. DWORD IsAdministrator()
  121. {
  122. return IsAdminRemote(DomainControllerName());
  123. }
  124. virtual CContainer CreateContainer(_bstr_t strRDN);
  125. CContainer GetContainer(_bstr_t strRelativeCanonicalPath, bool bCreate = false);
  126. virtual void QueryContainers(ContainerVector& rContainers);
  127. void QueryUsers(CContainer& rContainer, StringSet& setIncludeNames, StringSet& setExcludeNames, CDomainAccounts& rUsers);
  128. void QueryGroups(CContainer& rContainer, StringSet& setIncludeNames, StringSet& setExcludeNames, CDomainAccounts& rGroups);
  129. void QueryComputers(CContainer& rContainer, bool bIncludeDCs, StringSet& setIncludeNames, StringSet& setExcludeNames, CDomainAccounts& rComputers);
  130. void QueryComputersAcrossDomains(CContainer& rContainer, bool bIncludeDCs, StringSet& setIncludeNames, StringSet& setExcludeNames, CDomainAccounts& rComputers);
  131. virtual void QueryUsers(bool bRecurse, StringSet& setExcludeNames, CDomainAccounts& rUsers);
  132. virtual void QueryGroups(bool bRecurse, StringSet& setExcludeNames, CDomainAccounts& rGroups);
  133. virtual void QueryComputers(bool bIncludeDCs, bool bRecurse, StringSet& setExcludeNames, CDomainAccounts& rComputers);
  134. protected:
  135. CDomain(const CDomain& r) {}
  136. void GetDcName(_bstr_t strDomainName, _bstr_t& strDnsName, _bstr_t& strFlatName);
  137. _bstr_t GetGcName();
  138. _bstr_t GetSid();
  139. _bstr_t GetLDAPPath(_bstr_t strDN);
  140. _bstr_t GetWinNTPath(_bstr_t strName);
  141. _bstr_t GetDistinguishedName(_bstr_t strRelativeCanonicalPath);
  142. void QueryObjects(CContainer& rContainer, StringSet& setIncludeNames, StringSet& setExcludeNames, LPCTSTR pszClass, CDomainAccounts& rAccounts);
  143. void QueryUsers4(StringSet& setExcludeNames, CDomainAccounts& rUsers);
  144. void QueryUsers4(StringSet& setIncludeNames, StringSet& setExcludeNames, CDomainAccounts& rUsers);
  145. void QueryGroups4(StringSet& setExcludeNames, CDomainAccounts& rGroups);
  146. void QueryGroups4(StringSet& setIncludeNames, StringSet& setExcludeNames, CDomainAccounts& rGroups);
  147. void QueryComputers4(bool bIncludeDCs, StringSet& setExcludeNames, CDomainAccounts& rComputers);
  148. void QueryComputers4(bool bIncludeDCs, StringSet& setIncludeNames, StringSet& setExcludeNames, CDomainAccounts& rComputers);
  149. protected:
  150. bool m_bInitialized;
  151. bool m_bUpLevel;
  152. bool m_bNativeMode;
  153. _bstr_t m_strADsPath;
  154. _bstr_t m_strDcNameDns;
  155. _bstr_t m_strDcNameFlat;
  156. _bstr_t m_strGcName;
  157. _bstr_t m_strForestName;
  158. _bstr_t m_strDomainNameDns;
  159. _bstr_t m_strDomainNameFlat;
  160. _bstr_t m_strDomainSid;
  161. };