Entries in an LDAP directory can be read directly if
the exact DN is known. Usually, however, the directory is searched
for entries that match a particular set of specifications. In order
to perform a search, the directory server has to know the starting
place in the tree (called the
base), how
deep in the tree the user wants to look (called the
scope), and the search criteria (called the
filter).
The base
can be any DN that is served by the directory server that is being
queried. If the DN is outside the domain of the server, it might return
a
referral. The referral has the data that
is necessary to connect to another server that might have more entries
that match the filter. The client might decide either to
chase (peruse possible filter matches on the other
server) the referral or to ignore it.
A search can also contain
a scope. The scope determines how far down in the tree from the base
the search is made. A scope of BASE returns only the base object if
it exists and matches the filter. (The filter is required even with
a scope of BASE). A scope of ONE searches only the base and entries
immediately below the base entry. A scope of SUB searches the entire
sub tree starting at the base entry. Limiting the scope of a search
makes it more efficient. If you know that an entry is one level below
the base, then limiting the search to that scope makes the search
run faster. If you want to search all entries that are below the base,
search the sub tree.
A scope of BASE is used
when you retrieve special entries. For example, most servers support
a special entry with a DN of cn=monitor that returns information about
the state of the server. When you search for that entry, a scope of
BASE is required.
The search filter determines which entries below the base are returned.
A simple filter consists of an attribute name, an operator, and a
value. The following table describes the valid search operators.
LDAP Search Filter Operators
|
|
|
|
|
|
Attribute must exactly
match value.
|
|
|
|
Substring attribute
must contain substrings provided. The asterisk (*) matches zero or
more characters.
|
(cn=*Smith,
title=*Manager*)
|
|
|
Attribute must be greater
than or equal to value.
|
|
|
|
Attribute must be less
than or equal to value.
|
|
|
|
Entry has attribute
of specified name.
|
|
|
|
Usually implemented
as a "sounds like" algorithm. Attribute must be "approximately equal"
to value.
|
|
|
|
All filters must be
true.
|
(&(sn=Smith)(ou=Reservations))
|
|
|
Any of the filters might
be true.
|
(|(manager=cn=Jean
Smith,ou=Reservations,o=Alphalite Airways,c=US)(ou=Marketing))
|
|
|
None of the filters
might be true.
|
(&(!(ou=Maintenance)(!(ou=Finance))))
|