On 9 Jun 2014, at 23:31, Chris Franz <fr...@unicon.net> wrote:

> I imagine this is obvious to some but it isn't to me.  I wrote this simple 
> script to update 
> a single attribute of an existing 389 entry. It is shown below:
> 
> #!/usr/bin/perl
> 
> use Net::LDAP;
> use Net::LDAP::Entry;
> use Net::LDAP::LDIF;
> use Net::LDAP::Message;
> 
> $ldap = Net::LDAP->new('localhost') or die "$@";
> $bind_mesg = $ldap->bind( "cn=directory manager", password=>"secret" );
> $bind_mesg->code && die $bind_mesg->error;
> 
> $search_mesg = $ldap->search(base => "ou=People,dc=crud,dc=edu",
>                       filter => "uid=someuid");
> 
> die "error: ", $mesg->error()
>     if (($search_mesg->code()) || ($search_mesg->count !=1));
> 
> $cur_entry = $search_mesg->entry(0);
> 
> $cur_entry->replace('cn' => 'changedcn');
> $cur_entry->changetype(modify);
> $update_mesg = $cur_entry->update($ldap);
> $update_mesg->code && die $update_mesg->error;
> 
> $bind_mesg = $ldap->unbind;
> 
> When I include the "$cur_entry->changetype(modify);" line, the script returns:
> 
> No attributes to update at ./ldap-update.pl line 23, <DATA> line 751.
> 
> If I comment that out, the script works swimmingly.  I banged my head on this
> for a while.  What am I missing?

Break with the perl debugger at line 23 (which line's that?) and take a look at 
things.

The other approach is to think laterally. You don't *need* to read the previous 
entry contents to do a modify. Get the DN from $cur_entry, and then build a 
modify with that and your desired change.

Typed in Mail:

$update_mesg = $ldap->modify($cur_entry->dn(), replace => { 'cn' => 'changedcn' 
});

[replaces $cur->entry->replace('cn' => 'changedcn'); and the 2 following lines.]

The other problem that might occur is if your entry uses cn in the RDN, in 
which case you should do a moddn() instead as technically you're renaming the 
entry.

Chris

Reply via email to