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.

156 lines
3.8 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ConnInfo.c
  5. Abstract:
  6. Command line test for getting the connection information
  7. for various connections.
  8. Author:
  9. Cory West [corywest] 14-Nov-95
  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 ConnectionName;
  27. WCHAR ConnectionBuffer[512];
  28. ULONG BufferSize = 512;
  29. ULONG RequestSize, ReplyLen;
  30. PNWR_REQUEST_PACKET Request;
  31. BYTE *Reply;
  32. PCONN_INFORMATION pConnInfo;
  33. UNICODE_STRING Name;
  34. //
  35. // Check the arguments.
  36. //
  37. if ( argc != 2 ) {
  38. printf( "Usage: conninfo [connection name]\n" );
  39. printf( "For Example: conninfo x:, conninfo lpt1:, or conninfo \\\\server\\share\n" );
  40. return -1;
  41. }
  42. //
  43. // Allocate buffer space.
  44. //
  45. Request = (PNWR_REQUEST_PACKET) LocalAlloc( LMEM_ZEROINIT, BufferSize );
  46. if ( !Request ) {
  47. printf( "Insufficient memory to complete the request.\n" );
  48. return -1;
  49. }
  50. //
  51. // Convert the connect name to unicode.
  52. //
  53. ConnectionName.Length = 0;
  54. ConnectionName.MaximumLength = sizeof( ConnectionBuffer );
  55. ConnectionName.Buffer = ConnectionBuffer;
  56. OemArg.Length = strlen( argv[1] );
  57. OemArg.MaximumLength = OemArg.Length;
  58. OemArg.Buffer = argv[1];
  59. RtlOemStringToUnicodeString( &ConnectionName, &OemArg, FALSE );
  60. //
  61. // Set up the object attributes.
  62. //
  63. RtlInitUnicodeString( &OpenName, OpenString );
  64. InitializeObjectAttributes( &ObjectAttributes,
  65. &OpenName,
  66. OBJ_CASE_INSENSITIVE,
  67. NULL,
  68. NULL );
  69. ntstatus = NtOpenFile( &hRdr,
  70. DesiredAccess,
  71. &ObjectAttributes,
  72. &IoStatusBlock,
  73. FILE_SHARE_VALID_FLAGS,
  74. FILE_SYNCHRONOUS_IO_NONALERT );
  75. if ( !NT_SUCCESS(ntstatus) )
  76. return ntstatus;
  77. //
  78. // Fill out the request packet for FSCTL_NWR_GET_CONN_INFO.
  79. //
  80. Request->Parameters.GetConnInfo.ConnectionNameLength = ConnectionName.Length;
  81. RtlCopyMemory( &(Request->Parameters.GetConnInfo.ConnectionName[0]),
  82. ConnectionBuffer,
  83. ConnectionName.Length );
  84. RequestSize = sizeof( Request->Parameters.GetConnInfo ) + ConnectionName.Length;
  85. Reply = ((PBYTE)Request) + RequestSize;
  86. ReplyLen = BufferSize - RequestSize;
  87. ntstatus = NtFsControlFile( hRdr,
  88. NULL,
  89. NULL,
  90. NULL,
  91. &IoStatusBlock,
  92. FSCTL_NWR_GET_CONN_INFO,
  93. (PVOID) Request,
  94. RequestSize,
  95. (PVOID) Reply,
  96. ReplyLen );
  97. if ( !NT_SUCCESS( ntstatus ) ) {
  98. goto ExitWithClose;
  99. }
  100. //
  101. // Print out the CONN_INFO that is in the reply buffer.
  102. //
  103. pConnInfo = (PCONN_INFORMATION) Reply;
  104. Name.Length = Name.MaximumLength = (USHORT) pConnInfo->HostServerLength;
  105. Name.Buffer = pConnInfo->HostServer;
  106. printf( "Host Server: %wZ\n", &Name );
  107. Name.Length = Name.MaximumLength = (USHORT) pConnInfo->UserNameLength;
  108. Name.Buffer = pConnInfo->UserName;
  109. printf( "User Name: %wZ\n", &Name );
  110. ExitWithClose:
  111. LocalFree( Request );
  112. NtClose( hRdr );
  113. return ntstatus;
  114. }