Thischapter provides sample code that shows how to work with nodes. Finding a specific node, opening a
sessionwith the node, and authenticating a user to the node are fundamental Open Directory tasks.

Listing Registered Nodes

Thesample code in Listing 2-1 demonstrates how to get a list of all registered nodes. The sample code opens
anOpen Director y session and gets an Open Directory reference.Then it calls its own ListNodes routine.
TheListNodes routine calls dsGetDirNodeCount to get the number of registered nodes. If the number
ofregistered nodes is not zero, ListNodes calls dsDataBufferAllocate to allocate a data buffer and then
callsdsGetDirNodeList to fill the buffer with the list of registered node names. The ListNodes routine
thencalls dsDataListAllocate to allocate a data list and dsGetDirNodeName to fill the data list with
registerednode names from the data buffer. The ListNodes routine then calls its own PrintNodeName
routineto print the node names and passes to it a pointer to the data list.
ThePrintNodeName routine calls dsGetPathFromList to get a node name from the data list and prints
thename.
Whenthe PrintNodeName routine returns, the ListNodes routine cleans up by calling
dsDataListDeallocateand free() to deallocate the data list.
Listing2-1 Listingregistered nodes
tDirReference gDirRef = NULL;
void main ( )
{
long dirStatus = eDSNoErr;
dirStatus = dsOpenDirService( &gDirRef );
if ( dirStatus == eDSNoErr )
{
ListNodes();
}
if ( gDirRef != NULL )
{
dirStatus = dsCloseDirService( gDirRef );
}
}
void ListNodes ( void ) {
bool done = false;
long dirStatus = eDSNoErr;
unsigned long index = 0;
unsigned long nodeCount = 0;
unsigned long bufferCount = 0;
tDataBufferPtr dataBuffer = NULL;
tDataListPtr nodeName = NULL;
Listing Registered Nodes 25
2007-01-08 | ©2007 Apple Inc. All Rights Reserved.
CHAPTER 2
Working with Nodes