I want to check if a given DN exists in the LDAP directory, using Perl and Net::LDAP. So, I figured I'd do something like this:
my $dn = 'uid=foo,ou=bar,ou=baz';
$ldap->search(base => $dn, scope => 'base', attrs => ['dn']);
However, that results in a Bad filter
error. I can get it to work by adding filter => '(objectClass=*)'
, but that seems a little klugey.
Is this how I'm supposed to do this, or have I missed something? I'm new to Net::LDAP.
An LDAP client must supply a valid search filter to a search request. Try using (&)
for the filter. Note that some broken directory servers do not accept the legal filter (&)
. If your server is broken in this way, use the present filter (objectClass=*)
instead.