Help LDAP connectivity

C

cwoollard

Hello, I hope somebody can help me,

I have this program that is listed below that searches an ldap server
for parameters passed on the command line.

It does work but it doesn't skip binary data that is also returned (in
this case jpeg images). I thought that adding the below line would do
the trick, but it doesn't seem to. Maybe I am doing something wrong.

next if ( $entry =~ /;binary$/ );

Can anybody help

Thanks
chris


use Net::LDAP;

$server = $ARGV[0];
$port = getservbyname("ldap","tcp") || "389";
$basedn = "ou=staff,dc=somewhere,dc=co,dc=uk";
$scope = "sub";

$c = new Net::LDAP($server, port=>$port) or
die "Unable to connect to $server: $@\n";
$c->bind( ) or die "Unable to bind: $@\n"; # anonymous bind

$searchobj = $c->search(base => $basedn, scope => $scope,
filter => $ARGV[1]);
die "Bad search, errorcode #".$searchobj->code() if $searchobj->code(
);

@entries = $searchobj->entries;

foreach $entry (@entries) {
next if ( $entry =~ /;binary$/ );
$entry->dump;
}
 
J

J. Gleixner

Hello, I hope somebody can help me,

I have this program that is listed below that searches an ldap server
for parameters passed on the command line.

It does work but it doesn't skip binary data that is also returned (in
this case jpeg images). I thought that adding the below line would do
the trick, but it doesn't seem to. Maybe I am doing something wrong.

next if ( $entry =~ /;binary$/ );

Can anybody help

Take a look at the value of $entry. It seems that it's not the value
you think it is.

Hint..

entries ( )

Return an array of Net::LDAP::Entry objects that were returned from
the server.
 
C

Chris

Ok, you are right.

If i do

print("$entry\n");

i get

Net::LDAP::Entry=HASH(0x1c21d5c)

Which is very different from what I expected.

I have tried printing some of the other variables too.

print("@entries\n");

which returns
Net::LDAP::Entry=HASH(0x1c218b4)

I think I am not entirely understanding what is going on.

I think i'll go read up on Net::LDAP::Entry

thanks
chris
 
C

Chris

Hmmmm, maybe I should find another way of doing this.

CPAN Says:



dump ( [ FILEHANDLE ] )

Dump the entry to the given filehandle.

This method is intended for debugging purposes and does not treat
binary attributes specially.
 
A

A. Sinan Unur

Ok, you are right.

Who is right? Please provide some context when you post replies.
If i do

print("$entry\n");

i get

Net::LDAP::Entry=HASH(0x1c21d5c)

Which is very different from what I expected.

If $entry refers to an object of type Net::LDAP::Entry, then you should
be able to use the interface provided by that object to access the
fields.
I think i'll go read up on Net::LDAP::Entry

Good idea. You should have done it sooner:

The synopsis in the manual page shows you how to access the attributes of an
Net::LDAP::Entry object:

http://search.cpan.org/~gbarr/perl-ldap-0.33/lib/Net/LDAP/Entry.pod
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top