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.

453 lines
14 KiB

  1. //
  2. // Copyright (C) 2000, Microsoft Corporation
  3. //
  4. // File: DfsADBlobStore.hxx
  5. //
  6. // Contents: the ADBlob DFS Store class, this contains the
  7. // old AD blob store specific functionality.
  8. //
  9. // Classes: DfsADBlobStore.
  10. //
  11. // History: Dec. 8 2000, Author: udayh
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef __DFS_ADBLOB_STORE__
  15. #define __DFS_ADBLOB_STORE__
  16. #include "DfsStore.hxx"
  17. #include "dfsadblobcache.hxx"
  18. #include <shellapi.h>
  19. #include <ole2.h>
  20. #include <activeds.h>
  21. #include "netdfs.h"
  22. //+----------------------------------------------------------------------------
  23. //
  24. // Class: DfsADBlobStore
  25. //
  26. // Synopsis: This class inherits the basic DfsStore, and extends it
  27. // to include the old AD blob specific functionality.
  28. //
  29. //-----------------------------------------------------------------------------
  30. extern MARSHAL_INFO MiADBlobDfsIdProperty;
  31. #define INIT_ADBLOB_DFS_ID_PROPERTY_INFO() \
  32. static MARSHAL_TYPE_INFO _MCode_ADBlobDfsIdProperty[] = { \
  33. _MCode_guid(DFS_NAME_INFORMATION, VolumeId), \
  34. _MCode_pwstr(DFS_NAME_INFORMATION, Prefix), \
  35. _MCode_pwstr(DFS_NAME_INFORMATION, ShortPrefix), \
  36. _MCode_ul(DFS_NAME_INFORMATION, Type), \
  37. _MCode_ul(DFS_NAME_INFORMATION, State), \
  38. _MCode_pwstr(DFS_NAME_INFORMATION, Comment), \
  39. _MCode_struct(DFS_NAME_INFORMATION, PrefixTimeStamp, &MiFileTime), \
  40. _MCode_struct(DFS_NAME_INFORMATION, StateTimeStamp, &MiFileTime), \
  41. _MCode_struct(DFS_NAME_INFORMATION, CommentTimeStamp, &MiFileTime), \
  42. _MCode_ul(DFS_NAME_INFORMATION, Version), \
  43. }; \
  44. MARSHAL_INFO MiADBlobDfsIdProperty = _mkMarshalInfo(DFS_NAME_INFORMATION, _MCode_ADBlobDfsIdProperty);
  45. class DfsADBlobStore: public DfsStore {
  46. private:
  47. //
  48. // Function UnpackNameInformation: Takes the binary blob in ppBuffer
  49. // and unravels it to return the filled in DfsNameInfo.
  50. //
  51. DFSSTATUS
  52. PackGetNameInformation(
  53. IN PDFS_NAME_INFORMATION pDfsNameInfo,
  54. IN OUT PVOID *ppBuffer,
  55. IN OUT PULONG pSizeRemaining);
  56. //
  57. // Function UnpackNameInformation: Takes the binary blob in ppBuffer
  58. // and unravels it to return the filled in DfsNameInfo.
  59. //
  60. DFSSTATUS
  61. PackSetNameInformation(
  62. IN PDFS_NAME_INFORMATION pDfsNameInfo,
  63. IN OUT PVOID *ppBuffer,
  64. IN OUT PULONG pSizeRemaining);
  65. //
  66. // Function UnpackNameInformation: Takes the binary blob in ppBuffer
  67. // and unravels it to return the filled in DfsNameInfo.
  68. //
  69. ULONG
  70. PackSizeNameInformation(
  71. IN PDFS_NAME_INFORMATION pDfsNameInfo );
  72. DFSSTATUS
  73. RenameNameInfo(
  74. IN DFS_METADATA_HANDLE RootHandle,
  75. IN PUNICODE_STRING pLinkMetadataName,
  76. IN PUNICODE_STRING pNewDomainName,
  77. IN PUNICODE_STRING pOldDomainName);
  78. DFSSTATUS
  79. RenameReplicaInfo(
  80. IN DFS_METADATA_HANDLE RootHandle,
  81. IN PUNICODE_STRING pLinkMetadataName,
  82. IN PUNICODE_STRING pNewDomainName,
  83. IN PUNICODE_STRING pOldDomainName);
  84. public:
  85. DfsADBlobStore(DFSSTATUS *pStatus) :
  86. DfsStore(L"ADBlob", DFS_OBJECT_TYPE_ADBLOB_STORE, pStatus)
  87. {
  88. NOTHING;
  89. }
  90. ~DfsADBlobStore()
  91. {
  92. NOTHING;
  93. }
  94. DFSSTATUS
  95. RootEntryExists(
  96. IN PVOID DfsMetadataKey,
  97. PBOOLEAN pNewRoot )
  98. {
  99. PDFSBLOB_DATA BlobData;
  100. UNICODE_STRING BlobName;
  101. DfsADBlobCache * pBlobCache;
  102. DFSSTATUS Status;
  103. *pNewRoot = FALSE;
  104. RtlInitUnicodeString( &BlobName, NULL);
  105. pBlobCache = (DfsADBlobCache *)ExtractFromMetadataHandle( DfsMetadataKey );
  106. Status = pBlobCache->GetNamedBlob(&BlobName, &BlobData);
  107. if (Status == ERROR_SUCCESS)
  108. {
  109. pBlobCache->ReleaseBlobCacheReference(BlobData);
  110. *pNewRoot = FALSE;
  111. }
  112. else if (Status == ERROR_NOT_FOUND)
  113. {
  114. *pNewRoot = TRUE;
  115. Status = ERROR_SUCCESS;
  116. }
  117. return Status;
  118. }
  119. //
  120. // The recognizers: one to recognize and read in an
  121. // entire namespace, the other to do the same for
  122. // a specific root.
  123. //
  124. DFSSTATUS
  125. StoreRecognizer(
  126. LPWSTR Name );
  127. DFSSTATUS
  128. StoreRecognizer (
  129. LPWSTR DfsNameContext,
  130. PUNICODE_STRING pLogicalShare );
  131. //
  132. // Function CreateNewRootFolder: Creates a new root folder
  133. // for the passed in name context, and logical share.
  134. //
  135. DFSSTATUS
  136. CreateNewRootFolder (
  137. LPWSTR MachineName,
  138. LPWSTR RootRegKeyName,
  139. PUNICODE_STRING pLogicalShare,
  140. PUNICODE_STRING pPhysicalShare,
  141. DfsRootFolder **pRoot );
  142. DFSSTATUS
  143. CreateADBlobRoot(
  144. LPWSTR MachineName,
  145. LPWSTR DcName,
  146. LPWSTR PhysicalShare,
  147. LPWSTR LogicalShare,
  148. LPWSTR Comment,
  149. BOOLEAN NewRoot);
  150. DFSSTATUS
  151. DeleteADBlobRoot(
  152. LPWSTR MachineName,
  153. LPWSTR DcName,
  154. LPWSTR PhysicalShare,
  155. LPWSTR LogicalShare );
  156. DFSSTATUS
  157. DeleteADBlobRootForced(
  158. LPWSTR MachineName,
  159. LPWSTR DcName,
  160. LPWSTR PhysicalShare,
  161. LPWSTR LogicalShare );
  162. DFSSTATUS
  163. AddRootToBlob(
  164. LPWSTR MachineName,
  165. DfsRootFolder *pRootFolder,
  166. BOOLEAN NewRoot,
  167. LPWSTR LogicalShare,
  168. LPWSTR ShareName,
  169. LPWSTR Comment );
  170. DFSSTATUS
  171. RemoveRootFromBlob(
  172. DfsRootFolder *pRootFolder,
  173. LPWSTR MachineName,
  174. LPWSTR ShareName,
  175. PBOOLEAN IsLastRoot );
  176. VOID
  177. ReleaseMetadata(
  178. IN PVOID DfsMetadataHandle,
  179. IN PVOID pBuffer )
  180. {
  181. DfsADBlobCache * pBlobCache = (DfsADBlobCache *) DfsMetadataHandle;
  182. pBlobCache->ReleaseBlobCacheReference((PDFSBLOB_DATA) pBuffer);
  183. }
  184. //
  185. // Function ReleaseDataNameInformation: releases the metadata
  186. // information allocated in the prior get.
  187. //
  188. DFSSTATUS
  189. GetMetadata (
  190. IN PVOID DfsMetadataKey,
  191. IN LPWSTR RelativeName,
  192. IN LPWSTR RegistryValueNameString,
  193. OUT PVOID *ppData,
  194. OUT ULONG *pDataSize,
  195. OUT PFILETIME pLastModifiedTime);
  196. DFSSTATUS
  197. SetMetadata (
  198. IN PVOID DfsMetadataKey,
  199. IN LPWSTR RelativeName,
  200. IN LPWSTR RegistryValueNameString,
  201. IN PVOID pData,
  202. IN ULONG DataSize);
  203. DFSSTATUS
  204. RemoveMetadata (
  205. IN PVOID DfsMetadataKey,
  206. IN LPWSTR RelativeName);
  207. DFSSTATUS
  208. RemoveChild(
  209. DFS_METADATA_HANDLE DfsHandle,
  210. LPWSTR ChildName );
  211. DFSSTATUS
  212. EnumerateApiLinks(
  213. DFS_METADATA_HANDLE DfsHandle,
  214. PUNICODE_STRING pRootName,
  215. DWORD Level,
  216. LPBYTE pBuffer,
  217. LONG BufferSize,
  218. LPDWORD pEntriesToRead,
  219. LPDWORD pResumeHandle,
  220. PLONG pNextSizeRequired );
  221. DFSSTATUS
  222. GetMetadataNameBlob(
  223. DFS_METADATA_HANDLE RootHandle,
  224. LPWSTR MetadataName,
  225. PVOID *ppData,
  226. PULONG pDataSize,
  227. PFILETIME pLastModifiedTime );
  228. DFSSTATUS
  229. GetMetadataReplicaBlob(
  230. DFS_METADATA_HANDLE RootHandle,
  231. LPWSTR MetadataName,
  232. PVOID *ppData,
  233. PULONG pDataSize,
  234. PFILETIME pLastModifiedTime );
  235. DFSSTATUS
  236. SetMetadataNameBlob(
  237. DFS_METADATA_HANDLE RootHandle,
  238. LPWSTR MetadataName,
  239. PVOID pData,
  240. ULONG DataSize );
  241. DFSSTATUS
  242. SetMetadataReplicaBlob(
  243. DFS_METADATA_HANDLE RootHandle,
  244. LPWSTR MetadataName,
  245. PVOID pData,
  246. ULONG DataSize );
  247. DFSSTATUS
  248. GenerateMetadataLogicalName(
  249. IN PUNICODE_STRING pRootName,
  250. PUNICODE_STRING pInput,
  251. PUNICODE_STRING pOutput )
  252. {
  253. DFSSTATUS Status;
  254. UNICODE_STRING FirstComponent;
  255. UNICODE_STRING Remaining;
  256. //
  257. // For the ad blob store, the metadata prefix holds the
  258. // name context, the share name and the link name.
  259. // However, we will want to replace the first component
  260. // with the rootname, so that when domains are renamed,
  261. // we keep passing back correct information even though
  262. // the blob has not been updated.
  263. //
  264. Status = DfsGetFirstComponent( pInput,
  265. &FirstComponent,
  266. &Remaining );
  267. if (Status == ERROR_SUCCESS)
  268. {
  269. Status = DfsCreateUnicodePathStringFromUnicode( pOutput,
  270. 1, // 1 leading path sep
  271. pRootName,
  272. &Remaining );
  273. }
  274. return Status;
  275. }
  276. VOID
  277. ReleaseMetadataLogicalName(
  278. PUNICODE_STRING pName )
  279. {
  280. DfsFreeUnicodeString( pName );
  281. }
  282. DFSSTATUS
  283. GenerateApiLogicalPath (
  284. IN PUNICODE_STRING pRootName,
  285. IN PUNICODE_STRING pMetadataPrefix,
  286. IN PUNICODE_STRING pApiLogicalName );
  287. VOID
  288. ReleaseApiLogicalPath (
  289. PUNICODE_STRING pName )
  290. {
  291. DfsFreeUnicodeString( pName );
  292. }
  293. DFSSTATUS
  294. GenerateLinkMetadataName(
  295. UUID *pUid,
  296. PUNICODE_STRING pLinkMetadataName )
  297. {
  298. DFSSTATUS Status = ERROR_SUCCESS;
  299. LPWSTR String;
  300. Status = UuidToString( pUid,
  301. &String );
  302. if (Status == ERROR_SUCCESS)
  303. {
  304. Status = DfsCreateUnicodePathString ( pLinkMetadataName,
  305. 0, // no leading path sep
  306. ADBlobMetaDataNamePrefix,
  307. String );
  308. RpcStringFree(&String );
  309. }
  310. return Status;
  311. }
  312. VOID
  313. ReleaseLinkMetadataName(
  314. PUNICODE_STRING pLinkMetadataName )
  315. {
  316. DfsFreeUnicodeString( pLinkMetadataName );
  317. return NOTHING;
  318. }
  319. DFSSTATUS
  320. GetMetadataNameInformation(
  321. IN DFS_METADATA_HANDLE RootHandle,
  322. IN LPWSTR MetadataName,
  323. OUT PDFS_NAME_INFORMATION *ppInfo );
  324. VOID
  325. ReleaseMetadataNameInformation(
  326. IN DFS_METADATA_HANDLE RootHandle,
  327. IN PDFS_NAME_INFORMATION pNameInfo );
  328. DFSSTATUS
  329. SetMetadataNameInformation(
  330. IN DFS_METADATA_HANDLE RootHandle,
  331. IN LPWSTR MetadataName,
  332. IN PDFS_NAME_INFORMATION pNameInfo );
  333. DFSSTATUS
  334. AddChild(
  335. DFS_METADATA_HANDLE DfsHandle,
  336. IN PDFS_NAME_INFORMATION pNameInfo,
  337. IN PDFS_REPLICA_LIST_INFORMATION pReplicaListInfo,
  338. IN PUNICODE_STRING pMetadataName );
  339. DFSSTATUS
  340. AddChild(
  341. DFS_METADATA_HANDLE DfsHandle,
  342. IN PDFS_NAME_INFORMATION pNameInfo,
  343. IN PDFS_REPLICA_LIST_INFORMATION pReplicaListInfo,
  344. IN PUNICODE_STRING pMetadataName,
  345. IN LPWSTR DCName );
  346. DFSSTATUS
  347. RenameLinks(
  348. DFS_METADATA_HANDLE RootHandle,
  349. IN PUNICODE_STRING pLinkMetadataName,
  350. IN PUNICODE_STRING pOldDomainName,
  351. IN PUNICODE_STRING pNewDomainName);
  352. DFSSTATUS
  353. GetCompatRootFolder(
  354. PUNICODE_STRING pName,
  355. DfsRootFolder **pRoot );
  356. static DFSSTATUS
  357. CleanRegEntry(
  358. LPWSTR MachineName,
  359. LPWSTR LogicalShare);
  360. DFSSTATUS
  361. DoesUserHaveAccess(DfsRootFolder *pRootFolder,
  362. DWORD DesiredAccess);
  363. };
  364. #endif // __DFS_ADBLOB_STORE__