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.

149 lines
3.5 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include "restmap.h"
  6. #include "shellapi.h"
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. struct _EVENT_STR_MAP
  10. {
  11. DWORD EventId;
  12. LPWSTR pEventStr;
  13. } EventMap[ 12 ] =
  14. {
  15. {SrEventInvalid , L"INVALID " },
  16. {SrEventStreamChange, L"FILE-MODIFY" },
  17. {SrEventAclChange, L"ACL-CHANGE " },
  18. {SrEventAttribChange, L"ATTR-CHANGE" },
  19. {SrEventStreamOverwrite,L"FILE-MODIFY" },
  20. {SrEventFileDelete, L"FILE-DELETE" },
  21. {SrEventFileCreate, L"FILE-CREATE" },
  22. {SrEventFileRename, L"FILE-RENAME" },
  23. {SrEventDirectoryCreate,L"DIR-CREATE " },
  24. {SrEventDirectoryRename,L"DIR-RENAME " },
  25. {SrEventDirectoryDelete,L"DIR-DELETE " },
  26. {SrEventMaximum, L"INVALID-MAX" }
  27. };
  28. LPWSTR
  29. GetEventString(
  30. DWORD EventId
  31. )
  32. {
  33. LPWSTR pStr = L"NOT-FOUND";
  34. for( int i=0; i<sizeof(EventMap)/sizeof(_EVENT_STR_MAP);i++)
  35. {
  36. if ( EventMap[i].EventId == EventId )
  37. {
  38. pStr = EventMap[i].pEventStr;
  39. }
  40. }
  41. return pStr;
  42. }
  43. void
  44. PrintUsage()
  45. {
  46. printf("Usage: restmap <option>");
  47. printf("\n 1 = dumpmap [filename]");
  48. printf("\n 2 = createmap <filename> <drive> <RPNum>");
  49. }
  50. void
  51. PrintRestoreMap(LPWSTR pszFileName)
  52. {
  53. RestoreMapEntry *prme = NULL;
  54. HANDLE hFile;
  55. LPWSTR pszSrc, pszDest, pszTemp;
  56. LPBYTE pbAcl = NULL;
  57. hFile = CreateFile(pszFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  58. if (hFile == INVALID_HANDLE_VALUE)
  59. goto Err;
  60. while (ERROR_SUCCESS == ReadRestoreMapEntry(hFile, &prme))
  61. {
  62. GetPaths(prme, &pszSrc, &pszTemp, &pszDest, &pbAcl);
  63. printf("\n%S\tAttr=%08d\tAcl=%S\tSrc=%S\tTmp=%S\tDest=%S\tAcl=%S",
  64. GetEventString(prme->m_dwOperation),
  65. prme->m_dwAttribute,
  66. (prme->m_cbAcl > 0) ? L"Yes" : L"No",
  67. pszSrc,
  68. pszTemp ? pszTemp : L"",
  69. pszDest ? pszDest : L"",
  70. pbAcl ? (prme->m_fAclInline ? L"inline" : (LPWSTR) pbAcl) : L"");
  71. }
  72. FreeRestoreMapEntry(prme);
  73. CloseHandle(hFile);
  74. Err:
  75. return;
  76. }
  77. void __cdecl
  78. main()
  79. {
  80. LPWSTR * argv = NULL;
  81. int argc;
  82. HGLOBAL hMem = NULL;
  83. HANDLE hFile = NULL;
  84. int option;
  85. argv = CommandLineToArgvW(GetCommandLine(), &argc);
  86. if (! argv)
  87. {
  88. printf("Error parsing arguments");
  89. goto done;
  90. }
  91. if (argc < 2)
  92. {
  93. PrintUsage();
  94. goto done;
  95. }
  96. option = _wtoi(argv[1]);
  97. switch (option)
  98. {
  99. case 1:
  100. PrintRestoreMap(argv[2]);
  101. break;
  102. case 2:
  103. if (argc != 5)
  104. {
  105. PrintUsage();
  106. goto done;
  107. }
  108. hFile = CreateFile(argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  109. if (hFile != INVALID_HANDLE_VALUE)
  110. {
  111. printf("CreateRestoreMap...DWORD %ld", CreateRestoreMap(argv[3], _wtoi(argv[4]), hFile));
  112. CloseHandle(hFile);
  113. }
  114. else
  115. printf("Error creating file");
  116. break;
  117. default:
  118. PrintUsage();
  119. goto done;
  120. break;
  121. }
  122. done:
  123. if (argv) hMem = GlobalHandle(argv);
  124. if (hMem) GlobalFree(hMem);
  125. }