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.

235 lines
5.7 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2000, Microsoft Corporation
  4. //
  5. // File: DfsXForest.hxx
  6. //
  7. // Contents: the cross forest support
  8. //
  9. // Classes: DfsXForest
  10. //
  11. // History: Nov. 15 2002, Author: udayh
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef __DFS_X_FOREST__
  15. #define __DFS_X_FOREST__
  16. #include "dfsgeneric.hxx"
  17. #include "dsgetdc.h"
  18. #include "ntsecapi.h"
  19. #include <shash.h>
  20. #include <lm.h>
  21. #include <winsock2.h>
  22. #include <smbtypes.h>
  23. #pragma warning(disable: 4200) //nonstandard extension used: zero-sized array in struct/union (line 1085
  24. #include <smbtrans.h>
  25. #pragma warning(default: 4200)
  26. //+----------------------------------------------------------------------------
  27. //
  28. // Class: DfsXForest
  29. //
  30. // Synopsis: This class implements The Dfs ROOT folder.
  31. //
  32. //-----------------------------------------------------------------------------
  33. PVOID
  34. DfsAllocateForDomainTable(ULONG Size );
  35. VOID
  36. DfsDeallocateForDomainTable(PVOID pPointer );
  37. typedef struct _DFS_DOMAIN_NAME_INFO
  38. {
  39. UNICODE_STRING DomainName;
  40. UNICODE_STRING BindDomainName;
  41. BOOLEAN Netbios;
  42. BOOLEAN UseBindDomain;
  43. } DFS_DOMAIN_NAME_INFO, *PDFS_DOMAIN_NAME_INFO;
  44. typedef struct _DFS_DOMAIN_NAME_DATA
  45. {
  46. SHASH_HEADER Header;
  47. DFS_DOMAIN_NAME_INFO DomainInfo;
  48. } DFS_DOMAIN_NAME_DATA, *PDFS_DOMAIN_NAME_DATA;
  49. #define DFS_DEFAULT_NAME_BUCKETS 64
  50. class DfsDomainNameTable
  51. {
  52. private:
  53. PSHASH_TABLE _pDomainNameTable;
  54. SHASH_ITERATOR _Iter;
  55. BOOLEAN _IteratorStarted;
  56. ULONG _DomainReferralSize;
  57. ULONG _DomainsSkipped;
  58. private:
  59. VOID InvalidateDomainTable(VOID);
  60. public:
  61. DfsDomainNameTable()
  62. {
  63. _pDomainNameTable = NULL;
  64. _IteratorStarted = FALSE;
  65. _DomainReferralSize = 0;
  66. _DomainsSkipped = 0;
  67. //
  68. // we build the table to be no greater than the max
  69. // referral that we can return.
  70. //
  71. _DomainReferralSize += sizeof(RESP_GET_DFS_REFERRAL) + sizeof(UNICODE_NULL);
  72. }
  73. DFSSTATUS
  74. Initialize()
  75. {
  76. DFSSTATUS Status = ERROR_SUCCESS;
  77. NTSTATUS NtStatus = STATUS_SUCCESS;
  78. SHASH_FUNCTABLE FunctionTable;
  79. ZeroMemory(&FunctionTable, sizeof(FunctionTable));
  80. FunctionTable.AllocFunc = DfsAllocateForDomainTable;
  81. FunctionTable.FreeFunc = DfsDeallocateForDomainTable;
  82. FunctionTable.AllocHashEntryFunc = DfsAllocateForDomainTable;
  83. FunctionTable.FreeHashEntryFunc = DfsDeallocateForDomainTable;
  84. NtStatus = ShashInitHashTable(&_pDomainNameTable, &FunctionTable);
  85. Status = RtlNtStatusToDosError(NtStatus);
  86. return Status;
  87. }
  88. PDFS_DOMAIN_NAME_INFO
  89. GetNextDomainInfo()
  90. {
  91. PDFS_DOMAIN_NAME_DATA pExistingData = NULL;
  92. PDFS_DOMAIN_NAME_INFO pInfo = NULL;
  93. if (_IteratorStarted == FALSE)
  94. {
  95. pExistingData = (PDFS_DOMAIN_NAME_DATA) SHashStartEnumerate(&_Iter, _pDomainNameTable);
  96. _IteratorStarted = TRUE;
  97. }
  98. else
  99. {
  100. pExistingData = (PDFS_DOMAIN_NAME_DATA) SHashNextEnumerate(&_Iter, _pDomainNameTable);
  101. }
  102. if (pExistingData != NULL)
  103. {
  104. pInfo = &pExistingData->DomainInfo;
  105. }
  106. return pInfo;
  107. }
  108. ULONG GetSkippedDomainCount()
  109. {
  110. return _DomainsSkipped;
  111. }
  112. ~ DfsDomainNameTable( VOID )
  113. {
  114. if (_pDomainNameTable != NULL)
  115. {
  116. //
  117. // Shash should provide a more efficient way of doing this.
  118. //
  119. if (_IteratorStarted)
  120. {
  121. SHashFinishEnumerate(&_Iter, _pDomainNameTable);
  122. }
  123. InvalidateDomainTable();
  124. ShashTerminateHashTable( _pDomainNameTable );
  125. _pDomainNameTable = NULL;
  126. }
  127. }
  128. ULONG GetCount();
  129. DFSSTATUS AddDomain(PUNICODE_STRING DomainName,
  130. PUNICODE_STRING BindDomainName,
  131. BOOLEAN Netbios);
  132. VOID FinishDomainNameEnumerate( SHASH_ITERATOR *pIter );
  133. };
  134. class DfsXForest
  135. {
  136. private:
  137. UNICODE_STRING _ForestRootName;
  138. DfsDomainNameTable _DomainTable;
  139. private:
  140. DFSSTATUS DfsAddForestDomainsToDomainTable(LSA_HANDLE hPolicy,
  141. LPWSTR RootNameString );
  142. DFSSTATUS DfsAddLocalDomainsToDomainTable();
  143. DFSSTATUS DfsAddCrossForestDomainsToDomainTable();
  144. DFSSTATUS AddDomainToDomainTable(PUNICODE_STRING DomainName,
  145. PUNICODE_STRING BindDomainName,
  146. BOOLEAN Netbios);
  147. DFSSTATUS AddDomainToDomainTable(LPWSTR DomainName,
  148. LPWSTR BindDomainName,
  149. BOOLEAN Netbios);
  150. DFSSTATUS InitializeForestRootName();
  151. public:
  152. DfsXForest()
  153. {
  154. RtlInitUnicodeString(&_ForestRootName, NULL);
  155. }
  156. DFSSTATUS
  157. Initialize( DFSSTATUS *pXforestStatus );
  158. ULONG GetCount()
  159. {
  160. return _DomainTable.GetCount();
  161. }
  162. ULONG GetSkippedDomainCount()
  163. {
  164. return _DomainTable.GetSkippedDomainCount();
  165. }
  166. ~DfsXForest()
  167. {
  168. DfsFreeUnicodeString(&_ForestRootName);
  169. }
  170. PDFS_DOMAIN_NAME_INFO
  171. GetNextDomainInfo()
  172. {
  173. return _DomainTable.GetNextDomainInfo();
  174. }
  175. };
  176. #endif // __DFS_X_FOREST__