in reply to perl-LDAP process hangs

You should verify that your bind call goes right. For example with

use Net::LDAP::Util qw(ldap_error_text ldap_error_name) ; my $msg ; # you will need it several times $msg = $ldap->bind(%your_bind_params) ; if ($msg->is_error) { my $code = $msg->code ; die join "\n",ldap_error_name($code), ldap_error_text($code) ; }

you will get an idea of what goes wrong.

Next, it seems you don't cycle over the %petra hash, your $dn doesn't depend on the username... how could you get it to put all your users into the directory server?

To put the users in, I'd use something like this untested code, based on yours:

while (my ($username,$userdata) = each %petra) { my $entry = Net::LDAP::Entry->new(); my $dn = calculate_it_using($username) ; $entry->dn($dn) ; $entry->changetype("add"); $entry->add(@$userdata) ; $msg = $entry->update($ldap) ; if ($msg->is_error) { # die() the same way as before. I'd suggest # to create a subroutine to do the job, e.g. # die_ldap_error($msg->code) } }

I seldom use that syntax anyway. I prefer using $ldap->add($entry) instead. But that's a matter of taste :-)

Ciao!
--bronto

# Another Perl edition of a song:
# The End, by The Beatles
END {
  $you->take($love) eq $you->make($love) ;
}

Replies are listed 'Best First'.
Re: Re: perl-LDAP process hangs
by Anonymous Monk on Nov 03, 2002 at 19:05 UTC
    I ripped out the looping code while debugging - I couldn't even get one record to work. And I used the $entry object to verify that my array of attributes are correct, which they were. So I'll go back to the $ldap->add() style. Maybe I'll write a tutorial when I'm done with this. :)

      Ok. Anyway, let us know when you solve it and how. That will be useful.

      Ciao!
      --bronto

      # Another Perl edition of a song:
      # The End, by The Beatles
      END {
        $you->take($love) eq $you->make($love) ;
      }