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.

215 lines
6.1 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2000, Microsoft Corporation
  4. //
  5. // File: DfsGeneric.hxx
  6. //
  7. // Contents: the base DFS class, this contains the type of DFS object
  8. // and a reference count
  9. //
  10. // Classes: DfsGeneric
  11. //
  12. // History: Dec. 8 2000, Author: udayh
  13. //
  14. //-----------------------------------------------------------------------------
  15. #ifndef __DFS_GENERIC__
  16. #define __DFS_GENERIC__
  17. //
  18. // The common includes that almost all other components need.
  19. //
  20. #include <nt.h>
  21. #include <ntrtl.h>
  22. #include <nturtl.h>
  23. #include <windows.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <stddef.h>
  27. #include "dfsheader.h"
  28. #include "dfsmisc.h"
  29. #include <netevent.h>
  30. #include "dfseventlog.hxx"
  31. #include "dfslogmacros.hxx"
  32. typedef ULONG_PTR DFS_METADATA_HANDLE, *PDFS_METADATA_HANDLE;
  33. #define CreateMetadataHandle(_x) (DFS_METADATA_HANDLE)(_x)
  34. #define ExtractFromMetadataHandle(_x) (_x)
  35. #define DestroyMetadataHandle(_x)
  36. #define CTRL_CHARS_0 TEXT( "\001\002\003\004\005\006\007")
  37. #define CTRL_CHARS_1 TEXT("\010\011\012\013\014\015\016\017")
  38. #define CTRL_CHARS_2 TEXT("\020\021\022\023\024\025\026\027")
  39. #define CTRL_CHARS_3 TEXT("\030\031\032\033\034\035\036\037")
  40. #define CTRL_CHARS_STR CTRL_CHARS_0 CTRL_CHARS_1 CTRL_CHARS_2 CTRL_CHARS_3
  41. #define ILLEGAL_NAME_CHARS_STR TEXT("\"/\\:|<>?*") CTRL_CHARS_STR
  42. //
  43. // Character subsets
  44. //
  45. //
  46. // Checks if the token contains all valid characters
  47. //
  48. #define SPACE_STR L" "
  49. #define STANDARD_ILLEGAL_CHARS ILLEGAL_NAME_CHARS_STR
  50. #define SERVER_ILLEGAL_CHARS STANDARD_ILLEGAL_CHARS SPACE_STR
  51. #define IS_VALID_TOKEN(_Str, _StrLen) \
  52. ((BOOLEAN) (wcscspn((_Str), STANDARD_ILLEGAL_CHARS) == (_StrLen)))
  53. //
  54. // Checks if the server name contains all valid characters for the server name
  55. //
  56. #define IS_VALID_SERVER_TOKEN(_Str, _StrLen) \
  57. ((BOOLEAN) (wcscspn((_Str), SERVER_ILLEGAL_CHARS) == (_StrLen)))
  58. #define PRINTF printf
  59. #if defined (DEBUG)
  60. #define DFSLOG PRINTF
  61. #else
  62. #define DFSLOG
  63. #endif
  64. #define MAX_REFERRAL_SIZE 0xe000
  65. //+----------------------------------------------------------------------------
  66. //
  67. // Class: DfsGeneric
  68. //
  69. // Synopsis: This abstract class implements a reference counting
  70. // mechanism, that lets this instance be freed up when
  71. // all references to the object have been released.
  72. // This class also contains the type of dfs object.
  73. //
  74. //-----------------------------------------------------------------------------
  75. //
  76. // To recognize a DFS memory blob, the first few words of the allocated
  77. // memory contain the object type. We store a long word that contains
  78. // 4 characters (similar to the pool tags), so that we can determine
  79. // the Dfs object type.
  80. // DSRe is DfsStoreRegistry
  81. // DSAD is DfsStoreActiveDirectory
  82. // DSEn is DfsStoreEnterprise
  83. // DFRD is DfsFolderReferralData
  84. // DFol is DfsFolder
  85. // DRep is DfsReplica
  86. // DRRF is DfsRegistryRootFolder
  87. // DARF is DfsAdlegacyRootFolder
  88. // DERF is DfsEnterpriseRootFolder
  89. //
  90. enum DfsObjectTypeEnumeration
  91. {
  92. DFS_OBJECT_TYPE_REGISTRY_STORE = 'eRSD',
  93. DFS_OBJECT_TYPE_ADBLOB_STORE = 'DASD',
  94. DFS_OBJECT_TYPE_ENTERPRISE_STORE = 'nESD',
  95. DFS_OBJECT_TYPE_REFERRAL_DATA = 'aDRD',
  96. DFS_OBJECT_TYPE_FOLDER_REFERRAL_DATA = 'DRFD',
  97. DFS_OBJECT_TYPE_FOLDER = 'loFD',
  98. DFS_OBJECT_TYPE_REPLICA = 'peRD',
  99. DFS_OBJECT_TYPE_REGISTRY_ROOT_FOLDER = 'FRRD',
  100. DFS_OBJECT_TYPE_ADBLOB_ROOT_FOLDER = 'FRAD',
  101. DFS_OBJECT_TYPE_ENTERPRISE_ROOT_FOLDER = 'FRED',
  102. DFS_OBJECT_TYPE_SERVER_SITE_INFO = 'ISSD',
  103. DFS_OBJECT_TYPE_SITE_SUPPORT = 'uSSD',
  104. DFS_OBJECT_TYPE_STATISTICS = 'atSD',
  105. DFS_OBJECT_TYPE_ADBLOB_CACHE = 'acSD',
  106. DFS_OBJECT_TYPE_TRUSTED_DOMAIN = 'oDTD',
  107. DFS_OBJECT_TYPE_DOMAIN_INFO = 'nIDD',
  108. DFS_OBJECT_TYPE_SITE = 'tiSD',
  109. DFS_OBJECT_TYPE_SITECOST_CACHE = 'cCSD',
  110. DFS_OBJECT_TYPE_ISTG_HANDLE = 'hTSI',
  111. };
  112. class DfsGeneric
  113. {
  114. private:
  115. LONG _ReferenceCount; // this is the reference count.
  116. DfsObjectTypeEnumeration _ObjectType; // the object type.
  117. public:
  118. //
  119. // All objects are created with a reference count of 1.
  120. //
  121. DfsGeneric(DfsObjectTypeEnumeration DfsObjectType)
  122. {
  123. _ReferenceCount = 1;
  124. _ObjectType = DfsObjectType;
  125. }
  126. //
  127. // If the destructor is being called, the reference count
  128. // better be 0.
  129. //
  130. virtual ~DfsGeneric()
  131. {
  132. //
  133. // If we are in the destructor without having a reference
  134. // count of 0, something is wrong.
  135. // The only exceptions are those classes that do not use
  136. // the reference counting mechanisms. Currently the replica
  137. // class.
  138. //
  139. ASSERT( (_ReferenceCount == 0) ||
  140. (_ObjectType == DFS_OBJECT_TYPE_REPLICA) );
  141. }
  142. //
  143. // Function: AcquireReference. Increments the reference count
  144. // and returns the old value of the count.
  145. // Make sure we use interlocked. We will be dealing with
  146. // multiple threads.
  147. //
  148. LONG
  149. AcquireReference()
  150. {
  151. return InterlockedIncrement( &_ReferenceCount );
  152. }
  153. //
  154. // Function: ReleaseReference. Decrement the count: if we hit 0,
  155. // we are done. Delete this object since no one should be
  156. // refering to it.
  157. // No one should be having a pointer to this object,
  158. // and there should be no means by which the refcount can
  159. // go from 0 to 1. This should be enforced by the class
  160. // implementation that is derived from this base class.
  161. LONG
  162. ReleaseReference()
  163. {
  164. LONG Count;
  165. Count = InterlockedDecrement( &_ReferenceCount );
  166. ASSERT(Count >= 0);
  167. if ( Count == 0 )
  168. {
  169. DFSLOG("Deleting object %p, Type %d\n", this, _ObjectType);
  170. delete this;
  171. }
  172. return Count;
  173. }
  174. };
  175. #endif // __DFS_GENERIC__