Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ldap search problem.

18 views
Skip to first unread message

Andrew Meng

unread,
Feb 5, 2010, 2:02:26 PM2/5/10
to perl...@perl.org

Hello,

LDAP search failed to return any result but I can get the result back using the same base and filter in ldp.exe. Here is the code:

!/usr/bin/perl


use Net::LDAP;

$ldap = Net::LDAP->new("server", port =>389) or die 'Could not contact LDAP server';

$ldap->bind("cn=id,DC=aa,DC=bb", password=>"password") or die 'Could not bind';

$mesg = $ldap->search(filter=>"(&(objectCategory=person)(objectClass=user)(sn=name))",
base=> "DC=aa,DC=bb", attrs=> ['sAMAccountName'] );

@entries = $mesg->entries;

foreach $entry (@entries) {
@attrs = $entry->attributes();
foreach $attr (@attrs) {
printf("\t%s: %s\n", $attr, $entry->get_value($attr));
}
}


$ldap->unbind;

Does anyone know what is wrong?

Thanks a lot in advance!

Andrew

_________________________________________________________________

Clément OUDOT

unread,
Feb 7, 2010, 9:57:18 AM2/7/10
to Andrew Meng, perl...@perl.org
>
> Hello,
>
>
>
> LDAP search failed to return any result but I can get the result back
> using the same base and filter in ldp.exe. Here is the code:
>
>
>
> !/usr/bin/perl
>
>
> use Net::LDAP;
>
>
>
> $ldap = Net::LDAP->new("server", port =>389) or die 'Could not contact
> LDAP server';
>
> $ldap->bind("cn=id,DC=aa,DC=bb", password=>"password") or die 'Could not
> bind';
>
>
>
> $mesg =
> $ldap->search(filter=>"(&(objectCategory=person)(objectClass=user)(sn=name))",
> base=> "DC=aa,DC=bb", attrs=> ['sAMAccountName'] );
>
>
>
> @entries = $mesg->entries;
>
>
>
> foreach $entry (@entries) {
> @attrs = $entry->attributes();
> foreach $attr (@attrs) {
> printf("\t%s: %s\n", $attr, $entry->get_value($attr));
> }
> }
>
>
> $ldap->unbind;
>
>
>
>
>
> Does anyone know what is wrong?

You should maybe set the scope in you search method.

Cl�ment.

acon...@comcast.net

unread,
Feb 7, 2010, 2:34:54 PM2/7/10
to Clément OUDOT, perl...@perl.org, Andrew Meng

I keep getting your email traffic, can you delete me??

thanks,

Clément.

Graham Barr

unread,
Feb 8, 2010, 10:00:47 AM2/8/10
to Andrew Meng, perl...@perl.org

On Feb 5, 2010, at 1:02 PM, Andrew Meng wrote:

>
> Hello,
>
>
>
> LDAP search failed to return any result but I can get the result back using the same base and filter in ldp.exe. Here is the code:
>
>
>
> !/usr/bin/perl
>
>
> use Net::LDAP;
>
>
>
> $ldap = Net::LDAP->new("server", port =>389) or die 'Could not contact LDAP server';
>
> $ldap->bind("cn=id,DC=aa,DC=bb", password=>"password") or die 'Could not bind';

That line is wrong. bind will ALWAYS return true as it returns a message object. You must check the status code in the object

Graham.

Sheahan, John

unread,
Feb 8, 2010, 12:41:33 PM2/8/10
to Andrew Meng, perl...@perl.org
Your base needs to change to the exact container that you want to search or you can change your base to something higher up in the tree that encompasses the container you want to search in.

Perhaps if you change your base to one level up, it might work for you:

Try this: base=> "DC=bb"


From: Andrew Meng [mailto:ml...@hotmail.com]
Sent: Monday, February 08, 2010 12:29 PM
To: Sheahan, John; perl...@perl.org
Subject: RE: ldap search problem.

John,

It turns out to be a "user not found" error(error code 525). In ldp.exe, I need to specify the Windows domain name during the bind operation. So my follow-up question is how I specify the Windows domain in which that id was?

I try:

$ldap->bind("id@mydomain<mailto:id@mydomain>", password=>"password") or die 'Could not bind';
$ldap->bind("mydomain\id", password=>"password") or die 'Could not bind';

none is working.

Thanks a lot,
Andrew

> From: John.S...@priceline.com
> To: ml...@hotmail.com
> Date: Sat, 6 Feb 2010 22:47:04 -0500
> Subject: RE: ldap search problem.
>
> It looks just like the code I am using which works.
>
> Try adding this and see if you get any error messages:
>
> $ldap->debug(12);

________________________________
Live connected with Hotmail on your phone. Learn more.<http://go.microsoft.com/?linkid=9708117>

Andrew Meng

unread,
Feb 8, 2010, 12:28:49 PM2/8/10
to john.s...@priceline.com, perl...@perl.org

John,

It turns out to be a "user not found" error(error code 525). In ldp.exe, I need to specify the Windows domain name during the bind operation. So my follow-up question is how I specify the Windows domain in which that id was?

I try:

$ldap->bind("id@mydomain", password=>"password") or die 'Could not bind';

none is working.

Thanks a lot,

Andrew

_________________________________________________________________
Check your Hotmail from your phone.
http://go.microsoft.com/?linkid=9708121

0 new messages