Tech Support > Microsoft Windows > Development Resources > getting available nt domains
getting available nt domains
Posted by hs on June 8th, 2004



Hi!

Sorry if this topic comes back again, but the code I have found in msdn and
in google doesn't work for me. I need a list of nt domains, as it is shown
in a combo box after winlogon starts up.

a function GetPolicyHandle was found here
http://msdn.microsoft.com/library/de...us/security/se
curity/opening_a_policy_object_handle.asp

I get no entries in LsaEnumerateTrustedDomains but there is at least one
domain that I can log into
from my computer.

--
thanks in advance
hs

my function is here
void listDomains ()
{
LSA_HANDLE policy = GetPolicyHandle ();
LSA_ENUMERATION_HANDLE enumh;

ULONG l = 0, i;
NTSTATUS status;
USES_CONVERSION;
PLSA_TRUST_INFORMATION trustInfo = NULL;
WCHAR StringBuffer[256];


WriteLog ("list domains");
if (!policy)
{
WriteLog ("policy NULL!");
return;
}
ZeroMemory (&enumh, sizeof (enumh));
while (1)
{
WriteLog ("enumerate trusted domains...");
status = LsaEnumerateTrustedDomains (policy, &enumh, (PVOID*) &trustInfo,
32000, &l);
if (status == STATUS_NO_MORE_ENTRIES)
{
WriteLog ("no more entries");
break;
}
WriteLog ("found %d entries", l);
for (i=0; i<l; i++)


if( trustInfo[i].Name.Length < 256 )
{
wcsncpy(StringBuffer,
trustInfo[i].Name.Buffer,
trustInfo[i].Name.Length
);
StringBuffer[trustInfo[i].Name.Length] = (WCHAR) NULL;
WriteLog("%d %s", i, W2T (StringBuffer));
}


}
LsaFreeMemory (trustInfo);
if (status == STATUS_SUCCESS)
break;
}
}





Posted by hs on June 8th, 2004


I reply to myself

here is the needed code

#include <stdafx.h>


#include <atlbase.h>

#ifndef UNICODE
#define UNICODE
#endif

file://#include <stdio.h>
file://#include <assert.h>
#include <windows.h>
#include <lm.h>



#include "XGina.h"


void listDomains ()
{
LPSERVER_INFO_101 pBuf = NULL;
LPSERVER_INFO_101 pTmpBuf;
DWORD dwLevel = 101;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwTotalCount = 0;
DWORD dwServerType = SV_TYPE_DOMAIN_ENUM;
file://SV_TYPE_DOMAIN_CTRL;//SV_TYPE_SERVER; // all servers
DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
DWORD i;

USES_CONVERSION;

//
// Call the NetServerEnum function to retrieve information
// for all servers, specifying information level 101.
//
nStatus = NetServerEnum(NULL,
dwLevel,
(LPBYTE *) &pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
dwServerType,
NULL,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries and
// print the data for all server types.
//
for (i = 0; i < dwEntriesRead; i++)
{

if (pTmpBuf == NULL)
{
WriteLog("An access violation has occurred\n");
break;
}

if ((pTmpBuf->sv101_type & SV_TYPE_DOMAIN_CTRL) ||
(pTmpBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL))
{
WriteLog("\tPlatform: %d", pTmpBuf->sv101_platform_id);
WriteLog("\tName: %s", W2T((unsigned short*)pTmpBuf->sv101_name));
WriteLog("\tVersion: %d.%d",
pTmpBuf->sv101_version_major,
pTmpBuf->sv101_version_minor);
WriteLog("\tType: %d", pTmpBuf->sv101_type);
}


file://wprintf(L"\tComment: %s\n\n", pTmpBuf->sv101_comment);

pTmpBuf++;
dwTotalCount++;
}
// Display a warning if all available entries were
// not enumerated, print the number actually
// enumerated, and the total number available.

if (nStatus == ERROR_MORE_DATA)
{
WriteLog ("\nMore entries available!!!\n");
WriteLog("Total entries: %d", dwTotalEntries);
}

}
}
else
WriteLog("A system error has occurred: %d", nStatus);
//
// Free the allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);

}



Posted by Richard Ward on June 15th, 2004


That's not reliable since it is based on the old bowser
support. DsGetDcName() and DsEnumerateDomainTrusts()
are the functions you're looking for.


"hs" <nospam@del.null> wrote in message news:ca4gua$nns$1@news.onet.pl...



Similar Posts