On Sep 26, 2005, at 18:53 PM, Anthony M. Martinez wrote:

Originally I was planning on $entry->clone, deleting the old one, and adding the
new one, but then I remembered modrdn. So now,

I am planning on modrdn, loop over the values doing the replace, and going
$entry->update;

Right, Given $entry fro a search the following should work. If you know a list of attributes that can hold the uid, then only request those attributes in the search.

$ldap->moddn($entry, newrdn => $newrdn);

my $dn = $entry->dn;
$dn =~ s/.../.../; # Change the DN to the new one
$entry->dn($dn);
$entry->changetype('modify');

foreach my $attr ($entry->attributes) {
  my @val = $entry->get_value($attr);
  foreach my $val (@val) {
    (my $new = $val) =~ s/.../.../ or next; # change the uid
    if (@val == 1) {
      $entry->replace($attr, $new);
    }
    else {
      $entry->delete( $attr => $val);
      $entry->add( $attr => $val );
    }
  }
}

$entry->update($ldap);

Graham.

Reply via email to