Previous Contents Index Next |
iPlanet Directory Server Resource Kit 5.1 Tools Reference |
Chapter 4 ldapmodify
The ldapmodify tool edits the contents of an LDAP directory, either by adding new entries or by modifying existing ones. The tool takes update statements in LDIF as input and issues the corresponding LDAP request to the designated directory server. By placing all update statements in a file, ldapmodify can be used to process large numbers of modifications and transfer entries between directories.The ldapmodify tool is also provided with iPlanet Directory Server in the /usr/iplanet/servers/shared/bin directory. However, iPlanet DSRK and its updates include the latest version of the tool. If you use the Solaris operating environment, you may have an older version of ldapmodify in /usr/bin. Be sure your path is set to use the latest version in /opt/iPlanet/bin/idsrk51.
This chapter contains the following sections:
Command Usage
Command Usage
The ldapmodify tool processes update statements, also known as change records, defined by the LDIF standard. An update statement contains the DN of the target entry for the update, the operation to perform, and any data for the entry's attributes. The operation to perform is given by the changetype keyword, and the ldapmodify tool supports the following operations:
The syntax for each of these update statements is described in "LDIF Update Statements," in Chapter 2 of the iPlanet Directory Server Administrator's Guide. Some sample update statements are given in "Command-Line Examples".
- add delete modify modrdn moddn rename
The ldapmodify tool reads any number of update statements from the standard input or from a file, and it modifies the corresponding entries according to the LDIF instructions. For each DN in the LDIF file, the tool will perform the requested LDAP operation on the designated entry.
The ldapmodify tool also has a special option (-a) for adding entries in bulk. In this case, the input should not contain the changetype keyword, and each of the given DNs will be added as a new entry. Using this feature, the output of the ldapsearch tool may be used as input to the ldapmodify command.
Syntax
The syntax of the ldapmodify command line has three forms:
Where:
- ldapmodify [ options ]
- ldapmodify [ options ] < LDIFfile
- ldapmodify [ options ] -f LDIFfile
options are the command-line options and their parameters described in "Options".
In the first form without any LDIFfile input, the tool will expect you to type one or more LDIF update statements to the standard input. Once you enter all update statements and the EOF (end-of-file) marker, ldapmodify will process your input and perform all operations. The EOF marker is platform dependent:LDIFfile is an RFC 2849-compliant LDIF text file containing update statements (see "LDIF Update Statements," in Chapter 2 of the iPlanet Directory Server Administrator's Guide) or plain LDIF entries when using the -a option (see Appendix A, "LDAP Data Interchange Format," in the iPlanet Directory Server Administrator's Guide).
The ldapmodify -H command will display a usage help text that briefly describes all options.
Modification Prerequisites
When modifying the contents of a directory, you must satisfy several prerequisite conditions. First, the bind DN and password used for authentication must have the appropriate permissions for the operations you perform. Many high level directory operations, such as creating a database suffix, may only be performed by the Directory Manager with a bind DN of "cn=directory manager".Then, if schema checking is active in your directory, the server will check the contents of new and modified entries against the definition of their object class in the schema. All attributes of an entry, even those not being modified, are checked against their definition and must meet the following conditions:
The value and value type of all attributes being added or modified must conform to their definition in the entry's object class. When this is not the case, the modification of this entry will fail.
When a modification fails, only the operation on the faulty entry is affected, but ldapmodify will stop processing further input. All entries that were processed before the error was encountered will be successfully added or modified. Use the -c option to specify that the tool should continue processing input after any failed modification.Attributes and values not being modified must also conform to the schema. The modification of the entry will fail even if the offending attribute is not being modified. This situation can occur if you run the directory server with schema checking turned off, remove a required attribute or set an illegal value, and then turn schema checking on. For more information, see Chapter 9, "Extending the Directory Schema," in the iPlanet Directory Server Administrator's Guide.
Finally, you must ensure the coherence of the entries in the LDIF input. Updates are performed on entries in the order they are given in the input, allowing you to manage dependencies between operations. For example, if you want to add entries to a subtree that doesn't exist yet, your LDIF input must first give the update statement for adding the subtree entry, before the update statements for adding entries under the subtree.
Options
The ldapmodify command has three types of options:The common options listed in the following table control the binding and general behavior of the ldapmodify command.
Table 4-1    Common Options of the ldapmodify Command
Option
Parameter
Purpose
-h
Specify the hostname of the directory server. When this option is omitted, the default is localhost.
-p
Specify the port number for accessing the directory server host. The default is 389 normally and 636 when the SSL options are used.
-D
Specify a bind DN for accessing your directory, usually in double quotes ("") for the shell. If the bind DN and its password are omitted, the tool will use anonymous binding. The bind DN determines what entries and attributes may be modified, according to the DN's access permissions.
-w
Specify the password for the bind DN. CAUTION: Specifying the password on the command line is a possible security risk.
-w
Type the password for the bind DN when prompted in the terminal window. This is the most secure way of specifying the password.
-j
Specify a file containing the password for the bind DN. Use this option in scripts and place the password in a secure file to protect the password. This option is mutually exclusive with the -w option.
-f
Give the name of a file containing LDIF update statements (see "LDIF Update Statements," in Chapter 2 of the iPlanet Directory Server Administrator's Guide). The tool will perform each of the update operations (add, modify, or delete) in the order given in the file. When this option is omitted, ldapmodify will read LDIF update statements from the standard input.
-B
Specify the base DN when performing additions, usually in double quotes ("") for the shell. All entries will be placed under this suffix, thus providing bulk import functionality.
-V
Specify the LDAP protocol version number to be used for the modify operation, either 2 or 3. LDAP v3 is the default; only specify LDAP v2 when connecting to servers that do not support v3.
-Y
Specify the proxy DN to use for the modify operation, usually in double quotes ("") for the shell. For more information about proxy authorization, see Chapter 6, "Managing Access Control," in the iPlanet Directory Server Administrator's Guide.
-M
Manage smart referrals: when they are the target of the update, modify the actual entry containing the referral instead of the entry obtained by following the referral. For more information, see "Smart Referrals" in Chapter 5 of the iPlanet Directory Server Deployment Guide.
-O
(Capital letter O) Specify the maximum number of referral hops to follow while finding an entry to modify. By default, there is no limit.
-R
Specify that referrals should not be followed. By default, referrals are followed automatically.
-q
Quiet output mode: the tool will not display any output about the operations it performs.
-v
Verbose output mode: the tool will display additional information about the operations it performs.
-n
No-op mode: use with the -v option to show what the tool would do with the given input but do not perform any operations.
Allow runtime library version mismatches. When this option is omitted, the default behavior is to assert that the revision number of the LDAP API is greater than or equal to that used to compile the tool. Also, if the API library and the tool have the same vendor name, the tool will also assert that the vendor version number of the API is greater than or equal to that used to compile the tool. This information is based on the contents of the LDAPAPIInfo structure (see the iPlanet LDAP SDK for C Programming Guide).
-H
Display the usage help text that briefly describes all options.
The input and output options given in the following table control how ldapmodify processes input files and handles errors.
Table 4-2    Input and Output Options of the ldapmodify Command
Option
Parameter
Purpose
-a
Add entry mode: all input entries that do not contain an LDIF changetype statement are processed as add operations. Entries given with a changetype statement are processed accordingly.
The add entry mode provides an easy way to add entries in LDIF. In particular, it allows you to directly add entries from the output files of the ldapsearch tool.
-F
Force the application of all updates, regardless of the replica status.
-i
Specify the character set to use for the -f LDIFfile or standard input. The default is the character set specified in the LANG environment variable. You might want to use this option to perform the conversion from the specified character set to UTF8, thus overriding the LANG setting.
-k
Specify the path to a directory containing conversion routines. These routines are used if you wish to specify a locale that is not supported by default by your directory server. For more information, see "Searching an Internationalized Directory" in Appendix B of the iPlanet Directory Server Administrator's Guide.
-b
Handle binary files: the ldapmodify tool will scan every attribute value in the input to determine whether it is a valid file reference, and if so, it will use the contents of the file as the attribute's value. This option is used to input binary data for an attribute, such as a JPEG image. For example, the corresponding LDIF input would be:
This option allows you to directly process entries from the output files of the ldapsearch tool when it uses the -t option.
The ldapmodify tool also supports the LDIF :< URL notation for directly including file contents. For example:
If all of your input entries use this notation, you do not need to specify the -b option.
-A
Non-ASCII mode: display non-ASCII values, in conjunction with the -v option.
-c
Continuous mode: errors are reported but the ldapmodify tool will continue processing input and performing operations. When this option is omitted, the default is to quit after reporting an error.
-e
Invalid update statements in the input will be copied to the errorFile for debugging. Use with the -c option to correct errors when processing large LDIF input.
The SSL (Secure Socket Layer) options listed in the following table allow you to use LDAPS (LDAP over SSL) to establish a secure connection for the update operation. These options are valid only when LDAPS has been turned on and configured in your SSL-enabled directory server. For information on certificate-based authentication and creating a certificate database for use with LDAP clients, see Chapter 11, "Managing SSL" in the iPlanet Directory Server Administrator's Guide.
Only the -P option is required for server authentication. For the more secure client authentication, the -P, -N, -K and -W options are required. See "Using Authentication" for examples using the SSL options.
Return Values
The ldapmodify tool is based on the iPlanet LDAP SDK for C and its return values are those of the functions it uses, such as ldap_simple_bind_s(), ldap_add_ext_s(), ldap_modify_ext_s(), and ldap_delete_ext_s(). These functions return both client-side and server-side errors and codes.The following table shows the possible return values when the directory is hosted on an iPlanet Directory Server. Other LDAP servers may send these values under different circumstances or may send different values. The directory server responding to the ldapmodify tool may also send other result codes in addition to those described here, for example, custom result codes from a custom plug-in.
For further information about result codes, see the iPlanet LDAP SDK for C Programming Guide.
Command-Line Examples
The examples in this section demonstrate common uses of the ldapmodify tool to update the contents a directory. All examples assume the following context:
The given bind DN has the permission to perform all operations on the selected entries.
The directory server is located on a machine with the given hostname .
The server uses port number 389. Because this is the default port, you do not have to specify the port number on the search request.
SSL is enabled for the server on port 636 (the default SSL port number).
Adding an Entry
This example uses the -a option for bulk addition, so the changetype: add is not needed in the input. Instead, the input contains standard LDIF entries to be added. The input file is called newEntry.ldif and contains only one entry to add:
To perform this addition, launch the ldapmodify tool with the -a option and specify the input file with the -f option:
- dn: cn=Pete Minsky,ou=People,dc=siroe,dc=com
changetype: add
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Pete Minsky
givenName: Pete
sn: Minsky
ou: People
ou: Marketing
uid: peterm
- $ ldapmodify -h hostname -a -f newEntry.ldif \
-D "uid=bjensen,dc=siroe,dc=com" -w bindPassword
Modifying an Entry
The update statement for a modification includes statements for specifying the attributes to change and their new values. See "LDIF Update Statements," in Chapter 2 of the iPlanet Directory Server Administrator's Guide for a description of this syntax.In this example, the mofifyEntry.ldif file includes statements for adding a new attribute and modifying an existing one. The line with a single dash (-) is a separator for multiple modifications in the same entry:
To perform the operation, launch the ldapmodify tool and specify the filename on the command line.
- dn: cn=Pete Minsky,ou=People,dc=siroe,dc=com
changetype: modify
add: telephonenumber
telephonenumber: (408) 555-2468
-
replace: uid
uid: pminsky
- $ ldapmodify -h hostname -f mofifyEntry.ldif \
-D "uid=bjensen,dc=siroe,dc=com" -w bindPassword
Deleting an Entry
The update statement for a deletion requires only the DN and the changetype. This example shows how to enter this information as standard input:
- $ ldapmodify -h hostname \
-D "uid=bjensen,dc=siroe,dc=com" -w bindPassword
- dn: cn=Pete Minsky,ou=People,dc=siroe,dc=com
changetype: delete
^D
Using Authentication
There are two levels of authentication that the directory server may enforce on clients such as the ldapmodify tool: server and client authentication. In server authentication, the server accepts only connections from clients that have a trusted certificate. In the stronger client authentication, the certificate is not assumed to be trusted, so the client must sign it with a password-protected private key.To run the ldapmodify tool with server authentication, give only the -P option on the command line, in addition to other options. For example:
To perform an update with client authentication, you must give all SSL options on the command line, in addition to other options. However, do not use the -D and -w options with client authentication, otherwise the bind operation will use the authentication credentials specified with -D and -w instead of the certificate credentials. For example:
- $ ldapmodify -h hostname -p 636 -f LDIFfile \
-D "uid=bjensen,dc=siroe,dc=com" -w bindPassword \
-P /home/bjensen/certs/cert.db
In either case, use the -p option to specify your directory server's SSL port. All other options remain the same and may be used as necessary.
- $ ldapmodify -h hostname -p 636 -f LDIFfile \
-Z -P /home/bjensen/security/cert.db -N "bjscert" \
-K /home/bjensen/security/key.db -W KeyPassword
Previous Contents Index Next
Copyright 2002 Sun Microsystems, Inc.. All rights reserved.Last Updated April 15, 2002