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.

524 lines
12 KiB

  1. /*--
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. nltest.c
  5. Abstract:
  6. Test program for the Netlogon service.
  7. Author:
  8. 21-Apr-1993 (madana)
  9. Environment:
  10. User mode only.
  11. Contains NT-specific code.
  12. Requires ANSI C extensions: slash-slash comments, long external names.
  13. Revision History:
  14. --*/
  15. //
  16. // Common include files.
  17. //
  18. #include <logonsrv.h> // Include files common to entire service
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <align.h>
  22. //
  23. // delta entry in the list
  24. //
  25. typedef struct _DELTA_ENTRY {
  26. LIST_ENTRY Next;
  27. PCHANGELOG_ENTRY ChangeLogEntry;
  28. DWORD Order;
  29. } DELTA_ENTRY, *PDELTA_ENTRY;
  30. LIST_ENTRY GlobalDeltaLists[NUM_DBS + 1];
  31. // list of deltas, include VOID DB also.
  32. //
  33. // Externals needed by chutil.obj
  34. CRITICAL_SECTION NlGlobalChangeLogCritSect;
  35. CHANGELOG_DESCRIPTOR NlGlobalChangeLogDesc;
  36. CHANGELOG_DESCRIPTOR NlGlobalTempChangeLogDesc;
  37. CHANGELOG_ROLE NlGlobalChangeLogRole;
  38. WCHAR NlGlobalChangeLogFilePrefix[MAX_PATH+1];
  39. LARGE_INTEGER NlGlobalChangeLogPromotionIncrement = DOMAIN_PROMOTION_INCREMENT;
  40. LARGE_INTEGER PromotionMask = DOMAIN_PROMOTION_MASK;
  41. LONG NlGlobalChangeLogPromotionMask;
  42. //
  43. // Stub routines needed by chutil.obj
  44. //
  45. VOID
  46. NlpWriteEventlog (
  47. IN DWORD EventID,
  48. IN DWORD EventType,
  49. IN LPBYTE RawDataBuffer OPTIONAL,
  50. IN DWORD RawDataSize,
  51. IN LPWSTR *StringArray,
  52. IN DWORD StringCount
  53. )
  54. {
  55. return;
  56. UNREFERENCED_PARAMETER( EventID );
  57. UNREFERENCED_PARAMETER( EventType );
  58. UNREFERENCED_PARAMETER( RawDataBuffer );
  59. UNREFERENCED_PARAMETER( RawDataSize );
  60. UNREFERENCED_PARAMETER( StringArray );
  61. UNREFERENCED_PARAMETER( StringCount );
  62. }
  63. VOID
  64. MakeDeltaLists(
  65. VOID
  66. )
  67. /*++
  68. Routine Description:
  69. This routine make list of deltas of individual databases.
  70. Arguments:
  71. None
  72. Return Value:
  73. none.
  74. --*/
  75. {
  76. PCHANGELOG_ENTRY ChangeLogEntry;
  77. DWORD j;
  78. DWORD Order = 1;
  79. //
  80. // initialize list enties.
  81. //
  82. for( j = 0; j < NUM_DBS + 1; j++ ) {
  83. InitializeListHead(&GlobalDeltaLists[j]);
  84. }
  85. //
  86. // The cache is valid if it is empty.
  87. //
  88. if ( ChangeLogIsEmpty( &NlGlobalChangeLogDesc) ) {
  89. return;
  90. }
  91. ChangeLogEntry = (PCHANGELOG_ENTRY)(NlGlobalChangeLogDesc.Head+1);
  92. do {
  93. PDELTA_ENTRY NewDelta;
  94. //
  95. // make delta entry to insert in the list
  96. //
  97. NewDelta = (PDELTA_ENTRY)NetpMemoryAllocate( sizeof(DELTA_ENTRY) );
  98. if ( NewDelta == NULL ) {
  99. fprintf( stderr, "Not enough memory\n" );
  100. return;
  101. }
  102. NewDelta->ChangeLogEntry = ChangeLogEntry;
  103. NewDelta->Order = Order++;
  104. //
  105. // add this entry to appropriate list.
  106. //
  107. InsertTailList( &GlobalDeltaLists[ChangeLogEntry->DBIndex],
  108. &NewDelta->Next );
  109. } while ( ( ChangeLogEntry =
  110. NlMoveToNextChangeLogEntry(&NlGlobalChangeLogDesc, ChangeLogEntry) ) != NULL );
  111. return;
  112. }
  113. #if !NETLOGONDBG
  114. // This routine is defined in chutil.obj for the debug version
  115. VOID
  116. PrintChangeLogEntry(
  117. PCHANGELOG_ENTRY ChangeLogEntry
  118. )
  119. /*++
  120. Routine Description:
  121. This routine print the content of the given changelog entry.
  122. Arguments:
  123. ChangeLogEntry -- pointer to the change log entry to print
  124. Return Value:
  125. none.
  126. --*/
  127. {
  128. LPSTR DeltaName;
  129. switch ( ChangeLogEntry->DeltaType ) {
  130. case AddOrChangeDomain:
  131. DeltaName = "AddOrChangeDomain";
  132. break;
  133. case AddOrChangeGroup:
  134. DeltaName = "AddOrChangeGroup";
  135. break;
  136. case DeleteGroupByName:
  137. case DeleteGroup:
  138. DeltaName = "DeleteGroup";
  139. break;
  140. case RenameGroup:
  141. DeltaName = "RenameGroup";
  142. break;
  143. case AddOrChangeUser:
  144. DeltaName = "AddOrChangeUser";
  145. break;
  146. case DeleteUserByName:
  147. case DeleteUser:
  148. DeltaName = "DeleteUser";
  149. break;
  150. case RenameUser:
  151. DeltaName = "RenameUser";
  152. break;
  153. case ChangeGroupMembership:
  154. DeltaName = "ChangeGroupMembership";
  155. break;
  156. case AddOrChangeAlias:
  157. DeltaName = "AddOrChangeAlias";
  158. break;
  159. case DeleteAlias:
  160. DeltaName = "DeleteAlias";
  161. break;
  162. case RenameAlias:
  163. DeltaName = "RenameAlias";
  164. break;
  165. case ChangeAliasMembership:
  166. DeltaName = "ChangeAliasMembership";
  167. break;
  168. case AddOrChangeLsaPolicy:
  169. DeltaName = "AddOrChangeLsaPolicy";
  170. break;
  171. case AddOrChangeLsaTDomain:
  172. DeltaName = "AddOrChangeLsaTDomain";
  173. break;
  174. case DeleteLsaTDomain:
  175. DeltaName = "DeleteLsaTDomain";
  176. break;
  177. case AddOrChangeLsaAccount:
  178. DeltaName = "AddOrChangeLsaAccount";
  179. break;
  180. case DeleteLsaAccount:
  181. DeltaName = "DeleteLsaAccount";
  182. break;
  183. case AddOrChangeLsaSecret:
  184. DeltaName = "AddOrChangeLsaSecret";
  185. break;
  186. case DeleteLsaSecret:
  187. DeltaName = "DeleteLsaSecret";
  188. break;
  189. case SerialNumberSkip:
  190. DeltaName = "SerialNumberSkip";
  191. break;
  192. case DummyChangeLogEntry:
  193. DeltaName = "DummyChangeLogEntry";
  194. break;
  195. default:
  196. DeltaName ="(Unknown)";
  197. break;
  198. }
  199. NlPrint((NL_CHANGELOG,
  200. "DeltaType %s (%ld) SerialNumber: %lx %lx",
  201. DeltaName,
  202. ChangeLogEntry->DeltaType,
  203. ChangeLogEntry->SerialNumber.HighPart,
  204. ChangeLogEntry->SerialNumber.LowPart ));
  205. if ( ChangeLogEntry->ObjectRid != 0 ) {
  206. NlPrint((NL_CHANGELOG," Rid: 0x%lx", ChangeLogEntry->ObjectRid ));
  207. }
  208. if ( ChangeLogEntry->Flags & CHANGELOG_REPLICATE_IMMEDIATELY ) {
  209. NlPrint((NL_CHANGELOG," Immediately" ));
  210. }
  211. if ( ChangeLogEntry->Flags & CHANGELOG_PDC_PROMOTION ) {
  212. NlPrint((NL_CHANGELOG," Promotion" ));
  213. }
  214. if ( ChangeLogEntry->Flags & CHANGELOG_PASSWORD_CHANGE ) {
  215. NlPrint((NL_CHANGELOG," PasswordChanged" ));
  216. }
  217. if( ChangeLogEntry->Flags & CHANGELOG_NAME_SPECIFIED ) {
  218. NlPrint(( NL_CHANGELOG, " Name: '" FORMAT_LPWSTR "'",
  219. (LPWSTR)((PBYTE)(ChangeLogEntry)+ sizeof(CHANGELOG_ENTRY))));
  220. }
  221. if( ChangeLogEntry->Flags & CHANGELOG_SID_SPECIFIED ) {
  222. NlPrint((NL_CHANGELOG," Sid: "));
  223. NlpDumpSid( NL_CHANGELOG,
  224. (PSID)((PBYTE)(ChangeLogEntry)+ sizeof(CHANGELOG_ENTRY)) );
  225. } else {
  226. NlPrint((NL_CHANGELOG,"\n" ));
  227. }
  228. }
  229. #endif // NETLOGONDBG
  230. VOID
  231. PrintDelta(
  232. PDELTA_ENTRY Delta
  233. )
  234. /*++
  235. Routine Description:
  236. This routine print the content of the given delta.
  237. Arguments:
  238. Delta: pointer to a delta entry to be printed.
  239. Return Value:
  240. none.
  241. --*/
  242. {
  243. printf( "Order: %ld ", Delta->Order );
  244. PrintChangeLogEntry( Delta->ChangeLogEntry );
  245. }
  246. VOID
  247. PrintDeltaLists(
  248. )
  249. /*++
  250. Routine Description:
  251. This routine prints deltas of individual databases and validates the
  252. sequence.
  253. Arguments:
  254. none.
  255. Return Value:
  256. none.
  257. --*/
  258. {
  259. DWORD j;
  260. LARGE_INTEGER RunningChangeLogSerialNumber[NUM_DBS+1];
  261. for( j = 0; j < NUM_DBS + 1; j++ ) {
  262. RunningChangeLogSerialNumber[j].QuadPart = 0;
  263. }
  264. //
  265. // for each database.
  266. //
  267. for( j = 0; j < NUM_DBS + 1; j++ ) {
  268. if( j == SAM_DB ) {
  269. printf("Deltas of SAM DATABASE \n\n" );
  270. } else if( j == BUILTIN_DB ) {
  271. printf("Deltas of BUILTIN DATABASE \n\n" );
  272. } else if( j == LSA_DB ) {
  273. printf("Deltas of LSA DATABASE \n\n" );
  274. } else if( j == VOID_DB ) {
  275. printf("VOID Deltas \n\n" );
  276. }
  277. while( !IsListEmpty( &GlobalDeltaLists[j] ) ) {
  278. PDELTA_ENTRY NextDelta;
  279. PCHANGELOG_ENTRY ChangeLogEntry;
  280. NextDelta = (PDELTA_ENTRY)
  281. RemoveHeadList( &GlobalDeltaLists[j] );
  282. ChangeLogEntry = NextDelta->ChangeLogEntry;
  283. //
  284. // validate this delta.
  285. //
  286. if ( RunningChangeLogSerialNumber[j].QuadPart == 0 ) {
  287. //
  288. // first entry for this database
  289. //
  290. // Increment to next expected serial number
  291. //
  292. RunningChangeLogSerialNumber[j].QuadPart =
  293. ChangeLogEntry->SerialNumber.QuadPart + 1;
  294. //
  295. // Otherwise ensure the serial number is the value expected.
  296. //
  297. } else {
  298. //
  299. // If the order is wrong,
  300. // just report the problem.
  301. //
  302. if ( !IsSerialNumberEqual(
  303. &NlGlobalChangeLogDesc,
  304. ChangeLogEntry,
  305. &RunningChangeLogSerialNumber[j] ) ) {
  306. if ( j != NUM_DBS ) {
  307. printf("*** THIS ENTRY IS OUT OF SEQUENCE *** \n");
  308. }
  309. }
  310. RunningChangeLogSerialNumber[j].QuadPart =
  311. ChangeLogEntry->SerialNumber.QuadPart + 1;
  312. }
  313. //
  314. // print delta
  315. //
  316. PrintDelta( NextDelta );
  317. //
  318. // free this entry.
  319. //
  320. NetpMemoryFree( NextDelta );
  321. }
  322. printf("-----------------------------------------------\n");
  323. }
  324. }
  325. VOID
  326. ListDeltas(
  327. LPWSTR DeltaFileName
  328. )
  329. /*++
  330. Routine Description:
  331. This function prints out the content of the change log file in
  332. readable format. Also it also checks the consistency of the change
  333. log. If not, it will point out the inconsistency.
  334. Arguments:
  335. DeltaFileName - name of the change log file.
  336. Return Value:
  337. none.
  338. --*/
  339. {
  340. NTSTATUS Status;
  341. // Needed by routines in chutil.obj
  342. try {
  343. InitializeCriticalSection( &NlGlobalChangeLogCritSect );
  344. } except( EXCEPTION_EXECUTE_HANDLER ) {
  345. fprintf( stderr, "Cannot initialize NlGlobalChangeLogCritSect\n" );
  346. goto Cleanup;
  347. }
  348. NlGlobalChangeLogPromotionMask = PromotionMask.HighPart;
  349. InitChangeLogDesc( &NlGlobalChangeLogDesc );
  350. //
  351. // Read in the existing changelog file.
  352. //
  353. Status = NlOpenChangeLogFile( DeltaFileName, &NlGlobalChangeLogDesc, TRUE );
  354. if ( !NT_SUCCESS(Status) ) {
  355. fprintf( stderr, "Couldn't NlOpenChangeLogFile'" FORMAT_LPWSTR
  356. "': 0x%lx \n",
  357. DeltaFileName,
  358. Status );
  359. goto Cleanup;
  360. }
  361. //
  362. // Write to this file if conversion needed.
  363. //
  364. if ( NlGlobalChangeLogDesc.Version3 ) {
  365. printf( "Converting version 3 changelog to version 4 -- writing netlv40.chg\n");
  366. wcscpy( NlGlobalChangeLogFilePrefix, L"netlv40" );
  367. }
  368. //
  369. // Convert the changelog file to the right size/version.
  370. //
  371. Status = NlResizeChangeLogFile( &NlGlobalChangeLogDesc, NlGlobalChangeLogDesc.BufferSize );
  372. if ( !NT_SUCCESS(Status) ) {
  373. fprintf( stderr, "Couldn't NlOpenChangeLogFile'" FORMAT_LPWSTR
  374. "': 0x%lx \n",
  375. DeltaFileName,
  376. Status );
  377. goto Cleanup;
  378. }
  379. //
  380. // print change log signature
  381. printf( "FILE SIGNATURE : %s \n\n", NlGlobalChangeLogDesc.Buffer );
  382. MakeDeltaLists();
  383. PrintDeltaLists();
  384. Cleanup:
  385. return;
  386. }