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.

133 lines
2.6 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. GetUser.c
  5. Abstract:
  6. This is the command line NDS utility for getting the
  7. user name used to log into a specified tree or server.
  8. Author:
  9. Cory West [corywest] 25-Oct-95
  10. ***/
  11. #include "ndsapi32.h"
  12. int
  13. _cdecl main(
  14. int argc,
  15. char **argv
  16. ) {
  17. NTSTATUS ntstatus;
  18. IO_STATUS_BLOCK IoStatusBlock;
  19. OBJECT_ATTRIBUTES ObjectAttributes;
  20. ACCESS_MASK DesiredAccess = SYNCHRONIZE | FILE_LIST_DIRECTORY;
  21. HANDLE hRdr;
  22. WCHAR DevicePreamble[] = L"\\Device\\Nwrdr\\";
  23. UINT PreambleLength = 14;
  24. WCHAR NameStr[64];
  25. UNICODE_STRING OpenName;
  26. UINT i;
  27. OEM_STRING OemArg;
  28. UNICODE_STRING NdsTree;
  29. WCHAR TreeBuffer[64];
  30. WCHAR Reply[64];
  31. //
  32. // Check the arguments.
  33. //
  34. if ( argc != 2 ) {
  35. printf( "Usage: getuser [tree | server]\n" );
  36. return -1;
  37. }
  38. //
  39. // Copy over the preamble.
  40. //
  41. OpenName.MaximumLength = sizeof( NameStr );
  42. for ( i = 0; i < PreambleLength ; i++ )
  43. NameStr[i] = DevicePreamble[i];
  44. //
  45. // Convert the argument name to unicode.
  46. //
  47. OemArg.Length = strlen( argv[1] );
  48. OemArg.MaximumLength = OemArg.Length;
  49. OemArg.Buffer = argv[1];
  50. NdsTree.Length = 0;
  51. NdsTree.MaximumLength = sizeof( TreeBuffer );
  52. NdsTree.Buffer = TreeBuffer;
  53. RtlOemStringToUnicodeString( &NdsTree, &OemArg, FALSE );
  54. //
  55. // Copy the server or tree name.
  56. //
  57. for ( i = 0 ; i < ( NdsTree.Length / sizeof( WCHAR ) ) ; i++ ) {
  58. NameStr[i + PreambleLength] = NdsTree.Buffer[i];
  59. }
  60. OpenName.Length = ( i * sizeof( WCHAR ) ) +
  61. ( PreambleLength * sizeof( WCHAR ) );
  62. OpenName.Buffer = NameStr;
  63. //
  64. // Set up the object attributes.
  65. //
  66. InitializeObjectAttributes( &ObjectAttributes,
  67. &OpenName,
  68. OBJ_CASE_INSENSITIVE,
  69. NULL,
  70. NULL );
  71. ntstatus = NtOpenFile( &hRdr,
  72. DesiredAccess,
  73. &ObjectAttributes,
  74. &IoStatusBlock,
  75. FILE_SHARE_VALID_FLAGS,
  76. FILE_SYNCHRONOUS_IO_NONALERT );
  77. if ( !NT_SUCCESS(ntstatus) )
  78. return ntstatus;
  79. ntstatus = NtFsControlFile( hRdr,
  80. NULL,
  81. NULL,
  82. NULL,
  83. &IoStatusBlock,
  84. FSCTL_NWR_GET_USERNAME,
  85. (PVOID) TreeBuffer,
  86. NdsTree.Length,
  87. (PVOID) Reply,
  88. sizeof( Reply ) );
  89. if ( NT_SUCCESS( ntstatus )) {
  90. NdsTree.Length = (USHORT)IoStatusBlock.Information;
  91. NdsTree.MaximumLength = NdsTree.Length;
  92. NdsTree.Buffer = Reply;
  93. printf( "%wZ", &NdsTree );
  94. }
  95. NtClose( hRdr );
  96. return ntstatus;
  97. }