]> git.sur5r.net Git - openldap/blob - doc/man/man1/ldapsearch.1
ITS#5009
[openldap] / doc / man / man1 / ldapsearch.1
1 .TH LDAPSEARCH 1 "RELEASEDATE" "OpenLDAP LDVERSION"
2 .\" $OpenLDAP$
3 .\" Copyright 1998-2007 The OpenLDAP Foundation All Rights Reserved.
4 .\" Copying restrictions apply.  See COPYRIGHT/LICENSE.
5 .SH NAME
6 ldapsearch \- LDAP search tool
7 .SH SYNOPSIS
8 .B ldapsearch
9 [\c
10 .BR \-n ]
11 [\c
12 .BR \-c ]
13 [\c
14 .BR \-u ]
15 [\c
16 .BR \-v ]
17 [\c
18 .BR \-t[t] ]
19 [\c
20 .BI \-T \ path\fR]
21 [\c
22 .BI \-F \ prefix\fR]
23 [\c
24 .BR \-A ]
25 [\c
26 .BR \-C ]
27 [\c
28 .BR \-L[L[L]] ]
29 [\c
30 .BR \-M[M] ]
31 [\c
32 .BI \-S \ attribute\fR]
33 [\c
34 .BI \-d \ debuglevel\fR]
35 [\c
36 .BI \-f \ file\fR]
37 [\c
38 .BR \-x ]
39 [\c
40 .BI \-D \ binddn\fR]
41 [\c
42 .BR \-W ]
43 [\c
44 .BI \-w \ passwd\fR]
45 [\c
46 .BI \-y \ passwdfile\fR]
47 [\c
48 .BI \-H \ ldapuri\fR]
49 [\c
50 .BI \-h \ ldaphost\fR]
51 [\c
52 .BI \-p \ ldapport\fR]
53 [\c
54 .BI \-b \ searchbase\fR]
55 [\c
56 .BI \-s \ base\fR\||\|\fIone\fR\||\|\fIsub\fR\||\|\fIchildren\fR]
57 [\c
58 .BI \-a \ never\fR\||\|\fIalways\fR\||\|\fIsearch\fR\||\|\fIfind\fR]
59 [\c
60 .BI \-P \ 2\fR\||\|\fI3\fR]
61 [\c
62 .BR \-e \ [!]ext[=extparam]]
63 [\c
64 .BR \-E \ [!]ext[=extparam]]
65 [\c
66 .BI \-l \ timelimit\fR]
67 [\c
68 .BI \-z \ sizelimit\fR]
69 [\c
70 .BR \-O \ security-properties ]
71 [\c
72 .BR \-I ]
73 [\c
74 .BR \-Q ]
75 [\c
76 .BI \-U \ authcid\fR]
77 [\c
78 .BI \-R \ realm\fR]
79 [\c
80 .BI \-X \ authzid\fR]
81 [\c
82 .BI \-Y \ mech\fR]
83 [\c
84 .BR \-Z[Z] ]
85 .I filter
86 [\c
87 .IR attrs... ]
88 .SH DESCRIPTION
89 .I ldapsearch
90 is a shell-accessible interface to the
91 .BR ldap_search_ext (3)
92 library call.
93 .LP
94 .B ldapsearch
95 opens a connection to an LDAP server, binds, and performs a search
96 using specified parameters.   The \fIfilter\fP should conform to
97 the string representation for search filters as defined in RFC 4515.
98 If not provided, the default filter, (objectClass=*), is used.
99 .LP
100 If
101 .B ldapsearch
102 finds one or more entries, the attributes specified by
103 \fIattrs\fP are returned.  If * is listed, all user attributes are
104 returned.  If + is listed, all operational attributes are returned.
105 If no \fIattrs\fP are listed, all user attributes are returned.  If only
106 1.1 is listed, no attributes will be returned.
107 .SH OPTIONS
108 .TP
109 .B \-n
110 Show what would be done, but don't actually perform the search.  Useful for
111 debugging in conjunction with -v.
112 .TP
113 .B \-c
114 Continuous operation mode. Errors are reported, but ldapsearch will continue
115 with searches. The default is to exit after reporting an error.  Only useful
116 in conjunction with -f.
117 .TP
118 .B \-u
119 Include the User Friendly Name form of the Distinguished Name (DN)
120 in the output.
121 .TP
122 .B \-v
123 Run in verbose mode, with many diagnostics written to standard output.
124 .TP
125 .B \-t[t]
126 A single -t writes retrieved non-printable values to a set of temporary
127 files.  This is useful for dealing with values containing non-character
128 data such as jpegPhoto or audio. A second -t writes all retrieved values to
129 files.
130 .TP
131 .BI \-T \ path
132 Write temporary files to directory specified by \fIpath\fP (default:
133 /var/tmp/)
134 .TP
135 .BI \-F \ prefix
136 URL prefix for temporary files.  Default is file://\fIpath\fP/ where
137 \fIpath\fP is /var/tmp/ or specified with -T.
138 .TP
139 .B \-A
140 Retrieve attributes only (no values).  This is useful when you just want to
141 see if an attribute is present in an entry and are not interested in the
142 specific values.
143 .TP
144 .B \-C
145 Chase referrals (anonymously).
146 .TP
147 .B \-L
148 Search results are display in LDAP Data Interchange Format detailed in
149 .BR ldif (5).
150 A single -L restricts the output to LDIFv1.
151 A second -L disables comments.
152 A third -L disables printing of the LDIF version.
153 The default is to use an extended version of LDIF.
154 .TP
155 .B \-M[M]
156 Enable manage DSA IT control.
157 .B \-MM
158 makes control critical.
159 .TP
160 .BI \-S \ attribute
161 Sort the entries returned based on \fIattribute\fP. The default is not
162 to sort entries returned.  If \fIattribute\fP is a zero-length string (""),
163 the entries are sorted by the components of their Distinguished Name.  See
164 .BR ldap_sort (3)
165 for more details. Note that
166 .B ldapsearch
167 normally prints out entries as it receives them. The use of the
168 .B \-S
169 option defeats this behavior, causing all entries to be retrieved,
170 then sorted, then printed.
171 .TP
172 .BI \-d \ debuglevel
173 Set the LDAP debugging level to \fIdebuglevel\fP.
174 .B ldapsearch
175 must be compiled with LDAP_DEBUG defined for this option to have any effect.
176 .TP
177 .BI \-f \ file
178 Read a series of lines from \fIfile\fP, performing one LDAP search for
179 each line.  In this case, the \fIfilter\fP given on the command line
180 is treated as a pattern where the first and only occurrence of \fB%s\fP
181 is replaced with a line from \fIfile\fP.  Any other occurence of the
182 the \fB%\fP character in the pattern will be regarded as an error.
183 Where it is desired that the search filter include a \fB%\fP character,
184 the character should be encoded as \fB\\25\fP (see RFC 4515).
185 If \fIfile\fP is a single
186 \fI-\fP character, then the lines are read from standard input.
187 .B ldapsearch
188 will exit when the first non-successful search result is returned,
189 unless -c is used.
190 .TP
191 .B \-x 
192 Use simple authentication instead of SASL.
193 .TP
194 .BI \-D \ binddn
195 Use the Distinguished Name \fIbinddn\fP to bind to the LDAP directory.
196 .TP
197 .B \-W
198 Prompt for simple authentication.
199 This is used instead of specifying the password on the command line.
200 .TP
201 .BI \-w \ passwd
202 Use \fIpasswd\fP as the password for simple authentication.
203 .TP
204 .BI \-y \ passwdfile
205 Use complete contents of \fIpasswdfile\fP as the password for
206 simple authentication.
207 .TP
208 .BI \-H \ ldapuri
209 Specify URI(s) referring to the ldap server(s); only the protocol/host/port
210 fields are allowed; a list of URI, separated by whitespace or commas
211 is expected.
212 .TP
213 .BI \-h \ ldaphost
214 Specify an alternate host on which the ldap server is running.
215 Deprecated in favor of -H.
216 .TP
217 .BI \-p \ ldapport
218 Specify an alternate TCP port where the ldap server is listening.
219 Deprecated in favor of -H.
220 .TP
221 .BI \-b \ searchbase
222 Use \fIsearchbase\fP as the starting point for the search instead of
223 the default.
224 .TP
225 .BI \-s \ base\fR\||\|\fIone\fR\||\|\fIsub\fR\||\|\fIchildren
226 Specify the scope of the search to be one of
227 .IR base ,
228 .IR one ,
229 .IR sub ,
230 or
231 .I children
232 to specify a base object, one-level, subtree, or children search.
233 The default is
234 .IR sub .
235 Note:
236 .I children
237 scope requires LDAPv3 subordinate feature extension.
238 .TP
239 .BI \-a \ never\fR\||\|\fIalways\fR\||\|\fIsearch\fR\||\|\fIfind
240 Specify how aliases dereferencing is done.  Should be one of
241 .IR never ,
242 .IR always ,
243 .IR search ,
244 or
245 .I find
246 to specify that aliases are never dereferenced, always dereferenced,
247 dereferenced when searching, or dereferenced only when locating the
248 base object for the search.  The default is to never dereference aliases.
249 .TP
250 .BI \-P \ 2\fR\||\|\fI3
251 Specify the LDAP protocol version to use.
252 .TP
253 .B \-e \fI[!]ext[=extparam]\fP
254 .TP
255 .B \-E \fI[!]ext[=extparam]\fP
256
257 Specify general extensions with -e and search extensions with -E.
258 \'!\' indicates criticality.
259
260 General extensions:
261 .nf
262   [!]assert=<filter>   (an RFC 4515 Filter)
263   [!]authzid=<authzid> ("dn:<dn>" or "u:<user>")
264   [!]manageDSAit
265   [!]noop
266   ppolicy
267   [!]postread[=<attrs>]        (a comma-separated attribute list)
268   [!]preread[=<attrs>] (a comma-separated attribute list)
269   abandon, cancel (SIGINT sends abandon/cancel; not really controls)
270 .fi
271
272 Search extensions:
273 .nf
274   [!]domainScope                               (domain scope)
275   [!]mv=<filter>                               (matched values filter)
276   [!]pr=<size>[/prompt|noprompt]       (paged results/prompt)
277   [!]subentries[=true|false]           (subentries)
278   [!]sync=ro[/<cookie>]                        (LDAP Sync refreshOnly)
279           rp[/<cookie>][/<slimit>]     (LDAP Sync refreshAndPersist)
280 .fi
281 .TP
282 .BI \-l \ timelimit
283 wait at most \fItimelimit\fP seconds for a search to complete.
284 A timelimit of
285 .I 0
286 (zero) or
287 .I none
288 means no limit.
289 A timelimit of
290 .I max
291 means the maximum integer allowable by the protocol.
292 A server may impose a maximal timelimit which only
293 the root user may override.
294 .TP
295 .BI \-z \ sizelimit
296 retrieve at most \fIsizelimit\fP entries for a search.
297 A sizelimit of
298 .I 0
299 (zero) or
300 .I none
301 means no limit.
302 A sizelimit of
303 .I max
304 means the maximum integer allowable by the protocol.
305 A server may impose a maximal sizelimit which only
306 the root user may override.
307 .TP
308 .BI \-O \ security-properties
309 Specify SASL security properties.
310 .TP
311 .B \-I
312 Enable SASL Interactive mode.  Always prompt.  Default is to prompt
313 only as needed.
314 .TP
315 .B \-Q
316 Enable SASL Quiet mode.  Never prompt.
317 .TP
318 .BI \-U \ authcid
319 Specify the authentication ID for SASL bind. The form of the ID
320 depends on the actual SASL mechanism used.
321 .TP
322 .BI \-R \ realm
323 Specify the realm of authentication ID for SASL bind. The form of the realm
324 depends on the actual SASL mechanism used.
325 .TP
326 .BI \-X \ authzid
327 Specify the requested authorization ID for SASL bind.
328 .I authzid
329 must be one of the following formats:
330 .B dn:\c
331 .I <distinguished name>
332 or
333 .B u:\c
334 .I <username>
335 .TP
336 .BI \-Y \ mech
337 Specify the SASL mechanism to be used for authentication. If it's not
338 specified, the program will choose the best mechanism the server knows.
339 .TP
340 .B \-Z[Z]
341 Issue StartTLS (Transport Layer Security) extended operation. If you use
342 .B \-ZZ\c
343 , the command will require the operation to be successful.
344 .SH OUTPUT FORMAT
345 If one or more entries are found, each entry is written to standard
346 output in LDAP Data Interchange Format or
347 .BR ldif (5):
348 .LP
349 .nf
350     version: 1
351
352     # bjensen, example, net
353     dn: uid=bjensen,dc=example,dc=net
354     objectClass: person
355     objectClass: dcObject
356     uid: bjensen
357     cn: Barbara Jensen
358     sn: Jensen
359     ...
360 .fi
361 .LP
362 If the -t option is used, the URI of a temporary file
363 is used in place of the actual value.  If the -A option
364 is given, only the "attributename" part is written.
365 .SH EXAMPLE
366 The following command:
367 .LP
368 .nf
369     ldapsearch -LLL "(sn=smith)" cn sn telephoneNumber
370 .fi
371 .LP
372 will perform a subtree search (using the default search base and
373 other parameters defined in
374 .BR ldap.conf (5))
375 for entries with a surname (sn) of smith.  The common name (cn), surname
376 (sn) and telephoneNumber values will be retrieved and printed to
377 standard output.
378 The output might look something like this if two entries are found:
379 .LP
380 .nf
381     dn: uid=jts,dc=example,dc=com
382     cn: John Smith
383     cn: John T. Smith
384     sn: Smith
385     sn;lang-en: Smith
386     sn;lang-de: Schmidt
387     telephoneNumber: 1 555 123-4567
388
389     dn: uid=sss,dc=example,dc=com
390     cn: Steve Smith
391     cn: Steve S. Smith
392     sn: Smith
393     sn;lang-en: Smith
394     sn;lang-de: Schmidt
395     telephoneNumber: 1 555 765-4321
396 .fi
397 .LP
398 The command:
399 .LP
400 .nf
401     ldapsearch -LLL -u -t "(uid=xyz)" jpegPhoto audio
402 .fi
403 .LP
404 will perform a subtree search using the default search base for entries
405 with user id of "xyz".  The user friendly form of the entry's DN will be
406 output after the line that contains the DN itself, and the jpegPhoto
407 and audio values will be retrieved and written to temporary files.  The
408 output might look like this if one entry with one value for each of the
409 requested attributes is found:
410 .LP
411 .nf
412     dn: uid=xyz,dc=example,dc=com
413     ufn: xyz, example, com
414     audio:< file:///tmp/ldapsearch-audio-a19924
415     jpegPhoto:< file:///tmp/ldapsearch-jpegPhoto-a19924
416 .fi
417 .LP
418 This command:
419 .LP
420 .nf
421     ldapsearch -LLL -s one -b "c=US" "(o=University*)" o description
422 .fi
423 .LP
424 will perform a one-level search at the c=US level for all entries
425 whose organization name (o) begins begins with \fBUniversity\fP.
426 The organization name and description attribute values will be retrieved
427 and printed to standard output, resulting in output similar to this:
428 .LP
429 .nf
430     dn: o=University of Alaska Fairbanks,c=US
431     o: University of Alaska Fairbanks
432     description: Preparing Alaska for a brave new yesterday
433     description: leaf node only
434
435     dn: o=University of Colorado at Boulder,c=US
436     o: University of Colorado at Boulder
437     description: No personnel information
438     description: Institution of education and research
439
440     dn: o=University of Colorado at Denver,c=US
441     o: University of Colorado at Denver
442     o: UCD
443     o: CU/Denver
444     o: CU-Denver
445     description: Institute for Higher Learning and Research
446
447     dn: o=University of Florida,c=US
448     o: University of Florida
449     o: UFl
450     description: Warper of young minds
451
452     ...
453 .fi
454 .SH DIAGNOSTICS
455 Exit status is zero if no errors occur.
456 Errors result in a non-zero exit status and
457 a diagnostic message being written to standard error.
458 .SH "SEE ALSO"
459 .BR ldapadd (1),
460 .BR ldapdelete (1),
461 .BR ldapmodify (1),
462 .BR ldapmodrdn (1),
463 .BR ldap.conf (5),
464 .BR ldif (5),
465 .BR ldap (3),
466 .BR ldap_search_ext (3),
467 .BR ldap_sort (3)
468 .SH AUTHOR
469 The OpenLDAP Project <http://www.openldap.org/>
470 .SH ACKNOWLEDGEMENTS
471 .so ../Project