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.

188 lines
4.9 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (c) 2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. * chglog.cpp
  7. *
  8. * Abstract:
  9. * Tool for enumerating the change log - forward/reverse
  10. *
  11. * Revision History:
  12. * Brijesh Krishnaswami (brijeshk) 04/09/2000
  13. * created
  14. *
  15. *****************************************************************************/
  16. #include <nt.h>
  17. #include <ntrtl.h>
  18. #include <nturtl.h>
  19. #include <windows.h>
  20. #include <stdio.h>
  21. #include "srapi.h"
  22. #include <shellapi.h>
  23. #include "enumlogs.h"
  24. #include "srrpcapi.h"
  25. #include <dbgtrace.h>
  26. struct _EVENT_STR_MAP
  27. {
  28. DWORD EventId;
  29. LPWSTR pEventStr;
  30. } EventMap[ 13 ] =
  31. {
  32. {SrEventInvalid , L"INVALID " },
  33. {SrEventStreamChange, L"FILE-MODIFY" },
  34. {SrEventAclChange, L"ACL-CHANGE " },
  35. {SrEventAttribChange, L"ATTR-CHANGE" },
  36. {SrEventStreamOverwrite,L"FILE-MODIFY" },
  37. {SrEventFileDelete, L"FILE-DELETE" },
  38. {SrEventFileCreate, L"FILE-CREATE" },
  39. {SrEventFileRename, L"FILE-RENAME" },
  40. {SrEventDirectoryCreate,L"DIR-CREATE " },
  41. {SrEventDirectoryRename,L"DIR-RENAME " },
  42. {SrEventDirectoryDelete,L"DIR-DELETE " },
  43. {SrEventMountCreate, L"MNT-CREATE " },
  44. {SrEventMountDelete, L"MNT-DELETE " }
  45. };
  46. LPWSTR
  47. GetEventString(
  48. DWORD EventId
  49. )
  50. {
  51. LPWSTR pStr = NULL;
  52. static WCHAR EventStringBuffer[8];
  53. for( int i=0; i<sizeof(EventMap)/sizeof(_EVENT_STR_MAP);i++)
  54. {
  55. if ( EventMap[i].EventId == EventId )
  56. {
  57. pStr = EventMap[i].pEventStr;
  58. }
  59. }
  60. if (pStr == NULL)
  61. {
  62. pStr = &EventStringBuffer[0];
  63. wsprintf(pStr, L"0x%X", EventId);
  64. }
  65. return pStr;
  66. }
  67. void __cdecl
  68. main()
  69. {
  70. DWORD dwTargetRPNum = 0;
  71. LPWSTR * argv = NULL;
  72. int argc;
  73. HGLOBAL hMem = NULL;
  74. BOOL fSwitch = TRUE;
  75. BOOL fForward = TRUE;
  76. BOOL fExtended = FALSE;
  77. DWORD dwRc;
  78. InitAsyncTrace();
  79. argv = CommandLineToArgvW(GetCommandLine(), &argc);
  80. if (! argv)
  81. {
  82. printf("Error parsing arguments");
  83. goto done;
  84. }
  85. if (argc < 2)
  86. {
  87. printf("Usage: chglog <drive> <extended=0> <forward=1/0> <RPNum> <Switch=1/0>");
  88. goto done;
  89. }
  90. if (argc >= 3)
  91. {
  92. fExtended = _wtoi(argv[2]);
  93. }
  94. if (argc >= 4)
  95. {
  96. fForward = _wtoi(argv[3]);
  97. }
  98. if (argc >= 5)
  99. {
  100. dwTargetRPNum = (DWORD) _wtol(argv[4]);
  101. }
  102. if (argc >= 6)
  103. {
  104. fSwitch = _wtoi(argv[5]);
  105. }
  106. {
  107. if (fSwitch)
  108. {
  109. dwRc = SRSwitchLog();
  110. if (ERROR_SUCCESS != dwRc)
  111. {
  112. printf("! SRSwitchLog : %ld", dwRc);
  113. goto done;
  114. }
  115. }
  116. CChangeLogEntryEnum ChangeLog(argv[1], fForward, dwTargetRPNum, fSwitch);
  117. CChangeLogEntry cle;
  118. if (ERROR_SUCCESS != ChangeLog.FindFirstChangeLogEntry(cle))
  119. {
  120. printf("No change log entries");
  121. goto done;
  122. }
  123. do
  124. {
  125. if (fExtended)
  126. {
  127. printf(
  128. "%08I64ld\t%S\tFlags=%08d\tAttr=%08d\tAcl=%S\tProcess=%S\tPath1=%S\tPath2=%S\tTemp=%S\tShortName=%S\n",
  129. cle.GetSequenceNum(),
  130. GetEventString(cle.GetType()),
  131. cle.GetFlags(),
  132. cle.GetAttributes(),
  133. cle.GetAcl() ? L"Yes" : L"No",
  134. cle.GetProcess() ? cle.GetProcess() : L"null",
  135. cle.GetPath1() ? cle.GetPath1() : L"null",
  136. cle.GetPath2() ? cle.GetPath2() : L"null",
  137. cle.GetTemp() ? cle.GetTemp() : L"null",
  138. cle.GetShortName() ? cle.GetShortName() : L"null");
  139. }
  140. else
  141. {
  142. printf(
  143. "%08I64d\t%S\t%S\t%S\t%S\t%S\n",
  144. cle.GetSequenceNum(),
  145. GetEventString(cle.GetType()),
  146. cle.GetProcess() ? cle.GetProcess() : L"null",
  147. cle.GetPath1() ? cle.GetPath1() : L"null",
  148. cle.GetPath2() ? cle.GetPath2() : L"null",
  149. cle.GetTemp() ? cle.GetTemp() : L"null");
  150. }
  151. dwRc = ChangeLog.FindNextChangeLogEntry(cle);
  152. } while (dwRc == ERROR_SUCCESS);
  153. if (argc == 7 && 0 == lstrcmpi(argv[6], L"lock"))
  154. getchar();
  155. ChangeLog.FindClose();
  156. }
  157. done:
  158. if (argv) hMem = GlobalHandle(argv);
  159. if (hMem) GlobalFree(hMem);
  160. TermAsyncTrace();
  161. return;
  162. }