Source code of Windows XP (NT5)
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.

277 lines
7.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990, 1991 **/
  4. /**********************************************************************/
  5. /*
  6. domenum.hxx
  7. This file contains the class declaration for the BROWSE_DOMAIN_ENUM
  8. enumerator class. It also contains the class declaration for the
  9. BROWSE_DOMAIN_INFO class, which is the return "type" of the domain
  10. enumerator.
  11. The BROWSE_DOMAIN_ENUM class is used to enumerate domains. A number
  12. of bit flags are passed to the object's constructor to control the
  13. domain enumeration.
  14. BROWSE_DOMAIN_ENUM is quite different from the LM_ENUM class of
  15. enumerators. All of the "grunt" work is performed in the constructor
  16. (there is no GetInfo method).
  17. NOTE: This code is based on an initial design by Yi-HsinS.
  18. FILE HISTORY:
  19. KeithMo 22-Jul-1992 Created.
  20. Yi-HsinS 12-Nov-1992 Add a parameter to GetWorkgroupDomains
  21. KeithMo 16-Nov-1992 Removed the GetWorkgroupDomains parameter
  22. */
  23. #ifndef _DOMENUM_HXX
  24. #define _DOMENUM_HXX
  25. #include "domenum.h" // get the BROWSE_*_DOMAIN[S] bitflags
  26. #include "slist.hxx" // for SLIST & ITER_SLIST & macros
  27. #include "string.hxx"
  28. //
  29. // Forward references.
  30. //
  31. DLL_CLASS BROWSE_DOMAIN_INFO;
  32. DLL_CLASS BROWSE_DOMAIN_ENUM;
  33. /*************************************************************************
  34. NAME: BROWSE_DOMAIN_INFO
  35. SYNOPSIS: This is the return "type" of the domain enumerator.
  36. INTERFACE: BROWSE_DOMAIN_INFO - Class constructor.
  37. ~BROWSE_DOMAIN_INFO - Class destructor.
  38. QueryDomainName - Returns the name of the
  39. current domain.
  40. QueryDomainSources - Returns the "sources" of the
  41. current domain. This will be
  42. one or more of the
  43. BROWSE_*_DOMAIN[S] bitflags.
  44. USES: NLS_STR
  45. HISTORY:
  46. KeithMo 22-Jul-1992 Created.
  47. **************************************************************************/
  48. DLL_CLASS BROWSE_DOMAIN_INFO : public BASE
  49. {
  50. friend class BROWSE_DOMAIN_ENUM;
  51. private:
  52. //
  53. // The domain name & sources.
  54. //
  55. const NLS_STR _nlsDomainName;
  56. const TCHAR * _pszDomainName;
  57. ULONG _maskDomainSources;
  58. //
  59. // This private method is should only be invoked by
  60. // BROWSE_DOMAIN_ENUM::AddDomainToList.
  61. //
  62. VOID AddDomainSource( ULONG maskDomainSource )
  63. { _maskDomainSources |= maskDomainSource; }
  64. public:
  65. //
  66. // Usual constructor/destructor goodies.
  67. //
  68. BROWSE_DOMAIN_INFO( const TCHAR * pszDomainName,
  69. ULONG maskDomainSources );
  70. ~BROWSE_DOMAIN_INFO( VOID );
  71. //
  72. // Accessors.
  73. //
  74. const TCHAR * QueryDomainName( VOID ) const
  75. { return _pszDomainName; }
  76. ULONG QueryDomainSources( VOID ) const
  77. { return _maskDomainSources; }
  78. }; // class BROWSE_DOMAIN_INFO
  79. DECL_SLIST_OF( BROWSE_DOMAIN_INFO, DLL_BASED );
  80. //
  81. // This will make life a little easier...
  82. //
  83. typedef ITER_SL_OF( BROWSE_DOMAIN_INFO ) BDI_ITER;
  84. /*************************************************************************
  85. NAME: BROWSE_DOMAIN_ENUM
  86. SYNOPSIS: This class is used to enumerate domains.
  87. INTERFACE: BROWSE_DOMAIN_ENUM - Class constructor.
  88. ~BROWSE_DOMAIN_ENUM - Class destructor.
  89. Next - Returns the next domain in the
  90. list.
  91. Reset - Resets to the beginning of the
  92. domain list.
  93. FindFirst/FindNext - Implements a simple find first/
  94. find next strategy.
  95. QueryDomainCount - Returns the number of unique
  96. domains in the domain list.
  97. QuerySourcesUnion - Returns the "union" of all
  98. domain sources masks in the
  99. domain list.
  100. PARENT: BASE
  101. USES: BROWSE_DOMAIN_INFO
  102. SLIST
  103. ITER_SLIST
  104. NLS_STR
  105. HISTORY:
  106. KeithMo 22-Jul-1992 Created.
  107. **************************************************************************/
  108. DLL_CLASS BROWSE_DOMAIN_ENUM : public BASE
  109. {
  110. private:
  111. //
  112. // _slDomains contains the list of enumerated domains.
  113. // _iterDomains is an iterator used to scan the list.
  114. //
  115. SLIST_OF( BROWSE_DOMAIN_INFO ) _slDomains;
  116. BDI_ITER _iterDomains;
  117. //
  118. // This NLS_STR contains the name of the local machine.
  119. //
  120. NLS_STR _nlsComputerName;
  121. //
  122. // This will contain the union of all domain sources
  123. // in the domain list.
  124. //
  125. ULONG _maskSourcesUnion;
  126. //
  127. // These workers manipulate the domain list.
  128. //
  129. APIERR AddDomainToList( const TCHAR * pszDomainName,
  130. ULONG maskDomainSource,
  131. BOOL fBrowserList = FALSE );
  132. //
  133. // These worker routines retrieve domains from the various
  134. // domain sources.
  135. //
  136. APIERR GetLanmanDomains( ULONG maskDomainSources );
  137. APIERR GetTrustingDomains( VOID );
  138. APIERR GetWorkgroupDomains( VOID );
  139. APIERR GetLogonDomainDC( NLS_STR * pnlsLogonDC );
  140. APIERR DetermineIfDomainMember( BOOL * pfIsDomainMember );
  141. public:
  142. //
  143. // The constructor is responsible for invoking all of the API
  144. // necessary to fulfill the enumeration. If successful, then
  145. // _slDomains will contain the list of domains and _iterDomains
  146. // will be reset to the beginning of the list.
  147. //
  148. // If pmaskSuccessful is given, then it will receive a bitmask of
  149. // successful domain sources. For each 1 bit in maskDomainSources,
  150. // if the domain source successfully retrieved a domain, then the
  151. // corresponding bit in *pmaskSuccessful is set.
  152. //
  153. BROWSE_DOMAIN_ENUM( ULONG maskDomainSources = BROWSE_LM2X_DOMAINS,
  154. ULONG * pmaskSuccessful = NULL );
  155. ~BROWSE_DOMAIN_ENUM( VOID );
  156. //
  157. // Returns the next domain in the list, or NULL if we're at
  158. // the end of the list.
  159. //
  160. const BROWSE_DOMAIN_INFO * Next( VOID )
  161. { return _iterDomains.Next(); }
  162. const BROWSE_DOMAIN_INFO * operator()( VOID )
  163. { return Next(); }
  164. //
  165. // Resets the enumerator to the beginning of the list.
  166. //
  167. VOID Reset( VOID )
  168. { _iterDomains.Reset(); }
  169. //
  170. // These methods implement a simple (minded) FindFirst/FindNext
  171. // strategy for the enumerator.
  172. //
  173. const BROWSE_DOMAIN_INFO * FindFirst( ULONG maskDomainSources );
  174. const BROWSE_DOMAIN_INFO * FindNext( ULONG maskDomainSources );
  175. //
  176. // Returns the number of unique domain names in the list.
  177. //
  178. UINT QueryDomainCount( VOID )
  179. { return _slDomains.QueryNumElem(); }
  180. //
  181. // Returns a "union" of all sources in the domain list.
  182. //
  183. ULONG QuerySourcesUnion( VOID ) const
  184. { return _maskSourcesUnion; }
  185. }; // class BROWSE_DOMAIN_ENUM
  186. #endif // _DOMENUM_HXX