JoshWillis
MIS
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";
}
}
}
}
}
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";
}
}
}
}
}