On 7/6/06 9:25, Young, Darren <[EMAIL PROTECTED]> wrote:

> 
> How can/should I change one value in a multivalued attribue? The
> attribute I have in question is mailAlternateAddress of which there can
> be any number of them attached to a given dn. As in:
> 
> dn: uid=testacct,ou=people,o=gsb,dc=uchicago,dc=edu
> mailAlternateAddress: [EMAIL PROTECTED]
> mailAlternateAddress: [EMAIL PROTECTED]
> mailAlternateAddress: [EMAIL PROTECTED]
> 
> $ldap->modify or $ldap->replace? Or is it a delete the old and add a
> new?

You need a modify operation that deletes the old value and adds a new value.

> If I do:
> 
> replace => [ mailAlternateAddress => '[EMAIL PROTECTED]']
> 
> That'll replace all the others with that one.

Yes.

> Say I want to change the [EMAIL PROTECTED] to [EMAIL PROTECTED] in
> the above example, I could (but should I):
> 
> $entry->delete ( 'mailAlternateAddress' => [ '[EMAIL PROTECTED]' ] );
> $entry->add ( 'mailAlternateAddress' => [ '[EMAIL PROTECTED]' ] );

Yes. I don't tend to use the Net::LDAP::Entry class much myself, but I
believe that will do the right thing. You should be able to pass the single
values being deleted/added as simple scalars rather than wrapping them
inside an array. 

You will need to call $entry->update($ldap) after this.

Don't forget that you can do these exact modifications in a single protocol
exchange with the server. There's no need to do a read/mangle/modify cycle.

So something like this should also work and avoid the extra round trip:

    $ldap->modify("uid=testacct,ou=people,o=gsb,dc=uchicago,dc=edu",
        delete => { mailAternateAddress => '[EMAIL PROTECTED]' },
        add    => { mailAternateAddress => '[EMAIL PROTECTED]' });

(It would also work (and read/mangle/modify would not) in the situation
where you had permission to modify the values but not read the values.
Password attributes are often like this, though I suspect something like
mailAlternateAddress wouldn't be :-)

> Or is there a way to use the replace => an existing attribute/value pair
> with a new value method?

No, the "replace" modification type affects *all* the values of the
attribute. Delete and add is what you want.

Cheers,

Chris


Reply via email to