Apple OS X Server User Manual


 
This chapter provides sample code that shows how to work with nodes. Finding a specific node, opening a
session with the node, and authenticating a user to the node are fundamental Open Directory tasks.
Listing Registered Nodes
The sample code in Listing 2-1 demonstrates how to get a list of all registered nodes. The sample code opens
an Open Directory session and gets an Open Directory reference. Then it calls its own ListNodes routine.
The ListNodes routine calls dsGetDirNodeCount to get the number of registered nodes. If the number
of registered nodes is not zero, ListNodes calls dsDataBufferAllocate to allocate a data buffer and then
calls dsGetDirNodeList to fill the buffer with the list of registered node names. The ListNodes routine
then calls dsDataListAllocate to allocate a data list and dsGetDirNodeName to fill the data list with
registered node names from the data buffer. The ListNodes routine then calls its own PrintNodeName
routine to print the node names and passes to it a pointer to the data list.
The PrintNodeName routine calls dsGetPathFromList to get a node name from the data list and prints
the name.
When the PrintNodeName routine returns, the ListNodes routine cleans up by calling
dsDataListDeallocate and free() to deallocate the data list.
Listing 2-1 Listing registered 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