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.

633 lines
13 KiB

  1. /********************************************************************/
  2. /** Copyright(c) Microsoft Corp., 1990-1993 **/
  3. /********************************************************************/
  4. /* :ts=4 This file uses 4 space hard tabs */
  5. // *** vrddbg.c - VRedir debug routines
  6. //
  7. #ifdef DEBUG
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. #pragma code_seg("PAGE")
  11. #include <ifsdebug.h>
  12. #pragma intrinsic (memcmp, memcpy, memset, strcat, strcmp, strcpy, strlen)
  13. #define MAXPRO (2+2)
  14. extern NETPRO rgNetPro[MAXPRO];
  15. extern int cMacPro;
  16. extern LPSTR lpLogBuff;
  17. extern int indxCur;
  18. VOID
  19. DispThisIOReq(
  20. pioreq pir
  21. );
  22. VOID
  23. DispThisResource(
  24. PRESOURCE pResource
  25. );
  26. VOID
  27. DispThisFdb(
  28. PFDB pFdb
  29. );
  30. VOID
  31. DispThisFileInfo(
  32. PFILEINFO pFileInfo
  33. );
  34. VOID
  35. DispThisFindInfo(
  36. PFINDINFO pFindInfo
  37. );
  38. extern pimh
  39. DebugMenu(
  40. IFSMenu *pIFSMenu
  41. );
  42. IFSMenuHand DispNetPro, DispResource, DispFdb, DispFileInfo, DispFindInfo, DispIOReq, DispLog;
  43. IFSMenu SHDMainMenu[] = {
  44. {"NetPro info" , DispNetPro},
  45. {"Resource info", DispResource},
  46. {"Fdb info" , DispFdb},
  47. {"OpenFile Info", DispFileInfo},
  48. {"Find Info" , DispFindInfo},
  49. {"DisplayIOReq" , DispIOReq},
  50. {"DisplayLog" , DispLog},
  51. {0 , 0}
  52. };
  53. typedef struct {
  54. char *pName; // Command name (unique part uppercase, optional lowercase)
  55. int (*pHandler)(char *pArgs);
  56. } QD, *pQD;
  57. int NetProCmd(char *pCmd);
  58. int ResCmd(char *pCmd);
  59. int FdbCmd(char *pCmd);
  60. int FileInfoCmd(char *pCmd);
  61. int FindInfoCmd(char *pCmd);
  62. int IoReqCmd(char *pCmd);
  63. int FindInfoCmd(char *pCmd);
  64. int LogCmd(char *pCmd);
  65. QD QueryDispatch[] = {
  66. { "NETPRO" , NetProCmd },
  67. { "RES" , ResCmd },
  68. { "FDB" , FdbCmd },
  69. { "FILEINFO" , FileInfoCmd },
  70. { "FINDINFO" , FindInfoCmd },
  71. { "IOREQ" , IoReqCmd },
  72. { "LOG" , LogCmd },
  73. { "" , 0 },
  74. };
  75. #define MAX_ARG_LEN 30
  76. #define MAX_DEBUG_QUERY_COMMAND_LENGTH 100
  77. unsigned char DebugQueryCmdStr[MAX_DEBUG_QUERY_COMMAND_LENGTH+1] = "";
  78. ULONG DebugQueryCmdStrLen = MAX_DEBUG_QUERY_COMMAND_LENGTH;
  79. unsigned char CmdArg[MAX_ARG_LEN+1] = {0};
  80. unsigned char vrgchBuffDebug[MAX_PATH+1];
  81. /*
  82. GetArg - Gets a command line argument from a string.
  83. IN ppArg = pointer to pointer to argument string
  84. OUT *ppArg = pointer to next argument, or NULL if this was the last.
  85. Returns Pointer to uppercase ASCIZ argument with delimeters stripped, or NULL if
  86. no more arguments.
  87. Note Not reentrant
  88. */
  89. unsigned char *GetArg(unsigned char **ppArg)
  90. {
  91. // Note - Always returns at least one blank argument if string is valid, even
  92. // if the string is empty.
  93. unsigned char *pDest = CmdArg;
  94. unsigned char c;
  95. ULONG i;
  96. #define pArg (*ppArg)
  97. // If end of command already reached, fail
  98. if (!pArg)
  99. return NULL;
  100. // Skip leading whitespace
  101. while (*pArg == ' ' || *pArg == '\t')
  102. pArg++;
  103. // Copy the argument
  104. for (i = 0; i < MAX_ARG_LEN; i++) {
  105. if ((c = *pArg) == 0 || c == '\t' || c == ' ' || c == ';' ||
  106. c == '\n' || c == ',')
  107. break;
  108. if (c >= 'a' && c <= 'z')
  109. c -= ('a' - 'A');
  110. *(pDest++) = c;
  111. pArg++;
  112. }
  113. // Null terminate the result
  114. *pDest = '\0';
  115. // Skip trailing whitespace
  116. while (*pArg == ' ' || *pArg == '\t')
  117. pArg++;
  118. // strip up to one comma
  119. if (*pArg == ',')
  120. pArg++;
  121. // If end of command reached, make next request fail
  122. else if (*pArg == 0 || *pArg == ';' || *pArg == '\n')
  123. pArg = NULL;
  124. // return copy
  125. return CmdArg;
  126. #undef pArg
  127. }
  128. /*
  129. AtoI - Convert a string to a signed or unsigned integer
  130. IN pStr = ASCIZ representation of number with optional leading/trailing
  131. whitespace and optional leading '-'.
  132. Radix = Radix to use for conversion (2, 8, 10, or 16)
  133. OUT *pResult = Numeric result, or unchanged on failure
  134. Returns 1 on success, 0 if malformed string.
  135. Note Not reentrant
  136. */
  137. ULONG AtoI(unsigned char *pStr, ULONG Radix, ULONG *pResult)
  138. {
  139. ULONG r = 0;
  140. ULONG Sign = 0;
  141. unsigned char c;
  142. ULONG d;
  143. while (*pStr == ' ' || *pStr == '\t')
  144. pStr++;
  145. if (*pStr == '-') {
  146. Sign = 1;
  147. pStr++;
  148. }
  149. if (*pStr == 0)
  150. return 0; // Empty string!
  151. while ((c = *pStr) != 0 && c != ' ' && c != '\t') {
  152. if (c >= '0' && c <= '9')
  153. d = c - '0';
  154. else if (c >= 'A' && c <= 'F')
  155. d = c - ('A' - 10);
  156. else if (c >= 'a' && c <= 'f')
  157. d = c - ('a' - 10);
  158. else
  159. return 0; // Not a digit
  160. if (d >= Radix)
  161. return 0; // Not in radix
  162. r = r*Radix+d;
  163. pStr++;
  164. }
  165. while (*pStr == ' ' || *pStr == '\t')
  166. pStr++;
  167. if (*pStr != 0)
  168. return 0; // Garbage at end of string
  169. if (Sign)
  170. r = (ULONG)(-(int)r);
  171. *pResult = r;
  172. return 1; // Success!
  173. }
  174. VOID
  175. *GetPtr(char *pCmd)
  176. {
  177. char *pch;
  178. int p;
  179. pch = GetArg(&pCmd);
  180. //dprintf("cmd = '%s'\n");
  181. if (*pch == 0 || !AtoI(pch, 16, &p))
  182. return 0;
  183. return (VOID *) p;
  184. }
  185. int
  186. CmdDispatch(char *pCmdName, char *pCmd)
  187. {
  188. int ret = 0;
  189. int i=0;
  190. pQD pq;
  191. pq = QueryDispatch;
  192. while (pq->pName[0]) {
  193. if (strcmp(pCmdName, pq->pName) == 0) {
  194. ret = (*pq->pHandler)(pCmd);
  195. DbgPrint("\n");
  196. break;
  197. }
  198. pq++;
  199. }
  200. return ret;
  201. }
  202. //** Debug Command Handlers
  203. int
  204. NetProCmd(char *pCmd)
  205. {
  206. DispNetPro("");
  207. return 1;
  208. }
  209. int
  210. IoReqCmd(char *pCmd)
  211. {
  212. pioreq pir;
  213. if (pir = GetPtr(pCmd))
  214. DispThisIOReq(pir);
  215. else
  216. return 0;
  217. return 1;
  218. }
  219. int
  220. ResCmd(char *pCmd)
  221. {
  222. DispResource(pCmd);
  223. return 1;
  224. }
  225. int
  226. FdbCmd(char *pCmd)
  227. {
  228. PFDB pFdb;
  229. if (pFdb = GetPtr(pCmd)){
  230. DispThisFdb(pFdb);
  231. }
  232. return 1;
  233. }
  234. int
  235. FileInfoCmd(char *pCmd)
  236. {
  237. PFILEINFO pF;
  238. if (pF = GetPtr(pCmd))
  239. DispThisFileInfo(pF);
  240. return 1;
  241. }
  242. int
  243. FindInfoCmd(char *pCmd)
  244. {
  245. return 1;
  246. }
  247. int
  248. LogCmd(char *pCmd)
  249. {
  250. DispLog(pCmd);
  251. }
  252. // ** SHDDebug - handle Debug_Query request from windows
  253. //
  254. VOID
  255. SHDDebug(unsigned char *pCmd)
  256. {
  257. pimh phand;
  258. char *pCmdName;
  259. // dprintf("pCmd = '%s'\n", pCmd);
  260. //see if we got an explicit command
  261. pCmdName = GetArg(&pCmd);
  262. // dprintf("pCmdName = (%x) '%s'\n", pCmdName, pCmdName);
  263. if (*pCmdName != 0) { //got a command, try to process it
  264. if (!CmdDispatch(pCmdName, pCmd)) {
  265. DbgPrint("%* Shadow Command Options:\n");
  266. DbgPrint("%* NETPRO ----- dump network provider info\n");
  267. DbgPrint("%* RES [addr] ---- dump resource info\n");
  268. DbgPrint("%* FDB [addr] ---- dump File Descriptor Block\n");
  269. DbgPrint("%* FILEINFO [addr] --- dump per open file structure\n");
  270. DbgPrint("%* FINDINFO [addr] --- dump findinfo structure\n");
  271. DbgPrint("%* IOREQ [addr] --- dump IOReq structure\n");
  272. DbgPrint("%* LOG --- show trace log\n");
  273. }
  274. } else {
  275. //no args passed, do the menu thing
  276. while ((phand=DebugMenu(SHDMainMenu)) != 0) {
  277. if (phand(0) != 0)
  278. return;
  279. }
  280. }
  281. return;
  282. }
  283. /*+++
  284. Actual display functions
  285. +++*/
  286. VOID
  287. DispThisIOReq(
  288. pioreq pir
  289. )
  290. {
  291. // Display the ioreq structure
  292. DbgPrint("%*IoReq = \t\t%8.8x \n", pir );
  293. DbgPrint("%*ir_length=\t\t%x\n", pir->ir_length);
  294. DbgPrint("%*ir_flags=\t\t%x\n", pir->ir_flags);
  295. DbgPrint("%*ir_user=\t\t%x\n", pir->ir_user);
  296. DbgPrint("%*ir_sfn=\t\t%x\n", pir->ir_sfn);
  297. DbgPrint("%*ir_pid=\t\t%x\n", pir->ir_pid);
  298. DbgPrint("%*ir_ppath=\t\t%x\n", pir->ir_ppath);
  299. DbgPrint("%*ir_aux1=\t\t%x\n", pir->ir_aux1);
  300. DbgPrint("%*ir_data=\t\t%x\n", pir->ir_data);
  301. DbgPrint("%*ir_options=\t\t%x\n", pir->ir_options);
  302. DbgPrint("%*ir_error=\t\t%x\n", pir->ir_error);
  303. DbgPrint("%*ir_rh=\t\t%x\n", pir->ir_rh);
  304. DbgPrint("%*ir_fh=\t\t%x\n", pir->ir_fh);
  305. DbgPrint("%*ir_pos=\t\t%x\n", pir->ir_pos);
  306. DbgPrint("%*ir_aux2=\t\t%x\n", pir->ir_aux2);
  307. DbgPrint("%*ir_pev=\t\t%x\n", pir->ir_pev);
  308. }
  309. int DispIOReq(
  310. char *pCmd
  311. )
  312. {
  313. pioreq pir;
  314. if (pir = GetPtr(pCmd))
  315. {
  316. DispThisIOReq(pir);
  317. return (1);
  318. }
  319. return (0);
  320. }
  321. int
  322. DispNetPro(
  323. char *pcl
  324. )
  325. {
  326. int i;
  327. if (cMacPro > 1){
  328. DbgPrint("%d redirs hooked \n", cMacPro-1);
  329. for (i=1; i< cMacPro; ++i){
  330. DbgPrint("Info for Redir # %d \n", i);
  331. DbgPrint("Head of Resource Chain = \t%x\n", rgNetPro[i].pheadResource);
  332. DbgPrint("Shadow Connect Function = \t%x\n", rgNetPro[i].pOurConnectNet);
  333. DbgPrint("Redir Connect Function = \t%x\n", rgNetPro[i].pConnectNet);
  334. }
  335. return (1);
  336. }
  337. else {
  338. DbgPrint("No Redirs have been hooked \n");
  339. return (0);
  340. }
  341. }
  342. int
  343. DispResource(
  344. char *pCmd
  345. )
  346. {
  347. PRESOURCE pResource = GetPtr(pCmd);
  348. if (pResource)
  349. {
  350. DispThisResource(pResource);
  351. }
  352. else
  353. {
  354. if (cMacPro > 1)
  355. {
  356. pResource = rgNetPro[1].pheadResource;
  357. while (pResource)
  358. {
  359. DispThisResource(pResource);
  360. pResource = pResource->pnextResource;
  361. }
  362. }
  363. }
  364. }
  365. int
  366. DispFdb(
  367. char *pCmd
  368. )
  369. {
  370. PFDB pFdb = GetPtr(pCmd);
  371. if (pFdb)
  372. {
  373. DispThisFdb(pFdb);
  374. return (1);
  375. }
  376. return (0);
  377. }
  378. int
  379. DispFileInfo(
  380. char *pCmd
  381. )
  382. {
  383. PFILEINFO pFileInfo = GetPtr(pCmd);
  384. if (pFileInfo)
  385. {
  386. DispThisFileInfo(pFileInfo);
  387. return (1);
  388. }
  389. return (0);
  390. }
  391. int
  392. DispFindInfo(
  393. char *pCmd
  394. )
  395. {
  396. PFINDINFO pFindInfo = GetPtr(pCmd);
  397. if (pFindInfo)
  398. {
  399. DispThisFindInfo(pFindInfo);
  400. return (1);
  401. }
  402. return (0);
  403. }
  404. int
  405. DispLog(
  406. char *pCmd
  407. )
  408. {
  409. int indxT=0, len;
  410. LPSTR lpszT;
  411. pCmd;
  412. lpszT = lpLogBuff;
  413. while (indxCur > indxT)
  414. {
  415. DbgPrint(("%s"), lpszT);
  416. for (len=1; (*(lpszT+len) != 0xa) && ((indxT+len) < indxCur); ++len);
  417. // step over the string
  418. lpszT += len;
  419. indxT += len;
  420. }
  421. }
  422. /*+++
  423. Helper Functions
  424. +++*/
  425. VOID
  426. DispThisResource(
  427. PRESOURCE pResource
  428. )
  429. {
  430. DbgPrint("Resource \t%x \n", pResource);
  431. PpeToSvr(pResource->pp_elements, vrgchBuffDebug, MAX_PATH, BCS_OEM);
  432. DbgPrint("Share name: \t%s \n", vrgchBuffDebug);
  433. DbgPrint("Next Resource \t%x \n", pResource->pnextResource);
  434. DbgPrint("FileInfo structures list \t%x \n", pResource->pheadFileInfo);
  435. DbgPrint("FindInfo structures list \t%x \n", pResource->pheadFindInfo);
  436. DbgPrint("FDB structures list \t%x \n", pResource->pheadFdb);
  437. DbgPrint("hServer: \t%x\n", pResource->hServer);
  438. DbgPrint("Root shadow: \t%x\n", pResource->hRoot);
  439. DbgPrint("usFlags \t%x\n", (ULONG)(pResource->usFlags));
  440. DbgPrint("usLocalFlags \t%x\n", (ULONG)(pResource->usLocalFlags));
  441. DbgPrint("Our Network Provider \t%x\n", pResource->pOurNetPro);
  442. DbgPrint("Providers resource handle \t%x\n", pResource->rhPro);
  443. DbgPrint("fh_t \t%x\n", pResource->fhSys);
  444. DbgPrint("Providers Volume Function table \t%x\n", pResource->pVolTab);
  445. DbgPrint(" Count of locks on this resource \t%x\n", pResource->cntLocks);
  446. DbgPrint(" Bitmap of mapped drives \t%x\n", pResource->uDriveMap);
  447. }
  448. VOID
  449. DispThisFdb(
  450. PFDB pFdb
  451. )
  452. {
  453. DbgPrint("\n");
  454. memset(vrgchBuffDebug, 0, sizeof(vrgchBuffDebug));
  455. UniToBCSPath(vrgchBuffDebug, &(pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  456. DbgPrint("****** Fdb for \t%s ", vrgchBuffDebug);
  457. memset(vrgchBuffDebug, 0, sizeof(vrgchBuffDebug));
  458. PpeToSvr(pFdb->pResource->pp_elements, vrgchBuffDebug, MAX_PATH, BCS_OEM);
  459. DbgPrint("on \t%s \n", vrgchBuffDebug);
  460. DbgPrint("Next Fdb: \t%x \n", pFdb->pnextFdb);
  461. DbgPrint("Resource: \t%x\n", pFdb->pResource);
  462. DbgPrint("usFlags: \t%x\n", (ULONG)(pFdb->usFlags));
  463. DbgPrint("Total # of opens: \t%x\n", (ULONG)(pFdb->usCount));
  464. DbgPrint("File Inode: \t%x\n", pFdb->hShadow);
  465. DbgPrint("Dir Inode: \t%x\n", pFdb->hDir);
  466. }
  467. VOID
  468. DispThisFileInfo(
  469. PFILEINFO pFileInfo
  470. )
  471. {
  472. DbgPrint("\n");
  473. memset(vrgchBuffDebug, 0, sizeof(vrgchBuffDebug));
  474. UniToBCSPath(vrgchBuffDebug, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  475. DbgPrint("****** FileInfo for \t%s ", vrgchBuffDebug);
  476. memset(vrgchBuffDebug, 0, sizeof(vrgchBuffDebug));
  477. PpeToSvr(pFileInfo->pResource->pp_elements, vrgchBuffDebug, MAX_PATH, BCS_OEM);
  478. DbgPrint("on \t%s \n", vrgchBuffDebug);
  479. DbgPrint(" Next FileInfo \t%x\n", pFileInfo->pnextFileInfo);
  480. DbgPrint(" Resource off which it is hangin%x\n", pFileInfo->pResource);
  481. DbgPrint(" Shadow file handle \t%x\n", pFileInfo->hfShadow);
  482. DbgPrint(" pFdb: %x\n", pFileInfo->pFdb);
  483. DbgPrint(" providers file handle: \t%x\n", pFileInfo->fhProFile);
  484. DbgPrint(" providers file function table \t%x\n", pFileInfo->hfFileHandle);
  485. DbgPrint(" Acess-share flags for this open \t%x\n", (ULONG)(pFileInfo->uchAccess));
  486. DbgPrint(" usFlags: \t%x\n", (ULONG)(pFileInfo->usFlags));
  487. DbgPrint(" usLocalFlags: \t%x\n", (ULONG)(pFileInfo->usLocalFlags));
  488. DbgPrint(" sfnFile: \t%x\n", pFileInfo->sfnFile);
  489. DbgPrint(" pidFile: \t%x\n", pFileInfo->pidFile);
  490. DbgPrint(" userFile: \t%x\n", pFileInfo->userFile);
  491. }
  492. VOID
  493. DispThisFindInfo(
  494. PFINDINFO pFindInfo
  495. )
  496. {
  497. }
  498. #endif
  499.