ldapsearch Examples

ldapsearch -h mozilla -b "dc=example,dc=com" -s sub "objectclass=*"

"objectclass=*" is a search filter that matches any entry in the directory. Since every entry must have an object class, and the objectclass attribute is always indexed, this is a useful search filter to return every entry.

2.4.2. Specifying Search Filters on the Command Line

A search filter can be specified directly on the command line as long as the filter is enclosed in quotation marks ("filter"). If the filter is supplied with the command, do not specify the -foption. For example:

ldapsearch -h mozilla -b "dc=example,dc=com" "cn=babs jensen"

2.4.3. Searching the Root DSE Entry

The root DSE is a special entry that contains a list of all the suffixes supported by the local Directory Server. This entry can be searched by supplying a search base of "", a search scope of base, and a filter of "objectclass=*". For example:

ldapsearch -h mozilla -b "" -s base "objectclass=*"

2.4.4. Searching the Schema Entry

Directory Server stores all directory server schema in the special cn=schema entry. This entry contains information on every object class and attribute defined for the Directory Server. The following command searches the contents of the cn=schema entry:

ldapsearch -h mozilla -b "cn=schema" -s base "objectclass=*"

2.4.5. Using LDAP_BASEDN

To make searching easier, it is possible to set the search base using the LDAP_BASEDN environment variable. Doing this means that the search base does not have to be set with the -boption. For information on how to set environment variables, see the documentation for the operating system.

Typically, set LDAP_BASEDN to the directory's suffix value. Since the directory suffix is equal to the root, or topmost, entry in the directory, this causes all searches to begin from the directory's root entry.

For example, suppose LDAP_BASEDN is set to dc=example,dc=com. Then to search for cn=babs jensen in the directory, use the following command-line call:

557

Page 577
Image 577
HP UX Red Hat Direry Server Software manual Specifying Search Filters on the Command Line, Searching the Root DSE Entry