From: Chris R. <chr...@me...> - 2002-06-13 08:01:08
|
On 12/6/02 7:48 pm, Kent Perrier <kpe...@ev...> wrote: > I am attempting to use perl-ldap (both 0.25 and 0.251) to search and display > the results. I working with perl 5.005_03 on a Solaris 8 box and perl > 5.6.1, Activestate build 631 on a Win2K machine. First, here is my code: > > #!/usr/bin/perl -w > > use Net::LDAP; > use Net::LDAP::LDIF; > > my $server="idev.dobson.net"; > my $port="18251"; > my > $binddn="uid=admin,ou=Administrators,ou=TopologyManagement,o=NetscapeRoot"; > my $passwd="admin"; > my $basedn="o=dobson.net"; > my $scope="sub"; > > my $c = Net::LDAP->new($server, port => $port) or > die "Unable to connect to $server: $@\n"; > > $c->bind ($binddn, password => $passwd) or > die "Unable to bind: $@\n"; That is not the right way to detect bind failure or success. The bind method returns an object that contains the bind results (from the server), and you need to test the result code held in that object. You may also want to bind using LDAPv3 instead of LDAPv2. my $res = $c->bind($binddn, password => $passwd, version => 3); die "Unable to bind: " . ldap_error_name($res->code) . "\n" if $res->code; > my $searchobj = $c->search(base => $basedn, scope => $scope, > filter => $ARGV[0]); > die "Bad search, errorcode #".$searchobj->code() if $searchobj->code( ); > > # process the return values from search ( ) > if ($searchobj) { > my $ldif = new Net::LDAP::LDIF("-"); > $ldif->write($searchobj->entries( )); New Net::LDAP::LDIF objects are by default opened read-only. (perldoc Net::LDAP::LDIF). Try: my $ldif = new Net::LDAP::LDIF "-", "w"; (This is assuming you pass a valid filter to the script, as per your second email.) Cheers, Chris |