Source code of Windows XP (NT5)
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.

358 lines
9.2 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. user.c
  7. This module implements the "user" command of the W3 Server
  8. debugger extension DLL.
  9. The "user" command dumps the info pertaining to a specific user.
  10. There is one parameter to this command. If this parameter is
  11. positive, it is assumed to be the address of a USER_DATA structure
  12. for a specific user. If the parameter is negative, its absolute
  13. value is assumed to be a user ID. If no parameter is given, info
  14. for all connected users is dumped.
  15. FILE HISTORY:
  16. KeithMo 13-Aug-1992 Created.
  17. */
  18. #include "w3dbg.h"
  19. //
  20. // Private prototypes.
  21. //
  22. VOID DumpUserInfo( HANDLE hCurrentProcess,
  23. USER_DATA * puser );
  24. CHAR * InterpretState( USER_STATE state );
  25. CHAR * InterpretXferType( XFER_TYPE xferType );
  26. CHAR * InterpretXferMode( XFER_MODE xferMode );
  27. VOID InterpretFlags( DWORD dwFlags );
  28. /*******************************************************************
  29. NAME: user
  30. SYNOPSIS: Displays the info for a specific user.
  31. ENTRY: hCurrentProcess - Handle to the current process.
  32. hCurrentThread - Handle to the current thread.
  33. dwCurrentPc - The current program counter
  34. (EIP for x86, FIR for MIPS).
  35. lpExtensionApis - Points to a structure containing
  36. pointers to the debugger functions
  37. that the command may invoke.
  38. lpArgumentString - Points to any arguments passed
  39. to the command.
  40. NOTES: The argument string must contain either the address of
  41. a USER_DATA structure (if positive) or a user ID (if
  42. negative).
  43. HISTORY:
  44. KeithMo 13-Aug-1992 Created.
  45. ********************************************************************/
  46. VOID user( HANDLE hCurrentProcess,
  47. HANDLE hCurrentThread,
  48. DWORD dwCurrentPc,
  49. LPVOID lpExtensionApis,
  50. LPSTR lpArgumentString )
  51. {
  52. LONG lParam;
  53. USER_DATA user;
  54. //
  55. // Grab the debugger entrypoints.
  56. //
  57. GrabDebugApis( lpExtensionApis );
  58. //
  59. // Evaluate the parameter (if present).
  60. //
  61. if( ( lpArgumentString == NULL ) || ( *lpArgumentString == '\0' ) )
  62. {
  63. lParam = 0;
  64. }
  65. else
  66. {
  67. lParam = (LONG)DebugEval( lpArgumentString );
  68. }
  69. //
  70. // Interpret the parameter.
  71. //
  72. if( lParam > 0 )
  73. {
  74. //
  75. // User specified an address. Dump the user info
  76. // at that address.
  77. //
  78. ReadProcessMemory( hCurrentProcess,
  79. (LPVOID)lParam,
  80. (LPVOID)&user,
  81. sizeof(user),
  82. (LPDWORD)NULL );
  83. DumpUserInfo( hCurrentProcess, &user );
  84. }
  85. else
  86. {
  87. //
  88. // User specified either nothing (0) or a user ID (< 0).
  89. //
  90. LIST_ENTRY list;
  91. LIST_ENTRY * plist;
  92. LIST_ENTRY * plistHead;
  93. lParam = -lParam;
  94. plistHead = (LIST_ENTRY *)DebugEval( "listUserData" );
  95. ReadProcessMemory( hCurrentProcess,
  96. (LPVOID)plistHead,
  97. (LPVOID)&list,
  98. sizeof(list),
  99. (LPDWORD)NULL );
  100. plist = list.Flink;
  101. while( plist != plistHead )
  102. {
  103. ReadProcessMemory( hCurrentProcess,
  104. (LPVOID)CONTAINING_RECORD( plist,
  105. USER_DATA,
  106. link ),
  107. (LPVOID)&user,
  108. sizeof(user),
  109. (LPDWORD)NULL );
  110. if( ( lParam == 0 ) || ( user.idUser == (DWORD)lParam ) )
  111. {
  112. DumpUserInfo( hCurrentProcess, &user );
  113. if( lParam != 0 )
  114. {
  115. break;
  116. }
  117. }
  118. plist = user.link.Flink;
  119. //
  120. // Check for CTRL-C, to let the user bag-out early.
  121. //
  122. if( DebugCheckCtrlC() )
  123. {
  124. break;
  125. }
  126. }
  127. if( ( lParam != 0 ) && ( plist == plistHead ) )
  128. {
  129. DebugPrint( "user ID %ld not found\n", lParam );
  130. }
  131. }
  132. } // user
  133. VOID DumpUserInfo( HANDLE hCurrentProcess,
  134. USER_DATA * puser )
  135. {
  136. char szDir[MAX_PATH];
  137. int i;
  138. DebugPrint( "user @ %08lX:\n", puser );
  139. DebugPrint( " link.Flink = %08lX\n", puser->link.Flink );
  140. DebugPrint( " link.Blink = %08lX\n", puser->link.Blink );
  141. DebugPrint( " dwFlags = %08lX\n", puser->dwFlags );
  142. InterpretFlags( puser->dwFlags );
  143. DebugPrint( " sControl = %d\n", puser->sControl );
  144. DebugPrint( " sData = %d\n", puser->sData );
  145. DebugPrint( " hToken = %08lX\n", puser->hToken );
  146. DebugPrint( " state = %s\n", InterpretState( puser->state ) );
  147. DebugPrint( " idUser = %lu\n", puser->idUser );
  148. DebugPrint( " tConnect = %08lX\n", puser->tConnect );
  149. DebugPrint( " tAccess = %08lX\n", puser->tAccess );
  150. DebugPrint( " xferType = %s\n", InterpretXferType( puser->xferType ) );
  151. DebugPrint( " xferMode = %s\n", InterpretXferMode( puser->xferMode ) );
  152. DebugPrint( " inetLocal = %s\n", inet_ntoa( puser->inetLocal ) );
  153. DebugPrint( " inetHost = %s\n", inet_ntoa( puser->inetHost ) );
  154. DebugPrint( " inetData = %s\n", inet_ntoa( puser->inetData ) );
  155. DebugPrint( " portData = %u\n", puser->portData );
  156. DebugPrint( " hDir = %08lX\n", puser->hDir );
  157. DebugPrint( " pIoBuffer = %08lX\n", puser->pIoBuffer );
  158. DebugPrint( " pszRename = %s\n", puser->pszRename );
  159. for( i = 0 ; i < 26 ; i++ )
  160. {
  161. if( puser->apszDirs[i] != NULL )
  162. {
  163. ReadProcessMemory( hCurrentProcess,
  164. puser->apszDirs[i],
  165. szDir,
  166. sizeof(szDir),
  167. (LPDWORD)NULL );
  168. DebugPrint( " dir %c: = %s\n", 'A'+i, szDir );
  169. }
  170. }
  171. DebugPrint( " szDir = %s\n", puser->szDir );
  172. DebugPrint( " szUser = %s\n", puser->szUser );
  173. DebugPrint( " idThread = %lu\n", puser->idThread );
  174. DebugPrint( "\n" );
  175. } // DumpUserInfo
  176. CHAR * InterpretState( USER_STATE state )
  177. {
  178. CHAR * pszResult = "unknown";
  179. switch( state )
  180. {
  181. case Embryonic :
  182. pszResult = "Embryonic";
  183. break;
  184. case WaitingForUser :
  185. pszResult = "WaitingForUser";
  186. break;
  187. case WaitingForPass :
  188. pszResult = "WaitingForPass";
  189. break;
  190. case LoggedOn :
  191. pszResult = "LoggedOn";
  192. break;
  193. case Disconnected :
  194. pszResult = "Disconnected";
  195. break;
  196. default :
  197. break;
  198. }
  199. return pszResult;
  200. } // InterpretState
  201. CHAR * InterpretXferType( XFER_TYPE xferType )
  202. {
  203. CHAR * pszResult = "unknown";
  204. switch( xferType )
  205. {
  206. case AsciiType :
  207. pszResult = "ASCII";
  208. break;
  209. case BinaryType :
  210. pszResult = "BINARY";
  211. break;
  212. default :
  213. break;
  214. }
  215. return pszResult;
  216. } // InterpretXferType
  217. CHAR * InterpretXferMode( XFER_MODE xferMode )
  218. {
  219. CHAR * pszResult = "unknown";
  220. switch( xferMode )
  221. {
  222. case StreamMode :
  223. pszResult = "STREAM";
  224. break;
  225. case BlockMode :
  226. pszResult = "BLOCK";
  227. break;
  228. default :
  229. break;
  230. }
  231. return pszResult;
  232. } // InterpretXferMode
  233. typedef struct FLAG_MAP
  234. {
  235. DWORD flag;
  236. CHAR * pszName;
  237. } FLAG_MAP;
  238. FLAG_MAP flag_map[] =
  239. {
  240. { UF_MSDOS_DIR_OUTPUT, "UF_MSDOS_DIR_OUTPUT" },
  241. { UF_ANNOTATE_DIRS, "UF_ANNOTATE_DIRS" },
  242. { UF_READ_ACCESS, "UF_READ_ACCESS" },
  243. { UF_WRITE_ACCESS, "UF_WRITE_ACCESS" },
  244. { UF_OOB_ABORT, "UF_OOB_ABORT" },
  245. { UF_RENAME, "UF_RENAME" },
  246. { UF_PASSIVE, "UF_PASSIVE" },
  247. { UF_ANONYMOUS, "UF_ANONYMOUS" },
  248. { UF_TRANSFER, "UF_TRANSFER" },
  249. { UF_OOB_DATA, "UF_OOB_DATA" }
  250. };
  251. #define NUM_FLAG_MAP (sizeof(flag_map) / sizeof(flag_map[0]))
  252. VOID InterpretFlags( DWORD dwFlags )
  253. {
  254. INT i;
  255. FLAG_MAP * pmap = flag_map;
  256. for( i = 0 ; i < NUM_FLAG_MAP ; i++ )
  257. {
  258. if( dwFlags & pmap->flag )
  259. {
  260. DebugPrint( " %s\n", pmap->pszName );
  261. dwFlags &= ~pmap->flag;
  262. }
  263. pmap++;
  264. }
  265. if( dwFlags != 0 )
  266. {
  267. DebugPrint( " Remaining flags = %08lX\n", dwFlags );
  268. }
  269. } // InterpretFlags