Re: Net::LDAP compare question
- From: "lexx21" <max_headroom27606@xxxxxxxxx>
- Date: 19 Jun 2006 09:08:53 -0700
Ok, I added "use strict;" and found some defects. I am still not
getting the expected results though. This is where it should do the
compare:
my $href = $result->as_struct;
my @arrayOfDNs = keys %$href;
my $dn;
my $res;
my @entries;
my $entr;
my $mesg;
my $crap;
foreach ( @arrayOfDNs ) {
$dn = $_;
$res = $ldap->compare ( $dn,
attr => "$attrs",
value => ''
);
@entries = $res->dn;
foreach $entr ( @entries ) {
$crap = $entr->dn;
print $crap, "\n";
I think I am doing something wrong as far as the compare statement.
This should take the attribute list that I defined earlier in the
script, and return a value of true or false based on the value. If
true, print the DN for the entry. If false, go to the next entry. For
some reason this isn't happening and I don't see the reason why.
Good idea about using strict though.
James E Keenan wrote:
max_headroom27606@xxxxxxxxx wrote:
I am writing a perl script to query an ldap database and find users who
do not belong to any mail distribution list. I can run the query just
fine, but my problem is getting only results back for users who do have
an attribute entry for the field "memberOf". Here is my code
listing....
I'm not very familiar with Net::LDAP and, in any case, I don't have
access to an LDAP right now on which to test. But I think you should
rule out the possibility that you're getting problems by writing less
than optimal Perl code.
use strict; # this will require you to declare all variables with 'my'
use warnings;
$ldap = Net::LDAP->new( '**************' );
$mesg = $ldap->bind ( "$user",
# unnecessary stringification: $user will suffice; drop the quotes
# for this and all other instances
password => "$password",
version => 3 );
if (!$base) { $base = "ou=****,ou=*****,dc=******,dc=******"; }
if (!$attrs) { $attrs = [ 'memberOf' ]; }
$search = 'mail=*@**********.com';
$result = $ldap->search ( base => "$base",
scope => "sub",
filter => "$search",
attrs => $attrs
);
$href = $result->as_struct;
@arrayOfDNs = keys %$href;
foreach ( @arrayOfDNs ) {
$dn = $_;
# Above 2 lines could be reduced to:
foreach my $dn (@arrayOfDNs) {
$res = $ldap->compare ( $dn,
attr => "$attrs",
value => ''
);
@entries = $res->dn;
# Without thinking too hard about it, what does '->dn' mean in the above
line: method call? hash dereference?
foreach $entr ( @enties ) {
$butes = $entr->dn;
print $butes, "\n";
}
print "#-------------------------------\n";
}
$mesg = $ldap->unbind;
This is pretty much a cut/paste of the example given in CPAN,
That will only be true once you've coded it more cleanly and rerun it
with strictures and warnings.
jimk
.
- Follow-Ups:
- Re: Net::LDAP compare question
- From: Charles DeRykus
- Re: Net::LDAP compare question
- References:
- Net::LDAP compare question
- From: max_headroom27606
- Re: Net::LDAP compare question
- From: James E Keenan
- Net::LDAP compare question
- Prev by Date: Help with Module::Build
- Next by Date: Re: Help! SOAP::Lite: How to set the namespace prefix for the request?
- Previous by thread: Re: Net::LDAP compare question
- Next by thread: Re: Net::LDAP compare question
- Index(es):
Relevant Pages
|