List Info

Thread: net ldap, paging of large values from AD - problems




net ldap, paging of large values from AD - problems
user name
2006-04-13 07:41:40
Hello.
I'm having some trouble dealing with ranges or pages
being returned when I do a query.
I'm querying the homeMDBBL attribute which lists the
mailboxes in an Exchnage mail store.
When I view the entry using the Microsoft LDAP browser
(ldp.exe) it shows only a small amount of detail and
says tha tthe range returned is 0-1499. Apparently
Windows 2003 AD has a page size of 1500.
Anyway, I'm struggling to deal with this value
properly.  Here is the code I have put together from
looing at various srouces but it doesn't work.  It
seems to fail to  get a cookie and drops out when
doing the lookup.
If you have an exchnage environment it is a simple
case of altering the first four variables in the
script below and then running the script.  You can
browse with an LDAP browser - such as ldp.exe -to
determine what the values should be for your
environment.
Any suggestions?

* * * * *
#!/usr/bin/perl -w
use Net::LDAP;
use Net::LDAP::Control::Paged;
use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); 

$dc1 = "server01.mydomain.local";
$user="cn=testuser,cn=Users,dc=mydomain,dc=local"
;;
$passwd="password";
$ldap_query_string = "CN=SG1MDB2
(SERVER12),CN=SG1,CN=InformationStore,CN=SERVER12,CN=Servers
,CN=SITE006,CN=Administrative
Groups,CN=MAILORG,CN=Microsoft
Exchange,CN=Services,CN=Configuration,DC=mydomain,DC=local&
quot;;

$ldap = Net::LDAP->new($dc1);

$mesg = $ldap->bind ( dn => $user,
                     password =>$passwd,
		     version  => '3',
		    );
if ( $mesg->code()) {
    die ("error:",
$mesg->code(),"\n","error name:
",$mesg->error_name(),
        "\n", "error text:
",$mesg->error_text(),"\n");
}

my mailbox_return_array =
get_specific_value_via_ldap("homeMDBBL",
$ldap_query_string);
foreach my $mailbox (mailbox_return_array) {
	print "	mailbox is $mailbox -\n";
}

$ldap->unbind(); 


sub get_specific_value_via_ldap {
	my ($object_name, $ldap_query_string) = _;
	my ldap_object_value;

	my $page = Net::LDAP::Control::Paged->new( size =>
1490 );

	args = (
		base     => $ldap_query_string,
		scope    => "sub",
		filter => "(objectClass=*)",
		control  => [ $page ],
		attrs => $object_name,
		debug => 1
	        ); 

	my $cookie;

       	while(1) {
		print "	performing search...\n";
#		 Perform search
                my $mesg = $ldap->search( args );

                # Only continue on LDAP_SUCCESS
                if ($mesg->code) {
                        warn "ERROR - not
LDAP_SUCCESS";
       	                last;
               	}

                # Get cookie from paged control
                my($resp) = $mesg->control(
LDAP_CONTROL_PAGED ) or last;
                $cookie = $resp->cookie or last;
		print "cookie is $cookie -\n";
                # Set cookie in paged control
                $page->cookie($cookie);

                foreach my $entry ($mesg->all_entries)
{
			ldap_object_value =
$entry->get_value($object_name);
		}

       	}
        if ($cookie) {
                $page->cookie($cookie);
                $page->size(0);
                $ldap->search( args );
        } 

	return ldap_object_value;
}

* * * *

If I replace the subroutine with this one below it
still doesn't work on a mail store that has more than
1500 entries but if I run it on a mail store that has
less I get all the mail boxes back.

* * * *
sub get_specific_value_via_ldap {
	my ($object_name, $ldap_query_string) = _;
	my ldap_object_value;

	my $page = Net::LDAP::Control::Paged->new( size =>
1490 );

	args = (
		base     => $ldap_query_string,
		scope    => "sub",
		filter => "(objectClass=*)",
		control  => [ $page ],
		attrs => $object_name,
		debug => 1
	        ); 


	my $mesg = $ldap->search( args );

	foreach my $entry ( $mesg->entries ) {
		ldap_object_value =
$entry->get_value($object_name);
#		print "	ldap_object_value is $ldap_object_value[0]
-\n";
	}

	return ldap_object_value;
}

* * * *

Thanks,
PJ



Send instant messages to your online friends http://au.messenger.yah
oo.com 
_______________________________________________
Perl-Win32-Admin mailing list
Perl-Win32-Adminlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )