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.

211 lines
4.7 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2001, Microsoft Corporation
  4. //
  5. // File: DfsTrustedDomain.hxx
  6. //
  7. // Contents: the Dfs trusted domain info class
  8. //
  9. // Classes: Dfstrusteddomain
  10. //
  11. // History: apr. 8 2001, Author: udayh
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef __DFS_TRUSTED_DOMAIN__
  15. #define __DFS_TRUSTED_DOMAIN__
  16. #include "DfsGeneric.hxx"
  17. #include "dsgetdc.h"
  18. #include "lm.h"
  19. #include "DfsReferralData.hxx"
  20. enum DfsTrustedDomainDcLoadState
  21. {
  22. DfsTrustedDomainDcLoadStateUnknown = 0,
  23. DfsTrustedDomainDcLoaded,
  24. DfsTrustedDomainDcNotLoaded,
  25. DfsTrustedDomainDcLoadInProgress,
  26. DfsTrustedDomainDcLoadFailed,
  27. };
  28. class DfsTrustedDomain
  29. {
  30. private:
  31. UNICODE_STRING _DomainName;
  32. UNICODE_STRING _BindDomainName;
  33. BOOLEAN _Netbios;
  34. BOOLEAN _UseBindDomain;
  35. DfsReferralData *_pDcReferralData; // The loaded referral data
  36. DfsTrustedDomainDcLoadState _LoadState;
  37. CRITICAL_SECTION *_pLock;
  38. DFSSTATUS _LoadStatus;
  39. ULONG _RetryFailedLoadTimeout;
  40. private:
  41. DFSSTATUS
  42. LoadDcReferralData(
  43. IN DfsReferralData *pReferralData );
  44. public:
  45. DfsTrustedDomain()
  46. {
  47. RtlInitUnicodeString( &_DomainName, NULL );
  48. RtlInitUnicodeString( &_BindDomainName, NULL );
  49. _pDcReferralData = NULL;
  50. _pLock = NULL;
  51. _Netbios = FALSE;
  52. _UseBindDomain = FALSE;
  53. _LoadState = DfsTrustedDomainDcNotLoaded;
  54. _LoadStatus = 0;
  55. _RetryFailedLoadTimeout = 0;
  56. }
  57. ~DfsTrustedDomain()
  58. {
  59. DfsFreeUnicodeString( &_DomainName );
  60. if (_pDcReferralData != NULL)
  61. {
  62. _pDcReferralData->ReleaseReference();
  63. _pDcReferralData = NULL;
  64. }
  65. }
  66. VOID
  67. Initialize( CRITICAL_SECTION *pLock)
  68. {
  69. _pLock = pLock;
  70. return NOTHING;
  71. }
  72. DFSSTATUS
  73. AcquireLock()
  74. {
  75. return DfsAcquireLock( _pLock );
  76. }
  77. VOID
  78. ReleaseLock()
  79. {
  80. return DfsReleaseLock( _pLock );
  81. }
  82. DFSSTATUS
  83. SetDomainName(
  84. LPWSTR Name,
  85. BOOLEAN Netbios )
  86. {
  87. DFSSTATUS Status;
  88. Status = DfsCreateUnicodeStringFromString( &_DomainName,
  89. Name );
  90. _Netbios = Netbios;
  91. return Status;
  92. }
  93. DFSSTATUS
  94. SetDomainName(
  95. PUNICODE_STRING Name,
  96. BOOLEAN Netbios )
  97. {
  98. DFSSTATUS Status;
  99. Status = DfsCreateUnicodeString( &_DomainName,
  100. Name );
  101. _Netbios = Netbios;
  102. return Status;
  103. }
  104. DFSSTATUS
  105. SetBindDomainName( PUNICODE_STRING pName )
  106. {
  107. DFSSTATUS Status;
  108. Status = DfsCreateUnicodeString( &_BindDomainName,
  109. pName );
  110. if (Status == ERROR_SUCCESS)
  111. {
  112. _UseBindDomain = TRUE;
  113. }
  114. return Status;
  115. }
  116. PUNICODE_STRING
  117. GetDomainName()
  118. {
  119. return &_DomainName;
  120. }
  121. //
  122. // Function GetReferralData: Returns the referral data for this
  123. // c;ass, and indicates if the referral data was cached or needed
  124. // to be loaded.
  125. //
  126. DFSSTATUS
  127. GetDcReferralData( OUT DfsReferralData **ppReferralData,
  128. OUT BOOLEAN *pCacheHit );
  129. BOOLEAN
  130. IsMatchingDomainName(
  131. PUNICODE_STRING pName )
  132. {
  133. BOOLEAN ReturnValue = FALSE;
  134. if (_DomainName.Length == pName->Length)
  135. {
  136. if (_wcsnicmp( pName->Buffer,
  137. _DomainName.Buffer,
  138. (pName->Length/sizeof(WCHAR)) ) == 0)
  139. {
  140. ReturnValue = TRUE;
  141. }
  142. }
  143. return ReturnValue;
  144. }
  145. BOOLEAN
  146. IsTimeToRetry(VOID)
  147. {
  148. ULONG CurrentTime = GetTickCount();
  149. if ((CurrentTime > _RetryFailedLoadTimeout) &&
  150. ((CurrentTime - _RetryFailedLoadTimeout) > DfsServerGlobalData.RetryFailedReferralLoadInterval))
  151. {
  152. return TRUE;
  153. }
  154. // overflow
  155. if ((CurrentTime < _RetryFailedLoadTimeout) &&
  156. ((CurrentTime - 0) + (0xFFFFFFFF - _RetryFailedLoadTimeout) > DfsServerGlobalData.RetryFailedReferralLoadInterval))
  157. {
  158. return TRUE;
  159. }
  160. return FALSE;
  161. }
  162. DFSSTATUS
  163. RemoveDcReferralData(
  164. DfsReferralData *pRemoveReferralData,
  165. PBOOLEAN pRemoved );
  166. };
  167. #endif __DFS_TRUSTED_DOMAIN__