selena has asked for the wisdom of the Perl Monks concerning the following question:

Anyone had this problem? I am importing text from a file, using uuidgen to create a new uuid - but when I try to do the $entry->update, the script hangs.

I tried debug=>'4' on the ldap server connection and saw some weirdness - not all the text from my entry data was showing up in the output. So I tried to add an entry with just 'objectClass' => 'top'.. and that worked! However, as soon as I try to add even 'cn', the whole thing hangs again. Printing out the entry in LDIF format using Net::LDAP::LDIF yields a working entry that can be added to the ldap server. Also, I'm able to successfully modify or add attributes to existing entries on the server. Here's a stripped down version of the script that hangs.

The input file looks like:

FowlerActivity,Fowler Activity Directors,{MD5}laksdfjjkdkd==

Script is:

use Carp; use Net::LDAP; use Net::LDAP::Entry; my $server = "ldap"; my $searchstring = "objectClass=*"; my $ldap = Net::LDAP->new($server, debug =>4); my $mesg = $ldap->bind( 'cn=admin,dc=ldap', password => 'secret'); $mesg->is_error && warn $mesg->error, "\n"; my $filename = shift; open (FILE, "$filename") || croak "can't open file $filename: $?"; my %misc = (); while (<FILE>) { chomp; my @items = split(','); my $uuid = `/usr/bin/uuidgen`; chomp $uuid; $misc{$uuid} = \@items; } foreach my $u (keys %misc) { my $fullname = $misc{$u}->[1]; my ($firstname, $lastname) = split(' ', $fullname, 2); chomp $lastname; my $dn = "cn=" . $u . ",ou=Misc,dc=ldap"; $entry = new Net::LDAP::Entry->new; $entry->dn($dn); $entry->add( 'objectClass' => "person", 'cn' => $u, 'sn' => $lastname, ); my $result = $entry->update($ldap); $result->code && warn "couldn't add $dn: ", $result->error; }

Replies are listed 'Best First'.
Re: Net::LDAP::Entry->update hangs
by mikfire (Deacon) on Mar 02, 2004 at 19:41 UTC
    Could you post the equivalent LDIF for this record? Also, have you checked the errors logs on the LDAP server to see what it thought was going on?

    Just some other, random debug thoughts. Have you tried to seperate the creation from the population of the fields -- ie,

    $entry = new Net::LDAP::Entry->new; $entry->dn($dn); $entry->update($ldap); $entry->add....

    If I can see the resultant LDIF, I may be able to offer more assistance.

      Yes - I did try what you suggested. The error I got is that no attributes are available for updating. *grr!* There was some other thing I saw in Net::LDAP::Entry about using 'newrdn' attribute and changetype('moddn').. that didn't work either. Here's what I did to create an LDIF:
      open(FILE, ">$u.ldif"); Net::LDAP::LDIF->new(\*FILE, "w")->write($entry); close FILE;
      Here's the result:
      dn: cn=6c2f995b-c1de-41ee-8b70-07f134dac04a,ou=Misc,<censored> objectclass: person objectclass: inetOrgPerson objectclass: organizationalPerson objectclass: CourierMailAccount objectclass: CourierMailAlias objectclass: posixAccount objectclass: shadowAccount sn: McRitchie cn: T McRitchie cn: 6c2f995b-c1de-41ee-8b70-07f134dac04a givenname: T mail: tmcritchie@<censored> o: Misc telephonenumber: unknown title: unknown roomnumber: unknown homedirectory: /home/tmcritchie userpassword: {MD5}<censored> uidnumber: 20003 gidnumber: 20003 maildrop: tmcritchie shadowlastchange: 99999 shadowmax: 99999 shadowwarning: 7 uid: tmcritchie gecos: tmcritchie loginshell: /bin/false quota: 50