Apple OS X manual Setting the Name of a Record

Page 37

C H A P T E R 3

Working with Records

if ( dirStatus == eDSNoErr )

{

attrType = dsDataNodeAllocateString(gDirRef, kDS1AttrPrimaryGroupID );

if ( attrType != NULL )

{

dirStatus = dsGetRecordAttributeInfo(recRef, attrType,

&pAttrInfo );

if ( pAttrInfo != NULL )

{

dirStatus = dsDeallocAttributeEntry( gDirRef, pAttrInfo

);

pAttrInfo = NULL;

}

dirStatus = dsDataNodeDeAllocate( gDirRef, attrType ); attrType = NULL;

}

}

dirStatus = dsDataNodeDeAllocate( gDirRef, recType ); recType = NULL;

}

dirStatus = dsDataNodeDeAllocate( gDirRef, recName ); recName = NULL;

}

} // GetRecInfo

Setting the Name of a Record

The sample code in Listing 3-3 demonstrates how to set the name of a record. The sample code opens an Open Directory session and gets an Open Directory reference. Then it calls its MyOpenDirNode routine and passes to it the address of the node reference (nodeRef) that it has allocated. The MyOpenDirNode routine is described in the section “Opening and Closing a Node” (page 28).

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

The SetRecordName routine calls dsDataNodeAllocateString to allocate a data node (recName) containing the string “testuser”. This is the current name of the record. Then the SetRecordName routine calls dsDataNodeAllocateString to allocate a data node (recType) that specifies the record type (kDSStdRecordTypeUsers) of the record whose name is to be set.

The SetRecordName routine then calls dsOpenRecord with recName and recType as parameters to specify the record to open. If SetRecordName successfully opens the record, it receives a record reference (recRef). Then SetRecordName calls dsDataNodeAllocateString to allocate a data node (newRecName) containing the string “Robert Smith” (the new name that is it be set). The SetRecordName routine then calls dsSetRecordName to set the record’s new name and dsCloseRecord to close the record. It then cleans up by calling dsDataNodeDeAllocate to reclaim the memory associated with recName, recType, and

newRecName.

When the SetRecordName routine returns, the sample code in Listing 3-3 calls dsCloseDirNode to close the node that it opened in order to set the record’s name.

Setting the Name of a Record

37

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

Image 37
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