Hello All,

May I just start by saying thank heavens this the LDAP bundle exists!!!
 It holds the promise of greatly simplifying a lot of my directory
administration.  That said, I don't appear to fully understand the
Net::LDAP update() method's calling convention.

I have an LDIF file which contains many changes that need to be
performed on an LDAP server.  I have successfully created an $ldap
object for the server and have been able to bind() to the server with
no problems.  I have also created an $ldif object which opens my LDIF
in read-only mode.

Seriously, I have looked at result codes for every call up to this
point and even examined the objects returned in ptkdb and I know I'm
bound to the server and read_entry() is returning good Entry objects
from the LDIF.  So...operating on those assumptions...

The following code attempts to loop through the $ldif file, getting one
Entry at a time and performing the changes contained in that Entry
object on the $ldap server.  Here was my first stab:

while (my $entry = $ldif->read_entry())
{
   $mesg = $ldap->modify($entry);  ## THE ACTION LINE
   $mesg->code && die $mesg->error;
}

I figured, the modify() method is getting the DN from the $entry
object, so it's probably getting the changes from there, too, right?
Uhhh, I figured wrong.  It reports:

no modifications specified at ./ldap.pl line 27, <GEN1> line 2.

So I think, okay, well I'll just use the changes contained in
$entry->changes as an argument in OPTIONS.  So I substitute this for
the "action line" above:

  $mesg = $ldap->modify($entry, changes => $entry->changes);

No DN specified at ./ldap.pl line 27, <GEN1> line 2.

Oops.  That didn't work.  Looking closer at what OPTIONS expects in the
'changes =>' part, I see that it's actually expecting a hash, and
$entry->changes returns an array that's close but not quite right.  So
I try this:

while (my $entry = $ldif->read_entry())
{
   my %changes = $entry->changes;  # convert the array to a hash
   $mesg = $ldap->modify($entry, changes => \%changes);  ## THE ACTION
LINE
   $mesg->code && die $mesg->error;
}

Not an ARRAY reference at /usr/local/.../LDAP.pm line 475, <GEN1> line
2.

Okay, so I admit, I'm a little confounded at this point.  I thought
surely since the changes were all encoded in the $entry, I would be
able to leverage that either in $modify or even maybe by
$entry->update() but no luck.  Can someone help me figure this out?

I am smart enough to write a loop to look at every change and execute
it separately if I have to, but I can't help feeling that Graham's code
offers a more elegant solution.

Thank you to anyone who responds.

Reply via email to