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.

182 lines
4.3 KiB

  1. /***
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. Treebn.c
  5. Abstract:
  6. Command line test for getting the connection information
  7. for a particular NT user name.
  8. Author:
  9. Cory West [corywest] 1-March-1996
  10. ***/
  11. #include "ndsapi32.h"
  12. #include "ntddnwfs.h"
  13. int
  14. _cdecl main(
  15. int argc,
  16. char **argv
  17. ) {
  18. NTSTATUS ntstatus;
  19. IO_STATUS_BLOCK IoStatusBlock;
  20. OBJECT_ATTRIBUTES ObjectAttributes;
  21. ACCESS_MASK DesiredAccess = SYNCHRONIZE | FILE_LIST_DIRECTORY;
  22. HANDLE hRdr;
  23. WCHAR OpenString[] = L"\\Device\\Nwrdr\\*";
  24. UNICODE_STRING OpenName;
  25. OEM_STRING OemArg;
  26. UNICODE_STRING NtUserName;
  27. WCHAR NtUserBuffer[512];
  28. ULONG BufferSize = 4096;
  29. BYTE *Reply;
  30. PNWR_NDS_REQUEST_PACKET Request;
  31. BYTE RequestBuffer[2048];
  32. ULONG RequestSize;
  33. PCONN_INFORMATION pConnInfo;
  34. UNICODE_STRING Name;
  35. DWORD dwTrees, dwSize;
  36. //
  37. // Check the arguments.
  38. //
  39. if ( argc != 2 ) {
  40. printf( "Usage: treebn [nt user name]\n" );
  41. return -1;
  42. }
  43. //
  44. // Allocate buffer space.
  45. //
  46. Reply = LocalAlloc( LMEM_ZEROINIT, BufferSize );
  47. if ( !Reply ) {
  48. printf( "Insufficient memory to complete the request.\n" );
  49. return -1;
  50. }
  51. //
  52. // Convert the user name to unicode.
  53. //
  54. NtUserName.Length = 0;
  55. NtUserName.MaximumLength = sizeof( NtUserBuffer );
  56. NtUserName.Buffer = NtUserBuffer;
  57. OemArg.Length = strlen( argv[1] );
  58. OemArg.MaximumLength = OemArg.Length;
  59. OemArg.Buffer = argv[1];
  60. RtlOemStringToUnicodeString( &NtUserName, &OemArg, FALSE );
  61. //
  62. // Set up the object attributes.
  63. //
  64. RtlInitUnicodeString( &OpenName, OpenString );
  65. InitializeObjectAttributes( &ObjectAttributes,
  66. &OpenName,
  67. OBJ_CASE_INSENSITIVE,
  68. NULL,
  69. NULL );
  70. ntstatus = NtOpenFile( &hRdr,
  71. DesiredAccess,
  72. &ObjectAttributes,
  73. &IoStatusBlock,
  74. FILE_SHARE_VALID_FLAGS,
  75. FILE_SYNCHRONOUS_IO_NONALERT );
  76. if ( !NT_SUCCESS(ntstatus) )
  77. return ntstatus;
  78. //
  79. // Fill out the request packet for FSCTL_NWR_NDS_LIST_TREES;
  80. //
  81. Request = ( PNWR_NDS_REQUEST_PACKET ) RequestBuffer;
  82. Request->Parameters.ListTrees.NtUserNameLength = NtUserName.Length;
  83. RtlCopyMemory( &(Request->Parameters.ListTrees.NtUserName[0]),
  84. NtUserBuffer,
  85. NtUserName.Length );
  86. RequestSize = sizeof( Request->Parameters.ListTrees ) +
  87. NtUserName.Length +
  88. sizeof( DWORD );
  89. ntstatus = NtFsControlFile( hRdr,
  90. NULL,
  91. NULL,
  92. NULL,
  93. &IoStatusBlock,
  94. FSCTL_NWR_NDS_LIST_TREES,
  95. (PVOID) Request,
  96. RequestSize,
  97. (PVOID) Reply,
  98. BufferSize );
  99. if ( !NT_SUCCESS( ntstatus ) ) {
  100. goto ExitWithClose;
  101. }
  102. //
  103. // Print out the CONN_INFO array that is in the reply buffer.
  104. //
  105. dwTrees = Request->Parameters.ListTrees.TreesReturned;
  106. printf( "Returned %d trees.\n", dwTrees );
  107. printf( "Luid was %08lx\n", Request->Parameters.ListTrees.UserLuid.LowPart );
  108. printf( "------------------------\n" );
  109. pConnInfo = (PCONN_INFORMATION) Reply;
  110. while ( dwTrees > 0 ) {
  111. dwSize = sizeof( CONN_INFORMATION );
  112. Name.Length = Name.MaximumLength = (USHORT) pConnInfo->HostServerLength;
  113. Name.Buffer = pConnInfo->HostServer;
  114. printf( "Tree: %wZ\n", &Name );
  115. dwSize += Name.Length;
  116. Name.Length = Name.MaximumLength = (USHORT) pConnInfo->UserNameLength;
  117. Name.Buffer = pConnInfo->UserName;
  118. printf( "User Name: %wZ\n", &Name );
  119. dwSize += Name.Length;
  120. pConnInfo = (PCONN_INFORMATION) ( ((BYTE *)pConnInfo) + dwSize );
  121. dwTrees--;
  122. printf( "------------------------\n" );
  123. }
  124. ntstatus = STATUS_SUCCESS;
  125. ExitWithClose:
  126. LocalFree( Request );
  127. NtClose( hRdr );
  128. return ntstatus;
  129. }