'\" te .\" Copyright (C) 1990, Regents of the University of Michigan. All Rights Reserved. .\" Portions Copyright (C) 2006, Sun Microsystems, Inc. All Rights Reserved. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .TH ldapsearch 1 "6 Jan 2006" "SunOS 5.11" "User Commands" .SH NAME ldapsearch \- ldap search tool .SH SYNOPSIS .LP .nf \fBldapsearch\fR [\fB-n\fR] [\fB-u\fR] [\fB-v\fR] [\fB-t\fR] [\fB-A\fR] [\fB-B\fR] [\fB-L\fR] [\fB-R\fR] [\fB-H\fR] [\fB-?\fR] [\fB-t\fR] [\fB-T\fR] [\fB-B\fR] [\fB-E\fR] [\fB-J\fR] [\fB-e\fR] [\fB-l\fR] [\fB-Z\fR] [\fB-r\fR] [\fB-M\fR] [\fB-d\fR \fIdebuglevel\fR] [\fB-F\fR \fIsep\fR] [\fB-f\fR \fIfile\fR] [\fB-D\fR \fIbindDN\fR] [\fB-j\fR \fIfilename\fR] [\fB-V\fR \fIversion\fR] [\fB-Y\fR \fIproxyDN\fR] [\fB-O\fR \fIhopLimit\fR] [\fB-i\fR \fIlocale\fR] [\fB-k\fR \fIpath\fR] [\fB-S\fR [\fB-\fR] \fIattribute\fR] [\fB-C\fR \fIpattern\fR] [\fB-c\fR \fIauthzid\fR] [\fB-P\fR \fIpath\fR] [\fB-N\fR \fIcertificate\fR] [\fB-w\fR \fIpasswd\fR] [\fB-h\fR \fIldaphost\fR] [\fB-p\fR \fIldapport\fR] [\fB-o\fR \fIattributename\fR=\fIvalue\fR] [\fB-b\fR \fIsearchbase\fR] [\fB-s\fR \fIscope\fR] [\fB-a\fR \fIderef\fR] [\fB-l\fR \fItimelimit\fR] [\fB-z\fR \fIsizelimit\fR] \fIfilter\fR [\fIattrs\fR]... .fi .SH DESCRIPTION .sp .LP The \fBldapsearch\fR utility opens a connection to an LDAP server, binds, and performs a search using the filter \fIfilter\fR. .sp .LP If \fBldapsearch\fR finds one or more entries, the attributes specified by \fIattrs\fR are retrieved and the entries and values are printed to standard output. If no \fIattrs\fR are listed, all attributes are returned. .SS "Output Format" .sp .LP If one or more entries are found, each entry is written to standard output in the form: .sp .in +2 .nf dn: Distinguished Name (DN) attributename: value attributename: value attributename: value \&... .fi .in -2 .sp .sp .LP Multiple entries are separated with a single blank line. If the \fB-F\fR option is used to specify a different separator character, this character is used instead of the \fB:\fR character. If the \fB-t\fR option is used, the name of a temporary file is returned in place of the actual value. If the \fB-A\fR option is given, only the "attributename" is returned and not the attribute value. .SH OPTIONS .sp .LP The following options are supported: .sp .ne 2 .mk .na \fB\fB-A\fR\fR .ad .sp .6 .RS 4n Retrieve attributes only (no values). This is useful when you just want to see whether an attribute is present in an entry and are not interested in the specific value. .RE .sp .ne 2 .mk .na \fB\fB-a\fR \fIderef\fR\fR .ad .sp .6 .RS 4n Specify how aliases dereferencing is done. The possible values for \fIderef\fR are \fBnever\fR, \fBalways\fR, \fBsearch\fR, or \fBfind\fR to specify respectively that aliases are never dereferenced, always dereferenced, dereferenced when searching, or dereferenced only when finding the base object for the search. The default is to never dereference aliases. .RE .sp .ne 2 .mk .na \fB\fB-B\fR\fR .ad .sp .6 .RS 4n Display non-ASCII values and use the old non-LDIF format. This option disables the default \fB-L\fR option. .RE .sp .ne 2 .mk .na \fB\fB-b\fR \fIsearchbase\fR\fR .ad .sp .6 .RS 4n Use \fIsearchbase\fR as the starting point for the search instead of the default. .RE .sp .ne 2 .mk .na \fB\fB-C\fR \fIpattern\fR\fR .ad .sp .6 .RS 4n Persistent search. Perform a search that keeps the connection open and displays results whenever entries matching the scope and filter of the search are added, modified, or removed. With this option, the \fBldapsearch\fR tool runs indefinitely; you must type Control-c to stop it. The pattern has the following format: .sp .in +2 .nf ps:changeType[:changesOnly[:entryChangeControls]] .fi .in -2 .sp .RE .sp .ne 2 .mk .na \fB\fB-c\fR \fIauthzid\fR\fR .ad .sp .6 .RS 4n Specifies the \fBgetEffectiveRights\fR control \fIauthzid\fR. For example: .sp .in +2 .nf dn:uid=bjensen,dc=example,dc=com .fi .in -2 .sp .RE .sp .ne 2 .mk .na \fB\fB-D\fR \fIbindDN\fR\fR .ad .sp .6 .RS 4n Use the distinguished name \fIbindDN\fR to bind to the directory. .RE .sp .ne 2 .mk .na \fB\fB-d\fR \fIdebuglevel\fR\fR .ad .sp .6 .RS 4n Set the \fBLDAP\fR debugging level. Useful levels of debugging for \fBldapsearch\fR are: .sp .ne 2 .mk .na \fB\fB1\fR\fR .ad .RS 7n .rt Trace .RE .sp .ne 2 .mk .na \fB\fB2\fR\fR .ad .RS 7n .rt Packets .RE .sp .ne 2 .mk .na \fB\fB4\fR\fR .ad .RS 7n .rt Arguments .RE .sp .ne 2 .mk .na \fB\fB32\fR\fR .ad .RS 7n .rt Filters .RE .sp .ne 2 .mk .na \fB\fB128\fR\fR .ad .RS 7n .rt Access control .RE To request more than one category of debugging information, add the masks. For example, to request trace and filter information, specify a debuglevel of 33. .RE .sp .ne 2 .mk .na \fB\fB-E\fR\fR .ad .sp .6 .RS 4n Ask server to expose (report) bind identity by means of authentication response control. .RE .sp .ne 2 .mk .na \fB\fB-e\fR\fR .ad .sp .6 .RS 4n Minimize base-64 encoding of values. .RE .sp .ne 2 .mk .na \fB\fB-F\fR \fIsep\fR\fR .ad .sp .6 .RS 4n Use \fIsep\fR as the field separator between attribute names and values. If this option has been specified, the \fB-L\fR option is ignored. .RE .sp .ne 2 .mk .na \fB\fB-f\fR \fIfile\fR\fR .ad .sp .6 .RS 4n Read a series of lines from \fIfile\fR, performing one \fBLDAP\fR search for each line. In this case, the \fIfilter\fR given on the command line is treated as a pattern where the first occurrence of \fB%s\fR is replaced with a line from \fIfile\fR. If \fIfile\fR is a single \fI-\fR character, then the lines are read from standard input. .RE .sp .ne 2 .mk .na \fB\fB-G\fR \fIpattern\fR\fR .ad .sp .6 .RS 4n Virtual list view. Retrieve only a portion of all results, as determined by the index or value of the search target and the number of entries to be returned before and after the target. This option always requires the \fB-S\fR and \fB-x\fR options to specify the sorting order on the server. .RE .sp .ne 2 .mk .na \fB\fB-?\fR\fR .ad .sp .6 .RS 4n Display the usage help text that briefly describes all options. .RE .sp .ne 2 .mk .na \fB\fB-H\fR\fR .ad .sp .6 .RS 4n Display the usage help text that briefly describes all options. .RE .sp .ne 2 .mk .na \fB\fB-h\fR \fIldaphost\fR\fR .ad .sp .6 .RS 4n Specify an alternate host on which the secure LDAP server is running. .RE .sp .ne 2 .mk .na \fB\fB-i\fR \fIlocale\fR\fR .ad .sp .6 .RS 4n Specify the character set to use for command-line input. The default is the character set specified in the \fBLANG\fR environment variable. You might want to use this option to perform the conversion from the specified character set to UTF8, thus overriding the \fBLANG\fR setting. Using this argument, you can input the bind DN, base DN, and the search filter pattern in the specified character set. The \fBldapsearch\fR tool converts the input from these arguments before it processes the search request. For example, \fB-i\fR \fBno\fR indicates that the bind DN, base DN, and search filter are provided in Norwegian. This argument only affects the command-line input. If you specify a file containing a search filter (with the \fB-f\fR option), \fBldapsearch\fR does not convert the data in the file. .RE .sp .ne 2 .mk .na \fB\fB-j\fR \fIfilename\fR\fR .ad .sp .6 .RS 4n Specify a file containing the password for the bind DN or the password for the SSL client's key database. To protect the password, use this option in scripts and place the password in a secure file. This option is mutually exclusive of the \fB-w\fR and \fB-W\fR options. .RE .sp .ne 2 .mk .na \fB\fB-J\fR [:\fIcriticality\fR[:\fIvalue\fR|::\fIb64value\fR|\fIb64value\fR|:\ fIfileurl\fR]]\fR .ad .sp .6 .RS 4n Criticality is a boolean value (default is \fBfalse\fR). .RE .sp .ne 2 .mk .na \fB\fB-k\fR \fIpath\fR\fR .ad .sp .6 .RS 4n Specify the path to a directory containing conversion routines. These routines are used if you want to specify a locale that is not supported by default by your directory server. This is for NLS support. .RE .sp .ne 2 .mk .na \fB\fB-L\fR\fR .ad .sp .6 .RS 4n Display search results in LDIF format. This option also turns on the \fB-B\fR option. This behavior is the default. .RE .sp .ne 2 .mk .na \fB\fB-l\fR \fItimelimit\fR\fR .ad .sp .6 .RS 4n Wait at most \fItimelimit\fR seconds for a search to complete. .RE .sp .ne 2 .mk .na \fB\fB-M\fR\fR .ad .sp .6 .RS 4n Manage smart referrals. When they are the target of the operation, search the entry containing the referral instead of the entry obtained by following the referral. .RE .sp .ne 2 .mk .na \fB\fB-N\fR \fIcertificate\fR\fR .ad .sp .6 .RS 4n Specify the certificate name to use for certificate-based client authentication. For example: \fB-N\fR \fB"Directory-Cert"\fR\&. .RE .sp .ne 2 .mk .na \fB\fB-n\fR\fR .ad .sp .6 .RS 4n Show what would be done, but do not actually perform the search. Useful in conjunction with \fB-v\fR and \fB-d\fR for debugging. .RE .sp .ne 2 .mk .na \fB\fB-O\fR \fIhopLimit\fR\fR .ad .sp .6 .RS 4n Specify the maximum number of referral hops to follow while finding an entry to modify. By default, there is no limit. .RE .sp .ne 2 .mk .na \fB\fB-o\fR \fIattributename\fR=\fIvalue\fR\fR .ad .sp .6 .RS 4n For SASL mechanisms and other options such as security properties, mode of operation, authorization ID, authentication ID, and so forth. .sp The different attribute names and their values are as follows: .sp .ne 2 .mk .na \fB\fBsecProp\fR=\fI"number"\fR\fR .ad .RS 20n .rt For defining SASL security properties. .RE .sp .ne 2 .mk .na \fB\fBrealm\fR=\fI"value"\fR\fR .ad .RS 20n .rt Specifies SASL realm (default is \fBrealm=none\fR). .RE .sp .ne 2 .mk .na \fB\fBauthzid\fR=\fI"value"\fR\fR .ad .RS 20n .rt Specify the authorization ID name for SASL bind. .RE .sp .ne 2 .mk .na \fB\fBauthid\fR=\fI"value"\fR\fR .ad .RS 20n .rt Specify the authentication ID for SASL bind. .RE .sp .ne 2 .mk .na \fB\fBmech\fR=\fI"value"\fR\fR .ad .RS 20n .rt Specifies the various SASL mechanisms. .RE .RE .sp .ne 2 .mk .na \fB\fB-P\fR \fIpath\fR\fR .ad .sp .6 .RS 4n Specify the path and filename of the client's certificate database. For example: .sp .in +2 .nf -P /home/uid/.netscape/cert7.db .fi .in -2 .sp When using the command on the same host as the directory server, you can use the server's own certificate database. For example: .sp .in +2 .nf -P \fIinstallDir\fR/lapd-serverID/alias/cert7.db .fi .in -2 .sp Use the \fB-P\fR option alone to specify server authentication only. .RE .sp .ne 2 .mk .na \fB\fB-p\fR \fIldapport\fR\fR .ad .sp .6 .RS 4n Specify an alternate TCP port where the secure LAPD server is listening. .RE .sp .ne 2 .mk .na \fB\fB-R\fR\fR .ad .sp .6 .RS 4n Do not automatically follow referrals returned while searching. .RE .sp .ne 2 .mk .na \fB\fB-r\fR\fR .ad .sp .6 .RS 4n Display the output of the \fBldapsearch\fR command in the old format. .RE .sp .ne 2 .mk .na \fB\fB-S\fR [-]\fIattribute\fR\fR .ad .sp .6 .RS 4n Specify an attribute for sorting the entries returned by the search. The sort criteria is alphabetical on the attribute's value or reverse alphabetical with the form \fB-attribute\fR. You can give multiple \fB-S\fR options to refine the sorting, For example: .sp .in +2 .nf -S sn -S \fIgivenname\fR .fi .in -2 .sp By default, the entries are not sorted. Use the \fB-x\fR option to perform server-side sorting. .RE .sp .ne 2 .mk .na \fB\fB-s\fR \fIscope\fR\fR .ad .sp .6 .RS 4n Specify the scope of the search. The possible values of \fIscope\fR are \fBbase\fR, \fBone\fR, or \fBsub\fR to specify respectively a base object, one-level, or subtree search. The default is \fBsub\fR. .RE .sp .ne 2 .mk .na \fB\fB-T\fR\fR .ad .sp .6 .RS 4n Format the output of search results so that no line breaks are used within individual attribute values. .RE .sp .ne 2 .mk .na \fB\fB-t\fR\fR .ad .sp .6 .RS 4n Write retrieved values to a set of temporary files. This is useful for dealing with non-ASCII values such as jpegPhoto or audio. .RE .sp .ne 2 .mk .na \fB\fB-U\fR\fR .ad .sp .6 .RS 4n URL format (valid only with the \fB-t\fR option). When using temporary file output, the standard output of the tool includes the URL of the file instead of the attributes value. For example: .sp .in +2 .nf jpegPhoto:< file:/tmp/ldapsearch-jpegPhoto-YzaOMh .fi .in -2 .sp .RE .sp .ne 2 .mk .na \fB\fB-u\fR\fR .ad .sp .6 .RS 4n Include the user-friendly form of the Distinguished Name (DN) in the output. .RE .sp .ne 2 .mk .na \fB\fB-V\fR \fIversion\fR\fR .ad .sp .6 .RS 4n Specify the LDAP protocol version number to be used for the delete operation, either 2 or 3. LDAP v3 is the default. Specify LDAP v2 when connecting to servers that do not support v3. .RE .sp .ne 2 .mk .na \fB\fB-v\fR\fR .ad .sp .6 .RS 4n Run in verbose mode, with diagnostics written to standard output. .RE .sp .ne 2 .mk .na \fB\fB-W\fR \fIpassword\fR\fR .ad .sp .6 .RS 4n Specify the password for the client's key database given in the \fB-P\fR option. This option is required for certificate-based client authentication. Specifying \fIpassword\fR on the command line has security issues because the password can be seen by others on the system by means of the \fBps\fR command. Use the \fB-j\fR instead to specify the password from the file. This option is mutually exclusive of \fB-j\fR. .RE .sp .ne 2 .mk .na \fB\fB-w\fR \fIpasswd\fR\fR .ad .sp .6 .RS 4n Use \fIpasswd\fR as the password for authentication to the directory. When you use \fB-w\fR \fIpasswd\fR to specify the password to be used for authentication, the password is visible to other users of the system by means of the \fBps\fR command, in script files or in shell history. If you use the \fBldapsearch\fR command without this option, the command prompts for the password and read it from standard in. When used without the \fB-w\fR option, the password is not visible to other users. .RE .sp .ne 2 .mk .na \fB\fB-x\fR\fR .ad .sp .6 .RS 4n Use with the \fB-S\fR option to specify that search results be sorted on the server rather than by the \fBldapsearch\fR command running on the client. This is useful if you want to sort according to a matching rule, as with an international search. It is usually faster to sort on the server, if that is supported, rather than on the client. .RE .sp .ne 2 .mk .na \fB\fB-Y\fR \fIproxyDN\fR\fR .ad .sp .6 .RS 4n Specify the proxy DN (proxied authorization id) to use for the modify operation, usually in double quotes (" ") for the shell. .RE .sp .ne 2 .mk .na \fB\fB-Z\fR\fR .ad .sp .6 .RS 4n Specify that SSL be used to provide certificate-based client authentication. This option requires the \fB-N\fR and SSL password and any other of the SSL options needed to identify the certificate and the key database. .RE .sp .ne 2 .mk .na \fB\fB-z\fR \fIsizelimit\fR\fR .ad .sp .6 .RS 4n Retrieve at most \fIsizelimit\fR entries for a search to complete. .RE .SH EXAMPLES .LP \fBExample 1 \fRPerforming a Subtree Search .sp .LP The following command performs a subtree search (using the default search base) for entries with a commonName of "mark smith". The commonName and telephoneNumber values is retrieved and printed to standard output. Use the \fB-r\fR option to display this output in the old format. .sp .in +2 .nf example% ldapsearch "cn=mark smith" cn telephoneNumber .fi .in -2 .sp .sp .LP The output looks something like this: .sp .in +2 .nf dn: Mark D Smith, ou=Sales, ou=Atlanta, ou=People, o=XYZ, c=US cn: Mark Smith cn: Mark David Smith cn: Mark D Smith 1 cn: Mark D Smith telephoneNumber: +1 123 456-7890 dn: Mark C Smith, ou=Distribution, ou=Atlanta, ou=People, o=XYZ, c=US cn: Mark Smith cn: Mark C Smith 1 cn: Mark C Smith telephoneNumber: +1 123 456-9999 .fi .in -2 .sp .LP \fBExample 2 \fRPerforming a Subtree Search Using the Default Search Base .sp .LP The following command performs a subtree search using the \fB-r\fR option to display in old style format with a default search base for entries with user id of \fBmcs\fR. The user-friendly form of the entry's DN is output after the line that contains the DN itself, and the \fBjpegPhoto\fR and \fBaudio\fR values are retrieved and written to temporary files. .sp .in +2 .nf ldapsearch -r -u -t "uid=mcs" -r jpegPhoto audio .fi .in -2 .sp .sp .LP The output might look like this if one entry with one value for each of the requested attributes is found: .sp .in +2 .nf cn=Mark C Smith, ou=Distribution, ou=Atlanta, ou=People, o=XYZ, c=US Mark C Smith, Distribution, Atlanta, People, XYZ, US audio=/tmp/ldapsearch-audio-a19924 jpegPhoto=/tmp/ldapsearch-jpegPhoto-a19924 .fi .in -2 .sp .LP \fBExample 3 \fRPerforming a One-Level Search .sp .LP The following command performs a one-level search at the c=US level for all organizations whose organizationName begins with XY. .sp .in +2 .nf example% ldapsearch -s one -b "c=US" "o=XY*" o description .fi .in -2 .sp .sp .LP The \fBorganizationName\fR and \fBdescription\fR attribute values are retrieved and printed to standard output, resulting in output similar to this: .sp .in +2 .nf dn: o=XYZ c=US o: XYZ description: XYZ Corporation dn: o="XY Trading Company", c=US o: XY Trading Company description: Import and export specialists dn: o=XYInternational, c=US o: XYInternational o: XYI o: XY International .fi .in -2 .sp .LP \fBExample 4 \fRPerforming a Subtree Search on an IPv6 Server .sp .LP The following command performs a subtree search using the default search base for entries with a user id of \fBmcs\fR on an IPv6 (that is, \fB-h\fR) server: .sp .in +2 .nf example% ldapsearch -u -h '['fec0::111:a00:20ff:fea3:edcf']' \e -t "uid=mcs" jpegPhoto audio .fi .in -2 .sp .SH EXIT STATUS .sp .LP The following exit values are returned: .sp .ne 2 .mk .na \fB\fB0\fR\fR .ad .RS 6n .rt Successful completion. .RE .sp .ne 2 .mk .na \fB>\fB0\fR\fR .ad .RS 6n .rt An error occurred. A diagnostic message is written to standard error. .RE .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for a description of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE Stability LevelEvolving .TE .SH SEE ALSO .sp .LP \fBldapadd\fR(1), \fBldapdelete\fR(1), \fBldapmodify\fR(1), \fBldapmodrdn\fR(1), \fBattributes\fR(5)