summaryrefslogtreecommitdiffstats
path: root/private/nw/ndsutils/treebn.c
diff options
context:
space:
mode:
authorAdam <you@example.com>2020-05-17 05:51:50 +0200
committerAdam <you@example.com>2020-05-17 05:51:50 +0200
commite611b132f9b8abe35b362e5870b74bce94a1e58e (patch)
treea5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/nw/ndsutils/treebn.c
downloadNT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip
Diffstat (limited to 'private/nw/ndsutils/treebn.c')
-rw-r--r--private/nw/ndsutils/treebn.c182
1 files changed, 182 insertions, 0 deletions
diff --git a/private/nw/ndsutils/treebn.c b/private/nw/ndsutils/treebn.c
new file mode 100644
index 000000000..77a735e37
--- /dev/null
+++ b/private/nw/ndsutils/treebn.c
@@ -0,0 +1,182 @@
+/***
+
+Copyright (c) 1996 Microsoft Corporation
+
+Module Name:
+
+ Treebn.c
+
+Abstract:
+
+ Command line test for getting the connection information
+ for a particular NT user name.
+
+Author:
+
+ Cory West [corywest] 1-March-1996
+
+***/
+
+#include "ndsapi32.h"
+#include "ntddnwfs.h"
+
+int
+_cdecl main(
+ int argc,
+ char **argv
+) {
+
+ NTSTATUS ntstatus;
+ IO_STATUS_BLOCK IoStatusBlock;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ ACCESS_MASK DesiredAccess = SYNCHRONIZE | FILE_LIST_DIRECTORY;
+ HANDLE hRdr;
+
+ WCHAR OpenString[] = L"\\Device\\Nwrdr\\*";
+ UNICODE_STRING OpenName;
+
+ OEM_STRING OemArg;
+ UNICODE_STRING NtUserName;
+ WCHAR NtUserBuffer[512];
+
+ ULONG BufferSize = 4096;
+ BYTE *Reply;
+
+ PNWR_NDS_REQUEST_PACKET Request;
+ BYTE RequestBuffer[2048];
+ ULONG RequestSize;
+
+ PCONN_INFORMATION pConnInfo;
+ UNICODE_STRING Name;
+ DWORD dwTrees, dwSize;
+
+ //
+ // Check the arguments.
+ //
+
+ if ( argc != 2 ) {
+ printf( "Usage: treebn [nt user name]\n" );
+ return -1;
+ }
+
+ //
+ // Allocate buffer space.
+ //
+
+ Reply = LocalAlloc( LMEM_ZEROINIT, BufferSize );
+
+ if ( !Reply ) {
+ printf( "Insufficient memory to complete the request.\n" );
+ return -1;
+ }
+
+ //
+ // Convert the user name to unicode.
+ //
+
+ NtUserName.Length = 0;
+ NtUserName.MaximumLength = sizeof( NtUserBuffer );
+ NtUserName.Buffer = NtUserBuffer;
+
+ OemArg.Length = strlen( argv[1] );
+ OemArg.MaximumLength = OemArg.Length;
+ OemArg.Buffer = argv[1];
+
+ RtlOemStringToUnicodeString( &NtUserName, &OemArg, FALSE );
+
+ //
+ // Set up the object attributes.
+ //
+
+ RtlInitUnicodeString( &OpenName, OpenString );
+
+ InitializeObjectAttributes( &ObjectAttributes,
+ &OpenName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL );
+
+ ntstatus = NtOpenFile( &hRdr,
+ DesiredAccess,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ FILE_SHARE_VALID_FLAGS,
+ FILE_SYNCHRONOUS_IO_NONALERT );
+
+ if ( !NT_SUCCESS(ntstatus) )
+ return ntstatus;
+
+ //
+ // Fill out the request packet for FSCTL_NWR_NDS_LIST_TREES;
+ //
+
+ Request = ( PNWR_NDS_REQUEST_PACKET ) RequestBuffer;
+
+ Request->Parameters.ListTrees.NtUserNameLength = NtUserName.Length;
+
+ RtlCopyMemory( &(Request->Parameters.ListTrees.NtUserName[0]),
+ NtUserBuffer,
+ NtUserName.Length );
+
+ RequestSize = sizeof( Request->Parameters.ListTrees ) +
+ NtUserName.Length +
+ sizeof( DWORD );
+
+ ntstatus = NtFsControlFile( hRdr,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatusBlock,
+ FSCTL_NWR_NDS_LIST_TREES,
+ (PVOID) Request,
+ RequestSize,
+ (PVOID) Reply,
+ BufferSize );
+
+ if ( !NT_SUCCESS( ntstatus ) ) {
+ goto ExitWithClose;
+ }
+
+ //
+ // Print out the CONN_INFO array that is in the reply buffer.
+ //
+
+ dwTrees = Request->Parameters.ListTrees.TreesReturned;
+ printf( "Returned %d trees.\n", dwTrees );
+ printf( "Luid was %08lx\n", Request->Parameters.ListTrees.UserLuid.LowPart );
+
+ printf( "------------------------\n" );
+
+ pConnInfo = (PCONN_INFORMATION) Reply;
+
+ while ( dwTrees > 0 ) {
+
+ dwSize = sizeof( CONN_INFORMATION );
+
+ Name.Length = Name.MaximumLength = (USHORT) pConnInfo->HostServerLength;
+ Name.Buffer = pConnInfo->HostServer;
+ printf( "Tree: %wZ\n", &Name );
+
+ dwSize += Name.Length;
+
+ Name.Length = Name.MaximumLength = (USHORT) pConnInfo->UserNameLength;
+ Name.Buffer = pConnInfo->UserName;
+ printf( "User Name: %wZ\n", &Name );
+
+ dwSize += Name.Length;
+
+ pConnInfo = (PCONN_INFORMATION) ( ((BYTE *)pConnInfo) + dwSize );
+ dwTrees--;
+
+ printf( "------------------------\n" );
+ }
+
+ ntstatus = STATUS_SUCCESS;
+
+ExitWithClose:
+
+ LocalFree( Request );
+ NtClose( hRdr );
+ return ntstatus;
+
+}