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.

226 lines
7.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. * lmodom.hxx
  7. *
  8. * History
  9. * RustanL 08-Jan-1991 Created
  10. * rustanl 06-Mar-1991 Changed PSZ to const TCHAR * in ct
  11. * chuckc 7/3/91 Code review changes (from 2/28,
  12. * rustanl, chuckc, johnl, jonshu, annmc)
  13. * rustanl 23-Mar-1991 Added IsLANServerDomain
  14. * rustanl 08-Apr-1991 Cache domain name for domains with
  15. * no DC.
  16. * terryk 07-Oct-1991 type changes for NT
  17. *
  18. * CongpaY 18-Aug-1992 Add fBackupDCsOK
  19. * KeithMo 31-Aug-1992 Added ctor form with server name.
  20. * JonN 13-May-1998 Added SPECIAL CAUTION
  21. *
  22. * SPECIAL CAUTION In the NETBIOSless environment of NT5, there are some limitations with
  23. * SPECIAL CAUTION the variations of the constructor which take the pszServer parameter
  24. * SPECIAL CAUTION and fBackupDCIsOK==TRUE.
  25. * SPECIAL CAUTION
  26. * SPECIAL CAUTION Please read this carefully, and be sure you understand it, before adding or
  27. * SPECIAL CAUTION modifying such code! Contact JonN or CliffV with any questions.
  28. * SPECIAL CAUTION
  29. * SPECIAL CAUTION When you specify a target server and also fBackupDCIsOK==TRUE,
  30. * SPECIAL CAUTION DOMAIN will call NetGetAnyDCName with the target server parameter set.
  31. * SPECIAL CAUTION This will return a DC in the target domain which shares some
  32. * SPECIAL CAUTION network transport with pszServer. However, that server may not share
  33. * SPECIAL CAUTION any network parameters with your local machine! If you use the
  34. * SPECIAL CAUTION GetAnyValidDC variant, then the validation will fail and you will
  35. * SPECIAL CAUTION fall back to I_NetGetDCList. However, if you use just GetAnyDC,
  36. * SPECIAL CAUTION you are liable to wind up with a DC which really exists but
  37. * SPECIAL CAUTION does not share any transports with your local machine.
  38. * SPECIAL CAUTION JonN 5/13/98
  39. *
  40. */
  41. #ifndef _LMODOM_HXX_
  42. #define _LMODOM_HXX_
  43. #include "lmobj.hxx"
  44. /**********************************************************\
  45. NAME: DOMAIN
  46. WORKBOOK:
  47. SYNOPSIS: domain class in lan manager object collection
  48. INTERFACE:
  49. DOMAIN() - constructor
  50. ~DOMAIN() - destructor
  51. QueryName() - query name
  52. GetInfo() - get information
  53. WriteInfo() - write information
  54. QueryPDC() - query pdc
  55. PARENT: LM_OBJ
  56. USES:
  57. CAVEATS: If fBackupDCsOK = TRUE, QueryPDC() may return BDC.
  58. NOTES:
  59. HISTORY:
  60. \**********************************************************/
  61. DLL_CLASS DOMAIN : public LM_OBJ
  62. {
  63. private:
  64. VOID CtAux( const TCHAR * pszServer,
  65. const TCHAR * pszDomain );
  66. protected:
  67. /*
  68. * we allow extra bytes in _szDomain to allow us to store illegal
  69. * names (at least part of). This is for the benefit of validation
  70. * at after construction. If we cannot store an invalid name, we
  71. * cannot validate after construction. (2 bytes for DBCS worst case)
  72. */
  73. TCHAR _szDomain[DNLEN+3];
  74. TCHAR _szDC[MAX_PATH];
  75. TCHAR _szServer[MAX_PATH+3];
  76. BOOL _fBackupDCsOK;
  77. virtual APIERR ValidateName(VOID);
  78. static APIERR GetAnyDCWorker(const TCHAR * pszServer,
  79. const TCHAR * pszDomain,
  80. NLS_STR * pnlsDC,
  81. BOOL fValidate);
  82. public:
  83. DOMAIN( const TCHAR * pchDomain, BOOL fBackupDCsOK = FALSE );
  84. DOMAIN( const TCHAR * pszServer, // see SPECIAL CAUTION above
  85. const TCHAR * pszDomain,
  86. BOOL fBackupDCsOK = FALSE );
  87. ~DOMAIN();
  88. const TCHAR *QueryName( VOID ) const;
  89. APIERR GetInfo( VOID );
  90. APIERR WriteInfo( VOID );
  91. const TCHAR * QueryPDC( VOID ) const;
  92. const TCHAR * QueryAnyDC( VOID ) const;
  93. static APIERR GetAnyValidDC(const TCHAR * pszServer,
  94. const TCHAR * pszDomain,
  95. NLS_STR * pnlsDC); // see SPECIAL CAUTION above
  96. static APIERR GetAnyDC(const TCHAR * pszServer,
  97. const TCHAR * pszDomain,
  98. NLS_STR * pnlsDC); // see SPECIAL CAUTION above
  99. static BOOL IsValidDC( const TCHAR * pszServer,
  100. const TCHAR * pszDomain );
  101. }; // class DOMAIN
  102. /**********************************************************\
  103. NAME: DC_CACHE_ENTRY
  104. SYNOPSIS: structure for keeping cached DCs
  105. USES:
  106. NOTES:
  107. HISTORY: 9/30/92 chuckc created.
  108. \**********************************************************/
  109. typedef struct _DC_CACHE_ENTRY {
  110. TCHAR szDomain[DNLEN+1] ;
  111. TCHAR szServer[MAX_PATH+1] ;
  112. DWORD dwTickCount ;
  113. } DC_CACHE_ENTRY ;
  114. /**********************************************************\
  115. NAME: DOMAIN_WITH_DC_CACHE
  116. WORKBOOK:
  117. SYNOPSIS: as DOMAIN, except that it uses cached DC info.
  118. INTERFACE: as parent
  119. PARENT: DOMAIN
  120. USES:
  121. CAVEATS: If fBackupDCsOK = TRUE, QueryPDC() may return BDC.
  122. NOTES:
  123. HISTORY:
  124. \**********************************************************/
  125. DLL_CLASS DOMAIN_WITH_DC_CACHE : public DOMAIN
  126. {
  127. public:
  128. DOMAIN_WITH_DC_CACHE( const TCHAR * pchDomain, BOOL fBackupDCsOK = FALSE );
  129. DOMAIN_WITH_DC_CACHE( const TCHAR * pszServer, // see SPECIAL CAUTION above
  130. const TCHAR * pszDomain,
  131. BOOL fBackupDCsOK = FALSE );
  132. ~DOMAIN_WITH_DC_CACHE();
  133. APIERR GetInfo( VOID );
  134. static APIERR GetAnyDC(const TCHAR * pszServer,
  135. const TCHAR * pszDomain,
  136. NLS_STR * pnlsDC); // see SPECIAL CAUTION above
  137. static APIERR GetAnyValidDC(const TCHAR * pszServer,
  138. const TCHAR * pszDomain,
  139. NLS_STR * pnlsDC); // see SPECIAL CAUTION above
  140. protected:
  141. static APIERR GetAnyDCWorker(const TCHAR * pszServer,
  142. const TCHAR * pszDomain,
  143. NLS_STR * pnlsDC,
  144. BOOL fValidate);
  145. private:
  146. // static members that have the pointers to the cache tables
  147. static DC_CACHE_ENTRY *_pAnyDcCacheTable ;
  148. static DC_CACHE_ENTRY *_pPrimaryDcCacheTable ;
  149. static HANDLE _hCacheSema4 ;
  150. //
  151. // methods to manipulate the caches
  152. //
  153. // Note that they should not call each other (get hung up on the semaphore
  154. // protection)
  155. //
  156. static const TCHAR *FindDcCache(const DC_CACHE_ENTRY *pDcCacheEntry,
  157. const TCHAR *pszDomain) ;
  158. static APIERR AddDcCache(DC_CACHE_ENTRY **ppDcCacheEntry,
  159. const TCHAR *pszDomain,
  160. const TCHAR *pszDC) ;
  161. //
  162. // These two methods must be called under semaphore protection
  163. //
  164. static APIERR ClearDcCache(DC_CACHE_ENTRY *pDcCacheEntry) ;
  165. //static APIERR FreeDcCache(DC_CACHE_ENTRY **ppDcCacheEntry) ; // Not used
  166. static APIERR EnterCriticalSection( void ) ;
  167. static void LeaveCriticalSection( void ) ;
  168. }; // class DOMAIN_WITH_DC_CACHE
  169. #endif // _LMODOM_HXX_