Apple OS X manual Working with Nodes, Listing Registered Nodes

Page 25

C H A P T E R 2

Working with Nodes

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.

Image 25
Contents Open Directory Programming Guide Apple Inc Contents N T E N T S Figures, Tables, and Listings G U R E S , T a B L E S , a N D L I S T I N G S See Also Organization of This DocumentIntroduction See Also Open Directory Overview Concepts1Flow of an Open Directory request Nodes2An Open Directory request over a network Record Types Search Policies and Search NodesConstant Description Standard attribute for storing a unique ID commonly found Standard Attribute TypesNative Attribute Types AuthenticationBasic Authentication Open Directory Overview Local Windows Hash Authentication Local Cached User Authentication Disabled User Authentication Directory Proxy Directory Native AuthenticationOpen Directory, lookupd, and NetInfo 3lookupd and NetInfo interaction when using SSH Debugging Directory Service Command Line UtilityListing Registered Nodes Working with NodesWorking with Nodes Finding a Node Opening and Closing a Node Authenticating a User to a Node Authenticating using directory native authentication Directory Native AuthenticationWorking with Nodes Working with Nodes Authenticating a User to a Node Listing Records Working with RecordsListing Records Working with Records Getting Information About a Record’s AttributeGetting Information About a Record’s Attribute Setting the Name of a Record Working with Records Listing 3-3Setting the name of a record Creating a Record and Adding an Attribute Void CreateRecord const tDirNodeReference inDirNodeRef Deleting a Record Working with Records Document Revision History Document Revision History
Related manuals
Manual 32 pages 7.58 Kb