derobert
derobert

Reputation: 51177

How to do a search-by-DN using Net::LDAP

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.

Upvotes: 0

Views: 1511

Answers (1)

Terry Gardner
Terry Gardner

Reputation: 11132

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.

Upvotes: 2

Related Questions