he Directory SDK includes command-line utilities for searching and updating the directory. If you want to write shell scripts or simple programs for working with an LDAP server, you can use these utilities.
The command-line utilities provided with the Directory SDK allow you to do the following:
NOTE: If you are not adding or modifying entries, you can skip ahead to the next section "Using the Command-Line Utilities".The LDAP Data Interchange Format (LDIF) is used to represent entries or information about entries in text form.
dn: cn=June Rossi, ou=accounting, o=Ace Industry, c=US
cn: June Rossi
sn: Rossi
givenName: June
mail: rossi@aceindustry.com
userPassword: {sha}KDIE3AL9DK
telephoneNumber: 2616
roomNumber: 220
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
[<id>]Every new entry that you want to add must have the following information in LDIF: All other attributes and object classes are optional. You can specify object classes and attributes in any order. The following table describes the LDIF fields shown in the previous definition:
dn: <distinguished name>
objectClass: <object class>
objectClass: <object class>
...
<attribute type>:<attribute value>
<attribute type>:<attribute value>
...t
When you specify lines in LDIF, you can break and continue a line by indenting the continued portion of the line by exactly one space. For example, the following two statements are identical:
dn: cn=Jake Lupinski, ou=Accounting, o=Ace Industry, c=US
dn: cn=Jake Lup
inski, ou=Accoun
ting, o=Ace Industr
y, c=US Specifying an Organizational Person
The most common type of entry that you will include in your directory will describe a person within your organization. The LDIF you specify to define an organizational person should appear as follows:
dn: distinguished name
The following defines each aspect of the LDIF-formatted entry:
cn: common name
sn: surname
list of optional attributes
...
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPersondn: distinguished name
Specifies the DN for the entry. DNs are described in Appendix A,
"Distinguished Names.". A DN is required.
cn: common name
Specifies the common name for the person. That is, the full name
commonly used by the person. For example, cn: Bill Anderson. A
common name is required.
sn: surname
Specifies the person's surname, or last name. For example,
sn: Anderson. A surname is required.
list of attributes
Specifies the list of optional attributes that you want to maintain for the
entry. Refer to the online documentation that comes with the server for a
list of the attributes you can use with this object class. See Appendix A,
"Object classes and attributes".
objectClass: top
Specifies the top object class. This object class specification is optional.
Some older LDAP clients will require the existence of object class top
during search operations.
objectClass: person
Specifies the person object class. This object class specification should be
included because many LDAP clients will require the existence of object
class person during search operations for a person or an organizational
person.
objectClass: organizationalPerson
Specifies the organizationalPerson object class. This object class
specification should be included because some LDAP clients will require
the existence of object class organizationalPerson during search
operations for an organizational person.
objectClass: inetOrgPerson
Specifies the inetOrgPerson object class. The inetOrgPerson object
class is recommended for the creation of an organizational person entry
because this object class includes the widest range of attributes. Refer to the
online documentation that comes with the server for a list of the attributes
you can use with this object class. See Appendix A, "Object classes and
attributes".
Example: Using an LDIF File to Add Entries
The following example shows an LDIF file that contains three organizational person entries:
dn: cn=June Rossi, ou=accounting, o=Ace Industry, c=US
cn: June Rossi
sn: Rossi
givenName: June
mail: rossi@aceindustry.com
userPassword: {sha}KDIE3AL9DK
telephoneNumber: 2616
roomNumber: 220
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPersondn: cn=Marc Chambers, ou=manufacturing, o=Ace Industry, c=US
cn: Marc Chambers
sn: Chambers
givenName: Marc
mail: chambers@aceindustry.com
userPassword: {sha}jdl2alem87dlacz1
telephoneNumber: 2652
roomNumber: 167
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPersondn: cn=Robert Wong, ou=manufacturing, o=Ace Industry, c=US
cn: Robert Wong
cn: Bob Wong
sn: Wong
givenName: Robert
givenName: Bob
mail: bwong@aceindustry.com
userPassword: {sha}nn2msx761
telephoneNumber: 2881
roomNumber: 211
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson Using LDIF to Update Entries
If you want to update an entry in the directory, you need to use LDIF update statements to specify the changes. In general, LDIF update statements are a series of statements that:
dn: distinguished name
changetype identifier
change operation identifier
list of attributes
...
-
change operation identifier
list of attributes
...
-
...
Note A dash (-) must be used to denote the end of a change operation if subsequent change operations are specified. For example, the following statement adds the telephone number and manager attributes to the entry:
dn: cn=Lisa Jangles, ou=Sales, o=Ace Industry, c=USIn addition, the line continuation operator is a space. Therefore, the following two statements are identical:
changetype: modify
add: telephonenumber
telephonenumber: (408) 555-2468
-
add: manager
manager: cn=Harry Cruise, ou=Manufacturing, o=Ace Industry, c=US
dn: cn=Lisa Jangles, ou=Sales, o=Ace Industry, c=US
dn: cn=Lisa Jangles,The following sections describe the change types in detail.
ou=Sales,
o=Ace Industry,
c=US
modify change type can be used to add, replace, or remove attribute values.
dn: distinguished name
changetype: add
objectClass: objectClass
objectClass: objectClass
...
attribute type: attribute value
attribute type: attribute value
... changetype: delete
Deletes the entire entry. The format is:
dn: distinguished name
changetype: delete
changetype: modrdn
Modifies the relative distinguished name (RDN) of an entry. In essence, this renames the entry. An entry's RDN is the leftmost element in its distinguished name.
The format is:
dn: distinguished name
where
changetype: modrdn
newrdn: new rdn
deleteoldrdn: 0|1deleteoldrdn indicates whether the old RDN is to be deleted (1). If 0 is specified, then the attribute values of the old RDN are included in the entry corresponding to the new RDN.
changetype: modify
Adds, replaces, or removes attributes and/or attribute values to the entry. When changetype: modify is specified, a change operation is required to indicate how the entry is to be modified. Change operations can be:
dn: distinguished name
changetype: modify
add: attribute type
attribute type: attribute value
attribute type: attribute value
-
...
replace: attribute type
attribute type: attribute value
attribute type: attribute value
-
...
delete: attribute type
attribute type: attribute value
attribute type: attribute value
-
...
dn: cn=Barry Nixon, ou=Manufacturing, o=Ace Industry, c=USThe following example adds the attribute types
changetype: add
objectClass: top
objectClass: person
objectClass: orgperson
objectClass: inetorgperson
cn: Barry
cn: Barry Nixon
sn: Nixon
telephonenumber and manager to the existing entry. Note that two telephone numbers are added to the entry:
dn: cn=Barry Nixon, ou=Manufacturing, o=Ace Industry, c=USThe following example replaces the
changetype: modify
add: telephonenumber
telephonenumber: (408) 555-1357
telephonenumber: (408) 555-9753
-
add: manager
manager: cn=Harry Cruise, ou=Manufacturing, o=Ace Industry, c=US
manager attribute for the existing entry:
dn: cn=Barry Nixon, ou=Manufacturing, o=Ace Industry, c=USThe following example deletes a telephone number for the entry (you would use this method if multiple telephone numbers are specified for the entry, and you want to delete just one of them):
changetype: modify
replace: manager
manager: cn=Carrie King, ou=Manufacturing, o=Ace Industry, c=US
dn: cn=Barry Nixon, ou=Manufacturing, o=Ace Industry, c=USThe following example deletes all instances of the telephone number attribute from the entry:
changetype: modify
delete: telephonenumber
telephonenumber: (408) 555-9753
dn: cn=Barry Nixon, ou=Manufacturing, o=Ace Industry, c=USThe following example modifies the RDN for the entry:
changetype: modify
delete: telephonenumber
dn: cn=Barry Nixon, ou=Manufacturing, o=Ace Industry, c=USBecause deleteoldrdn is 0, this example retains the existing RDN in the new entry. The resulting entry would therefore have a common name attribute set to both Barry Nixon and Barney Nixon in addition to all the other attributes included in the original entry.
changetype: modrdn
newrdn: cn=Barney Nixon
deleteoldrdn: 0
ldapadd (for adding new entries to the directory)
ldapdelete (for deleting entries from the directory)
ldapmodify (for modifying entries in the directory)
-D "cn=Barbara Jensen, ou=Product Development, o=Ace Industry, c=US"
Note Depending on the command-line interpreter you are using, you should use either single or double quotation marks for this purpose. Refer to your operating system documentation for more information.
prompt> ldapmodify -D binddn -w password -h hostnameNote that the ldapsearch utility works somewhat differently from the other command-line utilities in that it requires you to either specify the -f option or supply a single search filter directly to the command-line call. For more information on using filters, refer to "ldapsearch" on page 348.
> dn: cn=Barry Nixon, ou=Manufacturing, o=Ace Industry, c=US
> changetype: modify
> delete: telephonenumber
> -
> add: manager
> manager: cn=Harry Cruise, ou=Manufacturing, o=Ace Industry, c=US
> ^D
prompt>
ldapadd
ldapadd adds one or more entries to the directory.
Syntax
ldapadd [-h <host>] [-p <port>] [-D <binddn>] [-w <password>]
The options for this command are described below. For convenience, commonly used options are listed first. The rest of the options are listed in alphabetical order.
[-f <ldiffile>] [-e <rejectedfile>] [-O <maxhops>]
[-Z -P <certdbpath>] [-bcFHnRv]
Description
The ldapadd utility opens a connection to the LDAP server specified by the -h and -p options, authenticates as the user specified by the -D and -w options, and adds the entries that are either specified on the command line or in the file identified by the -f option.
Note the following:
cn=Babs Jensen, ou=Product Development, o=Ace Industry, c=US
The directory must already contain the following entries:
c=US
o=Ace Industry, c=US
ou=Product Development, o=Ace Industry, c=US
newentry.ldif
ldapadd -h ldap.netscape.com -D "cn=Directory Manager,
o=Netscape Communications Corporation,c=US" -w "slapd"
-f newentry.ldif
ldapdelete deletes one or more entries from the directory.
ldapdelete [-h <host>] [-p <port>] [-D <binddn>] [-w <password>The options for this command are described below. For convenience, commonly used options are listed first. The rest of the options are listed in alphabetical order.
[-f <file_with_DNs>][-O <maxhops>]
[-Z -P <certdbpath>] [-cHnRv] [<dn_to_delete>]
Description
The ldapdelete utility opens a connection to the LDAP server specified by the -h and -p options, authenticates as the user specified by the -D and -w options, and deletes the entries for the specified DNs. The DNs are either specified on the command line or in the file identified by the -f option.
Note the following:
ou=Product Development, o=Ace Industry, c=US
You must first move or remove all of the subentries, such as:
cn=Babs Jensen, ou=Product Development, o=Ace Industry, c=US
To move an entry to a different location in the directory hierarchy, use the
ldapmodrdn command.
nukeentry.ldif
ldapdelete -h ldap.netscape.com -D "cn=Directory Manager,
o=Netscape Communications Corporation,c=US" -w "slapd"
-f nukeentry.ldif
ldapdelete -h ldap.netscape.com -D "cn=Directory Manager,
o=Netscape Communications Corporation,c=US" -w "slapd"
"cn=Babs Jensen,ou=Product Development,
o=Netscape Communications Corporation, c=US"
ldapmodify modifies one or more entries in the directory.
ldapmodify [-h <host>] [-p <port>] [-D <binddn>] [-w <password>]The options for this command are described below. For convenience, commonly used options are listed first. The rest of the options are listed in alphabetical order.
[-f <ldiffile>] [-e <rejectedfile>] [-O <maxhops>]
[-Z -P <certdbpath>] [-bcFHnRv]
Description
The ldapmodify utility opens a connection to the LDAP server specified by the -h and -p options, authenticates as the user specified by the -D and -w options, and makes the changes that are either specified by the LDIF update statements on the command line or in the file identified by the -f option.
Note the following:
changeentry.ldif
ldapmodify -h ldap.netscape.com -D "cn=Directory Manager,
o=Netscape Communications Corporation,c=US" -w "slapd"
-f changeentry.ldif
ldapmodrdn modifies the relative distinguished name (RDN) of one or more entries in the directory.
ldapmodrdn [-h <host>] [-p <port>] [-D <binddn>] [-w <password>]The options for this command are described below. For convenience, commonly used options are listed first. The rest of the options are listed in alphabetical order.
[-f <ldiffile>] [-e <rejectedfile>] [-O <maxhops>]
[-Z -P <certdbpath>] [-cFHnrRv]
Description
The ldapmodrdn utility opens a connection to the LDAP server specified by the -h and -p options, authenticates as the user specified by the -D and -w options, and changes the RDNs of entries specified either on the command line or in the file identified by the -f option.
Note the following:
changerdn.ldif
ldapmodrdn -h ldap.netscape.com -D "cn=Directory Manager,
o=Netscape Communications Corporation,c=US" -w "slapd"
-f changerdn.ldif
ldapsearch searches for entries in the directory that match some specified search criteria.
ldapsearch [-h <host>] [-p <port>] [-D <binddn>] [-w <password>]The options for this command are described below. For convenience, commonly used options are listed first. The rest of the options are listed in alphabetical order.
-b <basedn> [-s <scope>] [-f <filterfile> | <filter ] [<attributes>] [-S <sortby>] [-a <deref>] [-F <sep>] [-O <maxhops>] [-Z -P <certdbpath>] [-ABHnoRtuv]
Description
The ldapsearch utility opens a connection to the LDAP server specified by the -h and -p options, authenticates as the user specified by the -D and -w options, and searches for the entries under the base entry (specified by the -b option) within a given scope (specified by the -s option) that match the filter.
Note the following:
ldapsearch -h ldap.netscape.com -D "cn=Directory Manager,
o=Netscape Communications Corporation,c=US" -w "slapd"
-b "o=Netscape Communications Corporation,c=US"
-s "subtree" "(sn=Jensen)"
Last modified: March 31, 1997
Copyright © 1997 Netscape
Communications Corporation