entry->changetype("modify") returns "No attributes to update at ..."

10 views
Skip to first unread message

Chris Franz

unread,
Jun 9, 2014, 6:31:55 PM6/9/14
to perl...@perl.org
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?

Thanks, Chris

Chris Ridd

unread,
Jun 11, 2014, 5:19:05 PM6/11/14
to Chris Franz, perl...@perl.org
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

Peter Marschall

unread,
Jun 14, 2014, 11:18:02 AM6/14/14
to perl...@perl.org
Hi,

On Monday, 9. June 2014 15:31:55 Chris Franz wrote:
> $cur_entry->replace('cn' => 'changedcn');
> $cur_entry->changetype(modify);
> $update_mesg = $cur_entry->update($ldap);
> $update_mesg->code && die $update_mesg->error;
>
> [...]
>
> 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.

Net::LDAP::Entry's changetype() method clears all previous changes when called
with an argument.
Solution is simple: set the changetype first.

Best
Peter

--
Peter Marschall
pe...@adpm.de

Reply all
Reply to author
Forward
0 new messages