Re: Creating an entry to add or modify values

2009-05-14 Thread Dmitry Katsubo
Hi all!

After some playing with the module I've found out, that the type of the
entity should be defined _before_ you are going to add or replace
something in it. That should be mentioned in Net::LDAP::Entry pod, I
think. So, if you do:

my $entry = Net::LDAP::Entry-new('DN');
$entry-add('givenName' = $1);
$entry-changetype('modify')-update($ldap);

It will not work (will simply do nothing). Instead one should write:

my $entry = Net::LDAP::Entry-new('DN');
$entry-changetype('modify');
$entry-add('givenName' = $1);
$entry-update($ldap);

So, if one want the entry to be OK both for adding and for replacing do
the following:

my $entry = Net::LDAP::Entry-new('DN'); # 'add' is default changetype
$entry-add('givenName' = $1); # only for addingg
$entry-changetype('modify');
$entry-replace('mail' = $2); # for adding and updating
$entry-add(...);
$entry-update($ldap);

Correct me, if I am wrong.

Thanks!

Dmitry Katsubo wrote on 11-05-2009 20:45:
 Dear Perl LDAP users!
 
 I have some difficulties while trying to update the LDAP entry. I have
 looked through the mail archive and I see that this topic is raised
 quite often.
 
 Ideally I would like to create an entry, that I would like to use either
 for adding or for updating (the choice is not known at the moment of
 creation). I see from debug output, that changetype=add, but I call
 $ldap-modify() which should override this...



Re: Creating an entry to add or modify values

2009-05-14 Thread Peter Marschall
Hi Dmitry,

On Thursday, 14. May 2009, Dmitry Katsubo wrote:
 So, if one want the entry to be OK both for adding and for replacing do
 the following:
What do you mean exactly by one entry both for adding and replacing ?
Do you want to add/replace attributes in an existing entry ?

Or do you want to create an Entry object, push it to the server and
hope it is correctly set up so that it can be added, when it does not
exist there yet, or modified if it already exists there?

If you know the DN already, why don't you do a 
search(base = $DN, scope='base', filter='(objectclass=*)')
before and try to get the entry from the server.
If there is one, you get a nice Net::LDAP::Entry object with the
changetype set to 'modify'; if there is none, you know, you need
to create one yourself (where the changetype is automatically set 
to 'add' ;-).

 my $entry = Net::LDAP::Entry-new('DN'); # 'add' is default changetype
 $entry-add('givenName' = $1); # only for addingg
 $entry-changetype('modify');
 $entry-replace('mail' = $2); # for adding and updating
 $entry-add(...);
 $entry-update($ldap);

Personally I do not consider this approach a safe one.

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