ldapsearch opens a connection to an LDAP server, binds, and performs a search using the filter filter. The filter should conform to the string representation for LDAP filters as defined in RFC 1558.
If ldapsearch finds one or more entries, the attributes specified by attrs are retrieved and the entries and values are printed to standard output. If no attrs are listed, all attributes are returned.
A common problem when using ldapsearch is a failure to specify
a search base with the -b option. Without this, the result of
the search will be the message ldapsearch: partial results and referral
received
. The search base must match one of the suffix entries on
the LDAP server.
binddn should be a string-represented DN, as defined in RFC 1779 or its successor.
If a -D binddn option is not supplied, the command will take the binddn value from the LDAP_BINDDN_SEARCH environmental variable, if set. If LDAP_BINDDN_SEARCH specifies a null string, it is assumed that an anonymous bind is required.
If a -D option is not supplied, and LDAP_BINDDN_SEARCH is not used to specify the bind DN, the configuration file /etc/ldap_defaults will be examined for a default value to be used. If no default is supplied, a value of "" will be assumed.
The password is prompted for in a non-echoing input mode. If ldapsearch has no controlling terminal, then the password will be read from standard input.
More than one server can be specified, in which case the servers are tried in the order specified, stopping with the first one to which a successful connection is made.
The servers can be specified either as hostnames or as dotted strings giving IP addresses.
A server port may be specified along with the server names or addresses by using the notation servername:portnumber or serverIPaddr:portnumber. If a port number is not explicitly specified for the particular server, a default port (as described for the -p option) is used.
If a null string is supplied, the local host is assumed. See the -p option for how the local port is selected.
If no -h option is supplied, the command will take the ldaphost value from the LDAP_HOST environmental variable, if this is present.
If no -h option is supplied, and LDAP_HOST is not set, then the configuration file /etc/ldap_defaults will be examined for a default value to be used.
If no default is supplied, a value of "", implying the local host, will be assumed.
If no port number is explicitly supplied, the default LDAP port is assumed.
Distinguished Name (DN) User Friendly Name (this line present only if the -u option is used) attributename=value attributename=value attributename=value ...Multiple entries are separated with a single blank line. If the -F option is used to specify a separator character, it will be used instead of the equals sign (=). If the -t option is used, the name of a temporary file is used in place of the actual value. If the -A option is given, only the attributename part is written.
The commonName and telephoneNumber values will be retrieved and printed to standard output. The output might look something like this if two entries are found:
cn=Mark D Smith, ou="College of Literature, Science, and the Arts", ou=Students, ou=People, o=University of Michigan, c=US cn=Mark Smith cn=Mark David Smith cn=Mark D Smith 1 cn=Mark D Smith telephoneNumber=+1 313 930-9489The following command will perform a subtree search using the default search base for entries with user ID of ``mcs'':cn=Mark C Smith, ou=Information Technology Division, ou=Faculty and Staff, ou=People, o=University of Michigan, c=US cn=Mark Smith cn=Mark C Smith 1 cn=Mark C Smith telephoneNumber=+1 313 764-2277
The user friendly form of the entry's DN will be output after the line that contains the DN itself, and the jpegPhoto and audio values will be retrieved and written to temporary files. The output might look like this if one entry with one value for each of the requested attributes is found:
cn=Mark C Smith, ou=Information Technology Division, ou=Faculty and Staff, ou=People, o=University of Michigan, c=US Mark C Smith, Information Technology Division, Faculty and Staff, People, University of Michigan, US audio=/tmp/ldapsearch-audio-a19924 jpegPhoto=/tmp/ldapsearch-jpegPhoto-a19924The following command will perform a one-level search at the ``c=US'' level for all organizations whose organizationName begins with ``university'':
Search results will be displayed in the LDIF format. The organizationName and description attribute values will be retrieved and printed to standard output, resulting in output similar to this:
dn: o=University of Alaska Fairbanks, c=US o: University of Alaska Fairbanks description: Preparing Alaska for a brave new yesterday description: leaf node onlydn: o=University of Colorado at Boulder, c=US o: University of Colorado at Boulder description: No personnel information description: Institution of education and research
dn: o=University of Colorado at Denver, c=US o: University of Colorado at Denver o: UCD o: CU/Denver o: CU-Denver description: Institute for Higher Learning and Research
dn: o=University of Florida, c=US o: University of Florida o: UFl description: Warper of young minds
...
Kille, S., A String Representation of Distinguished Names, RFC 1779, ISODE Consortium, March 1995.
Howes, T., A String Representation of LDAP Search Filters, RFC 1558, University of Michigan, December 1993.