No part of this publication may be reproduced,
stored in a retrieval system, or transmitted, in
any form or by any means, mechanical,
electronic, photocopying, recording, or
otherwise, without prior written permission of
Apple Inc., with the following exceptions: Any
person is hereby authorized to store
documentation on a single computer for
personal use only and to print copies of
documentation for personal use provided that
the documentation contains Apple’s copyright
notice.
The Apple logo is a trademark of Apple Inc.
Use of the “keyboard” Apple logo
(Option-Shift-K) for commercial purposes
without the prior written consent of Apple may
constitute trademark infringement and unfair
competition in violation of federal and state
laws.
No licenses, express or implied, are granted
with respectto any of the technologydescribed
in this document. Apple retains all intellectual
property rights associated with the technology
described in this document. This document is
intended to assist application developers to
develop applications only for Apple-labeled
computers.
Every effort has been made to ensure that the
information inthis document is accurate. Apple
is not responsible for typographical errors.
Apple Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
ASSUMING THE ENTIRE RISK AS TO ITS QUALITY
AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES RESULTINGFROM ANY
DEFECT OR INACCURACY IN THIS DOCUMENT,even
if advised of the possibility of such damages.
THE WARRANTY AND REMEDIES SET FORTH ABOVE
ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL
OR WRITTEN, EXPRESS OR IMPLIED. No Apple
dealer, agent, or employee is authorized to make
any modification, extension, or addition to this
warranty.
Some states do not allow the exclusion or limitation
of implied warranties or liability for incidental or
consequential damages, so the above limitation or
exclusion may not apply to you. This warranty gives
you specific legal rights, and you may also have
other rights which vary from state to state.
.Mac is a registered service mark of Apple Inc.
Apple, theApple logo,AppleTalk, Bonjour, Mac,
Mac OS, and QuickTime are trademarks of
Apple Inc., registered in the United States and
other countries.
UNIX is a registered trademark of The Open
Group
Simultaneously published in the United States
and Canada.
Even though Apple has reviewed this document,
APPLE MAKES NO WARRANTY OR REPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH RESPECT TO
THIS DOCUMENT, ITS QUALITY, ACCURACY,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR
PURPOSE. AS A RESULT, THIS DOCUMENT IS
PROVIDED “AS IS,” AND YOU, THE READER, ARE
Contents
Introduction
Chapter 1
Chapter 2
Introduction 7
Organization of This Document 7
See Also 7
Concepts 9
Open Directory Overview 9
Nodes 10
Search Policies and Search Nodes 12
Record Types 12
Standard Attribute Types 14
Native Attribute Types 15
Authentication 15
Directory Proxy 21
Open Directory, lookupd, and NetInfo 22
Directory Service Command Line Utility 24
Debugging 24
Working with Nodes 25
Chapter 3
Listing Registered Nodes 25
Finding a Node 27
Opening and Closing a Node 28
Authenticating a User to a Node 29
Directory Native Authentication 30
Working with Records 33
Listing Records 33
Getting Information About a Record’s Attribute 35
Setting the Name of a Record 37
Creating a Record and Adding an Attribute 39
Deleting a Record 41
Figure 1-1Flow of an Open Directory request 10
Figure 1-2An Open Directory request over a network 11
Figure 1-3lookupd and NetInfo interaction when using SSH 23
Figure 1-4lookupd, NetInfo, and Open Directory interaction when using SSH 23
Table 1-1Standard record types13
Table 1-2Standard attribute types14
Working with Nodes 25
Listing 2-1Listing registered nodes 25
Listing 2-2Finding the node for a pathname 27
Listing 2-3Opening a node 28
Listing 2-4Authenticating using directory native authentication 30
Working with Records 33
Listing 3-1Listing records in a node 34
Listing 3-2Getting information about a record’s attribute 36
Listing 3-3Setting the name of a record 38
Listing 3-4Creating and opening a record and adding an attribute 39
Listing 3-5Deleting a record 41
This manual describes the Open Directory application programming interface for Mac OS X v10.4. Open
Directory is a directory service architecture whose programming interface provides a centralized way for
applications and services toretrieve information stored in directories. The Open Directory architecture consists
of the DirectoryServices daemon, which receives Open Directory client API calls and sends them to the
appropriate Open Directory plug-in.
Organization of This Document
This book contains the following chapters:
■“Concepts” (page 9) describes the concepts used in the Open Directory architecture.
■“Working with Nodes” (page 25) explains how to use the Open Directory API interact with nodes.
■“Working with Records” (page 33) explains how to use the Open Directory API to interact with records.
See Also
Refer to the following reference document for Open Directory:
■Open Directory Reference
For more information about writing plug-ins for Open Directory, read:
Open Directory is a directory service architecture whose programming interface provides a centralized way
for applications and services to retrieve information stored in directories. Often, the information that is being
sought is configuration information stored in a NetInfo database or in flat files, with each file having its own
record format and field delimiters. Examples of configuration information include users and groups
(/etc/passwd and /etc/group), and automount information (/mounts). Open Directory uses standard
record types and attributes to describe configuration information so that Open Directory clients have no
need to know the details of record formats and data encoding.
Earlier directory services, such as lookupd and NetInfo, took the first steps in providing access to configuration
information but were limited in their capabilities. For example, lookupd provides support for reading but
does not provide support for writing, and it does not provide support for authentication. Open Directory
continues the evolution of directory services by providingexpanded functionality. For example, Open Directory
can writedata as well as read it, and Open Directory includessupport for a variety of authentication methods.
While providing support for lookupd and NetInfo, Open Directory’s primary protocol is LDAP (supporting
LDAPv2 and LDAPv3). As a result, Open Directory provides a way of accessing and sharing data using both
LDAP and NetInfo. Open Directory provides seamless and automatic integration of Apple Computer’s directory
services and third-party directory services including Active Directory, iPlanet and OpenLDAP.
Open Directory Overview
Open Directory consists of the DirectoryService daemon and Open Directory plug-ins. Apple Computer
provides Open Directory plug-ins for LDAPv3 (which supports LDAPv2), NetInfo, AppleTalk, SLP, Windows,
and Bonjour. The AppleTalk, SLP, SMB, and Bonjour Open Directory plug-ins discover services that are available
on the local network. In Mac OS X, lookupd resolves DNS queries through UNIX function calls like
gethostbyname(). TheOpen Directory LDAP plug-in provides information aboutusers and groups of users.
For information on writing your own Open Directory plug-in, see the document Open Directory Plug-ins.
The Open Directory programming interface identifies the basic features that are common to many directory
services and provides the functions necessary to support the development of high-quality applications that
can work with a wide range of dissimilar directory services.
Nodes
From the viewpoint of Open Directory, a directory service is a collection of one or more nodes, where a node
is a place that can be searched for information. Each NetInfo database in a hierarchy and each LDAP service
configured by the Directory Access tool is a separate node. The following rules apply to nodes.
■A node is either the root of a directory or a child of another node.
■A registered node is a node that an Open Directory plug-in has registered with Open Directory or that
an administrator has registered using the Directory Access tool.
■A node is a collection of records and child nodes.
■A record can belong only to one node.
■A record has a type and can be of no more than one type. Examples of record types include user records
and group records.
■A record has a name and type that together make the record unique within its node. For example, there
can’t be two user records that have the name “admin,” but there can be a user record named “admin”
and a group record named “admin” within the same node.
■Nodes and records can contain any number of attributes.
■An attribute can have a value. Certain attributes can have more than one value.
■An attribute value is arbitrary data whose structure is unknown to the Open Directory programming
Figure 1-2 (page 11) shows how Open Directory and the Open Directory LDAPv3 and NetInfo plug-ins might
Note:An Open Directory plug-in is not required to return information that conforms exactly to the information
that the directory service maintains. A plug-in can generate information “on the fly.” In addition, a plug-in
may not return information about certain nodes; the plug-in's behavior in this respect can be configurable.
Search Policies and Search Nodes
A search policy defines the locations that are to be searched and the order in which those locations are
searched in order to get certain kinds of information. The first location that a search policy defines must be
the local NetInfo database.
Search nodes implement search policies, which are configured by administrators through the Directory Access
application. Search nodes are easy for Open Directory applications to find and are guaranteed to always be
available.
There are four search node types:
■authentication search node — Use this search node when you are looking for information that is needed
to authenticate a user. Use the pattern matching constant eDSAuthenticationSearchNodeName to
locate theauthentication search node. Examples of applications that use the authentication search node
include the login window and applications that set System Preferences. The authentication search node
is also used indirectly by all UNIX commands that use lookupd.
■contacts search node — Use this search node when you are looking for contact information, such as an
e-mail address, a telephone number, or a street address. Use the pattern matching constant
eDSContactsSearchNodeName to locate the contacts search node. Mail.app and Address Book use the
contacts search node to look up e-mail addresses and other types of contact information.
■network search node — Use this search node, which consolidates all of the nodes that are local to a
machine for service discovery purposes, to find services on the local network. When third-party Open
Directory plug-ins are loaded, they register their nodes with Open Directory so they can be found by
the network search node. Use the pattern matching constant eDSNetworkSearchNodeName to locate
the network search node.
■locally hosted nodes — Use a locally hosted node to find NetInfo domains stored on this machine (that
is, the local domain plus any shared domains that are running locally). Locally hosted nodes are a class
of nodes that have a special pattern match. Use the pattern matching constant eDSLocalHostedNodes
to locate locally hosted nodes.
When an Open Directory client application uses a search node to search for information, it can request the
fully qualified path for any record that matches a specific search criteria. As a result, Open Directory can
perform extremely precise searches and a high degree of control over the type of information that is returned.
Record Types
Apple Computer has defined a series of standard record types. The standard record types include but are
not limited to user records, group records, machine records, and printer records.
12
Providers of services can define their own record types (known as native record types) and are encouraged
to publishinformation about them. Developers are encouraged touse Apple’s standard record typeswhenever
possible.
Standard record for storing quota usage for a user in the
local node
Standard record for storing bootp informationkDSStdRecordTypeBootp
Standard record for storing net domainskDSStdRecordTypeNetDomains
Standard record for storing EthernetskDSStdRecordTypeEthernets
Standard record for storing net groupskDSStdRecordTypeNetGroups
Standard record for storing host serviceskDSStdRecordTypeHostServices
Standard Attribute Types
Apple Computer has defined a series of standard attributes. Developers can define their own attributes
(known as native attributes). An attribute can be required or optional. Each record type defines the attributes
that it requires.
Open Directory clients are responsible for interpreting the value of any particular attribute. All configuration
and discovery of information in the directory service can be accomplished by requesting the appropriate
attribute value.
Table 1-2 lists some of the standard attribute types. See the Open Directory Reference section for the complete
list of attributes. Constants for attributes that start with kDS1 represent attributes that can only have one
value; constants for attributes that start with kDSN represent attributes that can have multiple values.
Table 1-2Standard attribute types
DescriptionConstant
kDS1AttrPassword
kDS1AttrUniqueID
kDS1AttrPrimaryGroupID
kDS1AttrComment
kDS1AttrUserShell
kDS1AttrPrintServiceUserData
Standard attribute for storing a password; commonly found in
kDSStdRecordTypeUsers records
Standard attribute for storing a unique ID; commonly found in
kDSStdRecordTypeUsers records
Standard attribute for storing a Primary Group ID; commonly found in
kDSStdRecordTypeUsers and kDSStdRecordTypeGroups records
Standard attribute for storing a comment; commonly found in
kDSStdRecordTypeGroup, kDSStdRecordTypeUsers,
kDSStdRecordTypeComputers and other preset records
Standard attribute for storing the user’s shell; commonly found in
kDSStdRecordTypeUsers records
Standard attribute for print quota configuration or statistics; commonly
found in kDStdRecordTypePrintServiceUser records