Perl Net::LDAP:: Help

XBoxLPU

Diamond Member
Aug 21, 2001
4,249
1
0
I am rather new at Perl but I have searched to no end for a reason why my subroutine modifyAD will not return a result using the search filter. The search filter for the subroutine modifyLDAP returns valid results. Connection isn't the reason why I am not returning any results as I do enter the subroutine, it never enters the if statement in the code and goes to the else if statement. The input variable is not the reason either as the value is printed correctly in the logfile

$ldap is searching a Sun LDAP Enterprise Directory server
$AD is searching an Active Directory via Net::LDAP::


Any suggestions would be very helpful!

sub modifyLDAP
{
$result = $ldap->search(filter=>"(attribute)",
base=>"ou=value,dc=value,dc=value",
attrs=>['attribute','attribute','attribute', 'attribute']);

if ($result->count ==1)
{
code
}

}

sub modifyAD

{
$result = $AD->search(filter=>"(&(objectClass=*)(attribute=$input)",
base=>"ou=value,dc=value,dc=value",,
attrs=>['attribute','attribute','attribute', 'attribute']);

if ($result->count ==1)
{
code
}

elsif ($result->count ==0)
{
print LOGFILE "Zero entries for " . attribute . "\n";
$countMatch0 = $countMatch0 + 1;
}

}


 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
I haven't used Net::LDAP (maybe once, but so long ago I've forgotten), but I'll try to help nonetheless. Just glancing at the CPAN documentation your usage of the module looks fine.

Are you sure your search query only returns 1 entry? If it may return multiple entries, then the condition of your if statement should probably be $result->count > 0, not $result->count == 1. Can't see anything wrong otherwise.
 

XBoxLPU

Diamond Member
Aug 21, 2001
4,249
1
0
Originally posted by: esun
I haven't used Net::LDAP (maybe once, but so long ago I've forgotten), but I'll try to help nonetheless. Just glancing at the CPAN documentation your usage of the module looks fine.

Are you sure your search query only returns 1 entry? If it may return multiple entries, then the condition of your if statement should probably be $result->count > 0, not $result->count == 1. Can't see anything wrong otherwise.
If it was returning more than 1 entry, it wouldn't enter the elseif bock. The count would not equal 0
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Yeah, sorry I missed that. Have you checked $result->code and made sure it's zero? And if not, compared it to the error codes listed in Net::LDAP::Constant?
 

XBoxLPU

Diamond Member
Aug 21, 2001
4,249
1
0
Inserting the search filter into the softerra ldap admin (GUI) returns 1 result
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Are there any other attributes in the result "object" that you can look at that might give some insight on what is going on?
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Try setting the DEBUG option when creating the LDAP object. It will report incoming/outgoing packets to STDERR (depending on what you set DEBUG to) so you can try to determine what's going on from those.

1 Show outgoing packets (using asn_hexdump).
2 Show incoming packets (using asn_hexdump).
4 Show outgoing packets (using asn_dump).
8 Show incoming packets (using asn_dump).