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.

358 lines
9.5 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2000, Microsoft Corporation
  4. //
  5. // File: DfsRegistryRootFolder.hxx
  6. //
  7. // Contents: the Root DFS Folder class for Registry Store
  8. //
  9. // Classes: DfsRegistryRootFolder
  10. //
  11. // History: Dec. 8 2000, Author: udayh
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef __DFS_REGISTRY_ROOT_FOLDER__
  15. #define __DFS_REGISTRY_ROOT_FOLDER__
  16. #include "DfsRootFolder.hxx"
  17. #include "DfsRegistryStore.hxx"
  18. //+----------------------------------------------------------------------------
  19. //
  20. // Class: DfsRegistryRootFolder
  21. //
  22. // Synopsis: This class implements The Dfs Registry root folder.
  23. //
  24. //-----------------------------------------------------------------------------
  25. class DfsRegistryRootFolder: public DfsRootFolder
  26. {
  27. private:
  28. DfsRegistryStore *_pStore; // Pointer to registered store
  29. // that owns this root.
  30. protected:
  31. DfsStore *
  32. GetMetadataStore()
  33. {
  34. return _pStore;
  35. }
  36. //
  37. // Function GetMetadataKey: Gets the registry metadata key for
  38. // this root folder.
  39. //
  40. DFSSTATUS
  41. GetMetadataHandle( PDFS_METADATA_HANDLE pRootHandle )
  42. {
  43. HKEY RootKey;
  44. DFSSTATUS Status;
  45. Status = GetMetadataKey( &RootKey );
  46. if (Status == ERROR_SUCCESS)
  47. {
  48. *pRootHandle = CreateMetadataHandle(RootKey);
  49. }
  50. return Status;
  51. }
  52. VOID
  53. ReleaseMetadataHandle( DFS_METADATA_HANDLE RootHandle )
  54. {
  55. HKEY RootKey;
  56. RootKey = (HKEY)ExtractFromMetadataHandle(RootHandle);
  57. ReleaseMetadataKey(RootKey);
  58. DestroyMetadataHandle(RootHandle);
  59. return;
  60. }
  61. private:
  62. DFSSTATUS
  63. GetMetadataKey( PHKEY pOpenedKey )
  64. {
  65. return _pStore->GetRootKey( GetNameContextString(),
  66. GetRootRegKeyNameString(),
  67. NULL,
  68. pOpenedKey );
  69. }
  70. //
  71. // Function ReleaseMetadataKey: Clsoes the registry metadata key for
  72. // this root folder.
  73. //
  74. VOID
  75. ReleaseMetadataKey( HKEY OpenedKey )
  76. {
  77. RegCloseKey( OpenedKey );
  78. }
  79. public:
  80. //
  81. // Function DfsRegistryRootFolder: Constructor.
  82. // Initializes the RegistryRootFolder class instance.
  83. //
  84. DfsRegistryRootFolder(
  85. LPWSTR NameContext,
  86. LPWSTR RootRegistryName,
  87. PUNICODE_STRING pLogicalName,
  88. PUNICODE_STRING pPhysicalShare,
  89. DfsRegistryStore *pParentStore,
  90. DFSSTATUS *pStatus );
  91. ~DfsRegistryRootFolder()
  92. {
  93. DfsFreeUnicodeString(&_DfsVisibleContext);
  94. if (_pStore != NULL)
  95. {
  96. _pStore->ReleaseReference();
  97. _pStore = NULL;
  98. }
  99. }
  100. //
  101. // Function Synchronize: This function overrides the synchronize
  102. // defined in the base class.
  103. // The synchronize function updates the root folder's children
  104. // with the uptodate information available in the store's metadata.
  105. //
  106. DFSSTATUS
  107. Synchronize(BOOLEAN fForceSynch = FALSE, BOOLEAN CalledByApi = FALSE);
  108. DFSSTATUS
  109. GetMetadataLogicalToLinkName( PUNICODE_STRING pIn,
  110. PUNICODE_STRING pOut )
  111. {
  112. UNICODE_STRING FirstComp;
  113. return DfsGetFirstComponent( pIn,
  114. &FirstComp,
  115. pOut );
  116. }
  117. VOID
  118. ReleaseMetadataLogicalToLinkName( PUNICODE_STRING pIn )
  119. {
  120. UNREFERENCED_PARAMETER(pIn);
  121. return NOTHING;
  122. }
  123. //
  124. // The default behavior for ADBLOB roots is Force == FALSE. The reason
  125. // for that is because ADBLOBs have a GUID that it can do a first level
  126. // check on.
  127. // There is no such thing for the registry roots. We ignore the force flag
  128. // altogether.
  129. //
  130. DFSSTATUS
  131. ReSynchronize(BOOLEAN fForceSync)
  132. {
  133. DFSSTATUS Status = ERROR_SUCCESS;
  134. Status = Synchronize(fForceSync);
  135. return Status;
  136. }
  137. //
  138. // CheckPreSyncrhonize:
  139. // The registry store has an issue. If someone updates the registry
  140. // without going through the standard API, the service does not
  141. // know about deletions and only picks up new entries or modifications.
  142. // This can cause severe leaks if someone does put in a replication
  143. // for registries, causing all roots on the server to slow down.
  144. //
  145. // For longhorn, we should move the name_table usage to sash and use
  146. // the sash enumeration to enumerate and mark entries as stale etc.
  147. // This needs other fixes as well: in the meanwhile, we have a
  148. // fixed mechanism of checking before synchronize if each
  149. // folder we have actually exists in the registry.
  150. //
  151. //
  152. //
  153. VOID
  154. CheckPreSynchronize( HKEY RootKey)
  155. {
  156. struct _DFS_LINK_LIST {
  157. DfsFolder *pFolder;
  158. struct _DFS_LINK_LIST *pNext;
  159. };
  160. struct _DFS_LINK_LIST *pNewEntry = NULL, *pOldEntry = NULL;
  161. struct _DFS_LINK_LIST *pListEntry = NULL, *pUseEntry = NULL;
  162. PVOID pHandle = NULL;
  163. DfsFolder *pFolder;
  164. NTSTATUS NtStatus;
  165. DFSSTATUS Status;
  166. ULONG NumChild;
  167. Status = RegQueryInfoKey( RootKey, // Key
  168. NULL, // Class string
  169. NULL, // Size of class string
  170. NULL, // Reserved
  171. &NumChild, // # of subkeys
  172. NULL, // max size of subkey name
  173. NULL, // max size of class name
  174. NULL, // # of values
  175. NULL, // max size of value name
  176. NULL, // max size of value data,
  177. NULL, // security descriptor
  178. NULL ); // Last write time
  179. if ( (Status != ERROR_SUCCESS) ||
  180. (NumChild == GetChildCount()) )
  181. {
  182. return NOTHING;
  183. }
  184. NtStatus = DfsNameTableAcquireReadLock( _pMetadataNameTable );
  185. while (NtStatus == STATUS_SUCCESS)
  186. {
  187. NtStatus = DfsEnumerateNameTableLocked( _pMetadataNameTable,
  188. &pHandle,
  189. (PVOID *)&pFolder );
  190. if (NtStatus == STATUS_SUCCESS)
  191. {
  192. HKEY NewKey;
  193. Status = RegOpenKeyEx( RootKey,
  194. pFolder->GetFolderMetadataNameString(),
  195. 0,
  196. KEY_READ,
  197. &NewKey );
  198. if (Status == ERROR_SUCCESS)
  199. {
  200. RegCloseKey( NewKey );
  201. }
  202. if (Status == ERROR_FILE_NOT_FOUND)
  203. {
  204. pNewEntry = new struct _DFS_LINK_LIST;
  205. if (pNewEntry != NULL)
  206. {
  207. if (pOldEntry)
  208. {
  209. pOldEntry->pNext = pNewEntry;
  210. }
  211. else
  212. {
  213. pListEntry = pNewEntry;
  214. }
  215. pNewEntry->pFolder = pFolder;
  216. pNewEntry->pFolder->AcquireReference();
  217. pNewEntry->pNext = NULL;
  218. pOldEntry = pNewEntry;
  219. }
  220. }
  221. }
  222. }
  223. DfsNameTableReleaseLock( _pMetadataNameTable );
  224. while (pListEntry != NULL)
  225. {
  226. pUseEntry = pListEntry;
  227. pListEntry = pUseEntry->pNext;
  228. RemoveLinkFolder( pUseEntry->pFolder, TRUE);
  229. pUseEntry->pFolder->ReleaseReference();
  230. delete pUseEntry;
  231. }
  232. return NOTHING;
  233. }
  234. DFSSTATUS
  235. RootApiRequestPrologue( BOOLEAN WriteRequest,
  236. LPWSTR Name = NULL )
  237. {
  238. DFSSTATUS Status;
  239. UNREFERENCED_PARAMETER(Name);
  240. Status = CommonRootApiPrologue( WriteRequest );
  241. return Status;
  242. }
  243. VOID
  244. RootApiRequestEpilogue(
  245. BOOLEAN WriteRequest,
  246. DFSSTATUS CompletionStatus )
  247. {
  248. UNREFERENCED_PARAMETER(CompletionStatus);
  249. UNREFERENCED_PARAMETER(WriteRequest);
  250. return NOTHING;
  251. }
  252. DFSSTATUS
  253. RootRequestPrologue( LPWSTR Name )
  254. {
  255. UNREFERENCED_PARAMETER(Name);
  256. return ERROR_NOT_SUPPORTED;
  257. }
  258. VOID
  259. RootRequestEpilogue ()
  260. {
  261. }
  262. DFSSTATUS
  263. Flush()
  264. {
  265. return ERROR_SUCCESS;
  266. }
  267. DFSSTATUS
  268. RenameLinks( IN LPWSTR OldDomainName,
  269. IN LPWSTR NewDomainName)
  270. {
  271. UNREFERENCED_PARAMETER(OldDomainName);
  272. UNREFERENCED_PARAMETER(NewDomainName);
  273. return ERROR_NOT_SUPPORTED;
  274. }
  275. DFSSTATUS
  276. CheckResynchronizeAccess( DFSSTATUS AccessCheckStatus)
  277. {
  278. return AccessCheckStatus;
  279. }
  280. };
  281. #endif // __DFS_REGISTRY_ROOT_FOLDER__