Apple OS X manual Getting Information About a Record’s Attribute

Page 36

C H A P T E R 3

Working with Records

The sample code then calls its GetRecInfo routine and passes to it the node reference (nodeRef) obtained by calling its MyOpenDirNode routine.

The GetRecInfo routine calls dsDataNodeAllocateString to allocate two data nodes: one named recName allocated using the string “admin” and one named recType using the constant kDSStdRecordTypeGroups. Then the GetRecInfo routine calls dsOpenRecord to open the record whose name and record type match recName and recType.

If dsOpenRecord returns successfully, the GetRecInfo routine calls dsDataNodeAllocateString to allocate a data node (attrType) containing the constant kDS1AttrPrimaryGroupID. It then calls dsGetRecordAttributeInfo using attrType to specify which attribute to get information for. The dsGetRecordAttributeInfo function stores the attribute’s information in a tAttributeEntry structure.

To clean up, GetRecInfo calls dsDeallocAttributeEntry to deallocate the memory associated with pAttrInfo and call dsDataNodeDeAllocate to reclaim the memory asociated with attrType, recName, and recType.

When the GetRecInfo routine returns, the sample code in Listing 3-2 calls dsCloseDirNode to close the node that it opened in order to get the information about a record’s attribute.

Listing 3-2Getting information about a record’s attribute

void main ( )

{

long dirStatus = eDSNoErr; tDirNodeReference nodeRef = NULL; dirStatus = dsOpenDirService( &gDirRef ); if ( dirStatus == eDSNoErr )

{

dirStatus = MyOpenDirNode( &nodeRef ); if ( dirStatus == eDSNoErr )

{

GetRecInfo(nodeRef); dsCloseDirNode( nodeRef );

}

}

if ( gDirRef != NULL )

{

dirStatus = dsCloseDirService( gDirRef );

}

}

void GetRecInfo ( const tDirNodeReference inDirNodeRef )

{

long dirStatus = eDSNoErr; tRecordReference recRef = NULL; tAttributeEntryPtr pAttrInfo = NULL; tDataNodePtr recName = NULL; tDataNodePtr recType = NULL; tDataNodePtr attrType = NULL;

recName = dsDataNodeAllocateString( gDirRef, "admin" ); if ( recName != NULL )

{

recType = dsDataNodeAllocateString( gDirRef, kDSStdRecordTypeGroups); if ( recType != NULL )

{

dirStatus = dsOpenRecord( inDirNodeRef, recType, recName, &recRef

);

36Getting Information About a Record’s Attribute

2007-01-08 © 2007 Apple Inc. All Rights Reserved.

Image 36
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 Organization of This Document See AlsoIntroduction See Also Concepts Open Directory OverviewNodes 1Flow of an Open Directory request2An Open Directory request over a network Search Policies and Search Nodes Record TypesConstant Description Standard Attribute Types Standard attribute for storing a unique ID commonly foundAuthentication Native Attribute TypesBasic Authentication Open Directory Overview Local Windows Hash Authentication Local Cached User Authentication Disabled User Authentication Directory Native Authentication Directory ProxyOpen Directory, lookupd, and NetInfo 3lookupd and NetInfo interaction when using SSH Directory Service Command Line Utility DebuggingWorking with Nodes Listing Registered NodesWorking with Nodes Finding a Node Opening and Closing a Node Authenticating a User to a Node Directory Native Authentication Authenticating using directory native authenticationWorking with Nodes Working with Nodes Authenticating a User to a Node Working with Records Listing RecordsListing Records Getting Information About a Record’s Attribute Working with RecordsGetting 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