perldoc Net::LDAP::FAQ
You can subscribe to this list at http://lists.sourceforge.net/mailman/listinfo/perl-ldap-dev
http://www.geocrawler.com/lists/3/SourceForge/3482/0/
There is also an archive of the perl-ldap mailing list at http://www.xray.mpe.mpg.de/mailing-lists/perl-ldap/ which also has messages from before the move to sourceforge.
# replace 0.13 with the version you have
gunzip perl-ldap-0.13.tar.gz tar xvf perl-ldap-0.13.tar cd perl-ldap-0.13 perl Makefile.PL make make test make install
perl -V
This will output information about the version of perl you have installed. Near the bottom you will find something like
@INC: /usr/local/perl/perl5.005/lib/5.00502/sun4-solaris /usr/local/perl/perl5.005/lib/5.00502 /usr/local/perl/perl5.005/lib/site_perl/5.005/sun4-solaris /usr/local/perl/perl5.005/lib/site_perl/5.005 .
This is a list of directories that perl searches when it is looking for a
module. The directory you need is the site_perl directory, but without the
syatem architecture name, in this case it is
/usr/local/perl/perl5.005/lib/site_perl/5.005
. The files required can then be installed with
# replace 0.13 with the version you have
gunzip perl-ldap-0.13.tar.gz tar xvf perl-ldap-0.13.tar cd perl-ldap-0.13/lib
cp * /usr/local/perl/perl5.005/lib/site_perl/5.005
You can obtain the latest release from http://search.cpan.org/search?module=Convert::ASN1
You can obtain the latest release from http://search.cpan.org/search?module=Digest::MD5
You can obtain the latest release from http://search.cpan.org/search?module=URI::ldap
$ldap = Net::LDAP->new($server);
So, for example, to determine the result of the bind operation.
$mesg = $ldap->bind( $dn, password => $passwd); if ( $mesg->code ) { # Handle error codes here }
use Net::LDAP;
$ldap = Net::LDAP->new('ldap.acme.com') or die "$@"; $mesg = $ldap->search( base => "o=acme.com", filter => "uid=jsmith", );
$mesg
is a search object container. It is a reference blessed
into the
Net package. By calling methods on this object you can obtain information about
the result and also the individual entries.
The first thing to check is if the search was successful. This is done with
with the method $mesg-
code>. This method will return the status code that the server returned.
A success will yield a zero value, but there are other values, some of
which could also be considered a success. See Net
use Net::LDAP::Util qw(ldap_error_text);
die ldap_error_text($mesg->code) if $mesg->code;
There are two ways in which you can access the entries. You can access then with an index or you can treat the container like a stack and shift each entry in turn. For example
# as an array
my $max = $mesg->count; # How many entries were returned from the search
for( my $index = 0 ; $index < $max ; $index++) { my $entry = $mesg->entry($index); # ... }
# or as a stack while( my $entry = $mesg->shift_entry) { # ... }
In each case $entry
is an entry object container. It is a
reference blessed into the Net package. By calling methods on this object you can obtain information about
the entry.
For example, to obtain the DN for the entry
$dn = $entry->dn;
To obtain the attributes that a given entry has
@attrs = $entry->attributes;
And to get the list of values for a given attribute
$values = $entry->get( 'sn' );
Notice that the assignment is to a scalar. This is because get
will return a reference to a list, even if there is only one value for that
attribute, and undef
if the attribute does not exist. One thing to remember is that attribute
names are case insensitive, so 'sn', 'Sn', 'sN' and 'SN' are all the same.
So, if you want to print all the values for the attribute 'ou'
then this is as simple as
if( my $values = $entry->get( 'ou' )) { foreach (@$values) { print $_,"\n"; } }
Now if you just want to print all the values for all the attributes you can do
foreach my $attr ($entry->attributes) { foreach my $value ($entry->get($attr)) { print $attr, ": ", $value, "\n"; } }
Please report any bugs, or post any suggestions, to the perl-ldap mailing
list