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.

194 lines
9.1 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. CHAR *ProgName = "cscgetinfo";
  9. PBYTE InBuf[0x50];
  10. PBYTE OutBuf = NULL;
  11. #define STATUS_SUCCESS ((ULONG)0x00000000L)
  12. #define STATUS_BUFFER_TOO_SMALL ((ULONG)0xC0000023L)
  13. _cdecl
  14. main(LONG argc, CHAR *argv[])
  15. {
  16. BOOL bResult;
  17. HANDLE hShadow=NULL;
  18. ULONG junk;
  19. PULONG pl = NULL;
  20. PIOCTL_GET_DEBUG_INFO_ARG pInfoArg = NULL;
  21. ULONG i;
  22. ULONG j;
  23. ULONG BufSize = 0x1000;
  24. ULONG Cmd = DEBUG_INFO_SERVERLIST;
  25. // ULONG Cmd = DEBUG_INFO_CSCFCBSLIST;
  26. TryAgain:
  27. OutBuf = malloc(BufSize);
  28. if (OutBuf == NULL) {
  29. printf("Couldn't alloc memory\n");
  30. return 0;
  31. }
  32. hShadow = CreateFile(
  33. L"\\\\.\\shadow",
  34. GENERIC_READ | GENERIC_WRITE,
  35. FILE_SHARE_READ | FILE_SHARE_WRITE,
  36. NULL,
  37. OPEN_EXISTING,
  38. 0,
  39. NULL);
  40. if (hShadow == INVALID_HANDLE_VALUE) {
  41. printf("Failed open of shadow device\n");
  42. return 0;
  43. }
  44. memset(InBuf, 0, sizeof(InBuf));
  45. pl = (PULONG)InBuf;
  46. *pl = Cmd;
  47. bResult = DeviceIoControl(
  48. hShadow, // device
  49. IOCTL_GET_DEBUG_INFO, // control code
  50. (LPVOID)InBuf, // in buffer
  51. sizeof(InBuf), // inbuffer size
  52. (LPVOID)OutBuf, // out buffer
  53. BufSize, // out buffer size
  54. &junk, // bytes returned
  55. NULL); // overlapped
  56. CloseHandle(hShadow);
  57. pInfoArg = (PIOCTL_GET_DEBUG_INFO_ARG) OutBuf;
  58. if (bResult && pInfoArg->Status == STATUS_SUCCESS) {
  59. if (Cmd == DEBUG_INFO_SERVERLIST) {
  60. for (i = 0; i < pInfoArg->EntryCount; i++) {
  61. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].Name, OutBuf);
  62. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].DomainName, OutBuf);
  63. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].DfsRootName, OutBuf);
  64. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].DnsName, OutBuf);
  65. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].pNetRoots, OutBuf);
  66. for (j = 0; j < pInfoArg->ServerEntryObject[i].NetRootEntryCount; j++)
  67. OFFSET_TO_POINTER(pInfoArg->ServerEntryObject[i].pNetRoots[j].Name, OutBuf);
  68. }
  69. printf("Status: 0x%x\n"
  70. "Version: %d\n"
  71. "Entries: %d\n",
  72. pInfoArg->Status,
  73. pInfoArg->Version,
  74. pInfoArg->EntryCount);
  75. for (i = 0; i < pInfoArg->EntryCount; i++) {
  76. printf("=================================================\n");
  77. printf("Name: %ws\n"
  78. "DomainName: %ws\n"
  79. "ServerStatus: 0x%x\n"
  80. "DfsRootName: %ws\n"
  81. "DnsName: %ws\n"
  82. "SecuritySignaturesEnabled: 0x%x\n"
  83. "NetRootEntryCount: 0x%x\n"
  84. "=================================================\n",
  85. pInfoArg->ServerEntryObject[i].Name,
  86. pInfoArg->ServerEntryObject[i].DomainName,
  87. pInfoArg->ServerEntryObject[i].ServerStatus,
  88. pInfoArg->ServerEntryObject[i].DfsRootName,
  89. pInfoArg->ServerEntryObject[i].DnsName,
  90. pInfoArg->ServerEntryObject[i].SecuritySignaturesEnabled,
  91. pInfoArg->ServerEntryObject[i].NetRootEntryCount);
  92. for (j = 0; j < pInfoArg->ServerEntryObject[i].NetRootEntryCount; j++) {
  93. printf(" Name: %ws\n"
  94. " MaximalAccessRights: 0x%x\n"
  95. " GuestMaximalAccessRights: 0x%x\n"
  96. " DfsAware: 0x%x\n"
  97. " hShare: 0x%x\n"
  98. " hRootDir: 0x%x\n"
  99. " ShareStatus: 0x%x\n"
  100. " CscEnabled: 0x%x\n"
  101. " CscShadowable: 0x%x\n"
  102. " Disconnected: 0x%x\n",
  103. pInfoArg->ServerEntryObject[i].pNetRoots[j].Name,
  104. pInfoArg->ServerEntryObject[i].pNetRoots[j].MaximalAccessRights,
  105. pInfoArg->ServerEntryObject[i].pNetRoots[j].GuestMaximalAccessRights,
  106. pInfoArg->ServerEntryObject[i].pNetRoots[j].DfsAware,
  107. pInfoArg->ServerEntryObject[i].pNetRoots[j].hRootDir,
  108. pInfoArg->ServerEntryObject[i].pNetRoots[j].ShareStatus,
  109. pInfoArg->ServerEntryObject[i].pNetRoots[j].CscEnabled,
  110. pInfoArg->ServerEntryObject[i].pNetRoots[j].CscShadowable,
  111. pInfoArg->ServerEntryObject[i].pNetRoots[j].Disconnected);
  112. if (j < pInfoArg->ServerEntryObject[i].NetRootEntryCount-1)
  113. printf(" --------------------------------------------\n");
  114. }
  115. }
  116. printf("=================================================\n");
  117. } else if (Cmd == DEBUG_INFO_CSCFCBSLIST) {
  118. for (i = 0; i < pInfoArg->EntryCount; i++) {
  119. OFFSET_TO_POINTER(pInfoArg->FcbEntryObject[i].DfsPrefix, OutBuf);
  120. OFFSET_TO_POINTER(pInfoArg->FcbEntryObject[i].ActualPrefix, OutBuf);
  121. }
  122. printf("Status: 0x%x\n"
  123. "Version: %d\n"
  124. "Entries: %d\n",
  125. pInfoArg->Status,
  126. pInfoArg->Version,
  127. pInfoArg->EntryCount);
  128. for (i = 0; i < pInfoArg->EntryCount; i++) {
  129. printf("=================================================\n");
  130. printf("MFlags: 0x%x\n"
  131. "Tid: 0x%x\n"
  132. "ShadowIsCorrupt: 0x%x\n"
  133. "hShadow: 0x%x\n"
  134. "hParentDir: 0x%x\n"
  135. "hShadowRenamed: 0x%x\n"
  136. "hParentDirRenamed: 0x%x\n"
  137. "ShadowStatus: 0x%x\n"
  138. "LocalFlags: 0x%x\n"
  139. "LastComponentOffset: 0x%x\n"
  140. "LastComponentLength: 0x%x\n"
  141. "hShare: 0x%x\n"
  142. "hRootDir: 0x%x\n"
  143. "ShareStatus: 0x%x\n"
  144. "Flags: 0x%x\n"
  145. "DfsPrefix: %s\n"
  146. "ActualPrefix: %s\n",
  147. pInfoArg->FcbEntryObject[i].MFlags,
  148. pInfoArg->FcbEntryObject[i].Tid,
  149. pInfoArg->FcbEntryObject[i].ShadowIsCorrupt,
  150. pInfoArg->FcbEntryObject[i].hShadow,
  151. pInfoArg->FcbEntryObject[i].hParentDir,
  152. pInfoArg->FcbEntryObject[i].hShadowRenamed,
  153. pInfoArg->FcbEntryObject[i].hParentDirRenamed,
  154. pInfoArg->FcbEntryObject[i].ShadowStatus,
  155. pInfoArg->FcbEntryObject[i].LocalFlags,
  156. pInfoArg->FcbEntryObject[i].LastComponentOffset,
  157. pInfoArg->FcbEntryObject[i].LastComponentLength,
  158. pInfoArg->FcbEntryObject[i].hShare,
  159. pInfoArg->FcbEntryObject[i].hRootDir,
  160. pInfoArg->FcbEntryObject[i].ShareStatus,
  161. pInfoArg->FcbEntryObject[i].Flags,
  162. pInfoArg->FcbEntryObject[i].DfsPrefix,
  163. pInfoArg->FcbEntryObject[i].ActualPrefix);
  164. }
  165. }
  166. } else if (bResult && pInfoArg->Status == STATUS_BUFFER_TOO_SMALL) {
  167. // printf("Success but status = 0x%x\n", pInfoArg->Status);
  168. free(OutBuf);
  169. OutBuf = NULL;
  170. BufSize *= 2;
  171. goto TryAgain;
  172. }
  173. if (OutBuf != NULL)
  174. free(OutBuf);
  175. return 0;
  176. }