Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NET::LDAP::Control::Paged

Status
Not open for further replies.
Joined
Aug 24, 2006
Messages
1
Location
US
I need some help here. I have never used this functionality of PERL before. VBS makes the paging much easier but, I need PERL for this.

Here is the code that I am dealing with.

My question lies in the last section of code where I am iterating through my result set. How should I change this to take into account that I am now working with paged results? The code that is currently there will just process through everything that is returned. This was problematic because the LDAP server only returns 1000 results at a time. hence the paging.

Thanks!

#Define Criteria to search upon
my $searchString = 'DC=domain,DC=name,DC=com';
my $filter = "objectClass=group";
my $attrs = "distinguishedName, mail, member, cn";
my $scope = "sub";
my $control = $searchPage;

print STDOUT "\nSearching for all Groups...\n";

#Cookie for Paged Searching
my $cookie;

while (1){

#Begin Search
my $groupSearchResults = $groupSearchLDAP->search(base=>$searchString,filter=>$filter,attrs=>$attrs,scope=>$scope,control=>[$control]) or "Could Not Search!";

#Only continue on LDAP_SUCCESS
$groupSearchinResults->code and last;

my $response = $groupSearchResults->control( LDAP_CONTROL_PAGED ) or last;
$cookie = $response->cookie or last;

$searchPage->cookie($cookie);

}


if ($cookie) {
# We had an abnormal exit, so let the server know we do not want any more
$searchPage->cookie($cookie);
$searchPage->size(0);
$groupSearchLDAP->search(base=>$searchString,filter=>$filter,attrs=>$attrs,scope=>$scope,control=>[$control]) or "Could Not Search!";
}


print STDOUT "Completed Searching...\n";

#Count groupSearchResults returned
my $count = $groupSearchResults->count;

print STDOUT "Found $count total Groups...\n";

print STDOUT "Analyzing Groups for E-mail Attributes...\n";

#Iterate through the recordsets for $count -1 iterations
for (my $i = 0; $i < $count; $i++) {

#Get current entry
$entry = $groupSearchResults->entry($i);

my $hasMail = $entry->get_value('mail');
my $groupName = $entry->get_value('cn');

#Is group mail enabled?
if ($hasMail ne "" ){
my @groupMemberArray = $entry->get_value('member');

foreach my $member (@groupMemberArray){
if( $contactsHash{$member}){
my $emailAddress = $contactsHash{$member};

if( !($emailAddress =~ /.mil$/) ){
print OUTPUTFILE "$groupName\t$member\t$emailAddress\n";
}
}
}
}

}
 
Hi Josh,

Maybe I'm misreading your intentions, but your line

$cookie = $response->cookie or last;

within the while() loop is followed by the test

if ($cookie) {
# We had an abnormal exit......

outside the loop.

Isn't that the wrong way around? I would have said

$cookie = $response->cookie and last;

or is it the line before that which is the error get-out of the loop and will leave $cookie set?

Mike

The options are: fast, cheap and right - pick any two. [orientalbow] & [anakin]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top