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.

239 lines
11 KiB

  1. #define UNICODE
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5. #include <winioctl.h>
  6. #include <shdcom.h>
  7. #include <smbdebug.h>
  8. #include "struct.h"
  9. PBYTE InBuf[0x50];
  10. PBYTE OutBuf = NULL;
  11. #define STATUS_SUCCESS ((ULONG)0x00000000L)
  12. #define STATUS_BUFFER_TOO_SMALL ((ULONG)0xC0000023L)
  13. PWCHAR CscStateArray[] = {
  14. L"Shadowing",
  15. L"Disconnected",
  16. L"TransitioningToShadowing",
  17. L"TransitioningtoDisconnected"
  18. };
  19. DWORD
  20. CmdInfo(ULONG Cmd)
  21. {
  22. BOOL bResult;
  23. HANDLE hShadow=NULL;
  24. ULONG junk;
  25. PULONG pl = NULL;
  26. PIOCTL_GET_DEBUG_INFO_ARG pInfoArg = NULL;
  27. ULONG i;
  28. ULONG j;
  29. ULONG BufSize = 0x1000;
  30. ULONG Status = 0;
  31. if (fSwDebug == TRUE)
  32. MyPrintf(L"CmdInfo(0x%x)\r\n", Cmd);
  33. TryAgain:
  34. OutBuf = malloc(BufSize);
  35. if (OutBuf == NULL) {
  36. MyPrintf(L"CmdInfo:Couldn't alloc memory\r\n");
  37. Status = ERROR_NOT_ENOUGH_MEMORY;
  38. goto AllDone;
  39. }
  40. hShadow = CreateFile(
  41. L"\\\\.\\shadow",
  42. GENERIC_READ | GENERIC_WRITE,
  43. FILE_SHARE_READ | FILE_SHARE_WRITE,
  44. NULL,
  45. OPEN_EXISTING,
  46. 0,
  47. NULL);
  48. if (hShadow == INVALID_HANDLE_VALUE) {
  49. MyPrintf(L"CmdInfo:Failed open of shadow device\r\n");
  50. Status = GetLastError();
  51. goto AllDone;
  52. }
  53. memset(InBuf, 0, sizeof(InBuf));
  54. pl = (PULONG)InBuf;
  55. *pl = Cmd;
  56. bResult = DeviceIoControl(
  57. hShadow, // device
  58. IOCTL_GET_DEBUG_INFO, // control code
  59. (LPVOID)InBuf, // in buffer
  60. sizeof(InBuf), // inbuffer size
  61. (LPVOID)OutBuf, // out buffer
  62. BufSize, // out buffer size
  63. &junk, // bytes returned
  64. NULL); // overlapped
  65. CloseHandle(hShadow);
  66. if (!bResult) {
  67. MyPrintf(L"CmdInfo:DeviceIoControl failed\n");
  68. Status = GetLastError();
  69. goto AllDone;
  70. }
  71. pInfoArg = (PIOCTL_GET_DEBUG_INFO_ARG) OutBuf;
  72. if (bResult && pInfoArg->Status == STATUS_SUCCESS) {
  73. if (Cmd == DEBUG_INFO_SERVERLIST) {
  74. if (pInfoArg->Version != 2 && pInfoArg->Version != 3 && pInfoArg->Version != 4) {
  75. MyPrintf(L"Incorrect version.\r\n");
  76. goto AllDone;
  77. }
  78. for (i = 0; i < pInfoArg->EntryCount; i++) {
  79. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].Name, OutBuf);
  80. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].DomainName, OutBuf);
  81. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].DfsRootName, OutBuf);
  82. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].DnsName, OutBuf);
  83. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].pNetRoots, OutBuf);
  84. for (j = 0; j < pInfoArg->ServerEntryObject[i].NetRootEntryCount; j++)
  85. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].pNetRoots[j].Name, OutBuf);
  86. }
  87. MyPrintf(L"Status: 0x%x\r\n"
  88. L"Version: %d\r\n"
  89. L"Entries: %d\r\n",
  90. pInfoArg->Status,
  91. pInfoArg->Version,
  92. pInfoArg->EntryCount);
  93. for (i = 0; i < pInfoArg->EntryCount; i++) {
  94. PWCHAR FlagDesc = NULL;
  95. MyPrintf(L"=================================================\r\n");
  96. MyPrintf(L"Name: %ws\r\n"
  97. L"DomainName: %ws\r\n"
  98. L"ServerStatus: 0x%x\r\n"
  99. L"DfsRootName: %ws\r\n"
  100. L"DnsName: %ws\r\n"
  101. L"SecuritySignaturesEnabled: 0x%x\r\n"
  102. L"Server.CscState: 0x%x (%ws)\r\n"
  103. L"Sever.IsFakeDfsServerForOfflineUse: 0x%x\r\n"
  104. L"Sever.IsPinnedOffline: 0x%x\r\n"
  105. L"NetRootEntryCount: 0x%x\r\n"
  106. L"=================================================\n",
  107. pInfoArg->ServerEntryObject[i].Name,
  108. pInfoArg->ServerEntryObject[i].DomainName,
  109. pInfoArg->ServerEntryObject[i].ServerStatus,
  110. pInfoArg->ServerEntryObject[i].DfsRootName,
  111. pInfoArg->ServerEntryObject[i].DnsName,
  112. pInfoArg->ServerEntryObject[i].SecuritySignaturesEnabled,
  113. pInfoArg->ServerEntryObject[i].CscState,
  114. CscStateArray[pInfoArg->ServerEntryObject[i].CscState],
  115. pInfoArg->ServerEntryObject[i].IsFakeDfsServerForOfflineUse,
  116. pInfoArg->ServerEntryObject[i].IsPinnedOffline,
  117. pInfoArg->ServerEntryObject[i].NetRootEntryCount);
  118. for (j = 0; j < pInfoArg->ServerEntryObject[i].NetRootEntryCount; j++) {
  119. switch (pInfoArg->ServerEntryObject[i].pNetRoots[j].CscFlags) {
  120. case 0x0: FlagDesc = L"SMB_CSC_CACHE_MANUAL_REINT"; break;
  121. case 0x4: FlagDesc = L"SMB_CSC_CACHE_AUTO_REINT"; break;
  122. case 0x8: FlagDesc = L"SMB_CSC_CACHE_VDO"; break;
  123. case 0xc: FlagDesc = L"SMB_CSC_NO_CACHING"; break;
  124. default: FlagDesc = L"<unknown>"; break;
  125. }
  126. MyPrintf(L" Name: %ws\r\n"
  127. L" MaximalAccessRights: 0x%x\r\n"
  128. L" GuestMaximalAccessRights: 0x%x\r\n"
  129. L" DfsAware: 0x%x\r\n"
  130. L" hShare: 0x%x\r\n"
  131. L" hRootDir: 0x%x\r\n"
  132. L" ShareStatus: 0x%x\r\n"
  133. L" CscFlags: 0x%x (%ws)\r\n"
  134. L" CscEnabled: 0x%x\r\n"
  135. L" CscShadowable: 0x%x\r\n"
  136. L" Disconnected: 0x%x\r\n",
  137. pInfoArg->ServerEntryObject[i].pNetRoots[j].Name,
  138. pInfoArg->ServerEntryObject[i].pNetRoots[j].MaximalAccessRights,
  139. pInfoArg->ServerEntryObject[i].pNetRoots[j].GuestMaximalAccessRights,
  140. pInfoArg->ServerEntryObject[i].pNetRoots[j].DfsAware,
  141. pInfoArg->ServerEntryObject[i].pNetRoots[j].hShare,
  142. pInfoArg->ServerEntryObject[i].pNetRoots[j].hRootDir,
  143. pInfoArg->ServerEntryObject[i].pNetRoots[j].ShareStatus,
  144. pInfoArg->ServerEntryObject[i].pNetRoots[j].CscFlags,
  145. FlagDesc,
  146. pInfoArg->ServerEntryObject[i].pNetRoots[j].CscEnabled,
  147. pInfoArg->ServerEntryObject[i].pNetRoots[j].CscShadowable,
  148. pInfoArg->ServerEntryObject[i].pNetRoots[j].Disconnected);
  149. if (j < pInfoArg->ServerEntryObject[i].NetRootEntryCount-1)
  150. MyPrintf(L" --------------------------------------------\r\n");
  151. }
  152. if (pInfoArg->ServerEntryObject[i].NetRootEntryCount == 0)
  153. MyPrintf(L" no entries\r\n");
  154. }
  155. MyPrintf(L"=================================================\r\n");
  156. } else if (Cmd == DEBUG_INFO_CSCFCBSLIST) {
  157. for (i = 0; i < pInfoArg->EntryCount; i++) {
  158. OFFSET_TO_POINTER(pInfoArg->FcbEntryObject[i].DfsPrefix, OutBuf);
  159. OFFSET_TO_POINTER(pInfoArg->FcbEntryObject[i].ActualPrefix, OutBuf);
  160. }
  161. MyPrintf(L"Status: 0x%x\r\n"
  162. L"Version: %d\r\n"
  163. L"Entries: %d\r\n",
  164. pInfoArg->Status,
  165. pInfoArg->Version,
  166. pInfoArg->EntryCount);
  167. for (i = 0; i < pInfoArg->EntryCount; i++) {
  168. MyPrintf(L"=================================================\r\n");
  169. MyPrintf(L"MFlags: 0x%x\r\n"
  170. L"Tid: 0x%x\r\n"
  171. L"ShadowIsCorrupt: 0x%x\r\n"
  172. L"hShadow: 0x%x\r\n"
  173. L"hParentDir: 0x%x\r\n"
  174. L"hShadowRenamed: 0x%x\r\n"
  175. L"hParentDirRenamed: 0x%x\r\n"
  176. L"ShadowStatus: 0x%x\r\n"
  177. L"LocalFlags: 0x%x\r\n"
  178. L"LastComponentOffset: 0x%x\r\n"
  179. L"LastComponentLength: 0x%x\r\n"
  180. L"hShare: 0x%x\r\n"
  181. L"hRootDir: 0x%x\r\n"
  182. L"ShareStatus: 0x%x\r\n"
  183. L"Flags: 0x%x\r\n"
  184. L"DfsPrefix: %s\r\n"
  185. L"ActualPrefix: %s\r\n",
  186. pInfoArg->FcbEntryObject[i].MFlags,
  187. pInfoArg->FcbEntryObject[i].Tid,
  188. pInfoArg->FcbEntryObject[i].ShadowIsCorrupt,
  189. pInfoArg->FcbEntryObject[i].hShadow,
  190. pInfoArg->FcbEntryObject[i].hParentDir,
  191. pInfoArg->FcbEntryObject[i].hShadowRenamed,
  192. pInfoArg->FcbEntryObject[i].hParentDirRenamed,
  193. pInfoArg->FcbEntryObject[i].ShadowStatus,
  194. pInfoArg->FcbEntryObject[i].LocalFlags,
  195. pInfoArg->FcbEntryObject[i].LastComponentOffset,
  196. pInfoArg->FcbEntryObject[i].LastComponentLength,
  197. pInfoArg->FcbEntryObject[i].hShare,
  198. pInfoArg->FcbEntryObject[i].hRootDir,
  199. pInfoArg->FcbEntryObject[i].ShareStatus,
  200. pInfoArg->FcbEntryObject[i].Flags,
  201. pInfoArg->FcbEntryObject[i].DfsPrefix,
  202. pInfoArg->FcbEntryObject[i].ActualPrefix);
  203. }
  204. }
  205. } else if (bResult && pInfoArg->Status == STATUS_BUFFER_TOO_SMALL) {
  206. free(OutBuf);
  207. OutBuf = NULL;
  208. BufSize *= 2;
  209. goto TryAgain;
  210. }
  211. AllDone:
  212. if (OutBuf != NULL)
  213. free(OutBuf);
  214. if (fSwDebug == TRUE)
  215. MyPrintf(L"CmdInfo exit %d\r\n", Status);
  216. return Status;
  217. }