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.

235 lines
5.5 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ListConn.c
  5. Abstract:
  6. Command line test for getting the CONN_STATUS structures
  7. for various connections.
  8. Author:
  9. Cory West [corywest] 14-Nov-95
  10. ***/
  11. #include "ndsapi32.h"
  12. #include "ntddnwfs.h"
  13. ULONG DumpConnStatus(
  14. PCONN_STATUS pStatus
  15. );
  16. int
  17. _cdecl main(
  18. int argc,
  19. char **argv
  20. ) {
  21. NTSTATUS ntstatus;
  22. IO_STATUS_BLOCK IoStatusBlock;
  23. OBJECT_ATTRIBUTES ObjectAttributes;
  24. ACCESS_MASK DesiredAccess = SYNCHRONIZE | FILE_LIST_DIRECTORY;
  25. HANDLE hRdr;
  26. WCHAR OpenString[] = L"\\Device\\Nwrdr\\*";
  27. UNICODE_STRING OpenName;
  28. OEM_STRING OemArg;
  29. UNICODE_STRING NdsTree;
  30. WCHAR TreeBuffer[64];
  31. ULONG BufferSize = 256;
  32. ULONG RequestSize, ReplyLen;
  33. PNWR_REQUEST_PACKET Request;
  34. BYTE *Reply, *LocalBlock;
  35. DWORD Entries, BlockLen;
  36. //
  37. // Check the arguments.
  38. //
  39. if ( argc > 2 ) {
  40. printf( "Usage: listconn [tree | server]\n" );
  41. return -1;
  42. }
  43. //
  44. // Allocate buffer space.
  45. //
  46. Request = (PNWR_REQUEST_PACKET) LocalAlloc( LMEM_ZEROINIT, BufferSize );
  47. if ( !Request ) {
  48. printf( "Insufficient memory to complete the request.\n" );
  49. return -1;
  50. }
  51. //
  52. // Convert the argument name to unicode.
  53. //
  54. NdsTree.Length = 0;
  55. NdsTree.MaximumLength = sizeof( TreeBuffer );
  56. NdsTree.Buffer = TreeBuffer;
  57. if ( argc == 2 ) {
  58. OemArg.Length = strlen( argv[1] );
  59. OemArg.MaximumLength = OemArg.Length;
  60. OemArg.Buffer = argv[1];
  61. NdsTree.Length = 0;
  62. NdsTree.MaximumLength = sizeof( TreeBuffer );
  63. NdsTree.Buffer = TreeBuffer;
  64. RtlOemStringToUnicodeString( &NdsTree, &OemArg, FALSE );
  65. }
  66. //
  67. // Set up the object attributes.
  68. //
  69. RtlInitUnicodeString( &OpenName, OpenString );
  70. InitializeObjectAttributes( &ObjectAttributes,
  71. &OpenName,
  72. OBJ_CASE_INSENSITIVE,
  73. NULL,
  74. NULL );
  75. ntstatus = NtOpenFile( &hRdr,
  76. DesiredAccess,
  77. &ObjectAttributes,
  78. &IoStatusBlock,
  79. FILE_SHARE_VALID_FLAGS,
  80. FILE_SYNCHRONOUS_IO_NONALERT );
  81. if ( !NT_SUCCESS(ntstatus) )
  82. return ntstatus;
  83. //
  84. // Fill out the request packet for FSCTL_NWR_GET_CONN_STATUS.
  85. //
  86. Request->Parameters.GetConnStatus.ConnectionNameLength = NdsTree.Length;
  87. RtlCopyMemory( &(Request->Parameters.GetConnStatus.ConnectionName[0]),
  88. TreeBuffer,
  89. NdsTree.Length );
  90. RequestSize = sizeof( NWR_REQUEST_PACKET ) + NdsTree.Length;
  91. Reply = ((PBYTE)Request) + RequestSize;
  92. ReplyLen = BufferSize - RequestSize;
  93. do {
  94. ntstatus = NtFsControlFile( hRdr,
  95. NULL,
  96. NULL,
  97. NULL,
  98. &IoStatusBlock,
  99. FSCTL_NWR_GET_CONN_STATUS,
  100. (PVOID) Request,
  101. RequestSize,
  102. (PVOID) Reply,
  103. ReplyLen );
  104. if ( !NT_SUCCESS( ntstatus ) ) {
  105. goto ExitWithClose;
  106. }
  107. //
  108. // Print out this batch and see if we need to continue.
  109. //
  110. // ATTN!!! The only time that the caller needs to resize
  111. // the buffer is when there are no entries returned and the
  112. // status is STATUS_BUFFER_TOO_SMALL. When this happens,
  113. // the BytesNeeded field contains the smallest usable
  114. // buffer size.
  115. //
  116. Entries = Request->Parameters.GetConnStatus.EntriesReturned;
  117. printf( "%d entries returned for this call.\n", Entries );
  118. LocalBlock = Reply;
  119. while ( Entries-- ) {
  120. BlockLen = DumpConnStatus( (PCONN_STATUS) LocalBlock );
  121. LocalBlock += BlockLen;
  122. }
  123. } while ( Request->Parameters.GetConnStatus.ResumeKey != 0 );
  124. ExitWithClose:
  125. LocalFree( Request );
  126. NtClose( hRdr );
  127. return ntstatus;
  128. }
  129. ULONG DumpConnStatus(
  130. PCONN_STATUS pStatus
  131. ) {
  132. printf( "--------------------------------------------\n" );
  133. printf( "Server: %S\n", pStatus->pszServerName );
  134. printf( "User: %S\n", pStatus->pszUserName );
  135. printf( "NDS Tree: %S\n", pStatus->pszTreeName );
  136. printf( "Connection Number: %d\n", pStatus->nConnNum );
  137. if ( pStatus->fNds ) {
  138. printf( "Nds Connection: TRUE\n" );
  139. } else {
  140. printf( "Nds Connection: FALSE\n" );
  141. }
  142. if ( pStatus->fPreferred ) {
  143. printf( "Preferred Server: TRUE\n" );
  144. } else {
  145. printf( "Preferred Server: FALSE\n" );
  146. }
  147. switch ( pStatus->dwConnType ) {
  148. case NW_CONN_NOT_AUTHENTICATED:
  149. printf( "Authentication: NOT AUTHENTICATED\n" );
  150. break;
  151. case NW_CONN_BINDERY_LOGIN:
  152. printf( "Authentication: BINDERY LOGIN\n" );
  153. break;
  154. case NW_CONN_NDS_AUTHENTICATED_NO_LICENSE:
  155. printf( "Authentication: NDS AUTHENTICATED, NOT LICENSED\n" );
  156. break;
  157. case NW_CONN_NDS_AUTHENTICATED_LICENSED:
  158. printf( "Authentication: NDS AUTHENTICATED, LICENSED\n" );
  159. break;
  160. case NW_CONN_DISCONNECTED:
  161. printf( "Authentication: DISCONNECTED\n" );
  162. break;
  163. }
  164. printf( "--------------------------------------------\n" );
  165. return pStatus->dwTotalLength;
  166. }