Apple OS X manual Creating a Record and Adding an Attribute

Page 39

C H A P T E R 3

Working with Records

Note that for this example to work, it would have to be run by a root process on the local NetInfo domain, or by a user process that has called dsDoDirNodeAuth with the inDirNodeAuthOnlyFlag parameter set to FALSE to get permission to make this change.

Creating a Record and Adding an Attribute

The sample code in Listing 3-4 demonstrates how to create a record, open it, and add an attribute to it. 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 CreateRecord routine and passes to it the node reference (nodeRef) obtained by calling its MyOpenDirNode routine.

The CreateRecord routine calls dsDataNodeAllocateString to allocate a data node (recName) containing the string “NewUserRecordName” and another data node (recType) specifying kDSStdRecordTypeUsers as the record type for the record that is to be created.

Then the CreateRecord routine then calls dsCreateRecordAndOpen, passing to it the node reference created when dsOpenDirService was called, recName, recType, and the address of a record reference value (recRef) initialized to zero. If dsCreateRecordAndOpen returns successfully, recRef will contain a record reference that the CreateRecord routine will use to add an attribute for the record.

The CreateRecord routine then calls dsDataNodeAllocateString to allocate a data node (attrName) containing kDS1AttrDistinguishedName. It also calls dsDataNodeAllocateString to allocate a data node containing the string “User Record’s Display Name”, which will be set as the value of the attribute.

To add the attribute and set its value, the CreateRecord routine calls dsAddAttribute. It then cleans up by calling dsCloseRecord to close the record and dsDataNodeDeAllocate to reclaim the memory associated with attrName, recType, and recName.

When the CreateRecord routine returns, the sample code in Listing 3-4 calls dsCloseDirNode to close the node that it opened in order to create and open the record.

Listing 3-4Creating and opening a record and adding an attribute

void main ( )

{

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

{

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

{

CreateRecord( nodeRef ); dsCloseDirNode( nodeRef );

}

}

if ( gDirRef != NULL )

{

dirStatus = dsCloseDirService( gDirRef );

Creating a Record and Adding an Attribute

39

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

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