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.

232 lines
6.2 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2001, Microsoft Corporation
  4. //
  5. // File: DfsServerSiteInfo.hxx
  6. //
  7. // Contents: the Dfs Site Information class.
  8. //
  9. // Classes: DfsServerSiteInfo
  10. //
  11. // History: Jan. 8 2001, Author: udayh
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef __DFS_SITE_SUPPORT__
  15. #define __DFS_SITE_SUPPORT__
  16. #include "DfsGeneric.hxx"
  17. #include "DfsServerSiteInfo.hxx"
  18. #include "dfsnametable.h"
  19. class DfsServerSiteInfo;
  20. class DfsSiteSupport: public DfsGeneric
  21. {
  22. private:
  23. struct _DFS_NAME_TABLE *_pServerTable;
  24. public:
  25. ~DfsSiteSupport(void)
  26. {
  27. }
  28. DFSSTATUS
  29. DfsInitializeSiteSupport(void)
  30. {
  31. NTSTATUS NtStatus = STATUS_SUCCESS;
  32. DFSSTATUS Status = ERROR_SUCCESS;
  33. NtStatus = DfsInitializeNameTable ( 0,
  34. &_pServerTable );
  35. Status = RtlNtStatusToDosError(NtStatus);
  36. return Status;
  37. }
  38. static DfsSiteSupport *
  39. DfsCreateSiteSupport(DFSSTATUS * pStatus)
  40. {
  41. DFSSTATUS Status = ERROR_SUCCESS;
  42. DfsSiteSupport * pNewSiteTable = NULL;
  43. pNewSiteTable = new DfsSiteSupport();
  44. if(pNewSiteTable == NULL)
  45. {
  46. Status = ERROR_NOT_ENOUGH_MEMORY;
  47. }
  48. else
  49. {
  50. Status = pNewSiteTable->DfsInitializeSiteSupport();
  51. if(Status != ERROR_SUCCESS)
  52. {
  53. pNewSiteTable->ReleaseReference();
  54. pNewSiteTable = NULL;
  55. }
  56. }
  57. *pStatus = Status;
  58. return pNewSiteTable;
  59. }
  60. DFSSTATUS
  61. LookupServerSiteInfo(
  62. PUNICODE_STRING pServerName,
  63. DfsServerSiteInfo **ppServerInfo)
  64. {
  65. DFSSTATUS Status = ERROR_SUCCESS;
  66. NTSTATUS NtStatus = STATUS_SUCCESS;
  67. PVOID pData = NULL;
  68. NtStatus = DfsNameTableAcquireReadLock( _pServerTable );
  69. if ( NtStatus == STATUS_SUCCESS )
  70. {
  71. NtStatus = DfsLookupNameTableLocked( _pServerTable,
  72. pServerName,
  73. &pData );
  74. if (NtStatus == STATUS_SUCCESS)
  75. {
  76. Status = ERROR_SUCCESS;
  77. *ppServerInfo = (DfsServerSiteInfo *)pData;
  78. (*ppServerInfo)->AcquireReference();
  79. }
  80. DfsNameTableReleaseLock( _pServerTable );
  81. }
  82. if ( NtStatus != STATUS_SUCCESS )
  83. {
  84. Status = ERROR_NOT_FOUND;
  85. }
  86. return Status;
  87. }
  88. DFSSTATUS
  89. AddServerSiteInfo(
  90. PUNICODE_STRING pServerName,
  91. DfsServerSiteInfo **ppServerInfo)
  92. {
  93. DFSSTATUS Status = ERROR_SUCCESS;
  94. NTSTATUS NtStatus = STATUS_SUCCESS;
  95. DfsServerSiteInfo *pNewServer = NULL;
  96. //
  97. // Create and initialize a ServerSiteInfo instance to insert.
  98. //
  99. pNewServer = DfsServerSiteInfo::DfsCreateServerSiteInfo(&Status,
  100. pServerName );
  101. if (Status == ERROR_SUCCESS)
  102. {
  103. *ppServerInfo = pNewServer;
  104. NtStatus = DfsNameTableAcquireWriteLock( _pServerTable );
  105. if ( NtStatus == STATUS_SUCCESS )
  106. {
  107. NtStatus = DfsReplaceInNameTableLocked( _pServerTable,
  108. pNewServer->GetServerName(),
  109. (PVOID *)(&pNewServer));
  110. if (NtStatus == STATUS_SUCCESS)
  111. {
  112. (*ppServerInfo)->AcquireReference();
  113. //if we get something back, then release the reference
  114. if(pNewServer)
  115. {
  116. pNewServer->ReleaseReference();
  117. pNewServer = NULL;
  118. }
  119. }
  120. else
  121. {
  122. pNewServer->ReleaseReference();
  123. *ppServerInfo = NULL;
  124. }
  125. DfsNameTableReleaseLock( _pServerTable );
  126. }
  127. else
  128. {
  129. pNewServer->ReleaseReference();
  130. *ppServerInfo = NULL;
  131. }
  132. }
  133. return Status;
  134. }
  135. DFSSTATUS
  136. GetServerSiteInfo(
  137. IN PUNICODE_STRING pServerName,
  138. OUT DfsServerSiteInfo **ppServerInfo,
  139. OUT BOOLEAN * CacheHit,
  140. IN BOOLEAN SyncThread )
  141. {
  142. DFSSTATUS Status = ERROR_SUCCESS;
  143. //
  144. // See if we have this ServerName-to-Site
  145. // mapping cached already.
  146. //
  147. Status = LookupServerSiteInfo( pServerName,
  148. ppServerInfo );
  149. if (Status == ERROR_SUCCESS)
  150. {
  151. *CacheHit = TRUE;
  152. //
  153. // If it is time to refresh this entry,
  154. // get rid of it and add a new one.
  155. //
  156. Status = (*ppServerInfo)->Refresh();
  157. if(SyncThread && (Status == ERROR_SUCCESS))
  158. {
  159. (*ppServerInfo)->ReleaseReference();
  160. Status = AddServerSiteInfo( pServerName,
  161. ppServerInfo );
  162. }
  163. else
  164. {
  165. //
  166. // We are done. We found what we want in the cache.
  167. //
  168. Status = ERROR_SUCCESS;
  169. }
  170. } else {
  171. //
  172. // Create a new entry and put in the cache.
  173. //
  174. Status = AddServerSiteInfo( pServerName,
  175. ppServerInfo );
  176. *CacheHit = FALSE;
  177. }
  178. return Status;
  179. }
  180. DFSSTATUS
  181. ReleaseServerSiteInfo(
  182. DfsServerSiteInfo *pServerInfo )
  183. {
  184. pServerInfo->ReleaseReference();
  185. return STATUS_SUCCESS;
  186. }
  187. private:
  188. DfsSiteSupport() : DfsGeneric(DFS_OBJECT_TYPE_SITE_SUPPORT)
  189. {
  190. _pServerTable = NULL;
  191. }
  192. };
  193. #endif __DFS_SITE_SUPPORT__