#include <windows.h>
#include <lm.h>
#include <stdio.h>
#pragma hdrstop


/*
*** IMPORTANT NOTE ***

The header files in at least two SDK versions are incorrect.
They declare NetEnumerateTrustedDomains() like this:
	NTSTATUS
	NetEnumerateTrustedDomains (
		IN LPWSTR ServerName OPTIONAL,
		OUT LPWSTR *DomainNames
		);

The _correct_ declaration is this:

	NTSTATUS NET_API_FUNCTION
	NetEnumerateTrustedDomains (
		IN LPWSTR ServerName OPTIONAL,
		OUT LPWSTR *DomainNames
		);

Note the added "NET_API_FUNCTION". Make sure you change your
headers (or write your own declaration)!

Cheers,

Felix.
*/



//	Link with netapi32
#pragma comment( lib, "netapi32.lib" )

#define lenof(a) (sizeof(a)/sizeof((a)[0]))



int main( int argc, char *argv[] )
{
	NTSTATUS ns; // for definitions, see ntstatus.h in the DDK
	wchar_t server[256], *domains = 0, *p;

	if ( argc != 2 )
	{
		puts( "usage: netd \\\\servername" );
		return 1;
	}

	mbstowcs( server, argv[1], lenof( server ) - 1 );
	server[lenof( server ) - 1] = L'\0';

	ns = NetEnumerateTrustedDomains( server, &domains );
	if ( ns )
		printf( "NETD() returned %lu [%08lXh]\n", ns, ns );

	for ( p = domains; p != 0 && *p != L'\0'; p += wcslen( p ) + 1 )
		printf( "\"%S\"\n", p ); // note -- capital-S in an ANSI prog outputs Unicode

	NetApiBufferFree( domains );

	return ns;
}

