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.

367 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1991-1997 Microsoft Corporation
  3. Module Name:
  4. chutil.h
  5. Abstract:
  6. Definitions of the internals of the changelog.
  7. Currently only included sparingly.
  8. Author:
  9. Cliff Van Dyke (cliffv) 07-May-1992
  10. Environment:
  11. User mode only.
  12. Contains NT-specific code.
  13. Requires ANSI C extensions: slash-slash comments, long external names.
  14. Revision History:
  15. 02-Jan-1992 (madana)
  16. added support for builtin/multidomain replication.
  17. --*/
  18. #if ( _MSC_VER >= 800 )
  19. #pragma warning ( 3 : 4100 ) // enable "Unreferenced formal parameter"
  20. #pragma warning ( 3 : 4219 ) // enable "trailing ',' used for variable argument list"
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. //
  24. // Structures and variables describing the Change Log.
  25. //
  26. /////////////////////////////////////////////////////////////////////////////
  27. //
  28. // All of the following data is private to changelg.c and nltest1.c
  29. //
  30. //
  31. // change log file name
  32. //
  33. #define CHANGELOG_FILE_PREFIX L"\\NETLOGON"
  34. #define CHANGELOG_FILE_POSTFIX_LENGTH 4 // Length of all the following postfixes
  35. #define CHANGELOG_FILE_POSTFIX L".CHG"
  36. #define TEMP_CHANGELOG_FILE_POSTFIX L".CHT"
  37. #define BACKUP_CHANGELOG_FILE_POSTFIX L".BKP"
  38. #define REDO_FILE_POSTFIX L".RDO"
  39. //
  40. // Signature at front of changelog file
  41. //
  42. #define CHANGELOG_SIG_V3 "NT CHANGELOG 3"
  43. #define CHANGELOG_SIG "NT CHANGELOG 4"
  44. //
  45. // Change log block state
  46. //
  47. typedef enum _CHANGELOG_BLOCK_STATE {
  48. BlockFree = 1,
  49. BlockUsed,
  50. BlockHole
  51. } CHANGELOG_BLOCK_STATE, *PCHANGELOG_BLOCK_STATE;
  52. //
  53. // change log memory block header
  54. //
  55. typedef struct _CHANGELOG_BLOCK_HEADER {
  56. DWORD BlockSize;
  57. CHANGELOG_BLOCK_STATE BlockState;
  58. } CHANGELOG_BLOCK_HEADER, *PCHANGELOG_BLOCK_HEADER;
  59. typedef struct _CHANGELOG_BLOCK_TRAILER {
  60. DWORD BlockSize;
  61. } CHANGELOG_BLOCK_TRAILER, *PCHANGELOG_BLOCK_TRAILER;
  62. //
  63. // Macro to find a trailer (given a header)
  64. //
  65. #define ChangeLogBlockTrailer( _Header ) ( (PCHANGELOG_BLOCK_TRAILER)(\
  66. ((LPBYTE)(_Header)) + \
  67. (_Header)->BlockSize - \
  68. sizeof(CHANGELOG_BLOCK_TRAILER) ))
  69. //
  70. // Macro to find if the change log describe be a particular
  71. // changelog descriptor is empty.
  72. //
  73. //
  74. #define ChangeLogIsEmpty( _Desc ) \
  75. ( \
  76. (_Desc)->FirstBlock == NULL || \
  77. ((_Desc)->FirstBlock->BlockState == BlockFree && \
  78. (_Desc)->FirstBlock->BlockSize >= \
  79. (DWORD)((_Desc)->BufferEnd - (LPBYTE)(_Desc)->FirstBlock) ) \
  80. )
  81. //
  82. // Macro to initialize a changelog desriptor.
  83. //
  84. #define InitChangeLogDesc( _Desc ) \
  85. RtlZeroMemory( (_Desc), sizeof( *(_Desc) ) ); \
  86. (_Desc)->FileHandle = INVALID_HANDLE_VALUE;
  87. //
  88. // Macro to determine if the serial number on the change log entry matches
  89. // the serial number specified.
  90. //
  91. // The serial numbers match if there is an exact match or
  92. // if the changelog entry contains the serial number at the instant of promotion and the
  93. // requested serial number is the corresponding pre-promotion value.
  94. //
  95. #define IsSerialNumberEqual( _ChangeLogDesc, _ChangeLogEntry, _SerialNumber ) \
  96. ( \
  97. (_ChangeLogEntry)->SerialNumber.QuadPart == (_SerialNumber)->QuadPart || \
  98. (((_ChangeLogEntry)->Flags & CHANGELOG_PDC_PROMOTION) && \
  99. (_ChangeLogEntry)->SerialNumber.QuadPart == \
  100. (_SerialNumber)->QuadPart + NlGlobalChangeLogPromotionIncrement.QuadPart ) \
  101. )
  102. //
  103. // variables describing the change log
  104. //
  105. typedef struct _CHANGELOG_DESCRIPTOR {
  106. //
  107. // Start and end of the allocated block.
  108. //
  109. LPBYTE Buffer; // Cache of the changelog contents
  110. ULONG BufferSize; // Size (in bytes) of the buffer
  111. LPBYTE BufferEnd; // Address of first byte beyond the end of the buffer
  112. //
  113. // Offset of the first and last dirty bytes
  114. //
  115. ULONG FirstDirtyByte;
  116. ULONG LastDirtyByte;
  117. //
  118. // Address of the first physical block in the change log
  119. //
  120. PCHANGELOG_BLOCK_HEADER FirstBlock; // where delta buffer starts
  121. //
  122. // Description of the circular list of change log entries.
  123. //
  124. PCHANGELOG_BLOCK_HEADER Head; // start reading logs from here
  125. PCHANGELOG_BLOCK_HEADER Tail; // where next log is written
  126. //
  127. // Serial Number of each database.
  128. //
  129. // Access is serialized via NlGlobalChangeLogCritSect
  130. //
  131. LARGE_INTEGER SerialNumber[NUM_DBS];
  132. //
  133. // Number of change log entries in the log for the specified database
  134. //
  135. DWORD EntryCount[NUM_DBS];
  136. //
  137. // Handle to file acting as backing store for the buffer.
  138. //
  139. HANDLE FileHandle; // handle for change log file
  140. //
  141. // Version 3: True to indicate this is a version 3 buffer.
  142. //
  143. BOOLEAN Version3;
  144. //
  145. // True if this is a temporary change log
  146. //
  147. BOOLEAN TempLog;
  148. } CHANGELOG_DESCRIPTOR, *PCHANGELOG_DESCRIPTOR;
  149. #define IsObjectNotFoundStatus( _DeltaType, _NtStatus ) \
  150. (((ULONG)(_DeltaType) > MAX_OBJECT_NOT_FOUND_STATUS ) ? \
  151. FALSE : \
  152. (NlGlobalObjectNotFoundStatus[ (_DeltaType) ] == (_NtStatus)) )
  153. //
  154. // Tables of related delta types
  155. //
  156. //
  157. // Table of delete delta types.
  158. // Index into the table with a delta type,
  159. // the entry is the delta type that is used to delete the object.
  160. //
  161. // There are some objects that can't be deleted. In that case, this table
  162. // contains a delta type that uniquely identifies the object. That allows
  163. // this table to be used to see if two deltas describe the same object type.
  164. //
  165. #define MAX_DELETE_DELTA DummyChangeLogEntry
  166. extern const NETLOGON_DELTA_TYPE NlGlobalDeleteDeltaType[MAX_DELETE_DELTA+1];
  167. //
  168. // Table of add delta types.
  169. // Index into the table with a delta type,
  170. // the entry is the delta type that is used to add the object.
  171. //
  172. // There are some objects that can't be added. In that case, this table
  173. // contains a delta type that uniquely identifies the object. That allows
  174. // this table to be used to see if two deltas describe the same object type.
  175. //
  176. // In the table, Groups and Aliases are represented as renames. This causes
  177. // NlPackSingleDelta to return both the group attributes and the group
  178. // membership.
  179. //
  180. #define MAX_ADD_DELTA DummyChangeLogEntry
  181. extern const NETLOGON_DELTA_TYPE NlGlobalAddDeltaType[MAX_ADD_DELTA+1];
  182. //
  183. // Table of Status Codes indicating the object doesn't exist.
  184. // Index into the table with a delta type.
  185. //
  186. // Map to STATUS_SUCCESS for the invalid cases to explicitly avoid other error
  187. // codes.
  188. #define MAX_OBJECT_NOT_FOUND_STATUS DummyChangeLogEntry
  189. extern const NTSTATUS NlGlobalObjectNotFoundStatus[MAX_OBJECT_NOT_FOUND_STATUS+1];
  190. //
  191. // chutil.c
  192. //
  193. NTSTATUS
  194. NlCreateChangeLogFile(
  195. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc
  196. );
  197. NTSTATUS
  198. NlFlushChangeLog(
  199. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc
  200. );
  201. PCHANGELOG_ENTRY
  202. NlMoveToNextChangeLogEntry(
  203. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  204. IN PCHANGELOG_ENTRY ChangeLogEntry
  205. );
  206. VOID
  207. PrintChangeLogEntry(
  208. IN PCHANGELOG_ENTRY ChangeLogEntry
  209. );
  210. NTSTATUS
  211. NlResetChangeLog(
  212. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  213. IN DWORD NewChangeLogSize
  214. );
  215. NTSTATUS
  216. NlOpenChangeLogFile(
  217. IN LPWSTR ChangeLogFileName,
  218. OUT PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  219. IN BOOLEAN ReadOnly
  220. );
  221. VOID
  222. NlCloseChangeLogFile(
  223. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc
  224. );
  225. NTSTATUS
  226. NlResizeChangeLogFile(
  227. IN OUT PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  228. IN DWORD NewChangeLogSize
  229. );
  230. NTSTATUS
  231. NlWriteChangeLogEntry(
  232. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  233. IN PCHANGELOG_ENTRY ChangeLogEntry,
  234. IN PSID ObjectSid,
  235. IN PUNICODE_STRING ObjectName,
  236. IN BOOLEAN FlushIt
  237. );
  238. PCHANGELOG_ENTRY
  239. NlFindPromotionChangeLogEntry(
  240. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  241. IN LARGE_INTEGER SerialNumber,
  242. IN DWORD DBIndex
  243. );
  244. PCHANGELOG_ENTRY
  245. NlGetNextChangeLogEntry(
  246. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  247. IN LARGE_INTEGER SerialNumber,
  248. IN DWORD DBIndex,
  249. OUT LPDWORD ChangeLogEntrySize OPTIONAL
  250. );
  251. PCHANGELOG_ENTRY
  252. NlGetNextUniqueChangeLogEntry(
  253. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  254. IN LARGE_INTEGER SerialNumber,
  255. IN DWORD DBIndex,
  256. OUT LPDWORD ChangeLogEntrySize OPTIONAL
  257. );
  258. BOOL
  259. NlRecoverChangeLog(
  260. PCHANGELOG_ENTRY ChangeLogEntry
  261. );
  262. VOID
  263. NlDeleteChangeLogEntry(
  264. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  265. IN DWORD DBIndex,
  266. IN LARGE_INTEGER SerialNumber
  267. );
  268. BOOLEAN
  269. NlFixChangeLog(
  270. IN PCHANGELOG_DESCRIPTOR ChangeLogDesc,
  271. IN DWORD DBIndex,
  272. IN LARGE_INTEGER SerialNumber
  273. );
  274. BOOL
  275. NlValidateChangeLogEntry(
  276. IN PCHANGELOG_ENTRY ChangeLogEntry,
  277. IN DWORD ChangeLogEntrySize
  278. );
  279. #undef EXTERN