• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Perl Net::LDAP:: Help

XBoxLPU

Diamond Member
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;
}

}


 
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.
 
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
 
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?
 
Are there any other attributes in the result "object" that you can look at that might give some insight on what is going on?
 
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).
 
Back
Top