LDAP query trouble

N

Ninja67

I have the following code on a Windows 2003 server:

#---------------------------------------------------------------
#!C:/Perl/bin/perl.exe

use warnings;
use Net::LDAP;
use Net::LDAP::LDIF;
my @we_want = qw(cn mail telephoneNumber givenName);

$HOST = 'FTWWDDCNP002';

$ldap = Net::LDAP->new($HOST);
$ldap->bind ; # an anonymous bind

my $mesg = $ldap->search( filter=>"(cn=c*)", attrs=>[@we_want],
scope=>'sub');
my $count = $mesg->count;
print "$count matches retrieved from LDAP.\n";

$ldap->unbind; # take down session

exit;
#---------------------------------------------------------------

I installed the necessary modules and the script does indeed run, but
it always returns immediately with 0 matches. If I change the base
attribute to be more specific, it returns some matches, but they are
only from the root. It's as if it is ignoring my scope parameter. I
tried leaving the scope off since the derfault is already "sub" but
that didn't make a difference.

I'm able to connect open and view all of the LDAP fields when using the
free utility BeaverTail. Also, I the same query works perfectly from a
different server using VisualBasic.

Any suggestions appreciated.
 
N

Ninja67

Christian said:
Ninja67 said:
I have the following code on a Windows 2003 server:

#---------------------------------------------------------------
#!C:/Perl/bin/perl.exe

use warnings;
use Net::LDAP;
use Net::LDAP::LDIF;
my @we_want = qw(cn mail telephoneNumber givenName);

$HOST = 'FTWWDDCNP002';

$ldap = Net::LDAP->new($HOST);
$ldap->bind ; # an anonymous bind

my $mesg = $ldap->search( filter=>"(cn=c*)", attrs=>[@we_want],
scope=>'sub');

Did you try and see if there was any error from the query?
Inserting
$mesg->code() && die $mesg->error();
might give some more hints about what went wrong.
my $count = $mesg->count;
print "$count matches retrieved from LDAP.\n";

$ldap->unbind; # take down session

exit;
#---------------------------------------------------------------

It could have something to do with permissions. In the AD environments
I've worked with I had to use authenticated binds to successfully
perform all search operations. But as I don't know about your settings,
this is just a vague guess.

-Chris

Anything is possible, but I'm not providing credentials from the other
server which is working via VisualBasic. Plus, if I change the base,
then I do get some results (8), but they aren't what I expected. I
would think that if it is a permissions problem, I would always return
0 matches.
 
N

Ninja67

Christian said:
Ninja67 said:
I have the following code on a Windows 2003 server:

#---------------------------------------------------------------
#!C:/Perl/bin/perl.exe

use warnings;
use Net::LDAP;
use Net::LDAP::LDIF;
my @we_want = qw(cn mail telephoneNumber givenName);

$HOST = 'FTWWDDCNP002';

$ldap = Net::LDAP->new($HOST);
$ldap->bind ; # an anonymous bind

my $mesg = $ldap->search( filter=>"(cn=c*)", attrs=>[@we_want],
scope=>'sub');

Did you try and see if there was any error from the query?
Inserting
$mesg->code() && die $mesg->error();
might give some more hints about what went wrong.
my $count = $mesg->count;
print "$count matches retrieved from LDAP.\n";

$ldap->unbind; # take down session

exit;
#---------------------------------------------------------------

It could have something to do with permissions. In the AD environments
I've worked with I had to use authenticated binds to successfully
perform all search operations. But as I don't know about your settings,
this is just a vague guess.

-Chris

Yes. If I specifiy a base, then no error is returned but no results
either. If I don't specify a base or I specify base=>'' then I get:
NameErr:DSID_03100198, problem 2001 <NO_OJBECT>, data 0, best match of:
''
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top